Added test for empty or null username

This commit is contained in:
Luke Taylor 2006-05-21 01:40:00 +00:00
parent d8a28d6068
commit 360e9908b7
1 changed files with 20 additions and 0 deletions

View File

@ -32,6 +32,8 @@ public class LdapAuthenticationProviderTests extends AbstractLdapServerTestCase
LdapAuthenticationProvider ldapProvider
= new LdapAuthenticationProvider(new MockAuthenticator(), new MockAuthoritiesPopulator());
assertNotNull(ldapProvider.getAuthoritiesPoulator());
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("bob","bobspassword");
UserDetails user = ldapProvider.retrieveUser("bob", token);
assertEquals(2, user.getAuthorities().length);
@ -46,6 +48,24 @@ public class LdapAuthenticationProviderTests extends AbstractLdapServerTestCase
ldapProvider.additionalAuthenticationChecks(user, token);
}
public void testEmptyOrNullUserNameThrowsException() {
LdapAuthenticationProvider ldapProvider
= new LdapAuthenticationProvider(new MockAuthenticator(), new MockAuthoritiesPopulator());
try {
ldapProvider.retrieveUser("", new UsernamePasswordAuthenticationToken("bob","bobspassword"));
fail("Expected BadCredentialsException for empty username");
} catch(BadCredentialsException expected) {
}
try {
ldapProvider.retrieveUser(null, new UsernamePasswordAuthenticationToken("bob","bobspassword"));
fail("Expected BadCredentialsException for null username");
} catch(BadCredentialsException expected) {
}
}
// This test kills apacheDS in embedded mode because the search returns an invalid DN
// public void testIntegration() throws Exception {
// BindAuthenticator authenticator = new BindAuthenticator(getInitialCtxFactory());