Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test to get user defined local authenticators. #22077

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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);
Expand All @@ -211,6 +211,24 @@ public void testValidateCustomTagInGetMetaTags() {
}

@Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"})
public void testGetUserDefinedLocalAuthenticator() {

Response response = getResponseOfGetNoFilter(AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.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);
Expand All @@ -231,7 +249,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"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "custom-Authenticator";
Expand Down