Skip to content

Commit

Permalink
Add integration tests for /authenticator/meta/tags endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Dec 18, 2024
1 parent dab3a36 commit d5a2127
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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.hasItems;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsNull.notNullValue;

/**
Expand All @@ -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 {

Expand Down Expand Up @@ -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);
Expand All @@ -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)));
}
Expand All @@ -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));
}
Expand All @@ -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)));
}
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 d5a2127

Please sign in to comment.