use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class AbstractHttpAccessAuditFilterTest method shouldAuditAccessAttemptAndResult.
@Test(dataProvider = "handlerResponses")
public void shouldAuditAccessAttemptAndResult(Status responseStatus) throws AuditException {
//Given
Context context = new RequestAuditContext(mockContext());
Request request = new Request().setMethod("GET").setUri(URI.create("http://example.com:8080?query=value"));
request.getHeaders().put(ContentTypeHeader.valueOf("CONTENT_TYPE"));
enableAccessTopicAuditing();
Handler handler = mockHandler(context, request, responseStatus);
//When
auditFilter.filter(context, request, handler);
//Then
ArgumentCaptor<AuditEvent> auditEventCaptor = ArgumentCaptor.forClass(AuditEvent.class);
verify(eventPublisher, times(2)).tryPublish(eq(AuditConstants.ACCESS_TOPIC), auditEventCaptor.capture());
verifyAccessAttemptAuditEvent(auditEventCaptor.getAllValues().get(0).getValue());
if (responseStatus.isSuccessful()) {
verifyAccessSuccessAuditEvent(auditEventCaptor.getAllValues().get(1).getValue());
} else {
verifyAccessFailedAuditEvent(auditEventCaptor.getAllValues().get(1).getValue());
}
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class AbstractHttpAccessAuditFilterTest method shouldNotAuditIfAuditingIsNotEnabledForAccessTopic.
@Test(dataProvider = "handlerResponses")
public void shouldNotAuditIfAuditingIsNotEnabledForAccessTopic(Status responseStatus) throws AuditException {
//Given
Context context = new RequestAuditContext(mockContext());
Request request = new Request().setUri(URI.create("http://example.com"));
disableAccessTopicAuditing();
Handler handler = mockHandler(context, request, responseStatus);
//When
auditFilter.filter(context, request, handler);
//Then
verify(eventPublisher, never()).tryPublish(anyString(), any(AuditEvent.class));
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldReturnUnauthorizedCodeWithJsonErrorMessage.
@Test
public void shouldReturnUnauthorizedCodeWithJsonErrorMessage() throws IOException {
// given
Request httpRequest = new Request();
RestAuthException exception = new RestAuthException(401, "Invalid Password!!");
exception.setFailureUrl("http://localhost:8080");
// when
Response response = authServiceV1.handleErrorResponse(httpRequest, Status.valueOf(401), exception);
// then
assertThat(response.getStatus()).isEqualTo(Status.UNAUTHORIZED);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).stringAt("errorMessage").isEqualTo("Invalid Password!!");
assertThat(responseBody).stringAt("failureUrl").isEqualTo("http://localhost:8080");
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldReturnErrorMessageWithoutTemplate.
@Test
public void shouldReturnErrorMessageWithoutTemplate() throws IOException {
// given
Request httpRequest = new Request();
AuthLoginException ale = new AuthLoginException("amAuth", "119", null);
RestAuthException exception = new RestAuthException(401, ale);
// when
String message = authServiceV1.getLocalizedMessage(httpRequest, exception);
// then
assertThat(message).isEqualTo("Invalid Auth Level.");
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldReturnFrenchErrorMessageFromException.
@Test
public void shouldReturnFrenchErrorMessageFromException() throws IOException {
// given
Request httpRequest = new Request();
AuthLoginException exception = new AuthLoginException("amAuth", "120", null);
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.");
}
Aggregations