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

[integration tests] Pre issue access token with auth code grant type #21115

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ protected boolean isRedirectable(String method) {

actionId = createPreIssueAccessTokenAction();

try {
Thread.sleep(3600);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
actionsMockServer = new ActionsMockServer();
actionsMockServer.startServer();
actionsMockServer.setupStub(MOCK_SERVER_ENDPOINT_RESOURCE_PATH,
Expand Down Expand Up @@ -312,8 +317,8 @@ public void testTokenScopeOperations() throws Exception {
Assert.assertTrue(ArrayUtils.contains(scopes, NEW_SCOPE_2));
Assert.assertTrue(ArrayUtils.contains(scopes, NEW_SCOPE_3));
Assert.assertTrue(ArrayUtils.contains(scopes, NEW_SCOPE_4));
Assert.assertFalse(ArrayUtils.contains(scopes, CUSTOM_SCOPE_3));
Assert.assertFalse(ArrayUtils.contains(scopes, CUSTOM_SCOPE_2));
Assert.assertFalse(ArrayUtils.contains(scopes, INTERNAL_ORG_USER_MANAGEMENT_DELETE));
Assert.assertFalse(ArrayUtils.contains(scopes, INTERNAL_ORG_USER_MANAGEMENT_CREATE));
}

@Test(groups = "wso2.is", dependsOnMethods = "testPreIssueAccessTokenActionRequest", description =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@
package org.wso2.identity.integration.test.actions.mockserver;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
import org.apache.commons.lang.StringUtils;

import java.util.List;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;

/**
* Provides a mock server using WireMock for testing purposes.
Expand Down Expand Up @@ -76,133 +72,4 @@ public String getReceivedRequestPayload(String url) {

return requestList.get(0).getBodyAsString();
}

/**
* Create a mock server with wiremock.
*
* @throws Exception If an error occurred while creating the server
*/
public void createMockServer(String mockEndpoint) throws Exception {

wireMockServer = new WireMockServer(wireMockConfig().port(8587));

wireMockServer.start();

try {
// TODO: Read the response from a file
// TODO: Filter the response from the action type
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\": \"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" +
" }";

// TODO: Handle status codes related to different scenarios
wireMockServer.stubFor(post(urlEqualTo(mockEndpoint))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody(jsonResponse)));

} catch (Exception e) {
throw new Exception("Error occurred while creating the mock server: " + e);
}
}

/**
* Shut down the wiremock server instance.
*/
public void shutDownMockServer() {

wireMockServer.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ public AccessToken getAccessToken() {

@Override
public boolean equals(Object o) {

if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PreIssueAccessTokenEvent that = (PreIssueAccessTokenEvent) o;
return Objects.equals(request, that.request) &&

boolean isEqualGeneral = Objects.equals(request, that.request) &&
Objects.equals(accessToken, that.accessToken) &&
Objects.equals(tenant, that.tenant) &&
Objects.equals(user, that.user) &&
Objects.equals(userStore, that.userStore);
Objects.equals(tenant, that.tenant);

if (!"client_credentials".equals(that.request.getGrantType())) {
return isEqualGeneral &&
Objects.equals(user, that.user) &&
Objects.equals(userStore, that.userStore);
}
return isEqualGeneral;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,35 @@
},
{
"op": "replace",
"path": "/accessToken/scopes/7",
"path": "/accessToken/scopes/1",
"value": "replaced_scope"
},
{
"op": "replace",
"path": "/accessToken/claims/aud/-",
"value": "zzzR.com"
},
{
"op": "replace",
"path": "/accessToken/claims/given_name",
"value": "replaced_given_name"
},
{
"op": "replace",
"path": "/accessToken/claims/expires_in",
"value": 7200
},
{
"op": "remove",
"path": "/accessToken/scopes/6"
"path": "/accessToken/scopes/0"
},
{
"op": "remove",
"path": "/accessToken/claims/aud/-"
},
{
"op": "remove",
"path": "/accessToken/claims/family_name"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<class name="org.wso2.identity.integration.test.apiAuthorization.RBACWithAPIAuthorizationTestCase"/>
<class name="org.wso2.identity.integration.test.actions.PreIssueAccessTokenPasswordGrantTestCase"/>
<class name="org.wso2.identity.integration.test.actions.PreIssueAccessTokenClientCredentialsGrantTestCase"/>
<class name="org.wso2.identity.integration.test.actions.PreIssueAccessTokenCodeGrantTestCase"/>
<class name="org.wso2.identity.integration.test.oauth2.Oauth2ImpersonationTestCase"/>
<class name="org.wso2.identity.integration.test.oauth2.OAuth2AuthorizationCodeGrantJWTTokenTestCase"/>
</classes>
Expand Down