diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/idp/v1/IdPSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/idp/v1/IdPSuccessTest.java index c4b59dd883..3b32c0d64d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/idp/v1/IdPSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/idp/v1/IdPSuccessTest.java @@ -23,7 +23,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; -import org.hamcrest.Matchers; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; @@ -46,6 +45,8 @@ import javax.xml.xpath.XPathExpressionException; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.emptyIterable; +import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNull.nullValue; import static org.testng.Assert.assertNotNull; @@ -63,7 +64,10 @@ public class IdPSuccessTest extends IdPTestBase { private static final String OIDC_SCOPES_PLACEHOLDER = "\"\""; private static final String AUTHENTICATOR_PROPERTIES_PLACEHOLDER = "\"\""; private static final String FEDERATED_AUTHENTICATOR_ID = "Y3VzdG9tQXV0aGVudGljYXRvcg"; + private static final String OIDC_AUTHENTICATOR_ID = "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I"; + private static final String SAML_AUTHENTICATOR_ID = "U0FNTFNTT0F1dGhlbnRpY2F0b3I"; private static final String CUSTOM_IDP_NAME = "Custom Auth IDP"; + private static final String SAML_IDP_NAME = "SAML IdP"; private static final String ENDPOINT_URI = "https://abc.com/authenticate"; private static final String UPDATED_ENDPOINT_URI = "https://xyz.com/authenticate"; private static final String USERNAME = "username"; @@ -76,6 +80,8 @@ public class IdPSuccessTest extends IdPTestBase { private static final String TRUSTED_TOKEN_ISS_IDP_NAME = "Trusted Token Issuer IdP"; private static final String AUTHENTICATOR_NAME = "GoogleOIDCAuthenticator"; private static final String DEFINED_BY_SYSTEM = "SYSTEM"; + private static final String DEFINED_BY_USER = "USER"; + private static final String CUSTOM_TAGS = "Custom"; private UserDefinedAuthenticatorPayload userDefinedAuthenticatorPayload; private String idpCreatePayload; private String idPId; @@ -337,19 +343,30 @@ public void testGetMetaOutboundConnector() throws IOException { } @Test - public void testAddIdPWithUserDefinedAuthenticator() throws IOException { + public void testAddIdPWithUserDefinedAuthenticator() throws IOException, XPathExpressionException { + + String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" + + FEDERATED_AUTHENTICATOR_ID + "' }."; String body = idpCreatePayload.replace(FEDERATED_AUTHENTICATOR_ID_PLACEHOLDER, userDefinedAuthenticatorPayload.getAuthenticatorId()); body = body.replace(FEDERATED_AUTHENTICATOR_PLACEHOLDER, userDefinedAuthenticatorPayload.convertToJasonPayload()); body = body.replace(IDP_NAME_PLACEHOLDER, CUSTOM_IDP_NAME); + Response response = getResponseOfPost(IDP_API_BASE_PATH, body); response.then() .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_CREATED) - .header(HttpHeaders.LOCATION, notNullValue()); + .header(HttpHeaders.LOCATION, notNullValue()) + .body("name", equalTo(CUSTOM_IDP_NAME)) + .body(baseIdentifier + "authenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID)) + .body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID)))) + .body(baseIdentifier + "isEnabled", equalTo(true)) + .body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_USER)) + .body(baseIdentifier + "tags", hasItems(CUSTOM_TAGS)) + .body(baseIdentifier + "self", notNullValue()); String location = response.getHeader(HttpHeaders.LOCATION); assertNotNull(location); @@ -360,6 +377,7 @@ public void testAddIdPWithUserDefinedAuthenticator() throws IOException { @Test(dependsOnMethods = "testAddIdPWithUserDefinedAuthenticator") public void testGetUserDefinedAuthenticatorsOfIdP() throws XPathExpressionException { + String baseIdentifier = "authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }."; Response response = getResponseOfGet(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId + PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH); @@ -368,18 +386,18 @@ public void testGetUserDefinedAuthenticatorsOfIdP() throws XPathExpressionExcept .assertThat() .statusCode(HttpStatus.SC_OK) .body("defaultAuthenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID)) - .body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.name", - equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID)))) - .body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.isEnabled", - equalTo(true)) - .body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.self", - equalTo(getTenantedRelativePath("/api/server/v1/identity-providers/" + - customIdPId + "/federated-authenticators/" + FEDERATED_AUTHENTICATOR_ID, - context.getContextTenant().getDomain()))); + .body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID)))) + .body(baseIdentifier + "isEnabled", equalTo(true)) + .body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_USER)) + .body(baseIdentifier + "tags", hasItems(CUSTOM_TAGS)) + .body(baseIdentifier + "self", equalTo(getTenantedRelativePath( + "/api/server/v1/identity-providers/" + customIdPId + + "/federated-authenticators/" + FEDERATED_AUTHENTICATOR_ID, + context.getContextTenant().getDomain()))); } @Test(dependsOnMethods = "testGetUserDefinedAuthenticatorsOfIdP") - public void testUpdateUserDefinedAuthenticatorOfIdP() throws JsonProcessingException { + public void testUpdateUserDefinedAuthenticatorOfIdP() throws JsonProcessingException, XPathExpressionException { Response response = getResponseOfPut(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId + PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH + PATH_SEPARATOR + FEDERATED_AUTHENTICATOR_ID, @@ -392,7 +410,9 @@ public void testUpdateUserDefinedAuthenticatorOfIdP() throws JsonProcessingExcep .statusCode(HttpStatus.SC_OK) .body("authenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID)) .body("name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID)))) - .body("definedBy", equalTo("USER")) + .body("isEnabled", equalTo(true)) + .body("definedBy", equalTo(DEFINED_BY_USER)) + .body("tags", hasItems(CUSTOM_TAGS)) .body("endpoint.uri", equalTo(UPDATED_ENDPOINT_URI)) .body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.value())); } @@ -419,7 +439,10 @@ public void testDeleteIdPWithUserDefinedAuthenticator() { } @Test(dependsOnMethods = {"testGetMetaOutboundConnector"}) - public void testAddIdP() throws IOException { + public void testAddIdP() throws IOException, XPathExpressionException { + + String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" + + SAMPLE_FEDERATED_AUTHENTICATOR_ID + "' }."; String addIdpPayload = readResource("add-idp.json"); String properties = convertDuplicatedPropertiesToJson( @@ -431,7 +454,14 @@ public void testAddIdP() throws IOException { .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_CREATED) - .header(HttpHeaders.LOCATION, notNullValue()); + .header(HttpHeaders.LOCATION, notNullValue()) + .body("name", equalTo(IDP_NAME)) + .body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder(). + decode(SAMPLE_FEDERATED_AUTHENTICATOR_ID)))) + .body(baseIdentifier + "isEnabled", equalTo(true)) + .body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM)) + .body(baseIdentifier + "tags", hasItems("Social-Login", "APIAuth")) + .body(baseIdentifier + "self", notNullValue()); String location = response.getHeader(HttpHeaders.LOCATION); assertNotNull(location); @@ -448,7 +478,7 @@ public void addIdPWithoutAuthenticator() throws IOException { .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_CREATED) - .body("federatedAuthenticators.authenticators", Matchers.emptyIterable()) + .body("federatedAuthenticators.authenticators", emptyIterable()) .header(HttpHeaders.LOCATION, notNullValue()); String location = response.getHeader(HttpHeaders.LOCATION); @@ -467,6 +497,9 @@ public void addIdPWithoutAuthenticator() throws IOException { @Test public void addIdPWithDuplicatedOIDCScopes() throws IOException { + String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" + + OIDC_AUTHENTICATOR_ID + "' }."; + String oidcIdpPayload = readResource("add-oidc-idp.json"); String oidcScopesProperties = convertDuplicatedPropertiesToJson( createAuthenticatorProperties("Scopes","openid country profile"), @@ -479,7 +512,14 @@ public void addIdPWithDuplicatedOIDCScopes() throws IOException { .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_CREATED) - .header(HttpHeaders.LOCATION, notNullValue()); + .header(HttpHeaders.LOCATION, notNullValue()) + .body("name", equalTo("OIDC-IdP-1")) + .body(baseIdentifier + "authenticatorId", equalTo(OIDC_AUTHENTICATOR_ID)) + .body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(OIDC_AUTHENTICATOR_ID)))) + .body(baseIdentifier + "isEnabled", equalTo(true)) + .body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM)) + .body(baseIdentifier + "tags", hasItems("OIDC", "APIAuth")) + .body(baseIdentifier + "self", notNullValue()); String location = response.getHeader(HttpHeaders.LOCATION); assertNotNull(location); @@ -496,6 +536,9 @@ public void addIdPWithDuplicatedOIDCScopes() throws IOException { @Test(dependsOnMethods = "addIdPWithDuplicatedOIDCScopes") public void addOIDCIdPWithoutOpenidScope() throws IOException { + String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" + + OIDC_AUTHENTICATOR_ID + "' }."; + String oidcIdpPayload = readResource("add-oidc-idp.json"); String oidcScopesProperties = convertDuplicatedPropertiesToJson( createAuthenticatorProperties("Scopes","country profile"), null); @@ -507,7 +550,14 @@ public void addOIDCIdPWithoutOpenidScope() throws IOException { .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_CREATED) - .header(HttpHeaders.LOCATION, notNullValue()); + .header(HttpHeaders.LOCATION, notNullValue()) + .body("name", equalTo("OIDC-IdP-2")) + .body(baseIdentifier + "authenticatorId", equalTo(OIDC_AUTHENTICATOR_ID)) + .body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(OIDC_AUTHENTICATOR_ID)))) + .body(baseIdentifier + "isEnabled", equalTo(true)) + .body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM)) + .body(baseIdentifier + "tags", hasItems("OIDC", "APIAuth")) + .body(baseIdentifier + "self", notNullValue()); String location = response.getHeader(HttpHeaders.LOCATION); assertNotNull(location); @@ -518,7 +568,10 @@ public void addOIDCIdPWithoutOpenidScope() throws IOException { } @Test - public void addSAMLStandardBasedIdP() throws IOException { + public void addSAMLStandardBasedIdP() throws IOException, XPathExpressionException { + + String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" + + SAML_AUTHENTICATOR_ID + "' }."; String samlIdpPayload = readResource("add-saml-idp.json"); String body = samlIdpPayload.replace(METADATA_SAML_PLACEHOLDER, loadMetadataSamlFile( @@ -529,7 +582,14 @@ public void addSAMLStandardBasedIdP() throws IOException { .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_CREATED) - .header(HttpHeaders.LOCATION, notNullValue()); + .header(HttpHeaders.LOCATION, notNullValue()) + .body("name", equalTo(SAML_IDP_NAME)) + .body(baseIdentifier + "authenticatorId", equalTo(SAML_AUTHENTICATOR_ID)) + .body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(SAML_AUTHENTICATOR_ID)))) + .body(baseIdentifier + "isEnabled", equalTo(true)) + .body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM)) + .body(baseIdentifier + "tags", hasItems("SAML")) + .body(baseIdentifier + "self", notNullValue()); String location = response.getHeader(HttpHeaders.LOCATION); assertNotNull(location); @@ -540,7 +600,10 @@ public void addSAMLStandardBasedIdP() throws IOException { } @Test(dependsOnMethods = {"testAddIdP"}) - public void testGetIdP() throws IOException { + public void testGetIdP() throws IOException, XPathExpressionException { + + String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" + + SAMPLE_FEDERATED_AUTHENTICATOR_ID + "' }."; Response response = getResponseOfGet(IDP_API_BASE_PATH + PATH_SEPARATOR + idPId); response.then() @@ -552,8 +615,14 @@ public void testGetIdP() throws IOException { .body("description", equalTo("IDP for Google Federation")) .body("isEnabled", equalTo(true)) .body("isPrimary", equalTo(false)) - .body("federatedAuthenticators.authenticators.find { it.authenticatorId == '" + - SAMPLE_FEDERATED_AUTHENTICATOR_ID + "' }.definedBy", equalTo("SYSTEM")) + .body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder(). + decode(SAMPLE_FEDERATED_AUTHENTICATOR_ID)))) + .body(baseIdentifier + "isEnabled", equalTo(true)) + .body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM)) + .body(baseIdentifier + "tags", hasItems("Social-Login", "APIAuth")) + .body(baseIdentifier + "self", equalTo(getTenantedRelativePath( + "/api/server/v1/identity-providers/" + idPId + "/federated-authenticators/" + + SAMPLE_FEDERATED_AUTHENTICATOR_ID, context.getContextTenant().getDomain()))) .body("image", equalTo("google-logo-url")) .body("isFederationHub", equalTo(false)) .body("homeRealmIdentifier", equalTo("localhost")) @@ -646,7 +715,9 @@ public void testGetIdPFederatedAuthenticators() throws Exception { .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_OK) + .body(baseIdentifier + "authenticatorId", equalTo(SAMPLE_FEDERATED_AUTHENTICATOR_ID)) .body(baseIdentifier + "name", equalTo("GoogleOIDCAuthenticator")) + .body(baseIdentifier + "tags", hasItems("Social-Login", "APIAuth")) .body(baseIdentifier + "isEnabled", equalTo(true)) .body(baseIdentifier + "self", equalTo(getTenantedRelativePath( "/api/server/v1/identity-providers/" + idPId + "/federated-authenticators/" + diff --git a/pom.xml b/pom.xml index 125973638c..38e08404fc 100755 --- a/pom.xml +++ b/pom.xml @@ -2468,7 +2468,7 @@ 2.0.17 - 1.3.12 + 1.3.15 1.3.46 5.5.9