Skip to content

Commit

Permalink
Change code retrieval method
Browse files Browse the repository at this point in the history
  • Loading branch information
madurangasiriwardena committed Nov 22, 2024
1 parent 0f60df4 commit 0cac5a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ private void performUserLogin() throws Exception {

sendLoginPostForIdentifier(client, sessionDataKey, userObject.getUserName());
HttpResponse response = sendLoginPostForOtp(client, sessionDataKey, mockSMSProvider.getOTP());
EntityUtils.consume(response.getEntity());

authorizationCode = EntityUtils.toString(response.getEntity());
authorizationCode = mockClientCallback.getAuthorizationCode();
assertNotNull(authorizationCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.ResponseTransformerV2;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.http.Response;
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.util.Utils;

Expand All @@ -39,6 +42,8 @@ public class MockClientCallback {

public static final String CALLBACK_URL = "https://localhost:8091/dummyApp/oauth2client";

private final AtomicReference<String> authorizationCode = new AtomicReference<>();

private WireMockServer wireMockServer;

public void start() {
Expand All @@ -50,7 +55,26 @@ public void start() {
ISIntegrationTest.KEYSTORE_NAME).toAbsolutePath().toString())
.keystorePassword("wso2carbon")
.keyManagerPassword("wso2carbon")
.extensions(new ResponseTemplateTransformer(null, true, null, null)));
.extensions(new ResponseTemplateTransformer(null, true, null, null),
new ResponseTransformerV2() {

@Override
public Response transform(Response response, ServeEvent serveEvent) {

authorizationCode.set(serveEvent.getRequest().getQueryParams().get("code").firstValue());
return response;
}

@Override
public boolean applyGlobally() {
return false;
}

@Override
public String getName() {
return "authz-code-transformer";
}
}));

wireMockServer.start();

Expand All @@ -71,11 +95,15 @@ private void configureMockEndpoints() {
wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp/oauth2client"))
.withQueryParam("code", matching(".*"))
.willReturn(aResponse()
.withBody("{{request.query.code}}")
.withTransformers("response-template")
.withTransformers("response-template", "authz-code-transformer")
.withStatus(200)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public String getAuthorizationCode() {

return authorizationCode.get();
}
}

0 comments on commit 0cac5a3

Please sign in to comment.