public virtual void testRevokeAuthPermissions() { AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_REVOKE); authorization.setResource(Resources.DEPLOYMENT); assertFalse(authorization.isPermissionRevoked(ALL)); IList <Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values())); assertEquals(0, perms.Count); authorization.removePermission(READ); perms = Arrays.asList(authorization.getPermissions(Permissions.values())); assertTrue(perms.Contains(READ)); assertTrue(perms.Contains(ALL)); assertEquals(2, perms.Count); try { authorization.isPermissionGranted(READ); fail("Exception expected"); } catch (System.InvalidOperationException e) { assertTextPresent("ENGINE-03026 Method 'isPermissionGranted' cannot be used for authorization with type 'REVOKE'.", e.Message); } }
public virtual void testGlobalAuthPermissions() { AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_GRANT); authorization.setResource(Resources.DEPLOYMENT); assertFalse(authorization.isPermissionGranted(ALL)); assertTrue(authorization.isPermissionGranted(NONE)); IList <Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values())); assertTrue(perms.Contains(NONE)); assertEquals(1, perms.Count); authorization.addPermission(READ); perms = Arrays.asList(authorization.getPermissions(Permissions.values())); assertTrue(perms.Contains(NONE)); assertTrue(perms.Contains(READ)); assertEquals(2, perms.Count); assertTrue(authorization.isPermissionGranted(READ)); assertTrue(authorization.isPermissionGranted(NONE)); // (none is always granted => you are always authorized to do nothing) try { authorization.isPermissionRevoked(READ); fail("Exception expected"); } catch (System.InvalidOperationException e) { assertTextPresent("ENGINE-03026 Method 'isPermissionRevoked' cannot be used for authorization with type 'GRANT'.", e.Message); } }