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 Integration Tests for System Defined IdPs #21883

Merged
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 @@ -36,13 +36,15 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.testng.Assert.assertNotNull;

/**
* Test class for Identity Provider Management REST APIs failure paths.
*/
public class IdPFailureTest extends IdPTestBase {

private String idPId;
private static final String OIDC_IDP_ID = "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I";

@Factory(dataProvider = "restAPIUserConfigProvider")
public IdPFailureTest(TestUserMode userMode) throws Exception {
Expand Down Expand Up @@ -179,4 +181,58 @@ public void testPatchIdPNonExistentProperties() throws IOException {
Response response = getResponseOfPatch(IDP_API_BASE_PATH + PATH_SEPARATOR + idPId, body);
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "IDP-65005", "JWKS URI");
}

@Test
public void testUpdateIdPWithDuplicateOIDCScopes() throws IOException {

String body = readResource("add-idp-oidc-standard-based.json");
Response response = getResponseOfPost(IDP_API_BASE_PATH, body);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());

String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
String oidcIdPId = location.substring(location.lastIndexOf("/") + 1);
assertNotNull(oidcIdPId);

// update the OIDC IDP with duplicated scopes
String updateBody = readResource("update-idp-oidc-standard-based-duplicated-scopes.json");
Response updateResponse = getResponseOfPut(IDP_API_BASE_PATH + PATH_SEPARATOR + oidcIdPId +
PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH + PATH_SEPARATOR + OIDC_IDP_ID, updateBody);
updateResponse.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_BAD_REQUEST)
.body("message", equalTo("Duplicate OIDC Scopes."))
.body("description", equalTo("Cannot set scopes in both Scopes and Additional Query Parameters. " +
"Recommend to use Scopes field."));

deleteCreatedIdP(oidcIdPId);
}

/**
* Deletes an Identity Provider by its ID and verifies the deletion.
*
* @param idPId ID of the Identity Provider to be deleted.
*/
private void deleteCreatedIdP(String idPId) {

Response response = getResponseOfDelete(IDP_API_BASE_PATH + PATH_SEPARATOR + idPId);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);

Response responseOfGet = getResponseOfGet(IDP_API_BASE_PATH + PATH_SEPARATOR + idPId);
responseOfGet.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NOT_FOUND)
.body("message", equalTo("Resource not found."))
.body("description", equalTo("Unable to find a resource matching the provided identity " +
"provider identifier " + idPId + "."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
import org.wso2.carbon.automation.engine.context.TestUserMode;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.xml.xpath.XPathExpressionException;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
Expand All @@ -46,6 +49,7 @@ public class IdPSuccessTest extends IdPTestBase {

private String idPId;
private String idPTemplateId;
private static final String IDP_NAME = "Google";

@Factory(dataProvider = "restAPIUserConfigProvider")
public IdPSuccessTest(TestUserMode userMode) throws Exception {
Expand Down Expand Up @@ -310,6 +314,22 @@ public void testGetIdPs() throws Exception {
context.getContextTenant().getDomain())));
}

@Test(dependsOnMethods = "testGetIdP")
public void testSearchAllIdPs() throws XPathExpressionException {

Response response = getResponseOfGetWithQueryParams(IDP_API_BASE_PATH, Collections.singletonMap("filter",
"name sw " + IDP_NAME));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("identityProviders.find { it.id == '" + idPId + "' }.name", equalTo(IDP_NAME))
.body("identityProviders.find { it.id == '" + idPId + "' }.isEnabled", equalTo(true))
.body("identityProviders.find { it.id == '" + idPId + "' }.self", equalTo(getTenantedRelativePath(
"/api/server/v1/identity-providers/" + idPId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check whether there is constant for this "/api/server/v1/identity-providers/"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other similar instances also we have used the same way.

context.getContextTenant().getDomain())));
}

@Test(dependsOnMethods = {"testGetIdPs"})
public void testGetIdPsWithRequiredAttribute() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "OIDC IdP",
Shenali-SJ marked this conversation as resolved.
Show resolved Hide resolved
"alias": "",
"description": "Authenticate users with Enterprise OIDC connections.",
"image": "assets/images/logos/enterprise.svg",
"isPrimary": false,
"roles": {
"mappings": [],
"outboundProvisioningRoles": []
},
"certificate": {
"jwksUri": "https://test.com/jwks",
"certificates": [
""
]
},
"claims": {
"userIdClaim": {
"uri": ""
},
"provisioningClaims": [],
"roleClaim": {
"uri": ""
}
},
"federatedAuthenticators": {
"defaultAuthenticatorId": "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I",
"authenticators": [
{
"isEnabled": true,
"authenticatorId": "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I",
"properties": [
{
"key": "ClientId",
"value": "abcd1234wxyz5678ijklmnopqrst9012"
},
{
"key": "ClientSecret",
"value": "mnop3456qrst1234uvwx5678abcd9012"
},
{
"key": "OAuth2AuthzEPUrl",
"value": "https://test.com/authz"
},
{
"key": "OAuth2TokenEPUrl",
"value": "https://test.com/token"
},
{
"key": "callbackUrl",
"value": "https://test.com/commonauth"
}
]
}
]
},
"homeRealmIdentifier": "",
"isFederationHub": false,
"idpIssuerName": "",
"templateId": "enterprise-oidc-idp"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"authenticatorId": "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I",
"isEnabled": true,
"isDefault": true,
"properties": [
{
"key": "commonAuthQueryParams",
"value": "scope=openid country profile"
},
{
"key": "Scopes",
"value": "openid country profile"
}
]
}