From 92c2869db6a289e10d2b91d30e8f7a1ab6c36074 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish <62088117+mdanish98@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:16:06 +0100 Subject: [PATCH] Increases the Access Token and Refresh Token's Lifespan for tests (#591) * Improves token manager's refresh token handling Signed-off-by: Mohammad Ghazanfar Ali Danish * Adds relevant test Signed-off-by: Mohammad Ghazanfar Ali Danish * Removes unnecessary class Signed-off-by: Mohammad Ghazanfar Ali Danish * Addresses review remarks Signed-off-by: Mohammad Ghazanfar Ali Danish * Re-adjusts the review remarks Signed-off-by: Mohammad Ghazanfar Ali Danish * Refactors the code Signed-off-by: Mohammad Ghazanfar Ali Danish * Adjusts the wait time in token retrieval tests Signed-off-by: Mohammad Ghazanfar Ali Danish * Increases the Access Token and Refresh Token's Lifespan for tests Signed-off-by: Mohammad Ghazanfar Ali Danish --------- Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../basyx/client/internal/TokenManagerTest.java | 10 +++++----- ci/keycloak/realm/BaSyx-realm.json | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/basyx.common/basyx.client/src/test/java/org/eclipse/digitaltwin/basyx/client/internal/TokenManagerTest.java b/basyx.common/basyx.client/src/test/java/org/eclipse/digitaltwin/basyx/client/internal/TokenManagerTest.java index ce674202d..0951489cd 100644 --- a/basyx.common/basyx.client/src/test/java/org/eclipse/digitaltwin/basyx/client/internal/TokenManagerTest.java +++ b/basyx.common/basyx.client/src/test/java/org/eclipse/digitaltwin/basyx/client/internal/TokenManagerTest.java @@ -55,7 +55,7 @@ public void retrieveNewAccessTokenWhenExpired() throws IOException, InterruptedE String initialAccessToken = tokenManager.getAccessToken(); assertNotNull(initialAccessToken); - long tokenLifetime = 1000; + long tokenLifetime = 2000; Thread.sleep(tokenLifetime + 5); String newAccessToken = tokenManager.getAccessToken(); @@ -69,7 +69,7 @@ public void provideSameAccessTokenWhenNotExpired() throws IOException, Interrupt String initialAccessToken = tokenManager.getAccessToken(); assertNotNull(initialAccessToken); - long tokenLifetime = 350; + long tokenLifetime = 800; Thread.sleep(tokenLifetime); String newAccessToken = tokenManager.getAccessToken(); @@ -83,7 +83,7 @@ public void retrieveNewAccessTokenUsingRefreshTokenWhenAccessTokenIsExpired() th String initialAccessToken = tokenManager.getAccessToken(); assertNotNull(initialAccessToken); - long tokenLifetime = 1000; + long tokenLifetime = 2000; Thread.sleep(tokenLifetime + 15); String newAccessToken = tokenManager.getAccessToken(); @@ -97,7 +97,7 @@ public void retrieveNewAccessTokenUsingRefreshTokenWhenExpired() throws IOExcept String initialAccessToken = tokenManager.getAccessToken(); assertNotNull(initialAccessToken); - long tokenLifetime = 3000; + long tokenLifetime = 4000; Thread.sleep(tokenLifetime + 5); String newAccessToken = tokenManager.getAccessToken(); @@ -112,7 +112,7 @@ public void retrieveNewAccessTokenWhenSSOMaxReached() throws IOException, Interr String initialAccessToken = tokenManager.getAccessToken(); assertNotNull(initialAccessToken); - long timeLimit = 4000; + long timeLimit = 6000; String intermediateAccessToken = null; while (timeLimit > 0) { diff --git a/ci/keycloak/realm/BaSyx-realm.json b/ci/keycloak/realm/BaSyx-realm.json index 725b7d0af..31b2ddcff 100644 --- a/ci/keycloak/realm/BaSyx-realm.json +++ b/ci/keycloak/realm/BaSyx-realm.json @@ -1751,7 +1751,7 @@ "frontchannelLogout" : true, "protocol" : "openid-connect", "attributes" : { - "access.token.lifespan" : "1", + "access.token.lifespan" : "2", "client.secret.creation.time" : "1734780525", "post.logout.redirect.uris" : "+", "oauth2.device.authorization.grant.enabled" : "false", @@ -1764,7 +1764,7 @@ "require.pushed.authorization.requests" : "false", "acr.loa.map" : "{}", "display.on.consent.screen" : "false", - "client.session.max.lifespan" : "3", + "client.session.max.lifespan" : "4", "token.response.type.bearer.lower-case" : "false" }, "authenticationFlowBindingOverrides" : { },