From 60fd7e63d947461ac7a67445f66103761505f82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Barto=C5=A1?= Date: Tue, 18 Apr 2023 13:24:51 +0200 Subject: [PATCH] Fix OfflineServletsAdapterTest --- .../servlet/OfflineServletsAdapterTest.java | 18 +++++++++++------- .../offline-client/WEB-INF/keycloak.json | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/OfflineServletsAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/OfflineServletsAdapterTest.java index e7ae7f477c..16f655b0c5 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/OfflineServletsAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/OfflineServletsAdapterTest.java @@ -13,6 +13,7 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.keycloak.OAuth2Constants; +import org.keycloak.representations.RefreshToken; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.adapter.AbstractServletsAdapterTest; @@ -91,7 +92,8 @@ public class OfflineServletsAdapterTest extends AbstractServletsAdapterTest { @Override protected boolean isImportAfterEachMethod() { - return false; + // For proper cleanup of test methods + return true; } @Test @@ -111,12 +113,13 @@ public class OfflineServletsAdapterTest extends AbstractServletsAdapterTest { assertCurrentUrlStartsWith(offlineTokenPage); - assertThat(offlineTokenPage.getRefreshToken(), notNullValue()); - assertThat(TokenUtil.TOKEN_TYPE_OFFLINE, is(offlineTokenPage.getRefreshToken().getType())); - assertThat(offlineTokenPage.getRefreshToken().getExp(), nullValue()); + RefreshToken refreshToken = offlineTokenPage.getRefreshToken(); + assertThat(refreshToken, notNullValue()); + assertThat(TokenUtil.TOKEN_TYPE_OFFLINE, is(refreshToken.getType())); + assertThat(refreshToken.getExp(), nullValue()); String accessTokenId = offlineTokenPage.getAccessToken().getId(); - String refreshTokenId = offlineTokenPage.getRefreshToken().getId(); + String refreshTokenId = refreshToken.getId(); // online user session will be expired and removed setAdapterAndServerTimeOffset(9999); @@ -166,8 +169,9 @@ public class OfflineServletsAdapterTest extends AbstractServletsAdapterTest { loginPage.login(DEFAULT_USERNAME, DEFAULT_PASSWORD); assertCurrentUrlStartsWith(offlineTokenPage); - assertThat(offlineTokenPage.getRefreshToken(), notNullValue()); - assertThat(offlineTokenPage.getRefreshToken().getType(), is(TokenUtil.TOKEN_TYPE_OFFLINE)); + final RefreshToken refreshToken = offlineTokenPage.getRefreshToken(); + assertThat(refreshToken, notNullValue()); + assertThat(refreshToken.getType(), is(TokenUtil.TOKEN_TYPE_OFFLINE)); // Assert refresh works with increased time setAdapterAndServerTimeOffset(9999); diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/offline-client/WEB-INF/keycloak.json b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/offline-client/WEB-INF/keycloak.json index 335f969db0..80f66e0877 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/offline-client/WEB-INF/keycloak.json +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/offline-client/WEB-INF/keycloak.json @@ -5,5 +5,6 @@ "ssl-required" : "external", "credentials": { "secret": "secret1" - } + }, + "min-time-between-jwks-requests": 1 }