Skip to content

Commit

Permalink
Merge pull request #16238 from hwupathum/api-integration-test
Browse files Browse the repository at this point in the history
Create integration test for SAML SSO update endpoint
  • Loading branch information
hwupathum authored Jul 13, 2023
2 parents 372017b + aacf21f commit f24a914
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.wso2.carbon.automation.engine.context.TestUserMode;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.wso2.identity.integration.test.rest.api.server.application.management.v1.Utils.assertNotBlank;
import static org.wso2.identity.integration.test.rest.api.server.application.management.v1.Utils.extractApplicationIdFromLocationHeader;
Expand All @@ -37,27 +38,33 @@ public class ApplicationManagementSAMLSuccessTest extends ApplicationManagementB
private static final String MANUAL_CONFIG_ISSUER = "https://sp.wso2.com";

private String samlAppPostRequest;
private String samlAppPutRequest;
private String createdAppId;
private String expectedIssuer;

@Factory(dataProvider = "restAPIUserConfigProvider")
public ApplicationManagementSAMLSuccessTest(TestUserMode userMode, String samlAppPostRequest,
public ApplicationManagementSAMLSuccessTest(TestUserMode userMode, String samlAppPostRequest, String samlAppPutRequest,
String expectedIssuer) throws Exception {

super(userMode);
this.samlAppPostRequest = samlAppPostRequest;
this.expectedIssuer = expectedIssuer;
this.samlAppPutRequest = samlAppPutRequest;
}

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

return new Object[][]{
{TestUserMode.SUPER_TENANT_ADMIN, "create-saml-app-with-metadata-file.json", META_DATA_FILE_ISSUER},
{TestUserMode.SUPER_TENANT_ADMIN, "create-saml-app-with-manual-config.json", MANUAL_CONFIG_ISSUER},

{TestUserMode.TENANT_ADMIN, "create-saml-app-with-metadata-file.json", META_DATA_FILE_ISSUER},
{TestUserMode.TENANT_ADMIN, "create-saml-app-with-manual-config.json", MANUAL_CONFIG_ISSUER}
{TestUserMode.SUPER_TENANT_ADMIN, "create-saml-app-with-metadata-file.json",
"update-saml-app-with-metadata-file.json", META_DATA_FILE_ISSUER},
{TestUserMode.SUPER_TENANT_ADMIN, "create-saml-app-with-manual-config.json",
"update-saml-app-with-manual-config.json", MANUAL_CONFIG_ISSUER},

{TestUserMode.TENANT_ADMIN, "create-saml-app-with-metadata-file.json",
"update-saml-app-with-metadata-file.json", META_DATA_FILE_ISSUER},
{TestUserMode.TENANT_ADMIN, "create-saml-app-with-manual-config.json",
"update-saml-app-with-manual-config.json", MANUAL_CONFIG_ISSUER}
};
}

Expand Down Expand Up @@ -90,7 +97,31 @@ public void testGetSAMLInboundDetails() throws Exception {
.body("issuer", equalTo(expectedIssuer));
}

@Test(dependsOnMethods = "testGetSAMLInboundDetails")
@Test(dependsOnMethods = "testGetSAMLInboundDetails", description = "Test to verify the SAML inbound update")
public void testUpdateSAMLInbound() throws Exception {

String path = APPLICATION_MANAGEMENT_API_BASE_PATH + "/" + createdAppId + "/inbound-protocols/saml";

String body = readResource(samlAppPutRequest);

Response responseOfPut = getResponseOfPut(path, body);
responseOfPut.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK);

// Verify the updated details
Response responseOfGet = getResponseOfGet(path);
responseOfGet.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK).and()
.body("defaultAssertionConsumerUrl", equalTo("https://saml.wso2.com/acs3")).and()
.body("assertionConsumerUrls", hasSize(3)).and()
.body("requestValidation.enableSignatureValidation", equalTo(false));
}

@Test(dependsOnMethods = "testUpdateSAMLInbound", description = "Test to verify the SAML inbound delete")
public void testDeleteSAMLInbound() throws Exception {

String path = APPLICATION_MANAGEMENT_API_BASE_PATH + "/" + createdAppId + "/inbound-protocols/saml";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"manualConfiguration": {
"issuer": "https://sp.wso2.com",
"assertionConsumerUrls": [
"https://saml.wso2.com/acs1",
"https://saml.wso2.com/acs2",
"https://saml.wso2.com/acs3"
],
"defaultAssertionConsumerUrl": "https://saml.wso2.com/acs3",
"idpEntityIdAlias": "https://localhost/myidp",
"singleSignOnProfile": {
"bindings": [
"HTTP_POST",
"HTTP_REDIRECT",
"ARTIFACT"
],
"enableSignatureValidationForArtifactBinding": true,
"attributeConsumingServiceIndex": "480766126",
"enableIdpInitiatedSingleSignOn": true,
"assertion": {
"nameIdFormat": "urn/oasis/names/tc/SAML/1.1/nameid-format/unspecified",
"audiences": [],
"recipients": [],
"digestAlgorithm": "http://www.w3.org/2000/09/xmldsig#sha1",
"encryption": {
"enabled": false,
"assertionEncryptionAlgorithm": "http://www.w3.org/2001/04/xmlenc#aes256-cbc",
"keyEncryptionAlgorithm": "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"
}
}
},
"attributeProfile": {
"enabled": true,
"alwaysIncludeAttributesInResponse": true
},
"singleLogoutProfile": {
"enabled": true,
"logoutRequestUrl": "https://saml.wso2.com/slo",
"logoutMethod": "BACKCHANNEL",
"idpInitiatedSingleLogout": {
"enabled": false,
"returnToUrls": []
}
},
"requestValidation": {
"enableSignatureValidation": false,
"signatureValidationCertAlias": "wso2carbon"
},
"responseSigning": {
"enabled": false,
"signingAlgorithm": "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
},
"enableAssertionQueryProfile": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"metadataFile": "PD94bWwgdmVyc2lvbj0iMS4wIj8+CjxtZDpFbnRpdHlEZXNjcmlwdG9yIHhtbG5zOm1kPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6bWV0YWRhdGEiCiAgICAgICAgICAgICAgICAgICAgIHZhbGlkVW50aWw9IjIwMTktMTItMDVUMTY6NDk6NDRaIgogICAgICAgICAgICAgICAgICAgICBjYWNoZUR1cmF0aW9uPSJQVDYwNDgwMFMiCiAgICAgICAgICAgICAgICAgICAgIGVudGl0eUlEPSJodHRwczovL3NhbWwud3NvMi5jb20iPgogICAgPG1kOlNQU1NPRGVzY3JpcHRvciBXYW50QXNzZXJ0aW9uc1NpZ25lZD0idHJ1ZSIgcHJvdG9jb2xTdXBwb3J0RW51bWVyYXRpb249InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCI+CiAgICAgICAgPG1kOlNpbmdsZUxvZ291dFNlcnZpY2UgQmluZGluZz0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmJpbmRpbmdzOkhUVFAtUmVkaXJlY3QiCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgTG9jYXRpb249Imh0dHBzOi8vc2FtbC53c28yLmNvbS9zbG8iIC8+CiAgICAgICAgPG1kOk5hbWVJREZvcm1hdD51cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoxLjE6bmFtZWlkLWZvcm1hdDp1bnNwZWNpZmllZDwvbWQ6TmFtZUlERm9ybWF0PgogICAgICAgIDxtZDpBc3NlcnRpb25Db25zdW1lclNlcnZpY2UgQmluZGluZz0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmJpbmRpbmdzOkhUVFAtUE9TVCIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIExvY2F0aW9uPSJodHRwczovL3NhbWwud3NvMi5jb20vYWNzMyIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGluZGV4PSIxIiAvPgogICAgICAgIDxtZDpBc3NlcnRpb25Db25zdW1lclNlcnZpY2UgQmluZGluZz0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmJpbmRpbmdzOkhUVFAtUE9TVCIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIExvY2F0aW9uPSJodHRwczovL3NhbWwud3NvMi5jb20vYWNzMiIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGluZGV4PSIyIiAvPgogICAgICAgIDxtZDpBc3NlcnRpb25Db25zdW1lclNlcnZpY2UgQmluZGluZz0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmJpbmRpbmdzOkhUVFAtUE9TVCIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIExvY2F0aW9uPSJodHRwczovL3NhbWwud3NvMi5jb20vYWNzMSIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGluZGV4PSIzIiAvPgoKICAgIDwvbWQ6U1BTU09EZXNjcmlwdG9yPgo8L21kOkVudGl0eURlc2NyaXB0b3I+Cg=="
}

0 comments on commit f24a914

Please sign in to comment.