Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test case for expires_in claim modification #21034

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down