From 76f868c777bb793e296a34eca6ebe68172ada7c6 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 12 Mar 2005 21:27:22 +0000 Subject: [PATCH] More tests. --- .../x509/X509AuthenticationProviderTests.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/acegisecurity/providers/x509/X509AuthenticationProviderTests.java b/core/src/test/java/org/acegisecurity/providers/x509/X509AuthenticationProviderTests.java index 4c84394e30..4ba3e0b602 100644 --- a/core/src/test/java/org/acegisecurity/providers/x509/X509AuthenticationProviderTests.java +++ b/core/src/test/java/org/acegisecurity/providers/x509/X509AuthenticationProviderTests.java @@ -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 ==========================================================