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

Improve URL resolving logic of integration tests #17021

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
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 @@ -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 @@ -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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
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.keystore.management.v1.model.CertificateRequest;

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

public class KeystoreMgtRestClient extends RestBaseClient {

private static final String KEYSTORE_BASE_PATH = "t/%s/api/server/v1/keystores/certs";
private static final String KEYSTORE_BASE_PATH = "/api/server/v1/keystores/certs";
private final String serverUrl;
private final String tenantDomain;
private final String username;
Expand All @@ -53,7 +54,7 @@ public KeystoreMgtRestClient(String serverUrl, Tenant tenantInfo) {
*/
public void importCertToStore(CertificateRequest certificateRequest) throws Exception {
String jsonRequest = toJSONString(certificateRequest);
String endPointUrl = serverUrl + String.format(KEYSTORE_BASE_PATH, tenantDomain);
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(KEYSTORE_BASE_PATH, tenantDomain);

try (CloseableHttpResponse response = getResponseOfHttpPost(endPointUrl, jsonRequest, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_CREATED,
Expand All @@ -68,7 +69,8 @@ public void importCertToStore(CertificateRequest certificateRequest) throws Exce
* @return Boolean status of certificate availability in tenant keystore.
*/
public Boolean checkCertInStore(String alias) throws Exception {
String endPointUrl = serverUrl + String.format(KEYSTORE_BASE_PATH, tenantDomain) + PATH_SEPARATOR + alias;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(KEYSTORE_BASE_PATH, tenantDomain)
+ PATH_SEPARATOR + alias;

try (CloseableHttpResponse response = getResponseOfHttpGet(endPointUrl, getHeaders())) {
return response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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.oidc.scope.management.v1.model.ScopeUpdateRequest;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

Expand All @@ -37,7 +38,7 @@

public class OIDCScopeMgtRestClient extends RestBaseClient {
private final String serverUrl;
private final String OIDC_SCOPE_MGT_BASE_PATH = "t/%s/api/server/v1/oidc/scopes";
private final String OIDC_SCOPE_MGT_BASE_PATH = "/api/server/v1/oidc/scopes";
private final String tenantDomain;
private final String username;
private final String password;
Expand All @@ -57,8 +58,8 @@ public OIDCScopeMgtRestClient(String serverUrl, Tenant tenantInfo) {
* @return Scope object.
*/
public JSONObject getScope(String scopeId) throws Exception {
String endPointUrl = serverUrl + String.format(OIDC_SCOPE_MGT_BASE_PATH, tenantDomain) +
PATH_SEPARATOR + scopeId;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(OIDC_SCOPE_MGT_BASE_PATH,
tenantDomain) + PATH_SEPARATOR + scopeId;

try (CloseableHttpResponse response = getResponseOfHttpGet(endPointUrl, getHeaders())) {
return getJSONObject(EntityUtils.toString(response.getEntity()));
Expand All @@ -73,8 +74,8 @@ public JSONObject getScope(String scopeId) throws Exception {
*/
public void updateScope(String scopeId, ScopeUpdateRequest scopeUpdateObj) throws Exception {
String jsonRequest = toJSONString(scopeUpdateObj);
String endPointUrl = serverUrl + String.format(OIDC_SCOPE_MGT_BASE_PATH, tenantDomain) +
PATH_SEPARATOR + scopeId;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(OIDC_SCOPE_MGT_BASE_PATH,
tenantDomain) + PATH_SEPARATOR + scopeId;

try (CloseableHttpResponse response = getResponseOfHttpPut(endPointUrl, jsonRequest, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_OK,
Expand Down