Add tests to FIXME
This commit is contained in:
@@ -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 test() {
|
||||
fail("Not yet implemented");
|
||||
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 testAuthenticationSwitch() {
|
||||
this.listener.onApplicationEvent(new AuthenticationSwitchUserEvent(
|
||||
new UsernamePasswordAuthenticationToken("user", "password"), new User(
|
||||
"user", "password", AuthorityUtils
|
||||
.commaSeparatedStringToAuthorityList("USER"))));
|
||||
verify(this.publisher).publishEvent((ApplicationEvent) anyObject());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user