Skip to content

Commit

Permalink
Merge pull request #17138 from ImalshaG/fix-integration-tests-1
Browse files Browse the repository at this point in the history
Improve Tenanted URL Resolving Logic of Integration Tests
  • Loading branch information
ImalshaG authored Oct 24, 2023
2 parents 8d8741f + 9f44a5a commit 0e2c3b6
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public String getTenantQualifiedURL(String endpointURL, String tenantDomain) {
* @param tenantDomain Tenanted domain.
* @return Tenant qualified URL without hostname.
*/
public String getTenantedRelativePath(String endpointURLWithHostname, String tenantDomain) {
public static String getTenantedRelativePath(String endpointURLWithHostname, String tenantDomain) {

if(!tenantDomain.isBlank() && !tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
endpointURLWithHostname = TENANTED_URL_PATH_SPECIFIER + tenantDomain + endpointURLWithHostname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class OAuth2ScopesTestCase extends ISIntegrationTest {
public void testInit() throws Exception {
super.init();
String isServerBackendUrl = isServer.getContextUrls().getWebAppURLHttps();
scopeEndpoint = isServerBackendUrl + "/t/" + isServer.getContextTenant().getDomain() + SCOPE_ENDPOINT_SUFFIX;
scopeEndpoint = isServerBackendUrl +
getTenantedRelativePath(SCOPE_ENDPOINT_SUFFIX, isServer.getContextTenant().getDomain());
}

@AfterClass(alwaysRun = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class OAuth2ServiceJWTGrantTestCase extends OAuth2ServiceAbstractIntegrat
private static final String USERS_PATH = "users";
private static final String BEGIN_CERTIFICATE = "-----BEGIN CERTIFICATE-----\n";
private static final String END_CERTIFICATE = "\n-----END CERTIFICATE-----";
private static final String JWKS_BASE_PATH = "t/%s/oauth2/jwks";
private static final String JWKS_BASE_PATH = "/oauth2/jwks";
private static final String COUNTRY_CLAIM_VALUE = "USA";
private static final String COUNTRY_OIDC_CLAIM = "country";
private static final String COUNTRY_NEW_OIDC_CLAIM = "customclaim";
Expand Down Expand Up @@ -517,7 +517,7 @@ private void addFederatedIdentityProvider() throws Exception {
*/
private String getEncodedCertificate() throws Exception {
CloseableHttpClient client = HttpClients.createDefault();
String jwksEndpoint = serverURL + String.format(JWKS_BASE_PATH, tenantInfo.getDomain());
String jwksEndpoint = serverURL + getTenantedRelativePath(JWKS_BASE_PATH, tenantInfo.getDomain());
String certificate = BEGIN_CERTIFICATE + getPublicCertificate(client, jwksEndpoint) + END_CERTIFICATE;

return new String(Base64.getEncoder().encode(certificate.getBytes(StandardCharsets.UTF_8)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class RESTTestBase extends ISIntegrationTest {
+ File.separator + "deployment" + File.separator + "server" + File.separator + "webapps" + File
.separator + "api" + File.separator + "WEB-INF" + File.separator
+ "lib" + File.separator;
protected static final String TENANT_CONTEXT_IN_URL = "/t/%s";
private static final String JAR_EXTENSION = ".jar";
protected static final String SERVICES = "/services";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.wso2.identity.integration.test.rest.api.server.common;

import org.apache.axis2.AxisFault;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.common.RESTTestBase;

import java.rmi.RemoteException;
Expand All @@ -29,15 +30,13 @@ public class RESTAPIServerTestBase extends RESTTestBase {

protected static final String API_SERVER_BASE_PATH = "/api/server/%s";
protected static final String API_SERVER_BASE_PATH_IN_SWAGGER = "/t/\\{tenant-domain\\}" + API_SERVER_BASE_PATH;
protected static final String API_SERVER_BASE_PATH_WITH_TENANT_CONTEXT =
TENANT_CONTEXT_IN_URL + API_SERVER_BASE_PATH;

protected void testInit(String apiVersion, String apiDefinition, String tenantDomain)
throws RemoteException {

String basePathInSwagger = String.format(API_SERVER_BASE_PATH_IN_SWAGGER, apiVersion);
String basePath = String.format(API_SERVER_BASE_PATH_WITH_TENANT_CONTEXT,
tenantDomain, apiVersion);
String basePath = ISIntegrationTest.getTenantedRelativePath(String.format(API_SERVER_BASE_PATH, apiVersion),
tenantDomain);
super.init(apiDefinition, basePathInSwagger, basePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class UserAuthorizedAppsBaseTest extends RESTAPIUserTestBase {
static String API_PACKAGE_NAME = "org.wso2.carbon.identity.rest.api.user.authorized.apps.v1";

public static final String AUTHORIZED_APPS_ENDPOINT_URI = "/%s/authorized-apps/";
public static final String DCR_ENDPOINT_PATH_URI = "/t/%s/api/identity/oauth2/dcr/v1.1/register/";
public static final String DCR_ENDPOINT_PATH_URI = "/api/identity/oauth2/dcr/v1.1/register/";

protected String userAuthorizedAppsEndpointUri;
protected String dcrEndpointUri;
Expand All @@ -58,7 +58,7 @@ public class UserAuthorizedAppsBaseTest extends RESTAPIUserTestBase {
void initUrls(String pathParam) {

this.userAuthorizedAppsEndpointUri = String.format(AUTHORIZED_APPS_ENDPOINT_URI, pathParam);
this.dcrEndpointUri = String.format(DCR_ENDPOINT_PATH_URI, tenant);
this.dcrEndpointUri = getTenantedRelativePath(DCR_ENDPOINT_PATH_URI, tenant);
this.tokenEndpointUri = getTenantedRelativePath("/oauth2/token", tenant);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class UserAuthorizedAppsBaseTest extends RESTAPIUserTestBase {

public static final String AUTHORIZED_APPS_ENDPOINT_URI = "/%s/authorized-apps/";
public static final String APPLICATION_ENDPOINT_URI = "/authorized-apps/%s/tokens";
public static final String DCR_ENDPOINT_PATH_URI = "/t/%s/api/identity/oauth2/dcr/v1.1/register/";
public static final String DCR_ENDPOINT_PATH_URI = "/api/identity/oauth2/dcr/v1.1/register/";

protected String userAuthorizedAppsEndpointUri;
protected String userApplicationEndpointUri;
Expand All @@ -64,7 +64,7 @@ void initUrls(String pathParam) {

this.userAuthorizedAppsEndpointUri = String.format(AUTHORIZED_APPS_ENDPOINT_URI, pathParam);
this.userApplicationEndpointUri = APPLICATION_ENDPOINT_URI;
this.dcrEndpointUri = String.format(DCR_ENDPOINT_PATH_URI, tenant);
this.dcrEndpointUri = getTenantedRelativePath(DCR_ENDPOINT_PATH_URI, tenant);
this.tokenEndpointUri = getTenantedRelativePath("/oauth2/token", tenant);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty;
import org.wso2.carbon.integration.common.admin.client.AuthenticatorClient;
import org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.common.RESTTestBase;

/**
Expand All @@ -34,7 +35,6 @@ public class RESTAPIUserTestBase extends RESTTestBase {

protected static final String API_USERS_BASE_PATH = "/api/users/%s";
protected static final String API_USERS_BASE_PATH_IN_SWAGGER = "/t/\\{tenant-domain\\}" + API_USERS_BASE_PATH;
protected static final String API_USERS_BASE_PATH_WITH_TENANT_CONTEXT = TENANT_CONTEXT_IN_URL + API_USERS_BASE_PATH;
private static final String ADMIN = "admin";
private IdentityProviderMgtServiceClient superTenantIDPMgtClient;
private IdentityProviderMgtServiceClient tenantIDPMgtClient;
Expand All @@ -45,8 +45,8 @@ protected void testInit(String apiVersion, String apiDefinition, String tenantDo
throws XPathExpressionException, RemoteException {

String basePathInSwagger = String.format(API_USERS_BASE_PATH_IN_SWAGGER, apiVersion);
String basePath = String.format(API_USERS_BASE_PATH_WITH_TENANT_CONTEXT,
tenantDomain, apiVersion);
String basePath = ISIntegrationTest.getTenantedRelativePath(String.format(API_USERS_BASE_PATH, apiVersion),
tenantDomain);
super.init(apiDefinition, basePathInSwagger, basePath);
}

Expand All @@ -64,8 +64,8 @@ protected void testInit(String apiVersion, String apiDefinition, String tenantDo
throws XPathExpressionException, RemoteException {

String basePathInSwagger = String.format(apiUserBasePathInSwagger, apiVersion);
String basePath = String.format(apiUserBasePathWithTenantContext,
tenantDomain, apiVersion);
String basePath = ISIntegrationTest.getTenantedRelativePath(String.format(apiUserBasePathWithTenantContext,
apiVersion), tenantDomain);
super.init(apiDefinition, basePathInSwagger, basePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ public class LiteUserRegisterTestCase extends LiteUserRegisterTestBase {
protected static final String API_LITE_USER_REGISTER_BASE_PATH = "/api/identity/user/%s";
protected static final String API_LITE_USER_REGISTER_BASE_PATH_IN_SWAGGER =
"/t/\\{tenant-domain\\}" + API_LITE_USER_REGISTER_BASE_PATH;
protected static final String API_LITE_USER_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT =
TENANT_CONTEXT_IN_URL + API_LITE_USER_REGISTER_BASE_PATH;
protected static final String API_VERSION_LITE_USER = "v1.0";

@BeforeClass(alwaysRun = true)
public void init() throws Exception {

super.testInit(API_VERSION_LITE_USER, swaggerDefinitionLiteUserRegister, tenant,
API_LITE_USER_REGISTER_BASE_PATH_IN_SWAGGER, API_LITE_USER_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT);
API_LITE_USER_REGISTER_BASE_PATH_IN_SWAGGER, API_LITE_USER_REGISTER_BASE_PATH);
}

@BeforeMethod(alwaysRun = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void init() throws Exception {
this.tenant = context.getContextTenant().getDomain();

super.testInit(API_VERSION_SELF_REGISTER, swaggerDefinitionSelfRegister, tenant,
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT);
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH);
selfRegisterUserInfo = readResource("self-register-tenanted-user-request-body.json");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class SelfRegisterTestBase extends RESTAPIUserTestBase {
protected static final String API_SELF_REGISTER_BASE_PATH = "/api/identity/user/%s";
protected static final String API_SELF_REGISTER_BASE_PATH_IN_SWAGGER =
"/t/\\{tenant-domain\\}" + API_SELF_REGISTER_BASE_PATH;
protected static final String API_SELF_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT =
TENANT_CONTEXT_IN_URL + API_SELF_REGISTER_BASE_PATH;
protected static final String API_VERSION_SELF_REGISTER = "v1.0";

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void init() throws Exception {
this.tenant = context.getContextTenant().getDomain();

super.testInit(API_VERSION_SELF_REGISTER, swaggerDefinitionSelfRegister, tenant,
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT);
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH);
selfRegisterUserInfo = readResource("self-register-request-body.json");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.http.message.BasicHeader;
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.challenge.v1.model.UserChallengeAnswer;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

Expand Down Expand Up @@ -57,8 +58,8 @@ public void setChallengeQuestionAnswer(String userId, String questionSetId,
UserChallengeAnswer challengeAsnwerObj) throws Exception {

String jsonRequest = toJSONString(challengeAsnwerObj);
String endPointUrl = serverUrl + TENANT_PATH + tenantDomain + PATH_SEPARATOR +
String.format(CHALLENGE_QUESTION_BASE_PATH, userId) + PATH_SEPARATOR + questionSetId;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(String.format(
CHALLENGE_QUESTION_BASE_PATH, userId) + PATH_SEPARATOR + questionSetId, tenantDomain);

try (CloseableHttpResponse response = getResponseOfHttpPost(endPointUrl, jsonRequest, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_CREATED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import org.json.simple.JSONObject;
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.claim.management.v1.model.ExternalClaimReq;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ClaimManagementRestClient extends RestBaseClient {

private static final String TENANT_PATH = "t/%s";
private static final String API_SERVER_BASE_PATH = "/api/server/v1";
private static final String CLAIM_DIALECTS_ENDPOINT_URI = "/claim-dialects";

Expand All @@ -54,7 +54,7 @@ public ClaimManagementRestClient(String backendURL, Tenant tenantInfo) {

String tenantDomain = tenantInfo.getContextUser().getUserDomain();

serverBasePath = backendURL + String.format(TENANT_PATH, tenantDomain) + API_SERVER_BASE_PATH;
serverBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(API_SERVER_BASE_PATH, tenantDomain);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;

import java.io.IOException;

public class EmailTemplatesRestClient extends RestBaseClient {

private static final String TENANT_PATH = "t/%s";
private static final String API_SERVER_BASE_PATH = "/api/server/v1";
private static final String EMAIL_TEMPLATES_EMAIL_BASE_PATH = "/email";
private static final String EMAIL_TEMPLATE_TYPES_PATH = "/template-types";
Expand All @@ -51,8 +52,8 @@ public EmailTemplatesRestClient(String backendURL, Tenant tenantInfo) {

String tenantDomain = tenantInfo.getContextUser().getUserDomain();

emailTemplateApiBasePath = backendURL + String.format(TENANT_PATH, tenantDomain) + API_SERVER_BASE_PATH +
EMAIL_TEMPLATES_EMAIL_BASE_PATH + EMAIL_TEMPLATE_TYPES_PATH;
emailTemplateApiBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(API_SERVER_BASE_PATH
+ EMAIL_TEMPLATES_EMAIL_BASE_PATH + EMAIL_TEMPLATE_TYPES_PATH, tenantDomain);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import org.apache.http.message.BasicHeader;
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.ConnectorsPatchReq;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class IdentityGovernanceRestClient extends RestBaseClient {

private static final String TENANT_PATH = "t/%s";
private static final String API_SERVER_BASE_PATH = "/api/server/v1";
private static final String IDENTITY_GOVERNANCE_BASE_PATH = "/identity-governance";
private static final String CONNECTORS_BASE_PATH = "/connectors";
Expand All @@ -54,8 +54,8 @@ public IdentityGovernanceRestClient(String backendURL, Tenant tenantInfo) {

String tenantDomain = tenantInfo.getContextUser().getUserDomain();

identityGovernanceApiBasePath = backendURL + String.format(TENANT_PATH, tenantDomain) + API_SERVER_BASE_PATH +
IDENTITY_GOVERNANCE_BASE_PATH;
identityGovernanceApiBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(
API_SERVER_BASE_PATH + IDENTITY_GOVERNANCE_BASE_PATH, tenantDomain);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.json.simple.JSONObject;
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.idp.v1.model.Claims;
import org.wso2.identity.integration.test.rest.api.server.idp.v1.model.IdentityProviderPOSTRequest;
import org.wso2.identity.integration.test.utils.OAuth2Constant;
Expand All @@ -38,7 +39,7 @@ public class IdpMgtRestClient extends RestBaseClient {
private static final String CLAIMS_PATH = "/claims";
private static final String FEDERATED_AUTHENTICATORS_PATH = "/federated-authenticators/";
private final String serverUrl;
private final String IDENTITY_PROVIDER_BASE_PATH = "t/%s/api/server/v1/identity-providers";
private final String IDENTITY_PROVIDER_BASE_PATH = "/api/server/v1/identity-providers";
private final String tenantDomain;
private final String username;
private final String password;
Expand All @@ -58,7 +59,7 @@ public IdpMgtRestClient(String serverUrl, Tenant tenantInfo) {
*/
public String createIdentityProvider(IdentityProviderPOSTRequest idpCreateReqObj) throws Exception {
String jsonRequest = toJSONString(idpCreateReqObj);
String endPointUrl = serverUrl + String.format(IDENTITY_PROVIDER_BASE_PATH, tenantDomain);
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(IDENTITY_PROVIDER_BASE_PATH, tenantDomain);

try (CloseableHttpResponse response = getResponseOfHttpPost(endPointUrl, jsonRequest, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_CREATED,
Expand All @@ -76,8 +77,8 @@ public String createIdentityProvider(IdentityProviderPOSTRequest idpCreateReqObj
* @return JSONObject with Federated Authenticator details.
*/
public JSONObject getIdpFederatedAuthenticator(String idpId, String federatedAuthenticatorId) throws Exception {
String endPointUrl = serverUrl + String.format(IDENTITY_PROVIDER_BASE_PATH, tenantDomain)+ PATH_SEPARATOR +
idpId + FEDERATED_AUTHENTICATORS_PATH + federatedAuthenticatorId;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(IDENTITY_PROVIDER_BASE_PATH,
tenantDomain) + PATH_SEPARATOR + idpId + FEDERATED_AUTHENTICATORS_PATH + federatedAuthenticatorId;

try (CloseableHttpResponse response = getResponseOfHttpGet(endPointUrl, getHeaders())) {
String responseBody = EntityUtils.toString(response.getEntity());
Expand All @@ -93,8 +94,8 @@ public JSONObject getIdpFederatedAuthenticator(String idpId, String federatedAut
*/
public void updateIdpClaimConfig(String idpId, Claims idpClaims) throws IOException {
String jsonRequest = toJSONString(idpClaims);
String endPointUrl = serverUrl + String.format(IDENTITY_PROVIDER_BASE_PATH, tenantDomain) + PATH_SEPARATOR +
idpId + CLAIMS_PATH;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(IDENTITY_PROVIDER_BASE_PATH,
tenantDomain) + PATH_SEPARATOR + idpId + CLAIMS_PATH;

try (CloseableHttpResponse response = getResponseOfHttpPut(endPointUrl, jsonRequest, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_OK,
Expand All @@ -108,8 +109,8 @@ public void updateIdpClaimConfig(String idpId, Claims idpClaims) throws IOExcept
* @param idpId Identity Provider Id
*/
public void deleteIdp(String idpId) throws IOException {
String endPointUrl = serverUrl + String.format(IDENTITY_PROVIDER_BASE_PATH, tenantDomain) + PATH_SEPARATOR +
idpId;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(IDENTITY_PROVIDER_BASE_PATH,
tenantDomain) + PATH_SEPARATOR + idpId;

try (CloseableHttpResponse response = getResponseOfHttpDelete(endPointUrl, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_NO_CONTENT,
Expand Down
Loading

0 comments on commit 0e2c3b6

Please sign in to comment.