From 5148d3789f9c10da6d5b84361b1e036d384d8c65 Mon Sep 17 00:00:00 2001 From: Shenali Date: Mon, 2 Sep 2024 23:20:44 +0530 Subject: [PATCH] Update test case for expires_in claim modification --- ...IssueAccessTokenPasswordGrantTestCase.java | 10 +- .../integration/test/mocks/MockServer.java | 173 +++++++++--------- 2 files changed, 95 insertions(+), 88 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java index 2f6cbce0011..c1cd53f0995 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java @@ -52,6 +52,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -229,10 +230,11 @@ public void testTokenStringArrayClaimAddOperation() @Test(groups = "wso2.is", description = "Verify the replacement of the 'expires_in' claim in the access token") public void testTokenExpiresInClaimReplaceOperation() throws Exception { - if (jwtClaims.getClaim("expires_in") != null) { - Object expValue = jwtClaims.getLongClaim("expires_in"); - Assert.assertEquals(expValue, 7200); - } + Date exp = jwtClaims.getDateClaim("exp"); + Date iat = jwtClaims.getDateClaim("iat"); + long expiresIn = (exp.getTime() - iat.getTime()) / 1000; + + Assert.assertEquals(expiresIn, 7200); } /** diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/mocks/MockServer.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/mocks/MockServer.java index 74fbbaf6e11..bf51d80cc9d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/mocks/MockServer.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/mocks/MockServer.java @@ -35,92 +35,97 @@ public static void createMockServer(String mockEndpoint) throws Exception { String jsonResponse = "{\n" + " \"actionStatus\": \"SUCCESS\",\n" + " \"operations\": [\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/scopes/-\",\n" + - " \"value\": \"new_test_custom_scope_1\"\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/scopes/-\",\n" + - " \"value\": \"new_test_custom_scope_2\"\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/scopes/-\",\n" + - " \"value\": \"new_test_custom_scope_3\"\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/claims/aud/-\",\n" + - " \"value\": \"zzz1.com\"\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/claims/aud/-\",\n" + - " \"value\": \"zzz2.com\"\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/claims/aud/-\",\n" + - " \"value\": \"zzz3.com\"\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/claims/-\",\n" + - " \"value\": {\n" + - " \"name\": \"custom_claim_string_1\",\n" + - " \"value\": \"testCustomClaim1\"\n" + - " }\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/claims/-\",\n" + - " \"value\": {\n" + - " \"name\": \"custom_claim_number_1\",\n" + - " \"value\": 78\n" + - " }\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/claims/-\",\n" + - " \"value\": {\n" + - " \"name\": \"custom_claim_boolean_1\",\n" + - " \"value\": true\n" + - " }\n" + - " },\n" + - " {\n" + - " \"op\": \"add\",\n" + - " \"path\": \"/accessToken/claims/-\",\n" + - " \"value\": {\n" + - " \"name\": \"custom_claim_string_array_1\",\n" + - " \"value\": [\n" + - " \"TestCustomClaim1\",\n" + - " \"TestCustomClaim2\",\n" + - " \"TestCustomClaim3\"\n" + - " ]\n" + - " }\n" + - " },\n" + - " {\n" + - " \"op\": \"replace\",\n" + - " \"path\": \"/accessToken/scopes/7\",\n" + - " \"value\": \"replaced_scope\"\n" + - " },\n" + - " {\n" + - " \"op\": \"replace\",\n" + - " \"path\": \"/accessToken/claims/aud/-\",\n" + - " \"value\": \"zzzR.com\"\n" + - " },\n" + - " {\n" + - " \"op\": \"remove\",\n" + - " \"path\": \"/accessToken/scopes/6\"\n" + - " },\n" + - " {\n" + - " \"op\": \"remove\",\n" + - " \"path\": \"/accessToken/claims/aud/-\"\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/scopes/-\",\n" + + " \"value\": \"new_test_custom_scope_1\"\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/scopes/-\",\n" + + " \"value\": \"new_test_custom_scope_2\"\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/scopes/-\",\n" + + " \"value\": \"new_test_custom_scope_3\"\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/claims/aud/-\",\n" + + " \"value\": \"zzz1.com\"\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/claims/aud/-\",\n" + + " \"value\": \"zzz2.com\"\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/claims/aud/-\",\n" + + " \"value\": \"zzz3.com\"\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/claims/-\",\n" + + " \"value\": {\n" + + " \"name\": \"custom_claim_string_1\",\n" + + " \"value\": \"testCustomClaim1\"\n" + " }\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/claims/-\",\n" + + " \"value\": {\n" + + " \"name\": \"custom_claim_number_1\",\n" + + " \"value\": 78\n" + + " }\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/claims/-\",\n" + + " \"value\": {\n" + + " \"name\": \"custom_claim_boolean_1\",\n" + + " \"value\": true\n" + + " }\n" + + " },\n" + + " {\n" + + " \"op\": \"add\",\n" + + " \"path\": \"/accessToken/claims/-\",\n" + + " \"value\": {\n" + + " \"name\": \"custom_claim_string_array_1\",\n" + + " \"value\": [\n" + + " \"TestCustomClaim1\",\n" + + " \"TestCustomClaim2\",\n" + + " \"TestCustomClaim3\"\n" + + " ]\n" + + " }\n" + + " },\n" + + " {\n" + + " \"op\": \"replace\",\n" + + " \"path\": \"/accessToken/scopes/7\",\n" + + " \"value\": \"replaced_scope\"\n" + + " },\n" + + " {\n" + + " \"op\": \"replace\",\n" + + " \"path\": \"/accessToken/claims/aud/-\",\n" + + " \"value\": \"zzzR.com\"\n" + + " },\n" + + " {\n" + + " \"op\": \"replace\",\n" + + " \"path\": \"/accessToken/claims/expires_in\",\n" + + " \"value\": 7200\n" + + " },\n" + + " {\n" + + " \"op\": \"remove\",\n" + + " \"path\": \"/accessToken/scopes/6\"\n" + + " },\n" + + " {\n" + + " \"op\": \"remove\",\n" + + " \"path\": \"/accessToken/claims/aud/-\"\n" + + " }\n" + " ]\n" + - "}\n"; + " }"; // TODO: Handle status codes related to different scenarios wireMockServer.stubFor(post(urlEqualTo(mockEndpoint))