Example #1
0
        public void Allows_DefinedItemRoles(Permission allowedPermission)
        {
            var map = new DynamicPermissionMap { Permissions = Permission.ReadWrite };
            DynamicPermissionMap.SetRoles(item, Permission.ReadWrite, "rolename");

            bool isAuthorized = map.Authorizes(user, item, allowedPermission);

            Assert.That(isAuthorized, Is.True);
        }
Example #2
0
        public void Admin_IsAuthorized_ForWrite_WhileItemDisallowsRead()
        {
            var map = new DynamicPermissionMap(Permission.Full, new[] { "Administrators" }, new[] { "admin" });

            var item = new SecurityPage();
            DynamicPermissionMap.SetRoles(item, Permission.Read, new[] {"Administrators"});
            IPrincipal adminUser = CreatePrincipal("admin");

            bool isAuthorized = map.Authorizes(adminUser, item, Permission.Write);

            Assert.That(isAuthorized, Is.True);
        }
 /// <summary>Copies permissions from the source to the destination.</summary>
 /// <param name="source">The item whose permissions to carry over.</param>
 /// <param name="destination">The item whose permissions will be modified.</param>
 public void CopyPermissions(ContentItem source, ContentItem destination)
 {
     foreach (Permission p in permissions)
     {
         var roles = DynamicPermissionMap.GetRoles(source, p);
         if (roles == null)
         {
             continue;
         }
         DynamicPermissionMap.SetRoles(destination, p, roles.ToArray());
     }
 }
Example #4
0
        public void UsesMappedPermission_WhenItemCollection_IsNull(Permission permission, bool expectedResult)
        {
            var map = new DynamicPermissionMap { Permissions = Permission.ReadWrite, Roles = new[] { "rolename" } };

            Assert.That(map.Authorizes(user, item, permission), Is.EqualTo(expectedResult));
        }
Example #5
0
        public void SettingPermissions_AddsDetailCollection()
        {
            var map = new DynamicPermissionMap();
            DynamicPermissionMap.SetRoles(item, Permission.Write, "rolename");

            Assert.That(item.GetDetailCollection(DynamicPermissionMap.AuthorizedRolesPrefix + Permission.Write, false), Is.Not.Null);
        }
Example #6
0
        public void ResettingPermissions_RestoresAlteredPermissions()
        {
            var map = new DynamicPermissionMap();
            DynamicPermissionMap.SetRoles(item, Permission.Read, "rolename");
            DynamicPermissionMap.SetRoles(item, Permission.Read);

            Assert.That(item.AlteredPermissions, Is.EqualTo(Permission.None));
        }
Example #7
0
        public void IsAllRoles_RevertsTo_UserPermissions()
        {
            var map = new DynamicPermissionMap {Permissions = Permission.ReadWrite, Roles = new[] {"Writers"}};
            user = CreatePrincipal("joe writer", "Writers");

            bool isAuthorizedForPublish = map.Authorizes(user, item, Permission.Publish);

            Assert.That(isAuthorizedForPublish, Is.False);
        }
Example #8
0
        public void Ignores_UnmappedRoles()
        {
            var map = new DynamicPermissionMap { Permissions = Permission.ReadWrite, Roles = new[] { "rolename" } };

            var isAuthorized = map.Authorizes(user, item, Permission.Publish);

            Assert.That(isAuthorized, Is.False);
        }
Example #9
0
        public void DoesntMap_BeyondMapped_ReadWritePublishPermissios(Permission expectedPermission)
        {
            var map = new DynamicPermissionMap { Permissions = Permission.ReadWritePublish };

            Assert.That(map.MapsTo(expectedPermission), Is.False);
            Assert.That(map.Authorizes(null, null, expectedPermission), Is.False);
        }
Example #10
0
        public void Denies_NonDefinedItemRoles(Permission deniedPermission)
        {
            var map = new DynamicPermissionMap { Permissions = Permission.ReadWrite };
            DynamicPermissionMap.SetRoles(item, Permission.ReadWrite, "somerolename");

            bool isAuthorized = map.Authorizes(user, item, deniedPermission);

            Assert.That(isAuthorized, Is.False, deniedPermission + " is allowed which it shouldn't have been.");
        }
Example #11
0
        public void ChangingPermissions_ModifiesAlteredPermissions(Permission permission)
        {
            var map = new DynamicPermissionMap();
            DynamicPermissionMap.SetRoles(item, permission, "rolename");

            Assert.That(item.AlteredPermissions & permission, Is.EqualTo(permission));
        }