[keycloak-user] Add users in integration tests

Stian Thorgersen sthorger at redhat.com
Fri Jan 8 10:28:02 EST 2016


Just added a testcase for this and it works fine. Did you set enabled to
true in UserRepresentation?

On 8 January 2016 at 14:08, Stian Thorgersen <sthorger at redhat.com> wrote:

>
>
> On 7 January 2016 at 17:27, Juraci Paixão Kröhling <juraci at kroehling.de>
> wrote:
>
>> 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?
>>
>
> If you want to add users while the server is running then the admin client
> is the way to go. Looks like there may be an issue with password reset
> though, so you can create an issue for it.
>
> In 1.7 the admin password can be set for a server with the add-user script
> so will no longer have the issue of having to reset admin password first.
>
>
>>
>> - Juca.
>> _______________________________________________
>> keycloak-user mailing list
>> keycloak-user at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/keycloak-user
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160108/788395b0/attachment.html 


More information about the keycloak-user mailing list