use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.
the class AbstractLogbackAccessEventsTest method logbackAccessEvent.
/**
* Tests a Logback-access event.
*/
@Test
public void logbackAccessEvent() {
LocalDateTime startTime = LocalDateTime.now();
ResponseEntity<String> response = rest.getForEntity("/test/text", String.class);
IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
LocalDateTime endTime = LocalDateTime.now();
LogbackAccessEventQueuingListener.appendedEventQueue.pop();
assertThat(response).hasStatusCode(HttpStatus.OK).hasContentLengthHeader("TEST-TEXT".getBytes(StandardCharsets.UTF_8).length).hasBody("TEST-TEXT");
assertThat(event).hasTimestamp(startTime, endTime).hasServerName("localhost").hasLocalPort(port).hasRemoteAddr("127.0.0.1").hasRemoteHost("127.0.0.1").doesNotHaveRemoteUser().hasProtocol("HTTP/1.1").hasMethod(HttpMethod.GET).hasRequestUri("/test/text").hasQueryString("").hasRequestUrl(HttpMethod.GET, "/test/text", "HTTP/1.1").doesNotHaveRequestHeaderName("X-Test-Header").doesNotHaveRequestHeader("X-Test-Header").doesNotHaveRequestHeaderInMap("X-Test-Header").doesNotHaveRequestParameter("test-parameter").doesNotHaveRequestParameterInMap("test-parameter").hasStatusCode(HttpStatus.OK).hasContentLength("TEST-TEXT".getBytes(StandardCharsets.UTF_8).length).doesNotHaveResponseHeaderName("X-Test-Header").doesNotHaveResponseHeader("X-Test-Header").doesNotHaveResponseHeaderInMap("X-Test-Header").hasElapsedTime(startTime, endTime).hasElapsedSeconds(startTime, endTime).hasThreadName();
}
use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.
the class AbstractSecurityAttributesTest method logbackAccessEvent.
/**
* Tests a Logback-access event.
*/
@Test
public void logbackAccessEvent() {
ResponseEntity<String> response = rest.withBasicAuth("TEST-USER", "TEST-PASSWORD").getForEntity("/test/text", String.class);
IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
LogbackAccessEventQueuingListener.appendedEventQueue.pop();
assertThat(response).hasStatusCode(HttpStatus.OK);
assertThat(event).hasRemoteUser("TEST-USER");
}
use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.
the class TomcatServerPortUnusingTest method logbackAccessEvent.
/** {@inheritDoc} */
@Override
public void logbackAccessEvent() {
RequestEntity<Void> request = RequestEntity.get(rest.getRestTemplate().getUriTemplateHandler().expand("/test/text")).header("X-Forwarded-Port", "12345").build();
ResponseEntity<String> response = rest.exchange(request, String.class);
IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
LogbackAccessEventQueuingListener.appendedEventQueue.pop();
assertThat(response).hasStatusCode(HttpStatus.OK);
assertThat(event).hasLocalPort(port);
}
use of ch.qos.logback.access.spi.IAccessEvent in project dropwizard by dropwizard.
the class LogbackAccessRequestLogTest method logsRequestsToTheAppender.
@Test
public void logsRequestsToTheAppender() {
final IAccessEvent event = logAndCapture();
assertThat(event.getRemoteAddr()).isEqualTo("10.0.0.1");
assertThat(event.getMethod()).isEqualTo("GET");
assertThat(event.getRequestURI()).isEqualTo("/test/things?yay");
assertThat(event.getProtocol()).isEqualTo("HTTP/1.1");
assertThat(event.getStatusCode()).isEqualTo(200);
assertThat(event.getContentLength()).isEqualTo(8290L);
}
use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.
the class JettyForwardHeadersUsingTest method logbackAccessEvent.
/** {@inheritDoc} */
@Override
public void logbackAccessEvent() {
RequestEntity<Void> request = RequestEntity.get(rest.getRestTemplate().getUriTemplateHandler().expand("/test/text")).header("X-Forwarded-Host", "forwarded-host:12345").header("X-Forwarded-For", "1.2.3.4").header("X-Forwarded-Proto", "https").build();
ResponseEntity<String> response = rest.exchange(request, String.class);
IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
LogbackAccessEventQueuingListener.appendedEventQueue.pop();
assertThat(response).hasStatusCode(HttpStatus.OK);
assertThat(event).hasServerName("forwarded-host").hasLocalPort(12345).hasRemoteAddr("1.2.3.4").hasRemoteHost("1.2.3.4").hasProtocol("HTTP/1.1");
}
Aggregations