use of org.forgerock.http.protocol.Request 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.Request 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.Request 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.Request in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldReturnFrenchErrorMessageFromCause.
@Test
public void shouldReturnFrenchErrorMessageFromCause() throws IOException {
// given
Request httpRequest = new Request();
AuthLoginException ale = new AuthLoginException("amAuth", "120", null);
RestAuthException exception = new RestAuthException(401, ale);
httpRequest.getHeaders().put("Accept-Language", "fr-fr");
// when
String message = authServiceV1.getLocalizedMessage(httpRequest, exception);
// then
assertThat(message).isEqualTo("L’authentification sur module n’est pas autorisée.");
}
use of org.forgerock.http.protocol.Request 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