Author: olamy
Date: Fri Feb 1 15:30:18 2013
New Revision: 1441486
URL: http://svn.apache.org/viewvc?rev=1441486&view=rev
Log:
really add test !
Added:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
(with props)
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/resources/ldap-spring-test.xml
(with props)
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/security.properties
(with props)
Added:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java?rev=1441486&view=auto
==============================================================================
---
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
(added)
+++
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
Fri Feb 1 15:30:18 2013
@@ -0,0 +1,161 @@
+package org.apache.archiva.redback.rest.services;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.archiva.redback.components.apacheds.ApacheDs;
+import org.apache.archiva.redback.rest.api.services.LdapGroupMappingService;
+import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
+import org.fest.assertions.Assertions;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Olivier Lamy
+ */
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration(
+ locations = { "classpath:/ldap-spring-test.xml" } )
+@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
+public class LdapGroupMappingServiceTest
+ extends AbstractRestServicesTest
+{
+
+ @Inject
+ @Named( value = "apacheDS#test" )
+ private ApacheDs apacheDs;
+
+ List<String> groups =
+ Arrays.asList( "Archiva System Administrator", "Internal Repo
Manager", "Internal Repo Observer" );
+
+ private String suffix;
+
+ private String groupSuffix;
+
+ @Override
+ protected String getSpringConfigLocation()
+ {
+ return
"classpath*:spring-context.xml,classpath*:META-INF/spring-context.xml,classpath:/ldap-spring-test.xml";
+ }
+
+ @Override
+ public void startServer()
+ throws Exception
+ {
+ super.startServer();
+
+ groupSuffix = apacheDs.addSimplePartition( "test", new String[]{
"archiva", "apache", "org" } ).getSuffix();
+
+ log.info( "groupSuffix: {}", groupSuffix );
+
+ suffix = "ou=People,dc=archiva,dc=apache,dc=org";
+
+ log.info( "DN Suffix: {}", suffix );
+
+ apacheDs.startServer();
+
+ BasicAttribute objectClass = new BasicAttribute( "objectClass" );
+ objectClass.add( "top" );
+ objectClass.add( "organizationalUnit" );
+
+ Attributes attributes = new BasicAttributes( true );
+ attributes.put( objectClass );
+ attributes.put( "organizationalUnitName", "foo" );
+
+ apacheDs.getAdminContext().createSubcontext( suffix, attributes );
+
+ createGroups();
+ }
+
+ @Override
+ public void stopServer()
+ throws Exception
+ {
+ super.stopServer();
+ }
+
+ private void createGroups()
+ throws Exception
+ {
+ InitialDirContext context = apacheDs.getAdminContext();
+
+ for ( String group : groups )
+ {
+ createGroup( context, group, createGroupDn( group ) );
+ }
+
+ }
+
+ private void createGroup( DirContext context, String groupName, String dn )
+ throws Exception
+ {
+
+ Attributes attributes = new BasicAttributes( true );
+ BasicAttribute objectClass = new BasicAttribute( "objectClass" );
+ objectClass.add( "top" );
+ objectClass.add( "groupOfUniqueNames" );
+ attributes.put( objectClass );
+ attributes.put( "cn", groupName );
+ BasicAttribute basicAttribute = new BasicAttribute( "uniquemember" );
+
+ basicAttribute.add( "uid=admin," + suffix );
+
+ attributes.put( basicAttribute );
+ context.createSubcontext( dn, attributes );
+ }
+
+ private String createGroupDn( String cn )
+ {
+ return "cn=" + cn + "," + groupSuffix;
+ }
+
+ @Test
+ public void getAllGroups()
+ throws Exception
+ {
+
+ try
+ {
+ LdapGroupMappingService service = getLdapGroupMappingService(
authorizationHeader );
+
+ List<String> groups = service.getLdapGroups().getStrings();
+
+ Assertions.assertThat( groups ).isNotNull().isNotEmpty().hasSize(
3 ).contains( groups.toArray() );
+ }
+ catch ( Exception e )
+ {
+ log.error( e.getMessage(), e );
+ throw e;
+ }
+
+ }
+}
Propchange:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/resources/ldap-spring-test.xml
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/resources/ldap-spring-test.xml?rev=1441486&view=auto
==============================================================================
---
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/resources/ldap-spring-test.xml
(added)
+++
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/resources/ldap-spring-test.xml
Fri Feb 1 15:30:18 2013
@@ -0,0 +1,79 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
+
+ <context:property-placeholder system-properties-mode="OVERRIDE"/>
+
+
+ <alias name="userConfiguration#redback" alias="userConfiguration#default"/>
+
+ <bean name="commons-configuration"
class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry"
+ init-method="initialize">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <properties fileName="${basedir}/src/test/security.properties"
config-optional="true"
+ config-at="org.apache.archiva.redback"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="apacheDS#test"
class="org.apache.archiva.redback.components.apacheds.DefaultApacheDs"
+ scope="prototype">
+ <property name="basedir" value="${basedir}/target/apacheds"/>
+ <property name="port" value="${ldapPort}"/>
+ <property name="enableNetworking" value="true"/>
+ <property name="password" value="secret"/>
+ </bean>
+
+ <bean name="ldapConnectionFactory#configurable"
+
class="org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
+ <property name="hostname" value="localhost"/>
+ <property name="port" value="${ldapPort}"/>
+ <!--property name="baseDn"
value="dc=redback,dc=plexus,dc=codehaus,dc=org"/-->
+ <property name="baseDn" value="dc=archiva,dc=apache,dc=org"/>
+ <property name="contextFactory" value="com.sun.jndi.ldap.LdapCtxFactory"/>
+ <property name="password" value="secret"/>
+ <property name="bindDn" value="uid=admin,ou=system"/>
+ <property name="userConf" ref="userConfiguration#default"/>
+ </bean>
+
+ <alias name="ldapRoleMapper#test" alias="ldapRoleMapper#default"/>
+
+ <bean name="ldapRoleMapper#test"
class="org.apache.archiva.redback.common.ldap.role.DefaultLdapRoleMapper">
+ <property name="groupsDn" value="dc=archiva,dc=apache,dc=org"/>
+ <property name="ldapGroupClass" value="groupOfUniqueNames"/>
+ <property name="baseDn" value="ou=People,dc=archiva,dc=apache,dc=org"/>
+ <property name="ldapConnectionFactory"
ref="ldapConnectionFactory#configurable"/>
+ <property name="userConf" ref="userConfiguration#default"/>
+ </bean>
+
+</beans>
\ No newline at end of file
Propchange:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/resources/ldap-spring-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/resources/ldap-spring-test.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/security.properties
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/security.properties?rev=1441486&view=auto
==============================================================================
---
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/security.properties
(added)
+++
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/security.properties
Fri Feb 1 15:30:18 2013
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#ldap.config.groups.role.archiva-admin=Archiva System Administrator
+#ldap.config.groups.role.internal-repo-manager=Internal Repo Manager
+#ldap.config.groups.role.internal-repo-observer=Internal Repo Observer
+#ldap.config.hostname=localhost
+#ldap.config.port=1389
+#ldap.config.base.dn=ou=People,dc=archiva,dc=apache,dc=org
+#ldap.config.context.factory=com.sun.jndi.ldap.LdapCtxFactory
+#ldap.config.bind.dn=uid=admin,ou=People,dc=archiva,dc=apache,dc=org
+#ldap.config.bind.dn=cn=Directory Manager
+#ldap.config.password=admin
+#ldap.config.authentication.method=
+#ldap.config.mapper.attribute.user.id=uid
+
+ldap.config.groups.base.dn=dc=archiva,dc=apache,dc=org
+#ldap.config.groups.role.archiva-admin=System Administrator
+#ldap.config.groups.role.snapshot-manager=Repository Manager - snapshots
+#ldap.config.groups.role.snapshot-observer=Repository Observer - snapshots
+
+#ldap.config.writable=true
+#ldap.config.groups.use.rolename=true
\ No newline at end of file
Propchange:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/security.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/security.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision