}
@Test
public void testPerDbFileCannotContainUsersOrDatabases() throws Exception {
PolicyEngine policy;
ImmutableSet<String> permissions;
PolicyFile policyFile;
// test sanity
policyFile = PolicyFile.setAdminOnServer1("admin");
policyFile.addGroupsToUser("admin1", "admin");
policyFile.write(globalPolicyFile);
policyFile.write(otherPolicyFile);
policy = new DBPolicyFileBackend("server1", globalPolicyFile.getPath());
permissions = policy.getAllPrivileges(Sets.newHashSet("admin"), ActiveRoleSet.ALL);
Assert.assertEquals(permissions.toString(), "[server=server1]");
// test to ensure [users] fails parsing of per-db file
policyFile.addDatabase("other", otherPolicyFile.getPath());
policyFile.write(globalPolicyFile);
policyFile.write(otherPolicyFile);
policy = new DBPolicyFileBackend("server1", globalPolicyFile.getPath());
permissions = policy.getAllPrivileges(Sets.newHashSet("admin"), ActiveRoleSet.ALL);
Assert.assertEquals(permissions.toString(), "[server=server1]");
// test to ensure [databases] fails parsing of per-db file
// by removing the user mapping from the per-db policy file
policyFile.removeGroupsFromUser("admin1", "admin")
.write(otherPolicyFile);
policy = new DBPolicyFileBackend("server1", globalPolicyFile.getPath());
permissions = policy.getAllPrivileges(Sets.newHashSet("admin"), ActiveRoleSet.ALL);
Assert.assertEquals(permissions.toString(), "[server=server1]");
}