SEC-357: Added testIfSwitchUserWithNullUsernameThrowsException
This commit is contained in:
parent
fe0c99c816
commit
c2d1405f44
|
@ -180,6 +180,27 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||||
assertTrue(result != null);
|
assertTrue(result != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testIfSwitchUserWithNullUsernameThrowsException() throws Exception {
|
||||||
|
// set current user
|
||||||
|
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("dano", "hawaii50");
|
||||||
|
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||||
|
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
String username = null;
|
||||||
|
request.addParameter(SwitchUserProcessingFilter.ACEGI_SECURITY_SWITCH_USERNAME_KEY, username);
|
||||||
|
|
||||||
|
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||||
|
filter.setUserDetailsService(new MockAuthenticationDaoUserJackLord());
|
||||||
|
Authentication result = null ;
|
||||||
|
try {
|
||||||
|
result = filter.attemptSwitchUser(request);
|
||||||
|
fail("UsernameNotFoundException should have been thrown");
|
||||||
|
} catch (UsernameNotFoundException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
assertFalse(result != null);
|
||||||
|
}
|
||||||
|
|
||||||
public void testBadConfigMissingAuthenticationDao() {
|
public void testBadConfigMissingAuthenticationDao() {
|
||||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||||
filter.setSwitchUserUrl("/j_acegi_switch_user");
|
filter.setSwitchUserUrl("/j_acegi_switch_user");
|
||||||
|
|
Loading…
Reference in New Issue