Merge pull request #3684 from mposolda/master

Fix LDAP tests with mongo
This commit is contained in:
Marek Posolda 2016-12-21 10:10:09 +01:00 committed by GitHub
commit 3e8d4e4eb6
2 changed files with 23 additions and 9 deletions

View file

@ -41,7 +41,9 @@ import org.keycloak.models.Constants;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LDAPConstants;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider;
import org.keycloak.models.UserModel;
import org.keycloak.models.mongo.keycloak.adapters.MongoRealmProviderFactory;
import org.keycloak.models.utils.UserModelDelegate;
import org.keycloak.representations.idm.ComponentRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
@ -201,7 +203,15 @@ public class LDAPBinaryAttributesTest {
try {
joe.getAttributes().put("someOtherPhoto", Arrays.asList(JPEG_PHOTO_BASE64));
adminClient.realm("test").users().get(joe.getId()).update(joe);
Assert.fail("Not expected to successfully update user");
// TODO: Workaround as on Mongo it is not limit for length of attribute. Should be removed/improved...
KeycloakSession session = keycloakRule.startSession();
String realmProviderId = session.getKeycloakSessionFactory().getProviderFactory(RealmProvider.class).getId();
keycloakRule.stopSession(session, false);
if (!realmProviderId.equals("mongo")) {
Assert.fail("Not expected to successfully update user");
}
} catch (ClientErrorException cee) {
// Expected
}

View file

@ -124,18 +124,22 @@ public class LDAPSpecialCharsTest {
@Test
public void test01_userSearch() {
List<UserRepresentation> users = adminClient.realm("test").users().search("j*", 0, 10);
Assert.assertEquals(3, users.size());
List<String> usernames = users.stream().map((UserRepresentation user) -> {
assertContainsUsername(users, "jamees,key*cložak)ppp");
assertContainsUsername(users, "jameskeycloak");
assertContainsUsername(users, "johnkeycloak");
}
return user.getUsername();
private void assertContainsUsername(List<UserRepresentation> users, String username) {
boolean found = users.stream().filter((UserRepresentation user) -> {
}).collect(Collectors.toList());
Collections.sort(usernames);
return username.equals(user.getUsername());
Assert.assertEquals("jamees,key*cložak)ppp", usernames.get(0));
Assert.assertEquals("jameskeycloak", usernames.get(1));
Assert.assertEquals("johnkeycloak", usernames.get(2));
}).findFirst().isPresent();
if (!found) {
Assert.fail("Username " + username + " not found in the list");
}
}