From 78e6075f89a662c2b0e37c09010295ba9e9f5568 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Thu, 19 Dec 2024 09:40:18 +0530 Subject: [PATCH 1/3] Add integration test to get user defined local authenticators. --- .../v1/AuthenticatorSuccessTest.java | 27 ++++++++++++++++--- .../management/v1/AuthenticatorTestBase.java | 3 ++- 2 files changed, 25 insertions(+), 5 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 e6bfb92b0c4..6d12b2e34ff 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 @@ -164,7 +164,7 @@ public void testCreateUserDefinedLocalAuthenticator() throws JsonProcessingExcep .body("isEnabled", equalTo(true)) .body("tags", hasItem(CUSTOM_TAG)) .body("self", equalTo(getTenantedRelativePath( - AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); + BASE_PATH + AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); } @Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"}) @@ -188,8 +188,8 @@ public void getUserDefinedLocalAuthenticators() throws JSONException { 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)); + Assert.assertEquals(authenticator.getString("self"), getTenantedRelativePath( + BASE_PATH + AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant)); } } Assert.assertTrue(isUserDefinedAuthenticatorFound); @@ -211,6 +211,25 @@ public void testValidateCustomTagInGetMetaTags() { } @Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"}) + public void testGetUserDefinedLocalAuthenticator() { + + Response response = getResponseOfGet(AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .header(HttpHeaders.LOCATION, notNullValue()) + .body("id", equalTo(customIdPId)) + .body("name", equalTo(AUTHENTICATOR_NAME)) + .body("displayName", equalTo(AUTHENTICATOR_DISPLAY_NAME)) + .body("type", equalTo("LOCAL")) + .body("definedBy", equalTo("USER")) + .body("isEnabled", equalTo(true)) + .body("endpoint.uri", equalTo(AUTHENTICATOR_ENDPOINT_URI)) + .body("endpoint.authentication", equalTo("Basic")); + } + + @Test(dependsOnMethods = {"testGetUserDefinedLocalAuthenticator"}) public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingException { updatePayload.displayName(AUTHENTICATOR_DISPLAY_NAME + UPDATE_VALUE_POSTFIX); @@ -231,7 +250,7 @@ public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingExcep .body("isEnabled", equalTo(false)) .body("tags", hasItem(CUSTOM_TAG)) .body("self", equalTo(getTenantedRelativePath( - AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); + BASE_PATH + AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); } @Test(dependsOnMethods = {"testValidateCustomTagInGetMetaTags", "testUpdateUserDefinedLocalAuthenticator"}) 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 846eef15ead..546b013206d 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 @@ -41,10 +41,11 @@ public class AuthenticatorTestBase extends RESTAPIServerTestBase { protected static final String API_VERSION = "v1"; protected static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.authenticators.v1"; + protected static final String BASE_PATH = "/api/server/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 AUTHENTICATOR_CONFIG_API_BASE_PATH = "/configs/authenticators/"; protected static final String PATH_SEPARATOR = "/"; protected final String AUTHENTICATOR_NAME = "customAuthenticator"; From c235a3921da033bb29ebf181651635e5bb5b7061 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Fri, 3 Jan 2025 08:59:38 +0530 Subject: [PATCH 2/3] Bump versions. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 30349e85003..639cc4753c3 100755 --- a/pom.xml +++ b/pom.xml @@ -2356,7 +2356,7 @@ - 7.7.66 + 7.7.67 [5.14.67, 8.0.0) @@ -2468,7 +2468,7 @@ 2.0.17 - 1.3.16 + 1.3.17 1.3.47 5.5.9 From a9a9072364f3d4ca91541a8bf3debcbef567d41a Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Fri, 24 Jan 2025 08:14:47 +0530 Subject: [PATCH 3/3] Improve integration tests. --- .../test/rest/api/common/RESTTestBase.java | 17 +++++++++++++++++ .../management/v1/AuthenticatorSuccessTest.java | 7 ++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/RESTTestBase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/RESTTestBase.java index 9c35ada9f77..3b122ed2137 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/RESTTestBase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/RESTTestBase.java @@ -262,6 +262,23 @@ protected Response getResponseOfGet(String endpointUri) { .get(endpointUri); } + /** + * Invoke given endpointUri for GET with Basic authentication, authentication credential being the + * authenticatingUserName and authenticatingCredential with no filter. + * + * @param endpointUri endpoint to be invoked + * @return response + */ + protected Response getResponseOfGetNoFilter(String endpointUri) { + + return given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential) + .contentType(ContentType.JSON) + .header(HttpHeaders.ACCEPT, ContentType.JSON) + .log().ifValidationFails() + .when() + .get(endpointUri); + } + /** * Invoke given endpointUri for GET with Basic authentication, authentication credential being the * authenticatingUserName and authenticatingCredential 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 6d12b2e34ff..2ca731b09a1 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 @@ -213,20 +213,17 @@ public void testValidateCustomTagInGetMetaTags() { @Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"}) public void testGetUserDefinedLocalAuthenticator() { - Response response = getResponseOfGet(AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId); + Response response = getResponseOfGetNoFilter(AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId); response.then() .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_OK) - .header(HttpHeaders.LOCATION, notNullValue()) .body("id", equalTo(customIdPId)) .body("name", equalTo(AUTHENTICATOR_NAME)) .body("displayName", equalTo(AUTHENTICATOR_DISPLAY_NAME)) .body("type", equalTo("LOCAL")) .body("definedBy", equalTo("USER")) - .body("isEnabled", equalTo(true)) - .body("endpoint.uri", equalTo(AUTHENTICATOR_ENDPOINT_URI)) - .body("endpoint.authentication", equalTo("Basic")); + .body("isEnabled", equalTo(true)); } @Test(dependsOnMethods = {"testGetUserDefinedLocalAuthenticator"})