From 9cd66d3545f9f774e5469fd26c38560452f52fb7 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Wed, 18 Dec 2024 09:28:45 +0530 Subject: [PATCH 1/4] Add integration tests for /authenticator/meta/tags endpoint. --- .../v1/AuthenticatorSuccessTest.java | 31 ++++++++++++++++++- .../management/v1/AuthenticatorTestBase.java | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java index f06582739f..a72bf1d881 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java @@ -24,7 +24,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; -import org.checkerframework.checker.units.qual.A; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONArray; @@ -46,6 +45,7 @@ import java.io.IOException; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.*; import static org.hamcrest.core.IsNull.notNullValue; /** @@ -57,6 +57,8 @@ public class AuthenticatorSuccessTest extends AuthenticatorTestBase { private UserDefinedLocalAuthenticatorCreation creationPayload; private UserDefinedLocalAuthenticatorUpdate updatePayload; + private final String CUSTOM_TAG = "Custom"; + @Factory(dataProvider = "restAPIUserConfigProvider") public AuthenticatorSuccessTest(TestUserMode userMode) throws Exception { @@ -127,6 +129,30 @@ public void getAuthenticators() throws JSONException { } @Test(dependsOnMethods = {"getAuthenticators"}) + public void testGetMetaTags() throws JsonProcessingException { + + Response responseBefore = getResponseOfGet(AUTHENTICATOR_META_TAGS_PATH); + responseBefore.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("$", not(hasItem(CUSTOM_TAG))); + + getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, + UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload)); + + Response responseAfter = getResponseOfGet(AUTHENTICATOR_META_TAGS_PATH); + responseAfter.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("$", hasItem(CUSTOM_TAG)); + + getResponseOfDelete(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId); + } + + @Test(dependsOnMethods = {"testGetMetaTags"}) public void testCreateUserDefinedLocalAuthenticator() throws JsonProcessingException { String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); @@ -142,6 +168,7 @@ public void testCreateUserDefinedLocalAuthenticator() throws JsonProcessingExcep .body("type", equalTo("LOCAL")) .body("definedBy", equalTo("USER")) .body("isEnabled", equalTo(true)) + .body("tags", hasItems(CUSTOM_TAG)) .body("self", equalTo(getTenantedRelativePath( AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); } @@ -166,6 +193,7 @@ public void getUserDefinedLocalAuthenticators() throws JSONException { Assert.assertEquals(authenticator.getString("displayName"), AUTHENTICATOR_DISPLAY_NAME); Assert.assertEquals(authenticator.getString("type"), "LOCAL"); Assert.assertTrue(authenticator.getBoolean("isEnabled")); + Assert.assertTrue(authenticator.getString("tags").contains(CUSTOM_TAG)); Assert.assertEquals(authenticator.getString("self"), getTenantedRelativePath(AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant)); } @@ -192,6 +220,7 @@ public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingExcep .body("type", equalTo("LOCAL")) .body("definedBy", equalTo("USER")) .body("isEnabled", equalTo(false)) + .body("tags", hasItems(CUSTOM_TAG)) .body("self", equalTo(getTenantedRelativePath( AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java index 4503f72501..846eef15ea 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java @@ -42,6 +42,7 @@ public class AuthenticatorTestBase extends RESTAPIServerTestBase { protected static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.authenticators.v1"; protected static final String AUTHENTICATOR_API_BASE_PATH = "/authenticators"; + protected static final String AUTHENTICATOR_META_TAGS_PATH = "/authenticators/meta/tags"; protected static final String AUTHENTICATOR_CUSTOM_API_BASE_PATH = "/authenticators/custom"; protected static final String AUTHENTICATOR_CONFIG_API_BASE_PATH = "/api/server/v1/configs/authenticators/"; protected static final String PATH_SEPARATOR = "/"; From dab35c5c5fefa1d734d4e27b85b0153ffb687e09 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Wed, 18 Dec 2024 10:36:42 +0530 Subject: [PATCH 2/4] Bump dependency versions. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 51ee47a759..49cafe8fdb 100755 --- a/pom.xml +++ b/pom.xml @@ -2356,7 +2356,7 @@ - 7.7.45 + 7.7.46 [5.14.67, 8.0.0) @@ -2468,7 +2468,7 @@ 2.0.17 - 1.3.12 + 1.3.13 1.3.46 5.5.9 From d21f0ebe31a56e6f093fce8803bc4aad255f1550 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Wed, 18 Dec 2024 10:53:23 +0530 Subject: [PATCH 3/4] Address comments. --- .../v1/AuthenticatorSuccessTest.java | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java index a72bf1d881..72ad959d4e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java @@ -45,7 +45,8 @@ import java.io.IOException; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; import static org.hamcrest.core.IsNull.notNullValue; /** @@ -58,6 +59,8 @@ public class AuthenticatorSuccessTest extends AuthenticatorTestBase { private UserDefinedLocalAuthenticatorUpdate updatePayload; private final String CUSTOM_TAG = "Custom"; + private final String[] CURRENT_TAGS_LIST = new String[]{"APIAuth","MFA","Passwordless","Passkey", + "Username-Password", "Request-Path","Social-Login","OIDC","SAML","Enterprise"}; @Factory(dataProvider = "restAPIUserConfigProvider") public AuthenticatorSuccessTest(TestUserMode userMode) throws Exception { @@ -129,27 +132,18 @@ public void getAuthenticators() throws JSONException { } @Test(dependsOnMethods = {"getAuthenticators"}) - public void testGetMetaTags() throws JsonProcessingException { + public void testGetMetaTags() { - Response responseBefore = getResponseOfGet(AUTHENTICATOR_META_TAGS_PATH); - responseBefore.then() + Response response = getResponseOfGet(AUTHENTICATOR_META_TAGS_PATH); + response.then() .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_OK) .body("$", not(hasItem(CUSTOM_TAG))); - - getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, - UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload)); - - Response responseAfter = getResponseOfGet(AUTHENTICATOR_META_TAGS_PATH); - responseAfter.then() - .log().ifValidationFails() - .assertThat() - .statusCode(HttpStatus.SC_OK) - .body("$", hasItem(CUSTOM_TAG)); - - getResponseOfDelete(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR - + customIdPId); + for (String tag : CURRENT_TAGS_LIST) { + response.then() + .body("$", hasItem(tag)); + } } @Test(dependsOnMethods = {"testGetMetaTags"}) @@ -168,7 +162,7 @@ public void testCreateUserDefinedLocalAuthenticator() throws JsonProcessingExcep .body("type", equalTo("LOCAL")) .body("definedBy", equalTo("USER")) .body("isEnabled", equalTo(true)) - .body("tags", hasItems(CUSTOM_TAG)) + .body("tags", hasItem(CUSTOM_TAG)) .body("self", equalTo(getTenantedRelativePath( AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); } @@ -201,6 +195,21 @@ public void getUserDefinedLocalAuthenticators() throws JSONException { Assert.assertTrue(isUserDefinedAuthenticatorFound); } + @Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"}) + public void testValidateCustomTagInGetMetaTags() { + + Response response = getResponseOfGet(AUTHENTICATOR_META_TAGS_PATH); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("$", hasItem(CUSTOM_TAG)); + for (String tag : CURRENT_TAGS_LIST) { + response.then() + .body("$", hasItem(tag)); + } + } + @Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"}) public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingException { @@ -220,7 +229,7 @@ public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingExcep .body("type", equalTo("LOCAL")) .body("definedBy", equalTo("USER")) .body("isEnabled", equalTo(false)) - .body("tags", hasItems(CUSTOM_TAG)) + .body("tags", hasItem(CUSTOM_TAG)) .body("self", equalTo(getTenantedRelativePath( AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); } From be2056676e7e32162a24c3cf35977a2159a50c2c Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Wed, 18 Dec 2024 18:12:04 +0530 Subject: [PATCH 4/4] Update depending methods. --- .../authenticator/management/v1/AuthenticatorSuccessTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java index 72ad959d4e..e6bfb92b0c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java @@ -234,7 +234,7 @@ public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingExcep AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); } - @Test(dependsOnMethods = {"testUpdateUserDefinedLocalAuthenticator"}) + @Test(dependsOnMethods = {"testValidateCustomTagInGetMetaTags", "testUpdateUserDefinedLocalAuthenticator"}) public void testDeleteUserDefinedLocalAuthenticator() throws JsonProcessingException { Response response = getResponseOfDelete(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR @@ -245,7 +245,7 @@ public void testDeleteUserDefinedLocalAuthenticator() throws JsonProcessingExcep .statusCode(HttpStatus.SC_NO_CONTENT); } - @Test(dependsOnMethods = {"testUpdateUserDefinedLocalAuthenticator"}) + @Test(dependsOnMethods = {"testDeleteUserDefinedLocalAuthenticator"}) public void testDeleteNonExistingUserDefinedLocalAuthenticator() throws JsonProcessingException { Response response = getResponseOfDelete(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR