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

Add integration tests for email domain based organization discovery during self-registration feature. #21680

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-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
Expand Down Expand Up @@ -111,6 +111,25 @@ public void deleteExternalClaim(String dialectId, String claimId) throws IOExcep
}
}

/**
* Update the claim referenced by the provided id.
*
* @param dialectId Claim dialect id.
* @param claimId Claim id.
* @param requestBody Request body.
*/
public void updateClaim(String dialectId, String claimId, String requestBody) {

String endPointUrl = serverBasePath + CLAIM_DIALECTS_ENDPOINT_URI + PATH_SEPARATOR + dialectId +
CLAIMS_ENDPOINT_URI + PATH_SEPARATOR + claimId;
try (CloseableHttpResponse response = getResponseOfHttpPut(endPointUrl, requestBody, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_OK,
"Claim update failed");
} catch (IOException e) {
Assert.fail("Error occurred while updating the claim.");
}
}

public void updateExternalClaim(String dialectId, String claimId, ExternalClaimReq claimRequest) throws IOException {

String endPointUrl = serverBasePath + CLAIM_DIALECTS_ENDPOINT_URI + PATH_SEPARATOR + dialectId +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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.restclients;

import io.restassured.http.ContentType;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
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 java.io.IOException;

import javax.servlet.http.HttpServletResponse;

/**
* Rest client for organization discovery configuration management API.
*/
public class OrgDiscoveryConfigRestClient extends RestBaseClient {

private static final String API_BASE_PATH = "api/server/v1";
private static final String ORGANIZATION_CONFIG_PATH = "/organization-configs";
private static final String ORGANIZATIONS_PATH = "/organizations";
private static final String DISCOVERY_PATH = "/discovery";

private final String username;
private final String password;
private final String serverBasePath;

public OrgDiscoveryConfigRestClient(String backendURL, Tenant tenantInfo) {

this.username = tenantInfo.getContextUser().getUserName();
this.password = tenantInfo.getContextUser().getPassword();

String tenantDomain = tenantInfo.getContextUser().getUserDomain();
this.serverBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(API_BASE_PATH, tenantDomain);
}

/**
* Add organization discovery config to the root organization.
*
* @param requestBody Request body.
*/
public void addOrganizationDiscoveryConfig(String requestBody) {

try (CloseableHttpResponse httpResponse = getResponseOfHttpPost(
serverBasePath + ORGANIZATION_CONFIG_PATH + DISCOVERY_PATH, requestBody, getHeaders())) {
Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpServletResponse.SC_CREATED,
"Failed to add organization discovery config.");
} catch (IOException e) {
throw new RuntimeException("Error occurred while adding organization discovery config.", e);
}
}

/**
* Delete organization discovery config of the root organization.
*/
public void deleteOrganizationDiscoveryConfig() {

try (CloseableHttpResponse httpResponse = getResponseOfHttpDelete(
serverBasePath + ORGANIZATION_CONFIG_PATH + DISCOVERY_PATH, getHeaders())) {
Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpServletResponse.SC_NO_CONTENT,
"Failed to delete organization discovery config.");
} catch (IOException e) {
throw new RuntimeException("Error occurred while deleting organization discovery config.", e);
}
}

/**
* Map discovery attributes to an organization.
*
* @param orgId Organization ID.
* @param requestBody Request body.
*/
public void mapDiscoveryAttributes(String orgId, String requestBody) {

String endpointUrl = serverBasePath + ORGANIZATIONS_PATH + PATH_SEPARATOR + orgId + DISCOVERY_PATH;
try (CloseableHttpResponse httpResponse = getResponseOfHttpPut(endpointUrl, requestBody, getHeaders())) {
Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpServletResponse.SC_OK,
"Failed to map discovery attributes.");
} catch (IOException e) {
throw new RuntimeException("Error occurred while mapping discovery attributes.", e);
}
}

public void closeHttpClient() throws IOException {

client.close();
}

private Header[] getHeaders() {

return new Header[]{
new BasicHeader(CONTENT_TYPE_ATTRIBUTE, String.valueOf(ContentType.JSON)),
new BasicHeader(AUTHORIZATION_ATTRIBUTE, BASIC_AUTHORIZATION_ATTRIBUTE +
Base64.encodeBase64String((username + ":" + password).getBytes()).trim())
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[server]
hostname = "localhost"
node_ip = "127.0.0.1"
base_path = "https://$ref{server.hostname}:${carbon.management.port}"

[super_admin]
username = "admin"
password = "admin"
create_admin_account = true

[user_store]
type = "database_unique_id"

[database.identity_db]
type = "h2"
url = "jdbc:h2:./repository/database/WSO2IDENTITY_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000"
username = "wso2carbon"
password = "wso2carbon"

[database.shared_db]
type = "h2"
url = "jdbc:h2:./repository/database/WSO2SHARED_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000"
username = "wso2carbon"
password = "wso2carbon"

[keystore.primary]
file_name = "wso2carbon.p12"
password = "wso2carbon"
type="PKCS12"

[truststore]
file_name="client-truststore.p12"
password="wso2carbon"
type="PKCS12"

[account_recovery.endpoint.auth]
hash= "66cd9688a2ae068244ea01e70f0e230f5623b7fa4cdecb65070a09ec06452262"

[identity.auth_framework.endpoint]
app_password= "dashboard"

[tenant_mgt]
enable_email_domain= true

[identity_mgt.user_self_registration]
allow_self_registration = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"claimURI": "http://wso2.org/claims/username",
"description": "Username",
"displayOrder": 0,
"displayName": "Username",
"readOnly": false,
"required": false,
"supportedByDefault": false,
"attributeMapping": [
{
"mappedAttribute": "mail",
"userstore": "PRIMARY"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"properties": [
{
"key": "emailDomain.enable",
"value": "true"
},
{
"key": "emailDomainBasedSelfSignup.enable",
"value": "true"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"attributes": [
{
"type": "emailDomain",
"values": [
"wso2.com"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"/api/server/v1/organizations": [
"internal_organization_view",
"internal_organization_create",
"internal_organization_delete"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"claimURI": "http://wso2.org/claims/username",
"description": "Username",
"displayOrder": 0,
"displayName": "Username",
"readOnly": false,
"required": false,
"supportedByDefault": false,
"attributeMapping": [
{
"mappedAttribute": "uid",
"userstore": "PRIMARY"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@
<class name="org.wso2.identity.integration.test.oauth2.OAuth2TokenScopeValidatorTestCase" />
<class name="org.wso2.identity.integration.test.saml.SAMLSSOForAdminLoginTestCase"/>
<class name="org.wso2.identity.integration.test.oauth2.OAuthAppsWithSameClientIdTestCase"/>
<class name="org.wso2.identity.integration.test.organizationDiscovery.OrganizationDiscoveryTestCase"/>
</classes>
</test>

Expand Down