Exemplo n.º 1
0
        public virtual void testRevokeAuthPermissions()
        {
            AuthorizationEntity authorization = new AuthorizationEntity(AuthorizationFields.AuthTypeRevoke);

            Assert.IsFalse(authorization.IsPermissionRevoked(Permissions.All));
            IList <Permissions> perms = (authorization.GetPermissions(new Permissions[] { }));

            Assert.AreEqual(0, perms.Count);

            authorization.RemovePermission(Permissions.Read);
            perms = (authorization.GetPermissions(new Permissions[] { }));
            Assert.True(perms.Contains(Permissions.Read));
            Assert.True(perms.Contains(Permissions.All));
            Assert.AreEqual(2, perms.Count);

            try
            {
                authorization.IsPermissionGranted(Permissions.Read);
                Assert.Fail("Exception expected");
            }
            catch (System.InvalidOperationException e)
            {
                AssertTextPresent("ENGINE-03026 Method 'isPermissionGranted' cannot be used for authorization with type 'REVOKE'.", e.Message);
            }
        }
Exemplo n.º 2
0
        public virtual void testGlobalAuthPermissions()
        {
            AuthorizationEntity authorization = new AuthorizationEntity(AuthorizationFields.AuthTypeGrant);

            Assert.IsFalse(authorization.IsPermissionGranted(Permissions.All));
            Assert.True(authorization.IsPermissionGranted(Permissions.None));
            IList <Permissions> perms = (authorization.GetPermissions(new Permissions[] { }));

            Assert.True(perms.Contains(Permissions.None));
            Assert.AreEqual(1, perms.Count);

            authorization.AddPermission(Permissions.Read);
            perms = (authorization.GetPermissions(new Permissions[] { }));
            Assert.True(perms.Contains(Permissions.None));
            Assert.True(perms.Contains(Permissions.Read));
            Assert.AreEqual(2, perms.Count);
            Assert.True(authorization.IsPermissionGranted(Permissions.Read));
            Assert.True(authorization.IsPermissionGranted(Permissions.None));     // (none is always granted => you are always authorized to do nothing)

            try
            {
                authorization.IsPermissionRevoked(Permissions.Read);
                Assert.Fail("Exception expected");
            }
            catch (System.InvalidOperationException e)
            {
                AssertTextPresent("ENGINE-03026 Method 'isPermissionRevoked' cannot be used for authorization with type 'GRANT'.", e.Message);
            }
        }