[keycloak-user] Create Test Users - IT

Marko Strukelj mstrukel at redhat.com
Thu Jan 5 17:02:17 EST 2017


See:
http://lists.jboss.org/pipermail/keycloak-user/2016-December/008885.html

On Jan 5, 2017 20:25, "Dana Danet" <Dana.Danet at evisions.com> wrote:

> There must be something I am missing as I can’t get the Credentials to set
> when programmatically creating a test user for integration tests to a
> running Keycloak 2.5.0 instance with a known realm.  The user is created.
>
> When setting a breakpoint in my code I see that my user is created but no
> credentials are created.  This returns 0 tuples.
>
> select * from credential c where c.user_id = (select u.id from
> user_entity u where u.username = 'test-user’)
>
>
> Below is my code:
>
>
> @Before
> public void setup() {
>     log.debug("Setting up test harness user.");
>
>     keycloak = KeycloakBuilder.builder()
>                               .serverUrl(authServerUrl)
>                               .realm(realm)
>                               .username(adminUser)
>                               .password(adminPassword)
>                               .clientId("admin-cli")
>                               .resteasyClient(new ResteasyClientBuilder()
>                                       .connectionPoolSize(10)
>                                       .build()
>                               ).build();
>
>     setupTestUser();
> }
>
> private void setupTestUser() {
>     log.debug("\nSetting up test harness user.");
>
>     /*
>       Create the credentials via test config values
>      */
>     CredentialRepresentation credential = new CredentialRepresentation();
>     credential.setType(CredentialRepresentation.PASSWORD);
>     credential.setValue(password);
>     credential.setTemporary(false);
>
>     /*
>       Create the user via test config values
>      */
>     user = new UserRepresentation();
>     user.setUsername(username);
>     user.setFirstName("Test");
>     user.setLastName("User");
>     user.setCredentials(Arrays.asList(credential));
>     user.setEnabled(true) ;
>
>     Response result = keycloak.realm(realm).users().create(user);
>
>     final String locationHeader = result.getHeaderString("Location");
>     final String userId = locationHeader.replaceAll(".*/(.*)$", "$1");
>     user.setId(userId);
>
>     log.debug("\n\nTest Harness UserId  ************** {}\n", userId);
> }
>
> @After
> public void tearDown() {
>     keycloak.realm(realm).users().get(user.getId()).remove();
> }
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user


More information about the keycloak-user mailing list