Do not require after in audit events endpoint

Closes gh-11605
This commit is contained in:
Andy Wilkinson
2018-01-18 10:16:56 +00:00
parent c233125f1d
commit 849baa4c02
9 changed files with 21 additions and 236 deletions

View File

@@ -41,13 +41,16 @@ public class AuditEventsEndpointWebIntegrationTests {
private static WebTestClient client;
@Test
public void eventsWithoutParams() {
public void allEvents() {
client.get().uri((builder) -> builder.path("/actuator/auditevents").build())
.exchange().expectStatus().isBadRequest();
.exchange().expectStatus().isOk().expectBody()
.jsonPath("events.[*].principal")
.isEqualTo(new JSONArray().appendElement("admin").appendElement("admin")
.appendElement("user"));
}
@Test
public void eventsWithDateAfter() {
public void eventsAfter() {
client.get()
.uri((builder) -> builder.path("/actuator/auditevents")
.queryParam("after", "2016-11-01T13:00:00%2B00:00").build())
@@ -56,10 +59,9 @@ public class AuditEventsEndpointWebIntegrationTests {
}
@Test
public void eventsWithPrincipalAndDateAfter() {
public void eventsWithPrincipal() {
client.get()
.uri((builder) -> builder.path("/actuator/auditevents")
.queryParam("after", "2016-11-01T10:00:00%2B00:00")
.queryParam("principal", "user").build())
.exchange().expectStatus().isOk().expectBody()
.jsonPath("events.[*].principal")
@@ -67,12 +69,10 @@ public class AuditEventsEndpointWebIntegrationTests {
}
@Test
public void eventsWithPrincipalDateAfterAndType() {
public void eventsWithType() {
client.get()
.uri((builder) -> builder.path("/actuator/auditevents")
.queryParam("after", "2016-11-01T10:00:00%2B00:00")
.queryParam("principal", "admin").queryParam("type", "logout")
.build())
.queryParam("type", "logout").build())
.exchange().expectStatus().isOk().expectBody()
.jsonPath("events.[*].principal")
.isEqualTo(new JSONArray().appendElement("admin"))
@@ -97,12 +97,6 @@ public class AuditEventsEndpointWebIntegrationTests {
return new AuditEventsEndpoint(auditEventsRepository());
}
@Bean
public AuditEventsEndpointWebExtension auditEventsEndpointWebExtension(
AuditEventsEndpoint auditEventsEndpoint) {
return new AuditEventsEndpointWebExtension(auditEventsEndpoint);
}
private AuditEvent createEvent(String instant, String principal, String type) {
return new AuditEvent(Instant.parse(instant), principal, type,
Collections.emptyMap());

View File

@@ -1,63 +0,0 @@
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.audit;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link AuditEventsJmxEndpointExtension}.
*
* @author Andy Wilkinson
*/
public class AuditEventsJmxEndpointExtensionTests {
private final AuditEventRepository repository = mock(AuditEventRepository.class);
private final AuditEventsJmxEndpointExtension extension = new AuditEventsJmxEndpointExtension(
new AuditEventsEndpoint(this.repository));
private final AuditEvent event = new AuditEvent("principal", "type",
Collections.singletonMap("a", "alpha"));
@Test
public void eventsCreatedAfter() {
OffsetDateTime now = OffsetDateTime.now();
given(this.repository.find(null, now.toInstant(), null))
.willReturn(Collections.singletonList(this.event));
List<AuditEvent> result = this.extension.eventsAfter(now).getEvents();
assertThat(result).isEqualTo(Collections.singletonList(this.event));
}
@Test
public void eventsWithPrincipalAndDateAfter() {
OffsetDateTime now = OffsetDateTime.now();
given(this.repository.find("Joan", now.toInstant(), null))
.willReturn(Collections.singletonList(this.event));
List<AuditEvent> result = this.extension.eventsWithPrincipalAndAfter("Joan", now)
.getEvents();
assertThat(result).isEqualTo(Collections.singletonList(this.event));
}
}