Skip to content

Commit

Permalink
Merge pull request #22059 from Thisara-Welmilla/add-meta-tag-integration
Browse files Browse the repository at this point in the history
Add integration tests for /authenticator/meta/tags endpoint.
  • Loading branch information
Thisara-Welmilla authored Dec 19, 2024
2 parents 063668b + be20566 commit f1a597f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +45,8 @@
import java.io.IOException;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsNull.notNullValue;

/**
Expand All @@ -57,6 +58,10 @@ public class AuthenticatorSuccessTest extends AuthenticatorTestBase {
private UserDefinedLocalAuthenticatorCreation creationPayload;
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 {

Expand Down Expand Up @@ -127,6 +132,21 @@ public void getAuthenticators() throws JSONException {
}

@Test(dependsOnMethods = {"getAuthenticators"})
public void testGetMetaTags() {

Response response = getResponseOfGet(AUTHENTICATOR_META_TAGS_PATH);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("$", not(hasItem(CUSTOM_TAG)));
for (String tag : CURRENT_TAGS_LIST) {
response.then()
.body("$", hasItem(tag));
}
}

@Test(dependsOnMethods = {"testGetMetaTags"})
public void testCreateUserDefinedLocalAuthenticator() throws JsonProcessingException {

String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload);
Expand All @@ -142,6 +162,7 @@ public void testCreateUserDefinedLocalAuthenticator() throws JsonProcessingExcep
.body("type", equalTo("LOCAL"))
.body("definedBy", equalTo("USER"))
.body("isEnabled", equalTo(true))
.body("tags", hasItem(CUSTOM_TAG))
.body("self", equalTo(getTenantedRelativePath(
AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant)));
}
Expand All @@ -166,13 +187,29 @@ 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));
}
}
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 {

Expand All @@ -192,11 +229,12 @@ public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingExcep
.body("type", equalTo("LOCAL"))
.body("definedBy", equalTo("USER"))
.body("isEnabled", equalTo(false))
.body("tags", hasItem(CUSTOM_TAG))
.body("self", equalTo(getTenantedRelativePath(
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
Expand All @@ -207,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/";
Expand Down

0 comments on commit f1a597f

Please sign in to comment.