From c9023f01d12bbb645461b924db091b17536f89b8 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Mon, 18 Sep 2023 12:42:48 +0530 Subject: [PATCH 1/2] Add common methods to get tenant qualified URLs. --- .../common/utils/ISIntegrationTest.java | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java index 95a3cf7c940..f1471f3ada4 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java @@ -20,16 +20,18 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.configurations.UrlGenerationUtil; import org.wso2.carbon.automation.engine.context.AutomationContext; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.engine.context.beans.ContextUrls; +import org.wso2.carbon.automation.engine.context.beans.Instance; import org.wso2.carbon.automation.engine.context.beans.Tenant; import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil; import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; import org.wso2.carbon.integration.common.admin.client.AuthenticatorClient; import org.wso2.carbon.integration.common.utils.LoginLogoutClient; -import org.wso2.carbon.utils.CarbonUtils; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.xml.xpath.XPathExpressionException; import java.io.File; @@ -37,6 +39,9 @@ public class ISIntegrationTest { public static final String URL_SEPARATOR = "/"; + public static final String TENANTED_URL_PATH_SPECIFIER = "/t/"; + private static final String PRODUCT_GROUP_PORT_HTTPS = "https"; + protected Log log = LogFactory.getLog(getClass()); protected AutomationContext isServer; protected String backendURL; @@ -143,6 +148,62 @@ public void setSystemproperties() { System.setProperty("javax.net.ssl.trustStoreType", "JKS"); } + + /** + * Get the qualified endpoint URL with the hostname for the given tenant. + * + * @param endpointURL The endpoint URL with the hostname. + * @param tenantDomain Tenanted domain. + * @return Tenant qualified URL. + */ + public String getTenantQualifiedURL(String endpointURL, String tenantDomain) { + + try { + if(!tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String baseURL = getBaseURL(); + endpointURL = endpointURL.replace(baseURL, baseURL + TENANTED_URL_PATH_SPECIFIER + tenantDomain); + } + return endpointURL; + } catch (XPathExpressionException e) { + throw new RuntimeException(e); + } + } + + /** + * Get the qualified endpoint URL without the hostname for the given tenant. + * + * @param endpointURLWithHostname The endpoint URL without the hostname. + * @param tenantDomain Tenanted domain. + * @return Tenant qualified URL without hostname. + */ + public String getTenantQualifiedURLWithoutHostName(String endpointURLWithHostname, String tenantDomain) { + + if(!tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + endpointURLWithHostname = TENANTED_URL_PATH_SPECIFIER + tenantDomain + endpointURLWithHostname; + } + return endpointURLWithHostname; + } + + /** + * Get the based URL eg: https://localhost:9443. + * + * @return The base URL. + */ + private String getBaseURL() throws XPathExpressionException { + + String baseURL; + Instance instance = isServer.getInstance(); + String httpsPort = isServer.getInstance().getPorts().get(PRODUCT_GROUP_PORT_HTTPS); + String hostName = UrlGenerationUtil.getWorkerHost(instance); + + if(httpsPort != null) { + baseURL = PRODUCT_GROUP_PORT_HTTPS + "://" + hostName + ":" + httpsPort; + } else { + baseURL = PRODUCT_GROUP_PORT_HTTPS + "://" + hostName; + } + return baseURL; + } + // protected void addJDBCUserStore(String dbURI, String driverName, String userName, String password, // boolean disabled, String description, String domainName) throws Exception { // UserStoreConfigAdminServiceClient userStoreConfigurationClient = From fb8c8d4154bb869eb070374dde7ee5a4f1065ea0 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Thu, 21 Sep 2023 15:02:11 +0530 Subject: [PATCH 2/2] Add common methods to get tenant qualified URLs. --- .../common/utils/ISIntegrationTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java index f1471f3ada4..02ca8a12146 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/identity/integration/common/utils/ISIntegrationTest.java @@ -159,9 +159,12 @@ public void setSystemproperties() { public String getTenantQualifiedURL(String endpointURL, String tenantDomain) { try { - if(!tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + if(!tenantDomain.isBlank() && !tenantDomain.equalsIgnoreCase( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String baseURL = getBaseURL(); - endpointURL = endpointURL.replace(baseURL, baseURL + TENANTED_URL_PATH_SPECIFIER + tenantDomain); + endpointURL = endpointURL.replace(baseURL, + baseURL + TENANTED_URL_PATH_SPECIFIER + tenantDomain); } return endpointURL; } catch (XPathExpressionException e) { @@ -178,7 +181,7 @@ public String getTenantQualifiedURL(String endpointURL, String tenantDomain) { */ public String getTenantQualifiedURLWithoutHostName(String endpointURLWithHostname, String tenantDomain) { - if(!tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + if(!tenantDomain.isBlank() && !tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { endpointURLWithHostname = TENANTED_URL_PATH_SPECIFIER + tenantDomain + endpointURLWithHostname; } return endpointURLWithHostname; @@ -191,17 +194,14 @@ public String getTenantQualifiedURLWithoutHostName(String endpointURLWithHostnam */ private String getBaseURL() throws XPathExpressionException { - String baseURL; Instance instance = isServer.getInstance(); String httpsPort = isServer.getInstance().getPorts().get(PRODUCT_GROUP_PORT_HTTPS); String hostName = UrlGenerationUtil.getWorkerHost(instance); if(httpsPort != null) { - baseURL = PRODUCT_GROUP_PORT_HTTPS + "://" + hostName + ":" + httpsPort; - } else { - baseURL = PRODUCT_GROUP_PORT_HTTPS + "://" + hostName; + return PRODUCT_GROUP_PORT_HTTPS + "://" + hostName + ":" + httpsPort; } - return baseURL; + return PRODUCT_GROUP_PORT_HTTPS + "://" + hostName; } // protected void addJDBCUserStore(String dbURI, String driverName, String userName, String password,