[keycloak-user] Add users in integration tests

Juraci Paixão Kröhling juraci at kroehling.de
Thu Jan 7 11:27:23 EST 2016


I'm doing some integration tests for Hawkular and I want to add an user 
via this integration test, but I'm having some problems in doing it via 
the test itself.

I'm using the Admin Client from org.keycloak:keycloak-admin-client , and 
it look like this:

Keycloak adminClient = KeycloakBuilder
         .builder()
         .realm("master")
         .username("admin")
         .password("admin")
         .serverUrl("${baseURI}/auth")
         .clientId(Constants.ADMIN_CLI_CLIENT_ID)
         .build();

I then create an UserRepresentation (without credentials), and call:

adminClient.realm("hawkular").users().create(userRepresentation)

I then try to reset the password (or set it in a List of 
CredentialRepresentation to the UserRepresentation above):

CredentialRepresentation pass = new CredentialRepresentation()
pass.type = "password"
pass.value = password
pass.temporary = false
adminClient.realm("hawkular").users().usersResource.get(userId).resetPassword(pass)

But this password is not set. At this stage, I'm facing two problems:

1) The first admin request fails, as the admin has a pending action 
(reset the password).

2) The user's password is never correctly set. By that I mean that I try 
to use the password via the UI, and it reports that the password is 
invalid. I then login to the admin console, reset the password (setting 
the same as I used in the tests). After this, I can correctly login.

So, my questions:

- What is the recommended approach for adding users in the context of 
integration tests?

- If Admin Client is the way to go, what's the correct way to add an 
user with a password?

- Juca.


More information about the keycloak-user mailing list