Skip to content

Commit

Permalink
Update test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shenali-SJ committed Nov 30, 2024
1 parent f71392b commit 3860829
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public class IdPSuccessTest extends IdPTestBase {
private static final String IDP_NAME = "Custom Auth IDP";
private static final String ENDPOINT_URI = "https://abc.com/authenticate";
private static final String UPDATED_ENDPOINT_URI = "https://xyz.com/authenticate";
private static final String BASIC = "BASIC";
private static final String BEARER = "BEARER";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
private static final String ACCESS_TOKEN = "accessToken";
private static final String USERNAME_VALUE = "testUser";
private static final String ACCESS_TOKEN_VALUE = "testBearerToken";
private static final String PASSWORD_VALUE = "testPassword";
private String idPId;
private String customIdPId;
Expand All @@ -81,19 +85,19 @@ public IdPSuccessTest(TestUserMode userMode) throws Exception {
public void init() throws IOException {

super.testInit(API_VERSION, swaggerDefinition, tenant);
userDefinedAuthenticatorPayload = createUserDefinedAuthenticatorPayload();
userDefinedAuthenticatorPayload = createUserDefinedAuthenticatorPayloadWithBasic(ENDPOINT_URI);
idpCreatePayload = readResource("add-idp-with-custom-fed-auth.json");
}

private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayload() {
private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayloadWithBasic(String endpointUri) {

UserDefinedAuthenticatorPayload userDefinedAuthenticatorPayload = new UserDefinedAuthenticatorPayload();
userDefinedAuthenticatorPayload.setIsEnabled(true);
userDefinedAuthenticatorPayload.setAuthenticatorId(FEDERATED_AUTHENTICATOR_ID);
userDefinedAuthenticatorPayload.setDefinedBy(FederatedAuthenticatorRequest.DefinedByEnum.USER.toString());

Endpoint endpoint = new Endpoint();
endpoint.setUri(ENDPOINT_URI);
endpoint.setUri(endpointUri);
AuthenticationType authenticationType = new AuthenticationType();
authenticationType.setType(AuthenticationType.TypeEnum.BASIC);
Map<String, Object> properties = new HashMap<>();
Expand All @@ -106,7 +110,7 @@ private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayload()
return userDefinedAuthenticatorPayload;
}

private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayload(String endpointUri) {
private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayloadWithBearer(String endpointUri) {

UserDefinedAuthenticatorPayload userDefinedAuthenticatorPayload = new UserDefinedAuthenticatorPayload();
userDefinedAuthenticatorPayload.setIsEnabled(true);
Expand All @@ -116,10 +120,10 @@ private UserDefinedAuthenticatorPayload createUserDefinedAuthenticatorPayload(St
Endpoint endpoint = new Endpoint();
endpoint.setUri(endpointUri);
AuthenticationType authenticationType = new AuthenticationType();
authenticationType.setType(AuthenticationType.TypeEnum.BASIC);
authenticationType.setType(AuthenticationType.TypeEnum.BEARER);
Map<String, Object> properties = new HashMap<>();
properties.put(USERNAME, USERNAME_VALUE);
properties.put(PASSWORD, PASSWORD_VALUE);
authenticationType.setType(AuthenticationType.TypeEnum.BEARER);
properties.put(ACCESS_TOKEN, ACCESS_TOKEN_VALUE);
authenticationType.setProperties(properties);
endpoint.authentication(authenticationType);
userDefinedAuthenticatorPayload.setEndpoint(endpoint);
Expand Down Expand Up @@ -354,6 +358,8 @@ public void testGetUserDefinedAuthenticatorsOfIdP() {
.body("defaultAuthenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID))
.body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.name",
equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID))))
.body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.isEnabled",
equalTo(true))
.body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.isEnabled",
equalTo(true));
}
Expand All @@ -363,15 +369,17 @@ public void testUpdateUserDefinedAuthenticatorOfIdP() throws JsonProcessingExcep

Response response = getResponseOfPut(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId +
PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH + PATH_SEPARATOR + FEDERATED_AUTHENTICATOR_ID,
createUserDefinedAuthenticatorPayload(UPDATED_ENDPOINT_URI).convertToJasonPayload());
createUserDefinedAuthenticatorPayloadWithBearer(UPDATED_ENDPOINT_URI)
.convertToJasonPayload());

response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("authenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID))
.body("name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID))))
.body("endpoint.uri", equalTo(UPDATED_ENDPOINT_URI));
.body("endpoint.uri", equalTo(UPDATED_ENDPOINT_URI))
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.value()));
}

@Test(dependsOnMethods = "testUpdateUserDefinedAuthenticatorOfIdP")
Expand Down

This file was deleted.

0 comments on commit 3860829

Please sign in to comment.