From 8948a0665df8f5a429038e22df29683cb8a6d9b5 Mon Sep 17 00:00:00 2001 From: Maduranga Siriwardena Date: Fri, 29 Nov 2024 20:40:09 +0530 Subject: [PATCH 1/4] Remove playground apps --- .../tests-integration/tests-backend/pom.xml | 13 -- .../auth/PasswordlessSMSOTPAuthTestCase.java | 6 +- .../test/base/MockClientCallback.java | 99 +++++++++++- .../test/base/TomcatInitializerTestCase.java | 2 - .../oidc/OIDCAbstractIntegrationTest.java | 29 ++-- .../oidc/OIDCAuthCodeGrantSSOTestCase.java | 141 +++++++++--------- .../oidc/OIDCRPInitiatedLogoutTestCase.java | 46 +++--- .../OIDCSPWiseSkipLoginConsentTestCase.java | 16 +- .../test/oidc/OIDCSSOConsentTestCase.java | 111 ++++++-------- .../integration/test/oidc/OIDCUtilTest.java | 10 +- .../recovery/PasswordRecoveryTestCase.java | 21 ++- 11 files changed, 277 insertions(+), 217 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/pom.xml b/modules/integration/tests-integration/tests-backend/pom.xml index 51350a63419..ebf130c74ac 100644 --- a/modules/integration/tests-integration/tests-backend/pom.xml +++ b/modules/integration/tests-integration/tests-backend/pom.xml @@ -458,19 +458,6 @@ run - - packaging-war-artifacts-oidc - process-test-resources - - - - - - - - run - - packaging-war-artifacts-passivests process-test-resources diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java index 527dad0a3fb..26c6318d836 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java @@ -189,7 +189,7 @@ private void sendAuthorizeRequest() throws Exception { List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); urlParameters.add(new BasicNameValuePair("client_id", oidcApplication.getClientId())); - urlParameters.add(new BasicNameValuePair("redirect_uri", MockClientCallback.CALLBACK_URL)); + urlParameters.add(new BasicNameValuePair("redirect_uri", MockClientCallback.CALLBACK_URL_APP1)); urlParameters.add(new BasicNameValuePair("scope", "openid")); @@ -241,7 +241,7 @@ private HttpResponse sendTokenRequestForCodeGrant() throws Exception { List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("code", authorizationCode)); urlParameters.add(new BasicNameValuePair("grant_type", OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE)); - urlParameters.add(new BasicNameValuePair("redirect_uri", MockClientCallback.CALLBACK_URL)); + urlParameters.add(new BasicNameValuePair("redirect_uri", MockClientCallback.CALLBACK_URL_APP1)); urlParameters.add(new BasicNameValuePair("client_id", oidcApplication.getClientSecret())); urlParameters.add(new BasicNameValuePair("scope", "openid")); @@ -261,7 +261,7 @@ private OIDCApplication initOIDCApplication() { OIDCApplication playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName, OIDCUtilTest.playgroundAppOneAppContext, - MockClientCallback.CALLBACK_URL); + MockClientCallback.CALLBACK_URL_APP1); return playgroundApp; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockClientCallback.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockClientCallback.java index 955f56ba48d..b703d0e32b8 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockClientCallback.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockClientCallback.java @@ -19,6 +19,7 @@ package org.wso2.identity.integration.test.base; import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.common.ConsoleNotifier; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.extension.ResponseTransformerV2; import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; @@ -32,7 +33,10 @@ import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; 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.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; /** @@ -40,9 +44,11 @@ */ public class MockClientCallback { - public static final String CALLBACK_URL = "https://localhost:8091/dummyApp/oauth2client"; + public static final String CALLBACK_URL_APP1 = "https://localhost:8091/dummyApp/oauth2client"; + public static final String CALLBACK_URL_APP2 = "https://localhost:8091/dummyApp2/oauth2client"; private final AtomicReference authorizationCode = new AtomicReference<>(); + private final AtomicReference errorCode = new AtomicReference<>(); private WireMockServer wireMockServer; @@ -74,6 +80,25 @@ public boolean applyGlobally() { public String getName() { return "authz-code-transformer"; } + }, + new ResponseTransformerV2() { + + @Override + public Response transform(Response response, ServeEvent serveEvent) { + + errorCode.set(serveEvent.getRequest().getQueryParams().get("error").firstValue()); + return response; + } + + @Override + public boolean applyGlobally() { + return false; + } + + @Override + public String getName() { + return "error-code-transformer"; + } })); wireMockServer.start(); @@ -92,18 +117,90 @@ public void stop() { private void configureMockEndpoints() { try { + // Endpoints for App 1 wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp/oauth2client")) .withQueryParam("code", matching(".*")) .willReturn(aResponse() .withTransformers("response-template", "authz-code-transformer") .withStatus(200))); + wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp/oauth2client")) + .withQueryParam("code", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "authz-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp/oauth2client")) + .withQueryParam("code", matching(".*")) + .withQueryParam("session_state", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "authz-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp/oauth2client")) + .withQueryParam("code", matching(".*")) + .withQueryParam("session_state", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "authz-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp/oauth2client")) + .withQueryParam("error_description", matching(".*")) + .withQueryParam("error", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "error-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(get(urlEqualTo("/dummyApp/oauth2client")) + .willReturn(aResponse() + .withTransformers("response-template") + .withStatus(200))); + + // Endpoints for App 2 + wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp2/oauth2client")) + .withQueryParam("code", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "authz-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp2/oauth2client")) + .withQueryParam("code", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "authz-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp2/oauth2client")) + .withQueryParam("code", matching(".*")) + .withQueryParam("session_state", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "authz-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp2/oauth2client")) + .withQueryParam("code", matching(".*")) + .withQueryParam("session_state", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "authz-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp2/oauth2client")) + .withQueryParam("error_description", matching(".*")) + .withQueryParam("error", matching(".*")) + .willReturn(aResponse() + .withTransformers("response-template", "error-code-transformer") + .withStatus(200))); + wireMockServer.stubFor(get(urlEqualTo("/dummyApp2/oauth2client")) + .willReturn(aResponse() + .withTransformers("response-template") + .withStatus(200))); } catch (Exception e) { throw new RuntimeException(e); } } + public void verifyForLogoutRedirectionForApp1() { + + wireMockServer.verify(getRequestedFor(urlEqualTo("/dummyApp/oauth2client"))); + } + public String getAuthorizationCode() { return authorizationCode.get(); } + + public String getErrorCode() { + + return errorCode.get(); + } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/TomcatInitializerTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/TomcatInitializerTestCase.java index 743c9b3b19b..2fdc751b53c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/TomcatInitializerTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/TomcatInitializerTestCase.java @@ -43,8 +43,6 @@ public class TomcatInitializerTestCase extends ISIntegrationTest { "travelocity.com-registrymount", "avis.com", "PassiveSTSSampleApp", - "playground.appone", - "playground.apptwo", "playground2" }; private static final Log LOG = LogFactory.getLog(TomcatInitializerTestCase.class); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java index 6742e9b8823..1f5dc59d813 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAbstractIntegrationTest.java @@ -20,13 +20,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.CookieStore; import org.apache.http.client.HttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; +import org.apache.http.message.BasicNameValuePair; import org.testng.Assert; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.identity.integration.test.oauth2.OAuth2ServiceAbstractIntegrationTest; @@ -53,6 +51,8 @@ import java.util.List; import java.util.Map; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.AUTHORIZE_ENDPOINT_URL; + /** * This class defines basic functionality needed to initiate an OIDC test. */ @@ -188,28 +188,19 @@ public void testSendAuthenticationRequest(OIDCApplication application, boolean i HttpClient client, CookieStore cookieStore) throws Exception { - List urlParameters = OIDCUtilTest.getNameValuePairs(application, - getTenantQualifiedURL(OAuth2Constant.APPROVAL_URL, tenantInfo.getDomain())); - - HttpResponse response = sendPostRequestWithParameters(client, urlParameters, String.format - (OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + OAuth2Constant.PlaygroundAppPaths - .appUserAuthorizePath)); + List urlParameters = new ArrayList<>(); + urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); + urlParameters.add(new BasicNameValuePair("client_id", application.getClientId())); + urlParameters.add(new BasicNameValuePair("redirect_uri", application.getCallBackURL())); - Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION); - EntityUtils.consume(response.getEntity()); + urlParameters.add(new BasicNameValuePair("scope", "openid")); - if (isFirstAuthenticationRequest) { - response = sendGetRequest(client, locationHeader.getValue()); - } else { - HttpClient httpClientWithoutAutoRedirections = HttpClientBuilder.create().disableRedirectHandling() - .setDefaultCookieStore(cookieStore).build(); - response = sendGetRequest(httpClientWithoutAutoRedirections, locationHeader.getValue()); - } + HttpResponse response = sendPostRequestWithParameters(client, urlParameters, + getTenantQualifiedURL(AUTHORIZE_ENDPOINT_URL, tenantInfo.getDomain())); Map keyPositionMap = new HashMap<>(1); if (isFirstAuthenticationRequest) { OIDCUtilTest.setSessionDataKey(response, keyPositionMap); - } else { Assert.assertFalse(Utils.requestMissingClaims(response)); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java index 730c5aed824..fb325ebdc0a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java @@ -33,6 +33,7 @@ import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.cookie.RFC6265CookieSpecProvider; +import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.json.simple.JSONValue; @@ -40,6 +41,7 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import org.wso2.identity.integration.test.base.MockClientCallback; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; @@ -57,6 +59,11 @@ import java.util.List; import java.util.Map; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.ACCESS_TOKEN_ENDPOINT; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.AUTHORIZATION_HEADER; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.AUTHORIZE_ENDPOINT_URL; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE; + /** * This test class tests OIDC SSO functionality for two replying party applications. */ @@ -76,6 +83,7 @@ public class OIDCAuthCodeGrantSSOTestCase extends OIDCAbstractIntegrationTest { protected RequestConfig requestConfig; protected HttpClient client; protected List consentParameters = new ArrayList<>(); + private MockClientCallback mockClientCallback; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -100,6 +108,9 @@ public void testInit() throws Exception { .setDefaultCookieStore(cookieStore) .build(); + mockClientCallback = new MockClientCallback(); + mockClientCallback.start(); + } @AfterClass(alwaysRun = true) @@ -108,6 +119,7 @@ public void testClear() throws Exception { deleteUser(user); deleteApplications(); clear(); + mockClientCallback.stop(); } @Test(groups = "wso2.is", description = "Test authz endpoint before creating a valid session") @@ -122,12 +134,13 @@ public void testAuthzRequestWithoutValidSessionForIDENTITY5581() throws Exceptio .addParameter("prompt", "none") .addParameter("redirect_uri", application.getCallBackURL()).build(); HttpResponse httpResponse = sendGetRequest(client, uri.toString()); - String contentData = DataExtractUtil.getContentData(httpResponse); - Assert.assertTrue(contentData.contains("login_required")); + EntityUtils.consume(httpResponse.getEntity()); + Assert.assertTrue(mockClientCallback.getErrorCode().contains("login_required")); } - @Test(groups = "wso2.is", description = "Initiate authentication request from playground.appone", dependsOnMethods = "testAuthzRequestWithoutValidSessionForIDENTITY5581") + @Test(groups = "wso2.is", description = "Initiate authentication request from playground.appone", + dependsOnMethods = "testAuthzRequestWithoutValidSessionForIDENTITY5581") public void testSendAuthenticationRequestFromRP1() throws Exception { testSendAuthenticationRequest(applications.get(OIDCUtilTest.playgroundAppOneAppName), true, client, cookieStore); @@ -164,7 +177,8 @@ public void testUserClaimsFromRP1() throws Exception { @Test(groups = "wso2.is", description = "Initiate authentication request from playground.apptwo") public void testSendAuthenticationRequestFromRP2() throws Exception { - testSendAuthenticationRequest(applications.get(OIDCUtilTest.playgroundAppTwoAppName), false, client, cookieStore); + testSendAuthenticationRequest(applications.get(OIDCUtilTest.playgroundAppTwoAppName), false, client, + cookieStore); } @Test(groups = "wso2.is", description = "Approve consent for playground.apptwo", dependsOnMethods = @@ -189,23 +203,22 @@ public void testUserClaimsFromRP2() throws Exception { } public void testSendAuthenticationRequest(OIDCApplication application, boolean isFirstAuthenticationRequest, - HttpClient client, CookieStore cookieStore) - throws Exception { - - List urlParameters = OIDCUtilTest.getNameValuePairs(application); - HttpResponse response = sendPostRequestWithParameters(client, urlParameters, String.format - (OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + OAuth2Constant.PlaygroundAppPaths - .appUserAuthorizePath)); - Assert.assertNotNull(response, "Authorization request failed for " + application.getApplicationName() + ". " - + "Authorized response is null"); + HttpClient client, CookieStore cookieStore) throws Exception { - Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION); + List urlParameters = new ArrayList<>(); + urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); + urlParameters.add(new BasicNameValuePair("client_id", application.getClientId())); + urlParameters.add(new BasicNameValuePair("redirect_uri", application.getCallBackURL())); - Assert.assertNotNull(locationHeader, "Authorization request failed for " + application.getApplicationName() + - ". Authorized response header is null"); - EntityUtils.consume(response.getEntity()); + urlParameters.add(new BasicNameValuePair("scope", "openid email profile")); + HttpResponse response; if (isFirstAuthenticationRequest) { + response = sendPostRequestWithParameters(client, urlParameters, + getTenantQualifiedURL(AUTHORIZE_ENDPOINT_URL, tenantInfo.getDomain())); + Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION); + EntityUtils.consume(response.getEntity()); + response = sendGetRequest(client, locationHeader.getValue()); } else { HttpClient httpClientWithoutAutoRedirections = HttpClientBuilder.create() @@ -213,11 +226,12 @@ public void testSendAuthenticationRequest(OIDCApplication application, boolean i .setDefaultRequestConfig(requestConfig) .disableRedirectHandling() .setDefaultCookieStore(cookieStore).build(); - response = sendGetRequest(httpClientWithoutAutoRedirections, locationHeader.getValue()); + response = sendPostRequestWithParameters(httpClientWithoutAutoRedirections, urlParameters, + getTenantQualifiedURL(AUTHORIZE_ENDPOINT_URL, tenantInfo.getDomain())); } - Assert.assertNotNull(response, "Authorization request failed for " + application.getApplicationName() + ". " - + "Authorized user response is null."); + Assert.assertNotNull(response, "Authorization request failed for " + application.getApplicationName() + + ". Authorized user response is null."); Map keyPositionMap = new HashMap<>(1); if (isFirstAuthenticationRequest) { @@ -238,12 +252,11 @@ public void testSendAuthenticationRequest(OIDCApplication application, boolean i String pastrCookie = Utils.getPastreCookie(response); Assert.assertNotNull(pastrCookie, "pastr cookie not found in response."); EntityUtils.consume(response.getEntity()); - Header oauthConsentLocationHeader = consentLocationHeader; - Assert.assertNotNull(oauthConsentLocationHeader, "OAuth consent url is null for " + - oauthConsentLocationHeader.getValue()); + Assert.assertNotNull(consentLocationHeader, "OAuth consent url is null for " + + consentLocationHeader.getValue()); consentParameters.addAll(Utils.getConsentRequiredClaimsFromResponse(response)); - response = sendGetRequest(client, oauthConsentLocationHeader.getValue()); + response = sendGetRequest(client, consentLocationHeader.getValue()); keyPositionMap.put("name=\"sessionDataKeyConsent\"", 1); List keyValues = DataExtractUtil.extractSessionConsentDataFromResponse @@ -272,6 +285,7 @@ private void testAuthentication(OIDCApplication application) throws Exception { EntityUtils.consume(response.getEntity()); response = sendGetRequest(client, locationHeader.getValue()); + Map keyPositionMap = new HashMap<>(1); keyPositionMap.put("name=\"sessionDataKeyConsent\"", 1); List keyValues = DataExtractUtil.extractSessionConsentDataFromResponse(response, @@ -297,16 +311,10 @@ private void testConsentApproval(OIDCApplication application) throws Exception { EntityUtils.consume(response.getEntity()); response = sendPostRequest(client, locationHeader.getValue()); - Assert.assertNotNull(response, "Authorization code response is invalid for " + application.getApplicationName - ()); - - Map keyPositionMap = new HashMap<>(1); - keyPositionMap.put("Authorization Code", 1); - List keyValues = DataExtractUtil.extractTableRowDataFromResponse(response, - keyPositionMap); - Assert.assertNotNull(keyValues, "Authorization code not received for " + application.getApplicationName()); + Assert.assertNotNull(response, "Authorization code response is invalid for " + + application.getApplicationName()); - authorizationCode = keyValues.get(0).getValue(); + authorizationCode = mockClientCallback.getAuthorizationCode(); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); EntityUtils.consume(response.getEntity()); @@ -314,35 +322,33 @@ private void testConsentApproval(OIDCApplication application) throws Exception { private void testGetAccessToken(OIDCApplication application) throws Exception { - HttpResponse response = sendGetAccessTokenPost(client, application); - Assert.assertNotNull(response, "Access token response is invalid for " + application.getApplicationName()); - EntityUtils.consume(response.getEntity()); - - response = sendPostRequest(client, String.format(OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + - OAuth2Constant.PlaygroundAppPaths.appAuthorizePath)); - - Map keyPositionMap = new HashMap<>(1); - keyPositionMap.put("name=\"accessToken\"", 1); - List keyValues = DataExtractUtil.extractInputValueFromResponse(response, - keyPositionMap); - Assert.assertNotNull(keyValues, "Access token not received for " + application.getApplicationName()); - - accessToken = keyValues.get(0).getValue(); - Assert.assertNotNull(accessToken, "Access token not received for " + application.getApplicationName()); - EntityUtils.consume(response.getEntity()); - - response = sendPostRequest(client, String.format(OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + - OAuth2Constant.PlaygroundAppPaths.appAuthorizePath)); - - keyPositionMap = new HashMap<>(1); - keyPositionMap.put("id=\"loggedUser\"", 1); - keyValues = DataExtractUtil.extractLabelValueFromResponse(response, keyPositionMap); - Assert.assertNotNull(keyValues, "No user logged in for " + application.getApplicationName()); + List urlParameters = new ArrayList<>(); + urlParameters.add(new BasicNameValuePair("code", authorizationCode)); + urlParameters.add(new BasicNameValuePair("grant_type", OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE)); + urlParameters.add(new BasicNameValuePair("redirect_uri", application.getCallBackURL())); + urlParameters.add(new BasicNameValuePair("client_id", application.getClientSecret())); + + urlParameters.add(new BasicNameValuePair("scope", "openid")); + + List
headers = new ArrayList<>(); + headers.add(new BasicHeader(AUTHORIZATION_HEADER, + OAuth2Constant.BASIC_HEADER + " " + getBase64EncodedString(application.getClientId(), + application.getClientSecret()))); + headers.add(new BasicHeader("Content-Type", "application/x-www-form-urlencoded")); + headers.add(new BasicHeader("User-Agent", OAuth2Constant.USER_AGENT)); + + HttpResponse response = sendPostRequest(client, headers, urlParameters, + getTenantQualifiedURL(ACCESS_TOKEN_ENDPOINT, tenantInfo.getDomain())); + String responseString = EntityUtils.toString(response.getEntity()); + Map responseMap = (Map) JSONValue.parse(responseString); + accessToken = (String) responseMap.get("access_token"); + + String idToken = (String) responseMap.get("id_token"); + String[] tokenParts = idToken.split("\\."); + String payload = new String(java.util.Base64.getUrlDecoder().decode(tokenParts[1])); + Map parsedIdToken = (Map) JSONValue.parse(payload); + Assert.assertNotNull(parsedIdToken.get("sub"), "No user logged in for " + application.getApplicationName()); - String loggedUser = keyValues.get(0).getValue(); - Assert.assertNotNull(loggedUser, "Logged user is null for " + application.getApplicationName()); - Assert.assertNotEquals(loggedUser, "null", "Logged user is null for " + application.getApplicationName()); - Assert.assertNotEquals(loggedUser, "", "Logged user is null for " + application.getApplicationName()); EntityUtils.consume(response.getEntity()); } @@ -404,17 +410,4 @@ protected void deleteApplications() throws Exception { deleteApplication(entry.getValue()); } } - - protected HttpResponse sendGetAccessTokenPost(HttpClient client, OIDCApplication application) throws IOException { - - List urlParameters = new ArrayList<>(); - urlParameters.add(new BasicNameValuePair("callbackurl", application.getCallBackURL())); - urlParameters.add(new BasicNameValuePair("accessEndpoint", OAuth2Constant.ACCESS_TOKEN_ENDPOINT)); - urlParameters.add(new BasicNameValuePair("consumerSecret", application.getClientSecret())); - HttpResponse response = sendPostRequestWithParameters(client, urlParameters, String.format - (OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + OAuth2Constant.PlaygroundAppPaths - .accessTokenRequestPath)); - - return response; - } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java index f9729d7711c..04724bfc2a0 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java @@ -32,6 +32,7 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import org.wso2.identity.integration.test.base.MockClientCallback; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; @@ -45,6 +46,8 @@ import java.util.List; import java.util.Map; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.AUTHORIZE_ENDPOINT_URL; + /** * This test class tests the OIDC RP-Initiated logout flows */ @@ -62,6 +65,7 @@ public class OIDCRPInitiatedLogoutTestCase extends OIDCAbstractIntegrationTest { protected List consentParameters = new ArrayList<>(); OIDCApplication playgroundAppOne; OIDCApplication playgroundAppTwo; + private MockClientCallback mockClientCallback; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -88,6 +92,9 @@ public void testInit() throws Exception { .setDefaultCookieSpecRegistry(cookieSpecRegistry) .setDefaultRequestConfig(requestConfig) .build(); + + mockClientCallback = new MockClientCallback(); + mockClientCallback.start(); } @AfterClass(alwaysRun = true) @@ -97,6 +104,7 @@ public void testClear() throws Exception { deleteApplication(playgroundAppOne); deleteApplication(playgroundAppTwo); clear(); + mockClientCallback.stop(); } @AfterMethod @@ -145,12 +153,14 @@ public void testOIDCLogoutPrecedence() throws Exception { private void testInitiateOIDCRequest(OIDCApplication application, HttpClient client) throws Exception { - List urlParameters = OIDCUtilTest.getNameValuePairs(application); - HttpResponse response = sendPostRequestWithParameters(client, urlParameters, String.format - (OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + - OAuth2Constant.PlaygroundAppPaths.appUserAuthorizePath)); - Assert.assertNotNull(response, "Authorization request failed for " + application.getApplicationName() + - ". Authorized response is null."); + List urlParameters = new ArrayList<>(); + urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); + urlParameters.add(new BasicNameValuePair("client_id", application.getClientId())); + urlParameters.add(new BasicNameValuePair("redirect_uri", application.getCallBackURL())); + urlParameters.add(new BasicNameValuePair("scope", "openid email profile")); + + HttpResponse response = sendPostRequestWithParameters(client, urlParameters, + getTenantQualifiedURL(AUTHORIZE_ENDPOINT_URL, tenantInfo.getDomain())); Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION); @@ -196,13 +206,7 @@ private void testOIDCLogin(OIDCApplication application, boolean checkConsent) th sessionDataKeyConsent = keyValues.get(0).getValue(); Assert.assertNotNull(sessionDataKeyConsent, "sessionDataKeyConsent is null."); } else { - keyPositionMap.put("Authorization Code", 1); - List keyValues = DataExtractUtil.extractTableRowDataFromResponse(response, - keyPositionMap); - Assert.assertNotNull(keyValues, "Authorization code not received for " + - application.getApplicationName()); - - authorizationCode = new AuthorizationCode(keyValues.get(0).getValue()); + authorizationCode = new AuthorizationCode(mockClientCallback.getAuthorizationCode()); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); } @@ -221,17 +225,7 @@ private void testOIDCConsentApproval(OIDCApplication application) throws Excepti EntityUtils.consume(response.getEntity()); response = sendPostRequest(client, locationHeader.getValue()); - Assert.assertNotNull(response, "Authorization code response is invalid for " + - application.getApplicationName()); - - Map keyPositionMap = new HashMap<>(1); - keyPositionMap.put("Authorization Code", 1); - List keyValues = DataExtractUtil.extractTableRowDataFromResponse(response, - keyPositionMap); - Assert.assertNotNull(keyValues, "Authorization code not received for " + - application.getApplicationName()); - - authorizationCode = new AuthorizationCode(keyValues.get(0).getValue()); + authorizationCode = new AuthorizationCode(mockClientCallback.getAuthorizationCode()); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); EntityUtils.consume(response.getEntity()); @@ -296,10 +290,8 @@ private void testOIDCLogout(boolean checkSuccess, OIDCApplication application, B Assert.assertTrue(redirectUrl.contains(application.getCallBackURL()), "Not redirected to the" + "post logout redirect url"); response = sendGetRequest(client, redirectUrl); - Assert.assertNotNull(response, "OIDC Logout failed."); - String result = DataExtractUtil.getContentData(response); - Assert.assertTrue(result.contains("WSO2 OAuth2 Playground"), "OIDC logout failed."); EntityUtils.consume(response.getEntity()); + mockClientCallback.verifyForLogoutRedirectionForApp1(); } else { Assert.assertTrue(redirectUrl.contains("oauth2_error.do")); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java index 20061ed6240..2cadb8e417e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java @@ -30,6 +30,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.identity.integration.test.base.MockClientCallback; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.AdvancedApplicationConfiguration; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationPatchModel; @@ -46,6 +47,7 @@ public class OIDCSPWiseSkipLoginConsentTestCase extends OIDCAbstractIntegrationT private CookieStore cookieStore = new BasicCookieStore(); protected String sessionDataKey; protected String sessionDataKeyConsent; + private MockClientCallback mockClientCallback; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -57,6 +59,9 @@ public void testInit() throws Exception { createApplications(); configureSPToSkipConsent(); client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); + + mockClientCallback = new MockClientCallback(); + mockClientCallback.start(); } @AfterClass(alwaysRun = true) @@ -64,6 +69,7 @@ public void clearObjects() throws Exception { deleteObjects(); clear(); + mockClientCallback.stop(); } private void deleteObjects() throws Exception { @@ -83,16 +89,16 @@ private void configureSPToSkipConsent() throws Exception { @Test(groups = "wso2.is", description = "Test authz endpoint before creating a valid session") public void testCreateUserSession() throws Exception { - testSendAuthenticationRequest(OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppOneAppName), true, client, - cookieStore); + testSendAuthenticationRequest(OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppOneAppName), true, + client, cookieStore); testAuthentication(); } @Test(groups = "wso2.is", description = "Initiate authentication request from playground.apptwo") - public void testIntiateLoginRequestForAlreadyLoggedUser() throws Exception { + public void testInitiateLoginRequestForAlreadyLoggedUser() throws Exception { - testSendAuthenticationRequest(OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppTwoAppName), false, client - , cookieStore); + testSendAuthenticationRequest(OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppTwoAppName), false, + client, cookieStore); } private void testAuthentication() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java index e71147375b9..0aceb4d65eb 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java @@ -31,9 +31,11 @@ import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.cookie.RFC6265CookieSpecProvider; +import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.json.JSONObject; +import org.json.simple.JSONValue; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -41,6 +43,7 @@ import org.wso2.carbon.automation.engine.context.beans.Tenant; import org.wso2.carbon.automation.engine.context.beans.User; import org.apache.commons.lang.StringUtils; +import org.wso2.identity.integration.test.base.MockClientCallback; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationPatchModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim; @@ -55,8 +58,11 @@ import org.wso2.identity.integration.test.utils.OAuth2Constant; import static org.apache.commons.lang.StringUtils.isBlank; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.ACCESS_TOKEN_ENDPOINT; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.AUTHORIZATION_HEADER; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.AUTHORIZE_ENDPOINT_URL; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -81,6 +87,7 @@ public class OIDCSSOConsentTestCase extends OIDCAbstractIntegrationTest { protected List consentParameters = new ArrayList<>(); OIDCApplication playgroundApp; private String claimsToGetConsent; + private MockClientCallback mockClientCallback; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -105,6 +112,9 @@ public void testInit() throws Exception { .setDefaultCookieSpecRegistry(cookieSpecRegistry) .setDefaultRequestConfig(requestConfig) .build(); + + mockClientCallback = new MockClientCallback(); + mockClientCallback.start(); } @AfterClass(alwaysRun = true) @@ -113,6 +123,7 @@ public void testClear() throws Exception { deleteUser(user); deleteApplication(playgroundApp); clear(); + mockClientCallback.stop(); } @Test(groups = "wso2.is", description = "Test consent management after updating " + @@ -140,17 +151,16 @@ public void testConsentWithAppClaimConfigUpdate() throws Exception { public void testSendAuthenticationRequest(OIDCApplication application, HttpClient client) throws Exception { - List urlParameters = OIDCUtilTest.getNameValuePairs(application); - HttpResponse response = sendPostRequestWithParameters(client, urlParameters, String.format - (OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + - OAuth2Constant.PlaygroundAppPaths.appUserAuthorizePath)); - Assert.assertNotNull(response, "Authorization request failed for " + application.getApplicationName() + - ". Authorized response is null."); + List urlParameters = new ArrayList<>(); + urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); + urlParameters.add(new BasicNameValuePair("client_id", application.getClientId())); + urlParameters.add(new BasicNameValuePair("redirect_uri", application.getCallBackURL())); + + urlParameters.add(new BasicNameValuePair("scope", "openid email profile")); + HttpResponse response = sendPostRequestWithParameters(client, urlParameters, + getTenantQualifiedURL(AUTHORIZE_ENDPOINT_URL, tenantInfo.getDomain())); Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION); - - Assert.assertNotNull(locationHeader, "Authorization request failed for " + - application.getApplicationName() + ". Authorized response header is null."); EntityUtils.consume(response.getEntity()); response = sendGetRequest(client, locationHeader.getValue()); @@ -222,53 +232,41 @@ private void testConsentApproval(OIDCApplication application) throws Exception { EntityUtils.consume(response.getEntity()); response = sendPostRequest(client, locationHeader.getValue()); - Assert.assertNotNull(response, "Authorization code response is invalid for " + - application.getApplicationName()); - - Map keyPositionMap = new HashMap<>(1); - keyPositionMap.put("Authorization Code", 1); - List keyValues = DataExtractUtil.extractTableRowDataFromResponse(response, - keyPositionMap); - Assert.assertNotNull(keyValues, "Authorization code not received for " + - application.getApplicationName()); + EntityUtils.consume(response.getEntity()); - authorizationCode = keyValues.get(0).getValue(); + authorizationCode = mockClientCallback.getAuthorizationCode(); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); - EntityUtils.consume(response.getEntity()); } private void testGetAccessToken(OIDCApplication application) throws Exception { - HttpResponse response = sendGetAccessTokenPost(client, application); - Assert.assertNotNull(response, "Access token response is invalid for " + - application.getApplicationName()); - EntityUtils.consume(response.getEntity()); - - response = sendPostRequest(client, String.format(OIDCUtilTest.targetApplicationUrl, - application.getApplicationContext() + OAuth2Constant.PlaygroundAppPaths.appAuthorizePath)); - - Map keyPositionMap = new HashMap<>(1); - keyPositionMap.put("name=\"accessToken\"", 1); - List keyValues = DataExtractUtil.extractInputValueFromResponse(response, - keyPositionMap); - Assert.assertNotNull(keyValues, "Access token not received for " + application.getApplicationName()); - - accessToken = keyValues.get(0).getValue(); - Assert.assertNotNull(accessToken, "Access token not received for " + application.getApplicationName()); - EntityUtils.consume(response.getEntity()); - - response = sendPostRequest(client, String.format(OIDCUtilTest.targetApplicationUrl, - application.getApplicationContext() + OAuth2Constant.PlaygroundAppPaths.appAuthorizePath)); - - keyPositionMap = new HashMap<>(1); - keyPositionMap.put("id=\"loggedUser\"", 1); - keyValues = DataExtractUtil.extractLabelValueFromResponse(response, keyPositionMap); - Assert.assertNotNull(keyValues, "No user logged in for " + application.getApplicationName()); - - String loggedUser = keyValues.get(0).getValue(); - Assert.assertNotNull(loggedUser, "Logged user is null for " + application.getApplicationName()); - EntityUtils.consume(response.getEntity()); + List urlParameters = new ArrayList<>(); + urlParameters.add(new BasicNameValuePair("code", authorizationCode)); + urlParameters.add(new BasicNameValuePair("grant_type", OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE)); + urlParameters.add(new BasicNameValuePair("redirect_uri", application.getCallBackURL())); + urlParameters.add(new BasicNameValuePair("client_id", application.getClientSecret())); + + urlParameters.add(new BasicNameValuePair("scope", "openid")); + + List
headers = new ArrayList<>(); + headers.add(new BasicHeader(AUTHORIZATION_HEADER, + OAuth2Constant.BASIC_HEADER + " " + getBase64EncodedString(application.getClientId(), + application.getClientSecret()))); + headers.add(new BasicHeader("Content-Type", "application/x-www-form-urlencoded")); + headers.add(new BasicHeader("User-Agent", OAuth2Constant.USER_AGENT)); + + HttpResponse response = sendPostRequest(client, headers, urlParameters, + getTenantQualifiedURL(ACCESS_TOKEN_ENDPOINT, tenantInfo.getDomain())); + String responseString = EntityUtils.toString(response.getEntity()); + Map responseMap = (Map) JSONValue.parse(responseString); + accessToken = (String) responseMap.get("access_token"); + + String idToken = (String) responseMap.get("id_token"); + String[] tokenParts = idToken.split("\\."); + String payload = new String(java.util.Base64.getUrlDecoder().decode(tokenParts[1])); + Map parsedIdToken = (Map) JSONValue.parse(payload); + Assert.assertNotNull(parsedIdToken.get("sub"), "No user logged in for " + application.getApplicationName()); } protected void initUser() throws Exception { @@ -306,19 +304,6 @@ private void updateApplication(OIDCApplication playgroundApp) throws Exception { updateApplication(playgroundApp.getApplicationId(), new ApplicationPatchModel().claimConfiguration(claimConfig)); } - protected HttpResponse sendGetAccessTokenPost(HttpClient client, OIDCApplication application) throws IOException { - - List urlParameters = new ArrayList<>(); - urlParameters.add(new BasicNameValuePair("callbackurl", application.getCallBackURL())); - urlParameters.add(new BasicNameValuePair("accessEndpoint", OAuth2Constant.ACCESS_TOKEN_ENDPOINT)); - urlParameters.add(new BasicNameValuePair("consumerSecret", application.getClientSecret())); - HttpResponse response = sendPostRequestWithParameters(client, urlParameters, String.format - (OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + - OAuth2Constant.PlaygroundAppPaths.accessTokenRequestPath)); - - return response; - } - private void performOIDCLogout() { try { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java index 9fd38e90710..8abbd7ad2f6 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java @@ -22,6 +22,7 @@ import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.message.BasicNameValuePair; +import org.wso2.identity.integration.test.base.MockClientCallback; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; @@ -55,13 +56,14 @@ public class OIDCUtilTest { protected static String sessionDataKey; public static final String playgroundAppOneAppName = "playground.appone"; - public static final String playgroundAppOneAppCallBackUri = "http://localhost:" + TOMCAT_PORT + "/playground" + "" + - ".appone/oauth2client"; + public static final String playgroundAppOneAppCallBackUri = MockClientCallback.CALLBACK_URL_APP1; + + // TODO find the usages to identify the test cases that initiate the login from the app, instead of sending the + // login request directly to IS. public static final String playgroundAppOneAppContext = "/playground.appone"; public static final String playgroundAppTwoAppName = "playground.apptwo"; - public static final String playgroundAppTwoAppCallBackUri = "http://localhost:" + TOMCAT_PORT + "/playground" + "" + - ".apptwo/oauth2client"; + public static final String playgroundAppTwoAppCallBackUri = MockClientCallback.CALLBACK_URL_APP2; public static final String playgroundAppTwoAppContext = "/playground.apptwo"; public static final String targetApplicationUrl = "http://localhost:" + TOMCAT_PORT + "%s"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java index cc6f9981325..29a22407833 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java @@ -43,6 +43,7 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import org.wso2.identity.integration.test.base.MockClientCallback; import org.wso2.identity.integration.test.oidc.OIDCAbstractIntegrationTest; import org.wso2.identity.integration.test.oidc.OIDCUtilTest; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; @@ -60,6 +61,8 @@ import java.util.ArrayList; import java.util.List; +import static org.wso2.identity.integration.test.utils.OAuth2Constant.AUTHORIZE_ENDPOINT_URL; + /** * Test password recovery functionality. */ @@ -72,6 +75,7 @@ public class PasswordRecoveryTestCase extends OIDCAbstractIntegrationTest { private CloseableHttpClient client; private OIDCApplication oidcApplication; private UserObject userObject; + private MockClientCallback mockClientCallback; public static final String USERNAME = "recoverytestuser"; public static final String PASSWORD = "Oidcsessiontestuser@123"; @@ -103,6 +107,9 @@ public void testInit() throws Exception { userObject = initUser(); createUser(userObject); + + mockClientCallback = new MockClientCallback(); + mockClientCallback.start(); } @AfterClass(alwaysRun = true) @@ -114,6 +121,7 @@ public void testClear() throws Exception { identityGovernanceRestClient.closeHttpClient(); client.close(); Utils.getMailServer().purgeEmailFromAllMailboxes(); + mockClientCallback.stop(); } @Test @@ -129,12 +137,13 @@ public void testPasswordRecovery() throws Exception { private String retrievePasswordResetURL(OIDCApplication application, HttpClient client) throws Exception { - List urlParameters = OIDCUtilTest.getNameValuePairs(application, - getTenantQualifiedURL(OAuth2Constant.APPROVAL_URL, tenantInfo.getDomain())); - - HttpResponse response = sendPostRequestWithParameters(client, urlParameters, String.format - (OIDCUtilTest.targetApplicationUrl, application.getApplicationContext() + OAuth2Constant.PlaygroundAppPaths - .appUserAuthorizePath)); + List urlParameters = new ArrayList<>(); + urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); + urlParameters.add(new BasicNameValuePair("client_id", application.getClientId())); + urlParameters.add(new BasicNameValuePair("redirect_uri", application.getCallBackURL())); + urlParameters.add(new BasicNameValuePair("scope", "openid email profile")); + HttpResponse response = sendPostRequestWithParameters(client, urlParameters, + getTenantQualifiedURL(AUTHORIZE_ENDPOINT_URL, tenantInfo.getDomain())); Header authorizeRequestURL = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION); EntityUtils.consume(response.getEntity()); From 73d5450781125ac4f228849624b4dfa6a17a4aa1 Mon Sep 17 00:00:00 2001 From: Maduranga Siriwardena Date: Mon, 2 Dec 2024 13:47:43 +0530 Subject: [PATCH 2/4] Refactor mock client to represent 2 applications --- .../auth/PasswordlessSMSOTPAuthTestCase.java | 20 +-- ...llback.java => MockApplicationServer.java} | 139 +++++++++++------- .../oidc/OIDCAuthCodeGrantSSOTestCase.java | 15 +- .../oidc/OIDCRPInitiatedLogoutTestCase.java | 18 ++- .../OIDCSPWiseSkipLoginConsentTestCase.java | 10 +- .../test/oidc/OIDCSSOConsentTestCase.java | 12 +- .../integration/test/oidc/OIDCUtilTest.java | 13 +- .../recovery/PasswordRecoveryTestCase.java | 10 +- 8 files changed, 130 insertions(+), 107 deletions(-) rename modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/{MockClientCallback.java => MockApplicationServer.java} (57%) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java index 26c6318d836..c6a6fdb5250 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java @@ -39,7 +39,7 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.identity.integration.test.base.MockClientCallback; +import org.wso2.identity.integration.test.base.MockApplicationServer; import org.wso2.identity.integration.test.base.MockSMSProvider; import org.wso2.identity.integration.test.oidc.OIDCAbstractIntegrationTest; import org.wso2.identity.integration.test.oidc.OIDCUtilTest; @@ -90,7 +90,7 @@ public class PasswordlessSMSOTPAuthTestCase extends OIDCAbstractIntegrationTest private String authorizationCode; private MockSMSProvider mockSMSProvider; - private MockClientCallback mockClientCallback; + private MockApplicationServer mockApplicationServer; private TestUserMode userMode; @@ -116,8 +116,8 @@ public void testInit() throws Exception { mockSMSProvider = new MockSMSProvider(); mockSMSProvider.start(); - mockClientCallback = new MockClientCallback(); - mockClientCallback.start(); + mockApplicationServer = new MockApplicationServer(); + mockApplicationServer.start(); super.init(); @@ -170,7 +170,7 @@ public void atEnd() throws Exception { scim2RestClient.closeHttpClient(); mockSMSProvider.stop(); - mockClientCallback.stop(); + mockApplicationServer.stop(); } @Test(groups = "wso2.is", description = "Test passwordless authentication with SMS OTP") @@ -189,7 +189,7 @@ private void sendAuthorizeRequest() throws Exception { List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("response_type", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE)); urlParameters.add(new BasicNameValuePair("client_id", oidcApplication.getClientId())); - urlParameters.add(new BasicNameValuePair("redirect_uri", MockClientCallback.CALLBACK_URL_APP1)); + urlParameters.add(new BasicNameValuePair("redirect_uri", oidcApplication.getCallBackURL())); urlParameters.add(new BasicNameValuePair("scope", "openid")); @@ -212,7 +212,7 @@ private void performUserLogin() throws Exception { HttpResponse response = sendLoginPostForOtp(client, sessionDataKey, mockSMSProvider.getOTP()); EntityUtils.consume(response.getEntity()); - authorizationCode = mockClientCallback.getAuthorizationCode(); + authorizationCode = mockApplicationServer.getAuthorizationCodeForApp(oidcApplication.getApplicationName()); assertNotNull(authorizationCode); } @@ -241,7 +241,7 @@ private HttpResponse sendTokenRequestForCodeGrant() throws Exception { List urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("code", authorizationCode)); urlParameters.add(new BasicNameValuePair("grant_type", OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE)); - urlParameters.add(new BasicNameValuePair("redirect_uri", MockClientCallback.CALLBACK_URL_APP1)); + urlParameters.add(new BasicNameValuePair("redirect_uri", oidcApplication.getCallBackURL())); urlParameters.add(new BasicNameValuePair("client_id", oidcApplication.getClientSecret())); urlParameters.add(new BasicNameValuePair("scope", "openid")); @@ -259,9 +259,9 @@ private HttpResponse sendTokenRequestForCodeGrant() throws Exception { private OIDCApplication initOIDCApplication() { - OIDCApplication playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName, + OIDCApplication playgroundApp = new OIDCApplication(MockApplicationServer.Constants.APP1.NAME, OIDCUtilTest.playgroundAppOneAppContext, - MockClientCallback.CALLBACK_URL_APP1); + MockApplicationServer.Constants.APP1.CALLBACK_URL); return playgroundApp; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockClientCallback.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockApplicationServer.java similarity index 57% rename from modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockClientCallback.java rename to modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockApplicationServer.java index b703d0e32b8..df3874f95e5 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockClientCallback.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockApplicationServer.java @@ -19,7 +19,6 @@ package org.wso2.identity.integration.test.base; import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.common.ConsoleNotifier; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.extension.ResponseTransformerV2; import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; @@ -29,6 +28,8 @@ import org.wso2.identity.integration.test.util.Utils; import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; @@ -42,16 +43,47 @@ /** * Mock client callback endpoint to test OIDC related flows. */ -public class MockClientCallback { +public class MockApplicationServer { - public static final String CALLBACK_URL_APP1 = "https://localhost:8091/dummyApp/oauth2client"; - public static final String CALLBACK_URL_APP2 = "https://localhost:8091/dummyApp2/oauth2client"; + public class MockClient { + private final AtomicReference authorizationCode = new AtomicReference<>(); + private final AtomicReference errorCode = new AtomicReference<>(); - private final AtomicReference authorizationCode = new AtomicReference<>(); - private final AtomicReference errorCode = new AtomicReference<>(); + public AtomicReference getAuthorizationCode() { + return authorizationCode; + } + + public AtomicReference getErrorCode() { + return errorCode; + } + } + + public static class Constants { + public static class APP1 { + public static final String CALLBACK_URL = "https://localhost:8091/dummyApp/oauth2client"; + public static final String NAME = "playground.appone"; + public static final String CALLBACK_URL_PATH = "/dummyApp/oauth2client"; + } + + public static class APP2 { + public static final String CALLBACK_URL = "https://localhost:8091/dummyApp2/oauth2client"; + public static final String NAME = "playground.apptwo"; + public static final String CALLBACK_URL_PATH = "/dummyApp2/oauth2client"; + } + } + + private final Map apps = new HashMap<>(); private WireMockServer wireMockServer; + public MockApplicationServer() { + + MockClient app1 = new MockClient(); + MockClient app2 = new MockClient(); + apps.put(Constants.APP1.NAME, app1); + apps.put(Constants.APP2.NAME, app2); + } + public void start() { wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig() @@ -67,7 +99,10 @@ public void start() { @Override public Response transform(Response response, ServeEvent serveEvent) { - authorizationCode.set(serveEvent.getRequest().getQueryParams().get("code").firstValue()); + AtomicReference authorizationCode + = (AtomicReference) serveEvent.getTransformerParameters().get("code"); + authorizationCode.set(serveEvent.getRequest().getQueryParams().get("code") + .firstValue()); return response; } @@ -86,6 +121,8 @@ public String getName() { @Override public Response transform(Response response, ServeEvent serveEvent) { + AtomicReference errorCode + = (AtomicReference) serveEvent.getTransformerParameters().get("error"); errorCode.set(serveEvent.getRequest().getQueryParams().get("error").firstValue()); return response; } @@ -103,8 +140,10 @@ public String getName() { wireMockServer.start(); - // Configure the mock client endpoints. - configureMockEndpoints(); + // Configure the mock client endpoints for App 1 + configureMockEndpointsForApp(Constants.APP1.CALLBACK_URL_PATH, apps.get(Constants.APP1.NAME)); + // Configure the mock client endpoints for App 2 + configureMockEndpointsForApp(Constants.APP2.CALLBACK_URL_PATH, apps.get(Constants.APP2.NAME)); } public void stop() { @@ -114,73 +153,48 @@ public void stop() { } } - private void configureMockEndpoints() { + private void configureMockEndpointsForApp(String urlPath, MockClient app) { try { - // Endpoints for App 1 - wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp/oauth2client")) + wireMockServer.stubFor(get(urlPathEqualTo(urlPath)) .withQueryParam("code", matching(".*")) .willReturn(aResponse() .withTransformers("response-template", "authz-code-transformer") + .withTransformerParameter("code", app.getAuthorizationCode()) + .withTransformerParameter("error", app.getErrorCode()) .withStatus(200))); - wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp/oauth2client")) + wireMockServer.stubFor(post(urlPathEqualTo(urlPath)) .withQueryParam("code", matching(".*")) .willReturn(aResponse() .withTransformers("response-template", "authz-code-transformer") + .withTransformerParameter("code", app.getAuthorizationCode()) + .withTransformerParameter("error", app.getErrorCode()) .withStatus(200))); - wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp/oauth2client")) + wireMockServer.stubFor(get(urlPathEqualTo(urlPath)) .withQueryParam("code", matching(".*")) .withQueryParam("session_state", matching(".*")) .willReturn(aResponse() .withTransformers("response-template", "authz-code-transformer") + .withTransformerParameter("code", app.getAuthorizationCode()) + .withTransformerParameter("error", app.getErrorCode()) .withStatus(200))); - wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp/oauth2client")) + wireMockServer.stubFor(post(urlPathEqualTo(urlPath)) .withQueryParam("code", matching(".*")) .withQueryParam("session_state", matching(".*")) .willReturn(aResponse() .withTransformers("response-template", "authz-code-transformer") + .withTransformerParameter("code", app.getAuthorizationCode()) + .withTransformerParameter("error", app.getErrorCode()) .withStatus(200))); - wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp/oauth2client")) + wireMockServer.stubFor(get(urlPathEqualTo(urlPath)) .withQueryParam("error_description", matching(".*")) .withQueryParam("error", matching(".*")) .willReturn(aResponse() .withTransformers("response-template", "error-code-transformer") + .withTransformerParameter("code", app.getAuthorizationCode()) + .withTransformerParameter("error", app.getErrorCode()) .withStatus(200))); - wireMockServer.stubFor(get(urlEqualTo("/dummyApp/oauth2client")) - .willReturn(aResponse() - .withTransformers("response-template") - .withStatus(200))); - - // Endpoints for App 2 - wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp2/oauth2client")) - .withQueryParam("code", matching(".*")) - .willReturn(aResponse() - .withTransformers("response-template", "authz-code-transformer") - .withStatus(200))); - wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp2/oauth2client")) - .withQueryParam("code", matching(".*")) - .willReturn(aResponse() - .withTransformers("response-template", "authz-code-transformer") - .withStatus(200))); - wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp2/oauth2client")) - .withQueryParam("code", matching(".*")) - .withQueryParam("session_state", matching(".*")) - .willReturn(aResponse() - .withTransformers("response-template", "authz-code-transformer") - .withStatus(200))); - wireMockServer.stubFor(post(urlPathEqualTo("/dummyApp2/oauth2client")) - .withQueryParam("code", matching(".*")) - .withQueryParam("session_state", matching(".*")) - .willReturn(aResponse() - .withTransformers("response-template", "authz-code-transformer") - .withStatus(200))); - wireMockServer.stubFor(get(urlPathEqualTo("/dummyApp2/oauth2client")) - .withQueryParam("error_description", matching(".*")) - .withQueryParam("error", matching(".*")) - .willReturn(aResponse() - .withTransformers("response-template", "error-code-transformer") - .withStatus(200))); - wireMockServer.stubFor(get(urlEqualTo("/dummyApp2/oauth2client")) + wireMockServer.stubFor(get(urlEqualTo(urlPath)) .willReturn(aResponse() .withTransformers("response-template") .withStatus(200))); @@ -189,18 +203,29 @@ private void configureMockEndpoints() { } } - public void verifyForLogoutRedirectionForApp1() { + public void verifyLogoutRedirectionForApp(String appName) { - wireMockServer.verify(getRequestedFor(urlEqualTo("/dummyApp/oauth2client"))); + wireMockServer.verify(getRequestedFor(urlEqualTo(getCallbackUrlPath(appName)))); } - public String getAuthorizationCode() { + public String getAuthorizationCodeForApp(String appName) { - return authorizationCode.get(); + return apps.get(appName).getAuthorizationCode().get(); } - public String getErrorCode() { + public String getErrorCode(String appName) { - return errorCode.get(); + return apps.get(appName).getErrorCode().get(); + } + + private String getCallbackUrlPath(String appName) { + switch (appName) { + case Constants.APP1.NAME: + return Constants.APP1.CALLBACK_URL_PATH; + case Constants.APP2.NAME: + return Constants.APP2.CALLBACK_URL_PATH; + default: + throw new IllegalArgumentException("Unknown app name: " + appName); + } } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java index fb325ebdc0a..83d01d28224 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java @@ -41,7 +41,7 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.wso2.identity.integration.test.base.MockClientCallback; +import org.wso2.identity.integration.test.base.MockApplicationServer; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; @@ -51,7 +51,6 @@ import org.wso2.identity.integration.test.utils.OAuth2Constant; import java.io.BufferedReader; -import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import java.util.ArrayList; @@ -83,7 +82,7 @@ public class OIDCAuthCodeGrantSSOTestCase extends OIDCAbstractIntegrationTest { protected RequestConfig requestConfig; protected HttpClient client; protected List consentParameters = new ArrayList<>(); - private MockClientCallback mockClientCallback; + private MockApplicationServer mockApplicationServer; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -108,8 +107,8 @@ public void testInit() throws Exception { .setDefaultCookieStore(cookieStore) .build(); - mockClientCallback = new MockClientCallback(); - mockClientCallback.start(); + mockApplicationServer = new MockApplicationServer(); + mockApplicationServer.start(); } @@ -119,7 +118,7 @@ public void testClear() throws Exception { deleteUser(user); deleteApplications(); clear(); - mockClientCallback.stop(); + mockApplicationServer.stop(); } @Test(groups = "wso2.is", description = "Test authz endpoint before creating a valid session") @@ -136,7 +135,7 @@ public void testAuthzRequestWithoutValidSessionForIDENTITY5581() throws Exceptio HttpResponse httpResponse = sendGetRequest(client, uri.toString()); EntityUtils.consume(httpResponse.getEntity()); - Assert.assertTrue(mockClientCallback.getErrorCode().contains("login_required")); + Assert.assertTrue(mockApplicationServer.getErrorCode(application.getApplicationName()).contains("login_required")); } @Test(groups = "wso2.is", description = "Initiate authentication request from playground.appone", @@ -314,7 +313,7 @@ private void testConsentApproval(OIDCApplication application) throws Exception { Assert.assertNotNull(response, "Authorization code response is invalid for " + application.getApplicationName()); - authorizationCode = mockClientCallback.getAuthorizationCode(); + authorizationCode = mockApplicationServer.getAuthorizationCodeForApp(application.getApplicationName()); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); EntityUtils.consume(response.getEntity()); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java index 04724bfc2a0..cefc0ef217e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java @@ -32,7 +32,7 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.wso2.identity.integration.test.base.MockClientCallback; +import org.wso2.identity.integration.test.base.MockApplicationServer; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; @@ -65,7 +65,7 @@ public class OIDCRPInitiatedLogoutTestCase extends OIDCAbstractIntegrationTest { protected List consentParameters = new ArrayList<>(); OIDCApplication playgroundAppOne; OIDCApplication playgroundAppTwo; - private MockClientCallback mockClientCallback; + private MockApplicationServer mockApplicationServer; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -93,8 +93,8 @@ public void testInit() throws Exception { .setDefaultRequestConfig(requestConfig) .build(); - mockClientCallback = new MockClientCallback(); - mockClientCallback.start(); + mockApplicationServer = new MockApplicationServer(); + mockApplicationServer.start(); } @AfterClass(alwaysRun = true) @@ -104,7 +104,7 @@ public void testClear() throws Exception { deleteApplication(playgroundAppOne); deleteApplication(playgroundAppTwo); clear(); - mockClientCallback.stop(); + mockApplicationServer.stop(); } @AfterMethod @@ -206,7 +206,8 @@ private void testOIDCLogin(OIDCApplication application, boolean checkConsent) th sessionDataKeyConsent = keyValues.get(0).getValue(); Assert.assertNotNull(sessionDataKeyConsent, "sessionDataKeyConsent is null."); } else { - authorizationCode = new AuthorizationCode(mockClientCallback.getAuthorizationCode()); + authorizationCode = new AuthorizationCode( + mockApplicationServer.getAuthorizationCodeForApp(application.getApplicationName())); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); } @@ -225,7 +226,8 @@ private void testOIDCConsentApproval(OIDCApplication application) throws Excepti EntityUtils.consume(response.getEntity()); response = sendPostRequest(client, locationHeader.getValue()); - authorizationCode = new AuthorizationCode(mockClientCallback.getAuthorizationCode()); + authorizationCode = new AuthorizationCode( + mockApplicationServer.getAuthorizationCodeForApp(application.getApplicationName())); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); EntityUtils.consume(response.getEntity()); @@ -291,7 +293,7 @@ private void testOIDCLogout(boolean checkSuccess, OIDCApplication application, B + "post logout redirect url"); response = sendGetRequest(client, redirectUrl); EntityUtils.consume(response.getEntity()); - mockClientCallback.verifyForLogoutRedirectionForApp1(); + mockApplicationServer.verifyLogoutRedirectionForApp(application.getApplicationName()); } else { Assert.assertTrue(redirectUrl.contains("oauth2_error.do")); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java index 2cadb8e417e..ac33d2b6ef7 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSPWiseSkipLoginConsentTestCase.java @@ -30,7 +30,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.identity.integration.test.base.MockClientCallback; +import org.wso2.identity.integration.test.base.MockApplicationServer; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.AdvancedApplicationConfiguration; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationPatchModel; @@ -47,7 +47,7 @@ public class OIDCSPWiseSkipLoginConsentTestCase extends OIDCAbstractIntegrationT private CookieStore cookieStore = new BasicCookieStore(); protected String sessionDataKey; protected String sessionDataKeyConsent; - private MockClientCallback mockClientCallback; + private MockApplicationServer mockApplicationServer; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -60,8 +60,8 @@ public void testInit() throws Exception { configureSPToSkipConsent(); client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); - mockClientCallback = new MockClientCallback(); - mockClientCallback.start(); + mockApplicationServer = new MockApplicationServer(); + mockApplicationServer.start(); } @AfterClass(alwaysRun = true) @@ -69,7 +69,7 @@ public void clearObjects() throws Exception { deleteObjects(); clear(); - mockClientCallback.stop(); + mockApplicationServer.stop(); } private void deleteObjects() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java index 0aceb4d65eb..c5d2a849ffb 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java @@ -43,7 +43,7 @@ import org.wso2.carbon.automation.engine.context.beans.Tenant; import org.wso2.carbon.automation.engine.context.beans.User; import org.apache.commons.lang.StringUtils; -import org.wso2.identity.integration.test.base.MockClientCallback; +import org.wso2.identity.integration.test.base.MockApplicationServer; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationPatchModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim; @@ -87,7 +87,7 @@ public class OIDCSSOConsentTestCase extends OIDCAbstractIntegrationTest { protected List consentParameters = new ArrayList<>(); OIDCApplication playgroundApp; private String claimsToGetConsent; - private MockClientCallback mockClientCallback; + private MockApplicationServer mockApplicationServer; @BeforeClass(alwaysRun = true) public void testInit() throws Exception { @@ -113,8 +113,8 @@ public void testInit() throws Exception { .setDefaultRequestConfig(requestConfig) .build(); - mockClientCallback = new MockClientCallback(); - mockClientCallback.start(); + mockApplicationServer = new MockApplicationServer(); + mockApplicationServer.start(); } @AfterClass(alwaysRun = true) @@ -123,7 +123,7 @@ public void testClear() throws Exception { deleteUser(user); deleteApplication(playgroundApp); clear(); - mockClientCallback.stop(); + mockApplicationServer.stop(); } @Test(groups = "wso2.is", description = "Test consent management after updating " + @@ -234,7 +234,7 @@ private void testConsentApproval(OIDCApplication application) throws Exception { response = sendPostRequest(client, locationHeader.getValue()); EntityUtils.consume(response.getEntity()); - authorizationCode = mockClientCallback.getAuthorizationCode(); + authorizationCode = mockApplicationServer.getAuthorizationCodeForApp(application.getApplicationName()); Assert.assertNotNull(authorizationCode, "Authorization code not received for " + application .getApplicationName()); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java index 8abbd7ad2f6..63ad1ac394c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java @@ -22,7 +22,7 @@ import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.message.BasicNameValuePair; -import org.wso2.identity.integration.test.base.MockClientCallback; +import org.wso2.identity.integration.test.base.MockApplicationServer; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; @@ -55,15 +55,12 @@ public class OIDCUtilTest { public static final String profile = "default"; protected static String sessionDataKey; - public static final String playgroundAppOneAppName = "playground.appone"; - public static final String playgroundAppOneAppCallBackUri = MockClientCallback.CALLBACK_URL_APP1; - - // TODO find the usages to identify the test cases that initiate the login from the app, instead of sending the - // login request directly to IS. + public static final String playgroundAppOneAppName = MockApplicationServer.Constants.APP1.NAME; + public static final String playgroundAppOneAppCallBackUri = MockApplicationServer.Constants.APP1.CALLBACK_URL; public static final String playgroundAppOneAppContext = "/playground.appone"; - public static final String playgroundAppTwoAppName = "playground.apptwo"; - public static final String playgroundAppTwoAppCallBackUri = MockClientCallback.CALLBACK_URL_APP2; + public static final String playgroundAppTwoAppName = MockApplicationServer.Constants.APP2.NAME; + public static final String playgroundAppTwoAppCallBackUri = MockApplicationServer.Constants.APP2.CALLBACK_URL; public static final String playgroundAppTwoAppContext = "/playground.apptwo"; public static final String targetApplicationUrl = "http://localhost:" + TOMCAT_PORT + "%s"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java index 29a22407833..bb8469f32c4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java @@ -43,7 +43,7 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.wso2.identity.integration.test.base.MockClientCallback; +import org.wso2.identity.integration.test.base.MockApplicationServer; import org.wso2.identity.integration.test.oidc.OIDCAbstractIntegrationTest; import org.wso2.identity.integration.test.oidc.OIDCUtilTest; import org.wso2.identity.integration.test.oidc.bean.OIDCApplication; @@ -75,7 +75,7 @@ public class PasswordRecoveryTestCase extends OIDCAbstractIntegrationTest { private CloseableHttpClient client; private OIDCApplication oidcApplication; private UserObject userObject; - private MockClientCallback mockClientCallback; + private MockApplicationServer mockApplicationServer; public static final String USERNAME = "recoverytestuser"; public static final String PASSWORD = "Oidcsessiontestuser@123"; @@ -108,8 +108,8 @@ public void testInit() throws Exception { userObject = initUser(); createUser(userObject); - mockClientCallback = new MockClientCallback(); - mockClientCallback.start(); + mockApplicationServer = new MockApplicationServer(); + mockApplicationServer.start(); } @AfterClass(alwaysRun = true) @@ -121,7 +121,7 @@ public void testClear() throws Exception { identityGovernanceRestClient.closeHttpClient(); client.close(); Utils.getMailServer().purgeEmailFromAllMailboxes(); - mockClientCallback.stop(); + mockApplicationServer.stop(); } @Test From 9675a7da65030bc8f5f00cf400998ce11e28f86b Mon Sep 17 00:00:00 2001 From: Maduranga Siriwardena Date: Mon, 2 Dec 2024 13:55:34 +0530 Subject: [PATCH 3/4] Refactor code to remove unused references --- .../test/auth/PasswordlessSMSOTPAuthTestCase.java | 1 - .../test/auth/SecondaryStoreUserLoginTestCase.java | 2 +- .../oauth2/OAuth2TokenExchangeGrantTypeTestCase.java | 3 +-- .../test/oidc/OIDCAuthCodeGrantSSOTestCase.java | 3 +-- .../test/oidc/OIDCRPInitiatedLogoutTestCase.java | 2 -- .../test/oidc/OIDCSSOConsentTestCase.java | 1 - .../identity/integration/test/oidc/OIDCUtilTest.java | 8 ++------ .../integration/test/oidc/bean/OIDCApplication.java | 12 +----------- .../test/recovery/PasswordRecoveryTestCase.java | 1 - 9 files changed, 6 insertions(+), 27 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java index c6a6fdb5250..85de57987ae 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/PasswordlessSMSOTPAuthTestCase.java @@ -260,7 +260,6 @@ private HttpResponse sendTokenRequestForCodeGrant() throws Exception { private OIDCApplication initOIDCApplication() { OIDCApplication playgroundApp = new OIDCApplication(MockApplicationServer.Constants.APP1.NAME, - OIDCUtilTest.playgroundAppOneAppContext, MockApplicationServer.Constants.APP1.CALLBACK_URL); return playgroundApp; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java index 598c449f16a..e23be6dec76 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/auth/SecondaryStoreUserLoginTestCase.java @@ -208,7 +208,7 @@ private void checkAuthorizationCode(String sessionDataKeyConsent) throws Excepti private void createAndRegisterPlaygroundApplication() throws Exception { - playgroundApp = new OIDCApplication(PLAYGROUND_APP_NAME, PLAYGROUND_APP_CONTEXT, PLAYGROUND_APP_CALLBACK_URI); + playgroundApp = new OIDCApplication(PLAYGROUND_APP_NAME, PLAYGROUND_APP_CALLBACK_URI); playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri); playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri); playgroundApp.addRequiredClaim(OIDCUtilTest.lastNameClaimUri); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenExchangeGrantTypeTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenExchangeGrantTypeTestCase.java index 13921edf7ae..813b6bbb3be 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenExchangeGrantTypeTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2TokenExchangeGrantTypeTestCase.java @@ -566,8 +566,7 @@ private OAuthConsumerAppDTO getOAuthConsumerAppDTO(OIDCApplication application) private void updateServiceProviderWithOIDCConfigs(int portOffset, String applicationName, ServiceProvider serviceProvider) throws Exception { - OIDCApplication application = new OIDCApplication(applicationName, "/" + applicationName, - OAuth2Constant.CALLBACK_URL); + OIDCApplication application = new OIDCApplication(applicationName, OAuth2Constant.CALLBACK_URL); OAuthConsumerAppDTO appDTO = getOAuthConsumerAppDTO(application); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java index 83d01d28224..221ebf6e788 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCAuthCodeGrantSSOTestCase.java @@ -381,14 +381,13 @@ protected void initUser() throws Exception { protected void initApplications() throws Exception { OIDCApplication playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName, - OIDCUtilTest.playgroundAppOneAppContext, OIDCUtilTest.playgroundAppOneAppCallBackUri); playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri); playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri); playgroundApp.addRequiredClaim(OIDCUtilTest.lastNameClaimUri); applications.put(OIDCUtilTest.playgroundAppOneAppName, playgroundApp); - playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppTwoAppName, OIDCUtilTest.playgroundAppTwoAppContext, + playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppTwoAppName, OIDCUtilTest.playgroundAppTwoAppCallBackUri); playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri); playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java index cefc0ef217e..db6a2b48545 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCRPInitiatedLogoutTestCase.java @@ -314,7 +314,6 @@ protected void initUser() { protected OIDCApplication initApplicationOne() { playgroundAppOne = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName, - OIDCUtilTest.playgroundAppOneAppContext, OIDCUtilTest.playgroundAppOneAppCallBackUri); playgroundAppOne.addRequiredClaim(OIDCUtilTest.emailClaimUri); playgroundAppOne.addRequiredClaim(OIDCUtilTest.firstNameClaimUri); @@ -324,7 +323,6 @@ protected OIDCApplication initApplicationOne() { protected OIDCApplication initApplicationTwo() { playgroundAppTwo = new OIDCApplication(OIDCUtilTest.playgroundAppTwoAppName, - OIDCUtilTest.playgroundAppTwoAppContext, OIDCUtilTest.playgroundAppTwoAppCallBackUri); playgroundAppOne.addRequiredClaim(OIDCUtilTest.emailClaimUri); playgroundAppOne.addRequiredClaim(OIDCUtilTest.firstNameClaimUri); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java index c5d2a849ffb..138cd18c3c6 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCSSOConsentTestCase.java @@ -281,7 +281,6 @@ protected void initUser() throws Exception { protected OIDCApplication initApplication() { playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName, - OIDCUtilTest.playgroundAppOneAppContext, OIDCUtilTest.playgroundAppOneAppCallBackUri); playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri); playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java index 63ad1ac394c..8a5f866d25b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/OIDCUtilTest.java @@ -57,13 +57,9 @@ public class OIDCUtilTest { public static final String playgroundAppOneAppName = MockApplicationServer.Constants.APP1.NAME; public static final String playgroundAppOneAppCallBackUri = MockApplicationServer.Constants.APP1.CALLBACK_URL; - public static final String playgroundAppOneAppContext = "/playground.appone"; public static final String playgroundAppTwoAppName = MockApplicationServer.Constants.APP2.NAME; public static final String playgroundAppTwoAppCallBackUri = MockApplicationServer.Constants.APP2.CALLBACK_URL; - public static final String playgroundAppTwoAppContext = "/playground.apptwo"; - - public static final String targetApplicationUrl = "http://localhost:" + TOMCAT_PORT + "%s"; public static final String emailClaimUri = "http://wso2.org/claims/emailaddress"; public static final String firstNameClaimUri = "http://wso2.org/claims/givenname"; @@ -86,14 +82,14 @@ public static void initUser() { */ public static void initApplications() { - OIDCApplication playgroundApp = new OIDCApplication(playgroundAppOneAppName, playgroundAppOneAppContext, + OIDCApplication playgroundApp = new OIDCApplication(playgroundAppOneAppName, playgroundAppOneAppCallBackUri); playgroundApp.addRequiredClaim(emailClaimUri); playgroundApp.addRequiredClaim(firstNameClaimUri); playgroundApp.addRequiredClaim(lastNameClaimUri); applications.put(playgroundAppOneAppName, playgroundApp); - playgroundApp = new OIDCApplication(playgroundAppTwoAppName, playgroundAppTwoAppContext, + playgroundApp = new OIDCApplication(playgroundAppTwoAppName, playgroundAppTwoAppCallBackUri); playgroundApp.addRequiredClaim(emailClaimUri); playgroundApp.addRequiredClaim(firstNameClaimUri); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/bean/OIDCApplication.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/bean/OIDCApplication.java index c42ecbc0e9e..a71263f1109 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/bean/OIDCApplication.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oidc/bean/OIDCApplication.java @@ -27,7 +27,6 @@ public class OIDCApplication { private String applicationName; private String clientId; private String clientSecret; - private String applicationContext; private String callBackURL; private String subjectClaimURI; private List requiredClaims = null; @@ -36,9 +35,8 @@ public OIDCApplication() { } - public OIDCApplication(String applicationName, String applicationContext, String callBackURL) { + public OIDCApplication(String applicationName, String callBackURL) { this.applicationName = applicationName; - this.applicationContext = applicationContext; this.callBackURL = callBackURL; } @@ -74,14 +72,6 @@ public void setClientSecret(String clientSecret) { this.clientSecret = clientSecret; } - public String getApplicationContext() { - return applicationContext; - } - - public void setApplicationContext(String applicationContext) { - this.applicationContext = applicationContext; - } - public String getCallBackURL() { return callBackURL; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java index bb8469f32c4..c699c6006bd 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/recovery/PasswordRecoveryTestCase.java @@ -201,7 +201,6 @@ private void updatePasswordRecoveryFeatureStatus(boolean enable) throws IOExcept private OIDCApplication initApplication() { OIDCApplication playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName, - OIDCUtilTest.playgroundAppOneAppContext, OIDCUtilTest.playgroundAppOneAppCallBackUri); playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri); playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri); From bec40d4fc7c554ff9e0c95ad32b323819bbd58c2 Mon Sep 17 00:00:00 2001 From: Maduranga Siriwardena Date: Mon, 2 Dec 2024 17:10:36 +0530 Subject: [PATCH 4/4] Minor refactoring --- .../identity/integration/test/base/MockApplicationServer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockApplicationServer.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockApplicationServer.java index df3874f95e5..ab5455d8fd8 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockApplicationServer.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/base/MockApplicationServer.java @@ -41,11 +41,11 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; /** - * Mock client callback endpoint to test OIDC related flows. + * Mock application server to test OIDC related flows. */ public class MockApplicationServer { - public class MockClient { + public static class MockClient { private final AtomicReference authorizationCode = new AtomicReference<>(); private final AtomicReference errorCode = new AtomicReference<>();