From d2a5ad6fd159e6911f4a00e95f1f54b9abed328f Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 31 Jul 2012 13:54:59 -0500 Subject: [PATCH] SEC-2016: Update config integration tests to use specific ldif to work in Eclipse Due to Eclipse restrictions the classpath adding an project as a dependency picks up the test dependencies of other projects. This caused problems when running the config integration tests within Eclipse. Now the tests specify a specific ldif to load. There is also one new test that ensures that the ldif is defaulted properly, but does not rely on the ldif that is loaded. --- .../LdapServerBeanDefinitionParserTests.java | 31 ++++++++++++++++--- ...pUserServiceBeanDefinitionParserTests.java | 31 +++++++++++++------ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java index 72f44f9f13..ed6bf73ec9 100644 --- a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java +++ b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapServerBeanDefinitionParserTests.java @@ -1,14 +1,31 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ package org.springframework.security.config.ldap; +import static org.junit.Assert.*; + import org.junit.After; import org.junit.Test; import org.springframework.ldap.core.LdapTemplate; import org.springframework.security.config.BeanIds; import org.springframework.security.config.util.InMemoryXmlApplicationContext; import org.springframework.security.ldap.DefaultSpringSecurityContextSource; +import org.springframework.security.ldap.server.ApacheDSContainer; +import org.springframework.test.util.ReflectionTestUtils; /** * @author Luke Taylor + * @author Rob Winch */ public class LdapServerBeanDefinitionParserTests { InMemoryXmlApplicationContext appCtx; @@ -23,7 +40,7 @@ public class LdapServerBeanDefinitionParserTests { @Test public void embeddedServerCreationContainsExpectedContextSourceAndData() { - appCtx = new InMemoryXmlApplicationContext(""); + appCtx = new InMemoryXmlApplicationContext(""); DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) appCtx.getBean(BeanIds.CONTEXT_SOURCE); @@ -35,8 +52,8 @@ public class LdapServerBeanDefinitionParserTests { @Test public void useOfUrlAttributeCreatesCorrectContextSource() { // Create second "server" with a url pointing at embedded one - appCtx = new InMemoryXmlApplicationContext("" + - ""); + appCtx = new InMemoryXmlApplicationContext("" + + ""); // Check the default context source is still there. appCtx.getBean(BeanIds.CONTEXT_SOURCE); @@ -58,6 +75,12 @@ public class LdapServerBeanDefinitionParserTests { template.lookup("uid=pg,ou=gorillas"); } + @Test + public void defaultLdifFileIsSuccessful() { + appCtx = new InMemoryXmlApplicationContext( + ""); + ApacheDSContainer dsContainer = appCtx.getBean(ApacheDSContainer.class); - + assertEquals("classpath*:*.ldif", ReflectionTestUtils.getField(dsContainer, "ldifResources")); + } } diff --git a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapUserServiceBeanDefinitionParserTests.java b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapUserServiceBeanDefinitionParserTests.java index 6a156edad5..d862ca4e9d 100644 --- a/config/src/integration-test/java/org/springframework/security/config/ldap/LdapUserServiceBeanDefinitionParserTests.java +++ b/config/src/integration-test/java/org/springframework/security/config/ldap/LdapUserServiceBeanDefinitionParserTests.java @@ -1,3 +1,15 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ package org.springframework.security.config.ldap; import static org.junit.Assert.*; @@ -23,6 +35,7 @@ import java.util.*; /** * @author Luke Taylor + * @author Rob Winch */ public class LdapUserServiceBeanDefinitionParserTests { private InMemoryXmlApplicationContext appCtx; @@ -47,12 +60,12 @@ public class LdapUserServiceBeanDefinitionParserTests { @Test public void minimalConfigurationIsParsedOk() throws Exception { - setContext(""); + setContext(""); } @Test public void userServiceReturnsExpectedData() throws Exception { - setContext(""); + setContext(""); UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS"); UserDetails ben = uds.loadUserByUsername("ben"); @@ -67,7 +80,7 @@ public class LdapUserServiceBeanDefinitionParserTests { setContext(""); + " group-search-filter='member={0}' />"); UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS"); UserDetails joe = uds.loadUserByUsername("Joe Smeth"); @@ -83,7 +96,7 @@ public class LdapUserServiceBeanDefinitionParserTests { " group-search-filter='member={0}' role-prefix='PREFIX_'/>" + ""); + " group-search-filter='member={0}' role-prefix='none'/>"); UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS"); UserDetails ben = uds.loadUserByUsername("ben"); @@ -98,7 +111,7 @@ public class LdapUserServiceBeanDefinitionParserTests { @Test public void differentGroupRoleAttributeWorksAsExpected() throws Exception { - setContext(""); + setContext(""); UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS"); UserDetails ben = uds.loadUserByUsername("ben"); @@ -112,7 +125,7 @@ public class LdapUserServiceBeanDefinitionParserTests { @Test public void isSupportedByAuthenticationProviderElement() { setContext( - "" + + "" + "" + " " + " " + @@ -123,7 +136,7 @@ public class LdapUserServiceBeanDefinitionParserTests { @Test public void personContextMapperIsSupported() { setContext( - "" + + "" + ""); UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS"); UserDetails ben = uds.loadUserByUsername("ben"); @@ -133,7 +146,7 @@ public class LdapUserServiceBeanDefinitionParserTests { @Test public void inetOrgContextMapperIsSupported() { setContext( - "" + + "" + ""); UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS"); UserDetails ben = uds.loadUserByUsername("ben"); @@ -143,7 +156,7 @@ public class LdapUserServiceBeanDefinitionParserTests { @Test public void externalContextMapperIsSupported() { setContext( - "" + + "" + "" + "");