More tests.
This commit is contained in:
parent
765cc02599
commit
76f868c777
|
@ -3,11 +3,15 @@ package net.sf.acegisecurity.providers.x509;
|
|||
import junit.framework.TestCase;
|
||||
import net.sf.acegisecurity.*;
|
||||
import net.sf.acegisecurity.providers.dao.User;
|
||||
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* Tests {@link net.sf.acegisecurity.providers.x509.X509AuthenticationProvider}
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class X509AuthenticationProviderTests extends TestCase {
|
||||
//~ Constructors ===========================================================
|
||||
|
@ -26,7 +30,41 @@ public class X509AuthenticationProviderTests extends TestCase {
|
|||
super.setUp();
|
||||
}
|
||||
|
||||
public void testAuthenticationInvalidCertificate() throws Exception {
|
||||
public void testRequiresPopulator() throws Exception {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
try {
|
||||
provider.afterPropertiesSet();
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException failed) {
|
||||
//ignored
|
||||
}
|
||||
}
|
||||
|
||||
public void testNormalOperation () throws Exception {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
|
||||
provider.setX509AuthoritiesPopulator(new MockAuthoritiesPopulator(false));
|
||||
provider.afterPropertiesSet();
|
||||
|
||||
Authentication result = provider.authenticate(X509TestUtils.createToken());
|
||||
|
||||
assertNotNull(result);
|
||||
assertNotNull(result.getAuthorities());
|
||||
}
|
||||
|
||||
public void testFailsWithNullCertificate() {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
|
||||
provider.setX509AuthoritiesPopulator(new MockAuthoritiesPopulator(false));
|
||||
try {
|
||||
provider.authenticate(new X509AuthenticationToken(null));
|
||||
fail("Should have thrown BadCredentialsException");
|
||||
} catch(BadCredentialsException e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
public void testPopulatorRejectionCausesFailure() throws Exception {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
provider.setX509AuthoritiesPopulator(new MockAuthoritiesPopulator(true));
|
||||
try {
|
||||
|
@ -37,6 +75,12 @@ public class X509AuthenticationProviderTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testAuthenticationIsNullWithUnsupportedToken() {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
Authentication request = new UsernamePasswordAuthenticationToken("dummy","dummy");
|
||||
Authentication result = provider.authenticate(request);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
//~ Inner Classes ==========================================================
|
||||
|
||||
|
|
Loading…
Reference in New Issue