Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove playground.appone and playground.apptwo apps #21865

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions modules/integration/tests-integration/tests-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,6 @@
<goal>run</goal>
</goals>
</execution>
<execution>
<id>packaging-war-artifacts-oidc</id>
<phase>process-test-resources</phase>
<configuration>
<tasks>
<ant antfile="src/test/resources/artifacts/IS/oidc/oidc-sso-app-build.xml" target="playground.appone-app-build" />
<ant antfile="src/test/resources/artifacts/IS/oidc/oidc-sso-app-build.xml" target="playground.apptwo-app-build" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>packaging-war-artifacts-passivests</id>
<phase>process-test-resources</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +90,7 @@ public class PasswordlessSMSOTPAuthTestCase extends OIDCAbstractIntegrationTest
private String authorizationCode;

private MockSMSProvider mockSMSProvider;
private MockClientCallback mockClientCallback;
private MockApplicationServer mockApplicationServer;

private TestUserMode userMode;

Expand All @@ -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();

Expand Down Expand Up @@ -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")
Expand All @@ -189,7 +189,7 @@ private void sendAuthorizeRequest() throws Exception {
List<NameValuePair> 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", oidcApplication.getCallBackURL()));

urlParameters.add(new BasicNameValuePair("scope", "openid"));

Expand All @@ -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);
}

Expand Down Expand Up @@ -241,7 +241,7 @@ private HttpResponse sendTokenRequestForCodeGrant() throws Exception {
List<NameValuePair> 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", oidcApplication.getCallBackURL()));
urlParameters.add(new BasicNameValuePair("client_id", oidcApplication.getClientSecret()));

urlParameters.add(new BasicNameValuePair("scope", "openid"));
Expand All @@ -259,9 +259,8 @@ private HttpResponse sendTokenRequestForCodeGrant() throws Exception {

private OIDCApplication initOIDCApplication() {

OIDCApplication playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName,
OIDCUtilTest.playgroundAppOneAppContext,
MockClientCallback.CALLBACK_URL);
OIDCApplication playgroundApp = new OIDCApplication(MockApplicationServer.Constants.APP1.NAME,
MockApplicationServer.Constants.APP1.CALLBACK_URL);
return playgroundApp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.identity.integration.test.base;

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

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;
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;

/**
* Mock client callback endpoint to test OIDC related flows.
*/
public class MockApplicationServer {

public class MockClient {
private final AtomicReference<String> authorizationCode = new AtomicReference<>();
private final AtomicReference<String> errorCode = new AtomicReference<>();

public AtomicReference<String> getAuthorizationCode() {
return authorizationCode;
}

public AtomicReference<String> 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<String, MockClient> 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()
.httpsPort(8091)
.httpDisabled(true)
.keystorePath(Paths.get(Utils.getResidentCarbonHome(), "repository", "resources", "security",
ISIntegrationTest.KEYSTORE_NAME).toAbsolutePath().toString())
.keystorePassword("wso2carbon")
.keyManagerPassword("wso2carbon")
.extensions(new ResponseTemplateTransformer(null, true, null, null),
new ResponseTransformerV2() {

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

AtomicReference<String> authorizationCode
= (AtomicReference<String>) serveEvent.getTransformerParameters().get("code");
authorizationCode.set(serveEvent.getRequest().getQueryParams().get("code")
.firstValue());
return response;
}

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

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

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

AtomicReference<String> errorCode
= (AtomicReference<String>) serveEvent.getTransformerParameters().get("error");
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();

// 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() {

if (wireMockServer != null) {
wireMockServer.stop();
}
}

private void configureMockEndpointsForApp(String urlPath, MockClient app) {

try {
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(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(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(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(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(urlPath))
.willReturn(aResponse()
.withTransformers("response-template")
.withStatus(200)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public void verifyLogoutRedirectionForApp(String appName) {

wireMockServer.verify(getRequestedFor(urlEqualTo(getCallbackUrlPath(appName))));
}

public String getAuthorizationCodeForApp(String appName) {

return apps.get(appName).getAuthorizationCode().get();
}

public String getErrorCode(String appName) {

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);
}
}
}
Loading