directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1183562 - in /directory/apacheds/trunk/interceptors/authn/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/directory/ java/org/apache/directory/server/ java/org/apache/directory/server/core/ java/org/apache/directory/server/co...
Date Fri, 14 Oct 2011 23:34:17 GMT
Author: elecharny
Date: Fri Oct 14 23:34:17 2011
New Revision: 1183562

URL: http://svn.apache.org/viewvc?rev=1183562&view=rev
Log:
Still having some files to commit for interceptors decoupling

Added:
    directory/apacheds/trunk/interceptors/authn/src/test/
    directory/apacheds/trunk/interceptors/authn/src/test/java/
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/LdapPrincipalTest.java
    directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticatorOneWayEncryptedTest.java

Added: directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/LdapPrincipalTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/LdapPrincipalTest.java?rev=1183562&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/LdapPrincipalTest.java
(added)
+++ directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/LdapPrincipalTest.java
Fri Oct 14 23:34:17 2011
@@ -0,0 +1,107 @@
+/*
+ *  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.authn;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.LdapPrincipalSerializer;
+import org.apache.directory.shared.ldap.model.constants.AuthenticationLevel;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * 
+ * Test the LdapPrincipal class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class LdapPrincipalTest
+{
+    /** The schema manager instance */
+    private static SchemaManager schemaManager;
+
+    @BeforeClass
+    public static void setUp() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+
+    /**
+     * Test the serialization of an empty LdapPrincipal
+     */
+    @Test
+    public void testStaticSerializeEmptyLdapPrincipal() throws Exception
+    {
+        LdapPrincipal principal = new LdapPrincipal( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdapPrincipalSerializer.serialize( principal, out );
+        out.flush();
+
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdapPrincipal readPrincipal = LdapPrincipalSerializer.deserialize( schemaManager,
in );
+        assertEquals( principal.getAuthenticationLevel(), readPrincipal.getAuthenticationLevel()
);
+        assertEquals( principal.getName(), readPrincipal.getName() );
+    }
+    
+    
+    /**
+     * Test the serialization of an empty LdapPrincipal
+     */
+    @Test
+    public void testStaticSerializeLdapPrincipalWithSchemaManager() throws Exception
+    {
+        LdapPrincipal principal = new LdapPrincipal( schemaManager, new Dn( schemaManager,
"uid=admin,ou=system" ), AuthenticationLevel.STRONG );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdapPrincipalSerializer.serialize( principal, out );
+        out.flush();
+
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdapPrincipal readPrincipal = LdapPrincipalSerializer.deserialize( schemaManager,
in );
+        assertEquals( principal.getAuthenticationLevel(), readPrincipal.getAuthenticationLevel()
);
+        assertEquals( principal.getName(), readPrincipal.getName() );
+    }
+}

Added: directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticatorOneWayEncryptedTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticatorOneWayEncryptedTest.java?rev=1183562&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticatorOneWayEncryptedTest.java
(added)
+++ directory/apacheds/trunk/interceptors/authn/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticatorOneWayEncryptedTest.java
Fri Oct 14 23:34:17 2011
@@ -0,0 +1,80 @@
+/*
+ *  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.authn;
+
+
+import static org.junit.Assert.assertEquals;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+import org.apache.directory.shared.util.Strings;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test case for helper methods within SimpleAuthenticator.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SimpleAuthenticatorOneWayEncryptedTest
+{
+    private static SimpleAuthenticator auth = null;
+
+
+    @BeforeClass
+    public static void setUp() throws Exception
+    {
+
+        auth = new SimpleAuthenticator();
+    }
+
+
+    @Test
+    public void testGetAlgorithmForHashedPassword()
+    {
+        String digestetValue = "{SHA}LhkDrSoM6qr0fW6hzlfOJQW61tc=";
+        assertEquals( "SHA", auth.getAlgorithmForHashedPassword( Strings.getBytesUtf8(digestetValue)
) );
+        assertEquals( "SHA", auth.getAlgorithmForHashedPassword( digestetValue.getBytes()
) );
+
+        String noAlgorithm = "Secret1!";
+        assertEquals( null, auth.getAlgorithmForHashedPassword( Strings.getBytesUtf8(noAlgorithm)
) );
+        assertEquals( null, auth.getAlgorithmForHashedPassword( noAlgorithm.getBytes() )
);
+
+        String unknownAlgorithm = "{XYZ}LhkDrSoM6qr0fW6hzlfOJQW61tc=";
+        assertEquals( null, auth.getAlgorithmForHashedPassword( Strings.getBytesUtf8(unknownAlgorithm)
) );
+        assertEquals( null, auth.getAlgorithmForHashedPassword( unknownAlgorithm.getBytes()
) );
+    }
+
+
+    @Test
+    public void testCreateDigestedPassword() throws IllegalArgumentException
+    {
+        String pwd = "Secret1!";
+        String expected = "{SHA}znbJr3+tymFoQD4+Njh4ITtI7Cc=";
+        String digested = auth.createDigestedPassword( "SHA", Strings.getBytesUtf8(pwd) );
+
+        assertEquals( expected, digested );
+    }
+}
\ No newline at end of file



Mime
View raw message