Commit b74a9b2d authored by Dave Syer's avatar Dave Syer

Add tests to FIXME

parent 67cc427d
......@@ -16,23 +16,59 @@
package org.springframework.boot.actuate.security;
import org.junit.Ignore;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.actuate.security.AuthenticationAuditListener;
import org.mockito.Mockito;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.event.AuthenticationFailureExpiredEvent;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link AuthenticationAuditListener}.
*/
@Ignore
public class AuthenticationAuditListenerTests {
// FIXME
private AuthenticationAuditListener listener = new AuthenticationAuditListener();
private ApplicationEventPublisher publisher = Mockito
.mock(ApplicationEventPublisher.class);
@Before
public void init() {
this.listener.setApplicationEventPublisher(this.publisher);
}
@Test
public void testAuthenticationSuccess() {
this.listener.onApplicationEvent(new AuthenticationSuccessEvent(
new UsernamePasswordAuthenticationToken("user", "password")));
verify(this.publisher).publishEvent((ApplicationEvent) anyObject());
}
@Test
public void testAuthenticationFailed() {
this.listener.onApplicationEvent(new AuthenticationFailureExpiredEvent(
new UsernamePasswordAuthenticationToken("user", "password"),
new BadCredentialsException("Bad user")));
verify(this.publisher).publishEvent((ApplicationEvent) anyObject());
}
@Test
public void test() {
fail("Not yet implemented");
public void testAuthenticationSwitch() {
this.listener.onApplicationEvent(new AuthenticationSwitchUserEvent(
new UsernamePasswordAuthenticationToken("user", "password"), new User(
"user", "password", AuthorityUtils
.commaSeparatedStringToAuthorityList("USER"))));
verify(this.publisher).publishEvent((ApplicationEvent) anyObject());
}
}
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