Commit 2f24c186 authored by Andy Wilkinson's avatar Andy Wilkinson

Polish contribution

parent 3724db9e
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package org.springframework.boot.actuate.security; package org.springframework.boot.actuate.security;
import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
...@@ -89,31 +87,17 @@ public class AuthenticationAuditListenerTests { ...@@ -89,31 +87,17 @@ public class AuthenticationAuditListenerTests {
} }
@Test @Test
public void shouldPassDetailsToAuditEventOnAuthenticationFailureEvent() public void testDetailsAreIncludedInAuditEvent() throws Exception {
throws Exception { Object details = new Object();
// given UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
final Object details = new Object(); "user", "password");
final AuthenticationFailureExpiredEvent event =
createAuthenticationFailureEvent(details);
// when
this.listener.onApplicationEvent(event);
// then
final ArgumentCaptor<AuditApplicationEvent> applicationEventArgumentCaptor =
ArgumentCaptor.forClass(AuditApplicationEvent.class);
verify(this.publisher).publishEvent(applicationEventArgumentCaptor.capture());
final Map<String, Object> eventData =
applicationEventArgumentCaptor.getValue().getAuditEvent().getData();
assertThat(eventData, hasEntry("details", details));
}
private AuthenticationFailureExpiredEvent createAuthenticationFailureEvent(
final Object details) {
final UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken("user", "password");
authentication.setDetails(details); authentication.setDetails(details);
final BadCredentialsException exception = new BadCredentialsException("Bad user"); this.listener.onApplicationEvent(new AuthenticationFailureExpiredEvent(
return new AuthenticationFailureExpiredEvent(authentication, exception); authentication, new BadCredentialsException("Bad user")));
ArgumentCaptor<AuditApplicationEvent> auditApplicationEvent = ArgumentCaptor
.forClass(AuditApplicationEvent.class);
verify(this.publisher).publishEvent(auditApplicationEvent.capture());
assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(),
hasEntry("details", details));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment