From d5a212780437f4bae2821d6b13b1dbe061221e4d Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Wed, 18 Dec 2024 09:28:45 +0530 Subject: [PATCH] Add integration tests for /authenticator/meta/tags endpoint. --- .../v1/AuthenticatorSuccessTest.java | 32 ++++++++++++++++++- .../management/v1/AuthenticatorTestBase.java | 1 + 2 files changed, 32 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..338b211edc 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,8 @@ import java.io.IOException; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.not; import static org.hamcrest.core.IsNull.notNullValue; /** @@ -57,6 +58,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 +130,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(hasItems(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(not(hasItems(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 +169,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 +194,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 +221,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 = "/";