directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r727223 - in /directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare: ./ CompareDirserver1139IT.java
Date Tue, 16 Dec 2008 23:58:04 GMT
Author: elecharny
Date: Tue Dec 16 15:58:01 2008
New Revision: 727223

URL: http://svn.apache.org/viewvc?rev=727223&view=rev
Log:
Added a test for DIRSERVER-1139 : seems to be fixed.

Added:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/CompareDirserver1139IT.java

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/CompareDirserver1139IT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/CompareDirserver1139IT.java?rev=727223&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/CompareDirserver1139IT.java
(added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/compare/CompareDirserver1139IT.java
Tue Dec 16 15:58:01 2008
@@ -0,0 +1,191 @@
+/*
+ *  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. 
+ *  
+ */
+package org.apache.directory.server.core.operations.compare;
+
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
+
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+/**
+ * Tests for DIRSERVERR-1139
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+@RunWith ( CiRunner.class )
+@CleanupLevel ( Level.CLASS )
+public class CompareDirserver1139IT
+{
+    public static DirectoryService service;
+    
+    /**
+     * Activate the NIS and KRB5KDC schemas
+     * @throws Exception
+     */
+    @Before
+    public void init() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // Enable the nis schema
+        // -------------------------------------------------------------------
+        // check if nis is disabled
+        LdapContext schemaRoot = getSchemaContext( service );
+        Attributes nisAttrs = schemaRoot.getAttributes( "cn=nis" );
+        boolean isNisDisabled = false;
+        
+        if ( nisAttrs.get( "m-disabled" ) != null )
+        {
+            isNisDisabled = ( ( String ) nisAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase(
"TRUE" );
+        }
+
+        // if nis is disabled then enable it
+        if ( isNisDisabled )
+        {
+            Attribute disabled = new BasicAttribute( "m-disabled" );
+            ModificationItem[] mods = new ModificationItem[] {
+                new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled ) };
+            schemaRoot.modifyAttributes( "cn=nis", mods );
+        }
+
+        // -------------------------------------------------------------------
+        // Enable the krb5kdc schema
+        // -------------------------------------------------------------------
+        // check if krb5kdc is disabled
+        Attributes krb5kdcAttrs = schemaRoot.getAttributes( "cn=krb5kdc" );
+        boolean isKrb5kdcDisabled = false;
+        
+        if ( nisAttrs.get( "m-disabled" ) != null )
+        {
+            isKrb5kdcDisabled = ( ( String ) krb5kdcAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase(
"TRUE" );
+        }
+
+        // if krb5kdc is disabled then enable it
+        if ( isKrb5kdcDisabled )
+        {
+            Attribute disabled = new BasicAttribute( "m-disabled" );
+            ModificationItem[] mods = new ModificationItem[] {
+                new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled ) };
+            schemaRoot.modifyAttributes( "cn=krb5kdc", mods );
+        }
+    }
+    
+    
+    /**
+     * Inject entries into the server
+     */
+    private void injectEntries( LdapContext sysRoot ) throws Exception
+    {
+        // Add the group
+        Attributes attrs = new BasicAttributes( true );
+        Attribute oc = new BasicAttribute( "ObjectClass" );
+        oc.add( "groupOfNames" );
+        oc.add( "top" );
+        attrs.put( oc );
+        attrs.put( "cn", "group" );
+        attrs.put( "member", "cn=user,ou=users,ou=system" );
+        
+        sysRoot.createSubcontext( "cn=group,ou=groups", attrs );
+        
+        // Add the user
+        attrs = new BasicAttributes( "objectClass", "top", true );
+        oc = new BasicAttribute( "ObjectClass" );
+        oc.add( "top" );
+        oc.add( "organizationalPerson" );
+        oc.add( "person" );
+        oc.add( "krb5Principal" );
+        oc.add( "posixAccount" );
+        oc.add( "shadowAccount" );
+        oc.add( "krb5KDCEntry" );
+        oc.add( "inetOrgPerson" );
+        attrs.put( oc );
+        attrs.put( "cn", "user" );
+        attrs.put( "gidnumber", "100" );
+        attrs.put( "givenname", "user" );
+        attrs.put( "homedirectory", "/home/users/user" );
+        attrs.put( "krb5KeyVersionNumber", "1" );
+        attrs.put( "krb5PrincipalName", "user@APACHE.ORG" );
+        attrs.put( "loginshell", "/bin/bash" );
+        attrs.put( "mail", "user@apache.org" );
+        attrs.put( "sn", "User" );
+        attrs.put( "uid", "user" );
+        attrs.put( "uidnumber", "1001" );
+        
+        sysRoot.createSubcontext( "cn=user,ou=users", attrs );
+    }
+    
+    
+    /**
+     * Compare a member attribute. This test is used to check DIRSERVER-1139
+     */
+    @Test
+    public void testCompare() throws Exception
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        
+        injectEntries( sysRoot);
+
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        controls.setReturningAttributes(  new String[0] );
+
+        NamingEnumeration<SearchResult> list = 
+            sysRoot.search( "cn=group,ou=groups", "(member=cn=user,ou=users,ou=system)",
controls );
+        
+        int count = 0;
+        
+        while ( list.hasMore() )
+        {
+            SearchResult result = list.next();
+            assertNotNull( result );
+            assertTrue( StringTools.isEmpty( result.getName() ) );
+            assertNotNull( result.getAttributes() );
+            assertEquals( 0, result.getAttributes().size() );
+            count++;
+        }
+        
+        assertEquals( 1, count );
+    }
+
+}



Mime
View raw message