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 13de9c49d13..5d1924b2af3 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 @@ -35,6 +35,7 @@ import org.wso2.identity.integration.test.rest.api.server.idp.v1.util.UserDefinedAuthenticatorPayload; import java.io.IOException; +import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -53,13 +54,13 @@ public class IdPSuccessTest extends IdPTestBase { private String idPTemplateId; private UserDefinedAuthenticatorPayload userDefinedAuthenticatorPayload; private String idpCreatePayload; - private static final String FEDERATED_AUTHENTICATOR_ID_PLACEHOLDER = ""; private static final String FEDERATED_AUTHENTICATOR_PLACEHOLDER = "\"\""; private static final String IDP_NAME_PLACEHOLDER = ""; - private static final String FEDERATED_AUTHENTICATOR_ID = "Y3VzdG9tQXV0aGVudGljYXRvcg=="; + private static final String FEDERATED_AUTHENTICATOR_ID = "Y3VzdG9tQXV0aGVudGljYXRvcg"; private static final String IDP_NAME = "Custom Auth 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"; private static final String PASSWORD = "password"; private static final String USERNAME_VALUE = "testUser"; @@ -75,6 +76,15 @@ public IdPSuccessTest(TestUserMode userMode) throws Exception { this.tenant = context.getContextTenant().getDomain(); } + @DataProvider(name = "restAPIUserConfigProvider") + public static Object[][] restAPIUserConfigProvider() { + + return new Object[][]{ + {TestUserMode.SUPER_TENANT_ADMIN}, + {TestUserMode.TENANT_ADMIN} + }; + } + @BeforeClass(alwaysRun = true) public void init() throws IOException { @@ -105,6 +115,27 @@ private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayload() return userDefinedAuthenticatorPayload; } + private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayload(String endpointUri) { + + UserDefinedAuthenticatorPayload userDefinedAuthenticatorPayload = new UserDefinedAuthenticatorPayload(); + userDefinedAuthenticatorPayload.setIsEnabled(true); + userDefinedAuthenticatorPayload.setAuthenticatorId(FEDERATED_AUTHENTICATOR_ID); + userDefinedAuthenticatorPayload.setDefinedBy(FederatedAuthenticatorRequest.DefinedByEnum.USER.toString()); + + Endpoint endpoint = new Endpoint(); + endpoint.setUri(endpointUri); + AuthenticationType authenticationType = new AuthenticationType(); + authenticationType.setType(AuthenticationType.TypeEnum.BASIC); + Map properties = new HashMap<>(); + properties.put(USERNAME, USERNAME_VALUE); + properties.put(PASSWORD, PASSWORD_VALUE); + authenticationType.setProperties(properties); + endpoint.authentication(authenticationType); + userDefinedAuthenticatorPayload.setEndpoint(endpoint); + + return userDefinedAuthenticatorPayload; + } + @AfterClass(alwaysRun = true) public void testConclude() { @@ -123,15 +154,6 @@ public void testFinish() { RestAssured.basePath = StringUtils.EMPTY; } - @DataProvider(name = "restAPIUserConfigProvider") - public static Object[][] restAPIUserConfigProvider() { - - return new Object[][]{ - {TestUserMode.SUPER_TENANT_ADMIN}, - {TestUserMode.TENANT_ADMIN} - }; - } - @Test public void testListMetaFederatedAuthenticators() throws Exception { @@ -319,6 +341,60 @@ public void testAddIdPWithUserDefinedAuthenticator() throws IOException { assertNotNull(customIdPId); } + @Test(dependsOnMethods = "testAddIdPWithUserDefinedAuthenticator") + public void testGetUserDefinedAuthenticatorsOfIdP() { + + Response response = getResponseOfGet(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId + + PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH); + + response.then() + .log().ifValidationFails() + .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)); + } + + @Test(dependsOnMethods = "testAddIdPWithUserDefinedAuthenticator") + public void testUpdateUserDefinedAuthenticatorOfIdP() { + + // TODO: check the OpenAPI validation + // The following patch request fails from OpenAPI validations, as the response object does not contains + // "authentication" field in the "endpoint" object. + Response response = getResponseOfPut(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId + + PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH + PATH_SEPARATOR + FEDERATED_AUTHENTICATOR_ID, + createUserDefinedAuthenticatorPayload(UPDATED_ENDPOINT_URI).toString()); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("authenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID)) + .body("name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID)))) + .body("endpoint.uri", equalTo(UPDATED_ENDPOINT_URI)); + } + + @Test(dependsOnMethods = "testAddIdPWithUserDefinedAuthenticator") + public void testDeleteUserDefinedAuthenticatorOfIdP() throws IOException { + + // TODO: check the behaviour of the DELETE functionality + // When a put request is tried with empty authenticators list, postman request is successful + // but this put request fails from openAPI validation saying + // "Provided request body content is not in the expected format." + Response response = getResponseOfPut(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId + + PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH + PATH_SEPARATOR + + FEDERATED_AUTHENTICATOR_ID, readResource("empty-custom-fed-auth.json")); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) // Receiving 400 + .body("authenticators", nullValue()); + } + @Test(dependsOnMethods = {"testGetMetaOutboundConnector"}) public void testAddIdP() throws IOException { diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/idp/v1/empty-custom-fed-auth.json b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/idp/v1/empty-custom-fed-auth.json new file mode 100644 index 00000000000..b519af81612 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/idp/v1/empty-custom-fed-auth.json @@ -0,0 +1,4 @@ +{ + "authenticators": [], + "defaultAuthenticatorId": "" +} \ No newline at end of file