protected void assertCreateUserFromLdap(Fixture fixture, Map<String, List<String>> users) { LdapImpl ldap = fixture.ldap; for (String user : users.keySet()) { String dn = null; try { dn = ldap.findDN(user); } catch (ApiUsageException aue) { throw aue; } assertNotNull(dn); assertEquals( fixture.ignoreCaseLookup ? user.toLowerCase() : user, ldap.findExperimenter(user).getOmeName()); fixture.createUserWithGroup(this, dn, users.get(user).get(0)); assertNotNull(fixture.createUser(user)); try { fixture.createUser("nonExistingUserShouldNotBeCreated"); } catch (ApiUsageException aue) { // Expected continue; } fail("This user shouldn't have been created!"); } }
protected void assertFails(Fixture fixture, Map<String, List<String>> users) { LdapImpl ldap = fixture.ldap; for (String user : users.keySet()) { assertEquals(1, users.get(user).size()); try { String dn = ldap.findDN(user); assertNotNull(dn); fixture.createUserWithGroup(this, dn, users.get(user).get(0)); assertNotNull(fixture.createUser(user, "password", true)); fixture.login(user, users.get(user).get(0), "password"); // Parsing afterwards to force an explosion to reproduce #2557 assertEquals(user, ldap.findExperimenter(user).getOmeName()); fail("user didn't fail"); } catch (ValidationException e) { if (e.getMessage().equals("No group found for: cn=user,ou=attributeFilter")) { // Good. This is the expected result for #8357 } else { throw e; // This means that we couldn't insert. // See the thread on case-sensitivity in #2557 } } catch (ApiUsageException e) { // If not a ValidationException, but otherwise an // ApiUsageException, then this will be the // "Cannot find unique DN" which we are looking for. } catch (SecurityViolation sv) { // e.g. User 466 is not a member of group 54 and cannot login // Also good. } } }
protected void assertPasses(Fixture fixture, Map<String, List<String>> users) throws Exception { LdapImpl ldap = fixture.ldap; for (String user : users.keySet()) { String dn = null; assertTrue(1 <= users.get(user).size()); try { dn = ldap.findDN(user); } catch (ApiUsageException aue) { // This will be one of the major errors: when we can't find a // user that we expect to find. Adding a try/catch block for // debugging purposes. throw aue; } assertNotNull(dn); assertEquals( fixture.ignoreCaseLookup ? user.toLowerCase() : user, ldap.findExperimenter(user).getOmeName()); fixture.createUserWithGroup(this, dn, users.get(user).get(0)); assertNotNull(fixture.createUser(user, "password", true)); fixture.login( fixture.ignoreCaseLookup ? user.toLowerCase() : user, users.get(user).get(0), "password"); } }