Skip to content
Open
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 @@ -898,9 +898,11 @@ public static String getBasePath(String tenantDomain, String context, boolean is
}
}
} else {
// A configured server URL is a bare base URL, so qualify it with the tenant here unless it
// already carries one.
if (StringUtils.isNotBlank(tenantDomain) && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME
.equalsIgnoreCase(tenantDomain) && isEndpointTenantAware
&& !isServerURLAlreadyTenanted(tenantDomain)) {
&& !serverUrl.contains(FrameworkConstants.TENANT_CONTEXT_PREFIX)) {
basePath = serverUrl + FrameworkConstants.TENANT_CONTEXT_PREFIX + tenantDomain + context;
} else {
basePath = serverUrl + context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,62 @@
}
}

@DataProvider(name = "getBasePathConfiguredServerUrlData")
public Object[][] getBasePathConfiguredServerUrlData() {

return new Object[][] {
// contextUrl (configured server URL)
// tenantDomain
// isEndpointTenantAware
// inboundPath (stubbed serviceURL.getPath() - already tenant-qualified, the case that regressed)
// expected value

// A configured server URL is tenant-qualified even when the inbound request path already
// carries the tenant (the fix - the tenant must not be dropped here).
{ "https://foo.com",
SAMPLE_TENANT_DOMAIN,
true,
"/t/test.com/api/identity/recovery/v0.9",
"https://foo.com/t/test.com/api/identity/recovery/v0.9"
},
// Configured server URL already carries a tenant: no second /t/ prefix is added.
{ "https://foo.com/t/test.com",
SAMPLE_TENANT_DOMAIN,
true,
"/t/test.com/api/identity/recovery/v0.9",
"https://foo.com/t/test.com/api/identity/recovery/v0.9"
},
// Super tenant: no /t/ prefix.
{ "https://foo.com",
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
true,
"/t/carbon.super/api/identity/recovery/v0.9",
"https://foo.com/api/identity/recovery/v0.9"
},
// Not endpoint-tenant-aware: no /t/ prefix.
{ "https://foo.com",
SAMPLE_TENANT_DOMAIN,
false,
"/t/test.com/api/identity/recovery/v0.9",
"https://foo.com/api/identity/recovery/v0.9"
}
};
}

@Test(dataProvider = "getBasePathConfiguredServerUrlData")
public void testGetBasePathConfiguredServerUrl(String contextUrl, String tenantDomain,
boolean isEndpointTenantAware, String inboundPath, String expected) throws Exception {

String context = IdentityManagementEndpointConstants.UserInfoRecovery.RECOVERY_API_RELATIVE_PATH;
try (MockedStatic<IdentityTenantUtil> identityTenantUtil = mockStatic(IdentityTenantUtil.class);
MockedStatic<ServiceURLBuilder> serviceURLBuilder = mockStatic(ServiceURLBuilder.class)) {

Check warning on line 424 in components/identity-mgt/org.wso2.carbon.identity.mgt.endpoint.util/src/test/java/org/wso2/carbon/identity/mgt/endpoint/util/IdentityManagementEndpointUtilTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename "serviceURLBuilder" which hides the field declared at line 81.

See more on https://sonarcloud.io/project/issues?id=wso2_carbon-identity-framework&issues=AZ88F1aH1D_n3LGawGGY&open=AZ88F1aH1D_n3LGawGGY&pullRequest=8196
prepareGetBasePathTest(contextUrl, context, identityTenantUtil, serviceURLBuilder, true, false);
lenient().when(serviceURL.getPath()).thenReturn(inboundPath);
assertEquals(IdentityManagementEndpointUtil.getBasePath(tenantDomain, context, isEndpointTenantAware),
expected);
}
}

@DataProvider(name = "getBasePathUseOrgHandleFalseTestData")
public Object[][] getBasePathUseOrgHandleFalseTestData() {

Expand Down
Loading