use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class AuthenticationServiceV2Test method shouldReturnResponseContainingUnauthorizedCodeWithJsonErrorMessage.
@Test
public void shouldReturnResponseContainingUnauthorizedCodeWithJsonErrorMessage() throws IOException {
// given
Request httpRequest = new Request();
RestAuthException testException = new RestAuthException(401, "Invalid Password!!");
testException.setFailureUrl("http://localhost:8080");
// when
Response response = authServiceV2.handleErrorResponse(httpRequest, Status.valueOf(401), testException);
// then
assertThat(response.getStatus()).isEqualToComparingFieldByField(Status.UNAUTHORIZED);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).integerAt("code").isEqualTo(401);
assertThat(responseBody).stringAt("reason").isEqualTo("Unauthorized");
assertThat(responseBody).stringAt("message").isEqualTo("Invalid Password!!");
assertThat(responseBody).stringAt("detail/failureUrl").isEqualTo("http://localhost:8080");
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class AuthenticationServiceV2Test method shouldReturnUnauthorizedCodeWithJsonFailureMessage.
@Test
public void shouldReturnUnauthorizedCodeWithJsonFailureMessage() throws IOException {
// given
Request httpRequest = new Request();
JsonValue jsonValue = json(object(field("failure", true), field("reason", "http-auth-failed"), field("authId", "12345")));
RestAuthResponseException exception = new RestAuthResponseException(RestAuthException.UNAUTHORIZED, Collections.<String, String>emptyMap(), jsonValue);
// when
Response response = authServiceV2.handleErrorResponse(httpRequest, Status.valueOf(exception.getStatusCode()), exception);
// then
assertThat(response.getStatus()).isEqualToComparingFieldByField(Status.UNAUTHORIZED);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).booleanAt("failure").isTrue();
assertThat(responseBody).stringAt("reason").isEqualTo("http-auth-failed");
assertThat(responseBody).stringAt("authId").isEqualTo("12345");
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class AuthenticationServiceV2Test method shouldFailAuthenticationWithUnsupportedMediaTypeMessage.
@Test
public void shouldFailAuthenticationWithUnsupportedMediaTypeMessage() throws IOException {
// given
AttributesContext context = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
Request httpRequest = new Request();
httpRequest.setEntity("<xml></xml>");
httpRequest.getHeaders().put(ContentTypeHeader.NAME, "application/xml");
// when
Response response = authServiceV2.authenticate(context, httpRequest);
// then
assertThat(response.getStatus()).isEqualTo(Status.UNSUPPORTED_MEDIA_TYPE);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).integerAt("code").isEqualTo(415);
assertThat(responseBody).stringAt("reason").isEqualTo("Unsupported Media Type");
assertThat(responseBody).stringAt("message").isEqualTo("Unsupported Media Type");
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldReturnUnauthorizedCodeWithJsonFailureMessage.
@Test
public void shouldReturnUnauthorizedCodeWithJsonFailureMessage() throws IOException {
// given
Request httpRequest = new Request();
JsonValue jsonValue = json(object(field("failure", true), field("reason", "http-auth-failed"), field("authId", "12345")));
RestAuthResponseException exception = new RestAuthResponseException(RestAuthException.UNAUTHORIZED, Collections.<String, String>emptyMap(), jsonValue);
// when
Response response = authServiceV1.handleErrorResponse(httpRequest, Status.valueOf(exception.getStatusCode()), exception);
// then
assertThat(response.getStatus()).isEqualToComparingFieldByField(Status.UNAUTHORIZED);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).booleanAt("failure").isTrue();
assertThat(responseBody).stringAt("reason").isEqualTo("http-auth-failed");
assertThat(responseBody).stringAt("authId").isEqualTo("12345");
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldFailAuthenticationWithUnsupportedMediaTypeMessage.
@Test
public void shouldFailAuthenticationWithUnsupportedMediaTypeMessage() throws IOException {
// given
AttributesContext context = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
Request httpRequest = new Request();
httpRequest.setEntity("<xml></xml>");
httpRequest.getHeaders().put(ContentTypeHeader.NAME, "application/xml");
// when
Response response = authServiceV1.authenticate(context, httpRequest);
// then
assertThat(response.getStatus()).isEqualTo(Status.UNSUPPORTED_MEDIA_TYPE);
assertThat(json(response.getEntity().getJson())).stringAt("errorMessage").isEqualTo("Unsupported Media Type");
}
Aggregations