示例#1
0
        public void Should_Return_AccessLevel_NoPermissions()
        {
            RunActionInTransaction(session =>
            {
                var accessRules = new List <AccessRule>(new[] {
                    new AccessRule {
                        Identity = "RoleA", AccessLevel = AccessLevel.Deny, IsForRole = true
                    },
                    new AccessRule {
                        Identity = "RoleB", AccessLevel = AccessLevel.Read, IsForRole = true
                    }
                });

                var mediaFile = TestDataProvider.CreateNewMediaFile();
                accessRules.ForEach(mediaFile.AddRule);

                session.SaveOrUpdate(mediaFile);
                session.Flush();
                session.Clear();

                var service = CreateAccessControlService();

                var principal   = new GenericPrincipal(new GenericIdentity("John Doe"), new string[] { });
                var accessLevel = service.GetAccessLevel(mediaFile, principal);

                Assert.AreEqual(AccessLevel.Deny, accessLevel);
            });
        }
        private MediaFile CreateFakeFile(ISession session)
        {
            var file = TestDataProvider.CreateNewMediaFile();

            session.SaveOrUpdate(file);
            session.Flush();
            session.Clear();

            return(file);
        }
示例#3
0
        public void Should_Get_File_Access_Control()
        {
            RunActionInTransaction(session =>
            {
                var accessRule = TestDataProvider.CreateNewAccessRule();
                var file       = TestDataProvider.CreateNewMediaFile();
                file.AddRule(accessRule);

                session.SaveOrUpdate(file);
                session.Flush();

                var accessControlService = CreateAccessControlService();

                var level = accessControlService.GetAccessLevel(file, new GenericPrincipal(new GenericIdentity(accessRule.Identity), null));

                Assert.AreEqual(accessRule.AccessLevel, level);
            });
        }
示例#4
0
        public void Should_Return_AccessLevel_Read_For_Anonymous_User()
        {
            RunActionInTransaction(session =>
            {
                var accessRules = new List <AccessRule>(new[] {
                    new AccessRule {
                        Identity = "Everyone", AccessLevel = AccessLevel.Read, IsForRole = true
                    },
                    new AccessRule {
                        Identity = "RoleA", AccessLevel = AccessLevel.Deny, IsForRole = true
                    },
                    new AccessRule {
                        Identity = "John Doe", AccessLevel = AccessLevel.ReadWrite, IsForRole = false
                    },
                    new AccessRule {
                        Identity = "Admin", AccessLevel = AccessLevel.Read, IsForRole = true
                    },
                    new AccessRule {
                        Identity = "RoleB", AccessLevel = AccessLevel.Read, IsForRole = true
                    }
                });

                var mediaFile = TestDataProvider.CreateNewMediaFile();
                accessRules.ForEach(mediaFile.AddRule);

                session.SaveOrUpdate(mediaFile);
                session.Flush();
                session.Clear();

                var service = CreateAccessControlService();

                var identity = new GenericIdentity("");

                // Make sure identity is not authenticated:
                Assert.IsFalse(identity.IsAuthenticated);

                var principal = new GenericPrincipal(identity, new string[] { });

                var accessLevel = service.GetAccessLevel(mediaFile, principal);

                Assert.AreEqual(AccessLevel.Read, accessLevel);
            });
        }
示例#5
0
        public void Should_Insert_And_Retrieve_MediaFolder_Files_Successfully()
        {
            var mediaFolder = TestDataProvider.CreateNewMediaFolder();

            var files = new []
            {
                TestDataProvider.CreateNewMediaFile(mediaFolder),
                TestDataProvider.CreateNewMediaImage(mediaFolder),
                TestDataProvider.CreateNewMediaImage(mediaFolder)
            };

            mediaFolder.Medias = files;

            SaveEntityAndRunAssertionsInTransaction(
                mediaFolder,
                result =>
            {
                Assert.AreEqual(mediaFolder, result);
                Assert.AreEqual(files.OrderBy(f => f.Id), result.Medias.OrderBy(f => f.Id));
            });
        }
示例#6
0
        public void Should_Return_ReadWrite_If_There_Are_No_UserAccess()
        {
            RunActionInTransaction(session =>
            {
                var mediaFile = TestDataProvider.CreateNewMediaFile();

                session.SaveOrUpdate(mediaFile);
                session.Flush();
                session.Clear();

                var service = CreateAccessControlService();

                var identity = new GenericIdentity("");

                // Make sure identity is not authenticated:
                Assert.IsFalse(identity.IsAuthenticated);

                var principal = new GenericPrincipal(new GenericIdentity("Any Authenticated User"), new string[] { });

                var accessLevel = service.GetAccessLevel(mediaFile, principal);

                Assert.AreEqual(AccessLevel.ReadWrite, accessLevel);
            });
        }
示例#7
0
        public void Should_Insert_And_Retrieve_MediaFile_Successfully()
        {
            var entity = TestDataProvider.CreateNewMediaFile();

            RunEntityMapTestsInTransaction(entity);
        }
示例#8
0
        public void Should_Swap_Original_And_Reuploaded_Entities_Correctly()
        {
            var original   = TestDataProvider.CreateNewMediaFile();
            var newVersion = TestDataProvider.CreateNewMediaFile();

            var origTitle       = original.Title;
            var newVersionTitle = newVersion.Title;

            var cat11 = TestDataProvider.CreateNewCategory(new CategoryTree());
            var cat12 = TestDataProvider.CreateNewCategory(new CategoryTree());
            var cat21 = TestDataProvider.CreateNewCategory(new CategoryTree());

            var mcCat11 = new MediaCategory {
                Category = cat11, Media = original
            };
            var mcCat12 = new MediaCategory {
                Category = cat12, Media = original
            };
            var mcCat21 = new MediaCategory {
                Category = cat21, Media = newVersion
            };

            var tag11 = TestDataProvider.CreateNewTag();
            var tag12 = TestDataProvider.CreateNewTag();
            var tag21 = TestDataProvider.CreateNewTag();

            var mtTag11 = new MediaTag {
                Tag = tag11, Media = newVersion
            };
            var mtTag12 = new MediaTag {
                Tag = tag12, Media = newVersion
            };
            var mtTag21 = new MediaTag {
                Tag = tag21, Media = original
            };

            original.Categories   = new List <MediaCategory>();
            newVersion.Categories = new List <MediaCategory>();
            original.MediaTags    = new List <MediaTag>();
            newVersion.MediaTags  = new List <MediaTag>();

            original.Categories.Add(mcCat11);
            original.Categories.Add(mcCat12);
            newVersion.Categories.Add(mcCat21);

            newVersion.MediaTags.Add(mtTag11);
            newVersion.MediaTags.Add(mtTag12);
            original.MediaTags.Add(mtTag21);

            var service = GetMediaFileService(false);

            service.SwapOriginalMediaWithVersion(original, newVersion);

            // Ensure etity properies are switched
            Assert.AreNotEqual(original.Title, newVersion.Title);
            Assert.AreEqual(origTitle, newVersion.Title);
            Assert.AreEqual(newVersionTitle, original.Title);

            // Ensure original entity is set correctly
            Assert.AreEqual(newVersion.Original, original);

            // Ensure categories are switched correctly
            Assert.AreEqual(original.Categories.Count, 1);
            Assert.AreEqual(newVersion.Categories.Count, 2);

            Assert.IsTrue(newVersion.Categories.Contains(mcCat11));
            Assert.IsTrue(newVersion.Categories.Contains(mcCat12));
            Assert.IsTrue(original.Categories.Contains(mcCat21));

            // Ensure tags are switched correctly
            Assert.AreEqual(original.MediaTags.Count, 2);
            Assert.AreEqual(newVersion.MediaTags.Count, 1);

            Assert.IsTrue(original.MediaTags.Contains(mtTag11));
            Assert.IsTrue(original.MediaTags.Contains(mtTag12));
            Assert.IsTrue(newVersion.MediaTags.Contains(mtTag21));
        }
        private Media[] CreateFakeMedias(ISession session, bool fakeRoot = true)
        {
            // Files and folders structure:
            // Images1
            //      Images1_1
            //          Images1_1_1
            //          Images1_1_2
            //          FILE:Image1_1__1
            //      Images1_2
            //      FILE:Image1__1
            //      FILE:Image1__2
            // Images2
            //      Images2_1
            // Files1
            //      Files1_1
            //      FILE:File1_1
            // FILE:RootImage1
            // FILE:RootImage2
            // FILE:RootImage3
            // FILE:RootFile1

            MediaFolder rootFolder = null;

            if (fakeRoot)
            {
                rootFolder        = TestDataProvider.CreateNewMediaFolder(false);
                rootFolder.Folder = null;
                rootFolder.Title  = string.Concat("TestFolder_", Guid.NewGuid().ToString());
            }

            var images1     = TestDataProvider.CreateNewMediaFolder(false);
            var images2     = TestDataProvider.CreateNewMediaFolder(false);
            var images1_1   = TestDataProvider.CreateNewMediaFolder(false);
            var images1_2   = TestDataProvider.CreateNewMediaFolder(false);
            var images2_1   = TestDataProvider.CreateNewMediaFolder(false);
            var images1_1_1 = TestDataProvider.CreateNewMediaFolder(false);
            var images1_1_2 = TestDataProvider.CreateNewMediaFolder(false);

            var files1   = TestDataProvider.CreateNewMediaFolder(false, MediaType.File);
            var files1_1 = TestDataProvider.CreateNewMediaFolder(false, MediaType.File);

            images1.Folder     = rootFolder;
            images2.Folder     = rootFolder;
            images1_1.Folder   = images1;
            images1_2.Folder   = images1;
            images2_1.Folder   = images2;
            images1_1_1.Folder = images1_1;
            images1_1_2.Folder = images1_1;
            files1.Folder      = rootFolder;
            files1_1.Folder    = files1;

            images1.Title     = "Images1";
            images2.Title     = "Images2";
            images1_1.Title   = "Images1_1";
            images1_2.Title   = "Images1_2";
            images2_1.Title   = "Images2_1";
            images1_1_1.Title = "Images1_1_1";
            images1_1_2.Title = "Images1_1_2";
            files1.Title      = "Files1";
            files1_1.Title    = "Files1_1";

            var rootImage1  = TestDataProvider.CreateNewMediaImage();
            var rootImage2  = TestDataProvider.CreateNewMediaImage();
            var rootImage3  = TestDataProvider.CreateNewMediaImage();
            var image1__1   = TestDataProvider.CreateNewMediaImage(images1);
            var image1__2   = TestDataProvider.CreateNewMediaImage(images1);
            var image1_1__1 = TestDataProvider.CreateNewMediaImage(images1_1);
            var rootFile1   = TestDataProvider.CreateNewMediaFile();
            var file1_1     = TestDataProvider.CreateNewMediaFile(files1);

            rootImage1.Folder = rootFolder;
            rootImage2.Folder = rootFolder;
            rootImage3.Folder = rootFolder;
            rootFile1.Folder  = rootFolder;

            rootImage1.Title  = "RootImage1";
            rootImage2.Title  = "RootImage2";
            rootImage3.Title  = "RootImage3";
            image1__1.Title   = "Image1__1";
            image1__2.Title   = "Image1__2";
            image1_1__1.Title = "Image1_1__1";
            rootFile1.Title   = "RootFile1";
            file1_1.Title     = "File1_1";

            var medias = new Media[] {
                // Image folders
                images1,
                images2,
                images1_1,
                images1_2,
                images2_1,
                images1_1_1,
                images1_1_2,

                // File folders
                files1,
                files1_1,

                // Images
                rootImage1,
                rootImage2,
                rootImage3,
                image1__1,
                image1__2,
                image1_1__1,

                // Files
                rootFile1,
                file1_1
            };

            if (!fakeRoot)
            {
                var suffix = Guid.NewGuid().ToString();
                medias.ToList().ForEach(m => m.Title = string.Concat(m.Title, "_", suffix));
            }
            medias.ToList().ForEach(m => session.SaveOrUpdate(m));
            session.Flush();
            session.Clear();

            return(medias);
        }