SEC-357: Added testIfSwitchUserWithNullUsernameThrowsException

This commit is contained in:
Vishal Puri 2007-04-24 06:35:15 +00:00
parent fe0c99c816
commit c2d1405f44
1 changed files with 21 additions and 0 deletions

View File

@ -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");