This commit is contained in:
Luke Taylor
2010-01-02 19:53:19 +00:00
parent b737fa451d
commit 893f212fa5
25 changed files with 323 additions and 473 deletions

View File

@@ -83,19 +83,19 @@ public class TestHelperTests {
authoritiesStrings5.add("ROLE_A");
assertTrue(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities1), authoritiesStrings1));
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities1), authoritiesStrings1));
assertTrue(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities2), authoritiesStrings2));
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities2), authoritiesStrings2));
assertTrue(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities3), authoritiesStrings3));
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities3), authoritiesStrings3));
assertTrue(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities4), authoritiesStrings4));
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities4), authoritiesStrings4));
assertTrue(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities5), authoritiesStrings5));
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities5), authoritiesStrings5));
}
// SEC-863

View File

@@ -47,6 +47,7 @@ public class MapBasedMethodSecurityMetadataSourceTests {
assertEquals(ROLE_B, mds.getAttributes(someMethodString, MockService.class));
}
@SuppressWarnings("unused")
private class MockService {
public void someMethod(String s) {
}

View File

@@ -60,6 +60,7 @@ public class AbstractAclVoterTests {
assertEquals("The Argument", voter.getDomainObjectInstance(mi));
}
@SuppressWarnings("unused")
private static class TestClass {
public void methodTakingAString(String arg) {
}

View File

@@ -89,10 +89,6 @@ public class GrantedAuthorityImplTests {
this.role = role;
}
public int compareTo(GrantedAuthority o) {
throw new UnsupportedOperationException();
}
public String getAuthority() {
return this.role;
}

View File

@@ -30,91 +30,91 @@ import org.junit.Before;
import org.junit.Test;
/**
*
*
* @author Mike Wiesner
* @since 3.0
* @version $Id$
*/
public class JndiDnsResolverTest {
private JndiDnsResolver dnsResolver;
private InitialContextFactory contextFactory;
private DirContext context;
@Before
public void setup() {
contextFactory = mock(InitialContextFactory.class);
context = mock(DirContext.class);
dnsResolver = new JndiDnsResolver();
dnsResolver.setCtxFactory(contextFactory);
when(contextFactory.getCtx()).thenReturn(context);
}
@Test
public void testResolveIpAddress() throws Exception {
Attributes records = new BasicAttributes("A","63.246.7.80");
when(context.getAttributes("www.springsource.com", new String[] {"A"})).thenReturn(records);
String ipAddress = dnsResolver.resolveIpAddress("www.springsource.com");
assertEquals("63.246.7.80", ipAddress);
}
@Test(expected=DnsEntryNotFoundException.class)
public void testResolveIpAddressNotExisting() throws Exception {
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NameNotFoundException("not found"));
dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
}
@Test
public void testResolveServiceEntry() throws Exception {
BasicAttributes records = createSrvRecords();
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] {"SRV"})).thenReturn(records);
String hostname = dnsResolver.resolveServiceEntry("ldap", "springsource.com");
assertEquals("kdc.springsource.com", hostname);
}
@Test(expected=DnsEntryNotFoundException.class)
public void testResolveServiceEntryNotExisting() throws Exception {
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NameNotFoundException("not found"));
dnsResolver.resolveServiceEntry("wrong", "secpod.de");
}
@Test
public void testResolveServiceIpAddress() throws Exception {
BasicAttributes srvRecords = createSrvRecords();
BasicAttributes aRecords = new BasicAttributes("A", "63.246.7.80");
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] {"SRV"})).thenReturn(srvRecords);
when(context.getAttributes("kdc.springsource.com", new String[] {"A"})).thenReturn(aRecords);
String ipAddress = dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
assertEquals("63.246.7.80", ipAddress);
}
@Test(expected=DnsLookupException.class)
public void testUnknowError() throws Exception {
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NamingException("error"));
dnsResolver.resolveIpAddress("");
}
private JndiDnsResolver dnsResolver;
private InitialContextFactory contextFactory;
private DirContext context;
@Before
public void setup() {
contextFactory = mock(InitialContextFactory.class);
context = mock(DirContext.class);
dnsResolver = new JndiDnsResolver();
dnsResolver.setCtxFactory(contextFactory);
when(contextFactory.getCtx()).thenReturn(context);
}
private BasicAttributes createSrvRecords() {
BasicAttributes records = new BasicAttributes();
BasicAttribute record = new BasicAttribute("SRV");
// the structure of the service records is:
// priority weight port hostname
// for more information: http://en.wikipedia.org/wiki/SRV_record
record.add("20 80 389 kdc3.springsource.com.");
record.add("10 70 389 kdc.springsource.com.");
record.add("20 20 389 kdc4.springsource.com.");
record.add("10 30 389 kdc2.springsource.com");
records.put(record);
return records;
}
@Test
public void testResolveIpAddress() throws Exception {
Attributes records = new BasicAttributes("A","63.246.7.80");
when(context.getAttributes("www.springsource.com", new String[] {"A"})).thenReturn(records);
String ipAddress = dnsResolver.resolveIpAddress("www.springsource.com");
assertEquals("63.246.7.80", ipAddress);
}
@Test(expected=DnsEntryNotFoundException.class)
public void testResolveIpAddressNotExisting() throws Exception {
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NameNotFoundException("not found"));
dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
}
@Test
public void testResolveServiceEntry() throws Exception {
BasicAttributes records = createSrvRecords();
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] {"SRV"})).thenReturn(records);
String hostname = dnsResolver.resolveServiceEntry("ldap", "springsource.com");
assertEquals("kdc.springsource.com", hostname);
}
@Test(expected=DnsEntryNotFoundException.class)
public void testResolveServiceEntryNotExisting() throws Exception {
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NameNotFoundException("not found"));
dnsResolver.resolveServiceEntry("wrong", "secpod.de");
}
@Test
public void testResolveServiceIpAddress() throws Exception {
BasicAttributes srvRecords = createSrvRecords();
BasicAttributes aRecords = new BasicAttributes("A", "63.246.7.80");
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] {"SRV"})).thenReturn(srvRecords);
when(context.getAttributes("kdc.springsource.com", new String[] {"A"})).thenReturn(aRecords);
String ipAddress = dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
assertEquals("63.246.7.80", ipAddress);
}
@Test(expected=DnsLookupException.class)
public void testUnknowError() throws Exception {
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NamingException("error"));
dnsResolver.resolveIpAddress("");
}
private BasicAttributes createSrvRecords() {
BasicAttributes records = new BasicAttributes();
BasicAttribute record = new BasicAttribute("SRV");
// the structure of the service records is:
// priority weight port hostname
// for more information: http://en.wikipedia.org/wiki/SRV_record
record.add("20 80 389 kdc3.springsource.com.");
record.add("10 70 389 kdc.springsource.com.");
record.add("20 20 389 kdc4.springsource.com.");
record.add("10 30 389 kdc2.springsource.com");
records.put(record);
return records;
}
}