dasniko / testcontainers-keycloak

A Testcontainer implementation for Keycloak IAM & SSO.
Apache License 2.0
328 stars 51 forks source link

Unable to reuse the test container between tests with the new version 2.1.1 (KC 17) #66

Closed semangard closed 2 years ago

semangard commented 2 years ago

Hello,

It seems since version 2.x test container cannot be reused between tests. The next test cannot reuse the test container which was not stopped (stop() method not called).

We have an exception indicating the test realm cannot be imported (because already/previously imported)

2022-03-14 10:32:01,910 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (executor-thread-2) Unique index or primary key violation: "PRIMARY_KEY_62 ON PUBLIC.REALM(ID) VALUES ('test', 23)"; SQL statement:
insert into REALM (ACCESS_CODE_LIFESPAN, LOGIN_LIFESPAN, USER_ACTION_LIFESPAN, ACCESS_TOKEN_LIFESPAN, ACCESS_TOKEN_LIFE_IMPLICIT, ACCOUNT_THEME, ADMIN_EVENTS_DETAILS_ENABLED, ADMIN_EVENTS_ENABLED, ADMIN_THEME, ALLOW_USER_MANAGED_ACCESS, BROWSER_FLOW, CLIENT_AUTH_FLOW, DEFAULT_LOCALE, DEFAULT_ROLE, DIRECT_GRANT_FLOW, DOCKER_AUTH_FLOW, DUPLICATE_EMAILS_ALLOWED, EDIT_USERNAME_ALLOWED, EMAIL_THEME, ENABLED, EVENTS_ENABLED, EVENTS_EXPIRATION, INTERNATIONALIZATION_ENABLED, LOGIN_THEME, LOGIN_WITH_EMAIL_ALLOWED, MASTER_ADMIN_CLIENT, NAME, NOT_BEFORE, OFFLINE_SESSION_IDLE_TIMEOUT, OTP_POLICY_ALG, OTP_POLICY_DIGITS, OTP_POLICY_COUNTER, OTP_POLICY_WINDOW, OTP_POLICY_PERIOD, OTP_POLICY_TYPE, PASSWORD_POLICY, REFRESH_TOKEN_MAX_REUSE, REGISTRATION_ALLOWED, REG_EMAIL_AS_USERNAME, REGISTRATION_FLOW, REMEMBER_ME, RESET_CREDENTIALS_FLOW, RESET_PASSWORD_ALLOWED, REVOKE_REFRESH_TOKEN, SSL_REQUIRED, SSO_IDLE_TIMEOUT, SSO_IDLE_TIMEOUT_REMEMBER_ME, SSO_MAX_LIFESPAN, SSO_MAX_LIFESPAN_REMEMBER_ME, VERIFY_EMAIL, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-197]

Could you please check that ?

Regards

dasniko commented 2 years ago

Thanks for this issue. I'll investigate into it in the next days. I know already what's going on, but I need some time to fix it.

dasniko commented 2 years ago

Most likely, I can remove my custom code to import realms on startup again when KC18 is available, as it should bring back the auto-import ability: https://github.com/keycloak/keycloak/issues/10216

dasniko commented 2 years ago

I've found a Testcontainers internal api, which might help and do the trick.

Would you mind to test a fix on the development branch with tag development-SNAPSHOT with the help of JitPack: https://jitpack.io/#dasniko/testcontainers-keycloak/development-SNAPSHOT Your feedback is appreciated! Thanks.

semangard commented 2 years ago

I've just tested it few times with your SNAPSHOT version and yes it seems to be fixed. Thanks and regards.

dasniko commented 2 years ago

merged into main