directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208842 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapUrlTest.java
Date Sat, 02 Jul 2005 15:17:26 GMT
Author: elecharny
Date: Sat Jul  2 08:17:25 2005
New Revision: 208842

URL: http://svn.apache.org/viewcvs?rev=208842&view=rev
Log:
A test case for the LdapUrl class. The RFC 2255 examples have been used, but it contains an
error...

Added:
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapUrlTest.java

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapUrlTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapUrlTest.java?rev=208842&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapUrlTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapUrlTest.java
Sat Jul  2 08:17:25 2005
@@ -0,0 +1,568 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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.apache.asn1.ldap.codec.utils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ldap.codec.primitives.LdapURL;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+
+/**
+ * Test the class LdapURL
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapUrlTest extends TestCase
+{
+    /** Logger */
+    protected static Logger log = Logger.getLogger( LdapUrlTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Setup the test
+     */
+    protected void setUp()
+    {
+    }
+
+    /**
+     * Utility function that return a char array from a String
+     *
+     * @param value The String 
+     *
+     * @return A char[] representing the String
+     */
+    private char[] getChars( String value )
+    {
+
+        char[] charArray = new char[value.length()];
+
+        value.getChars( 0, value.length(), charArray, 0 );
+        return charArray;
+    }
+
+    /**
+     * Test a null LdapURL
+     */
+    public void testLdapUrlNull() throws DecoderException
+    {
+        Assert.assertEquals( "ldap:///", new LdapURL( null ).toString() );
+    }
+
+    /**
+     * test an empty LdapURL
+     */
+    public void testLdapDNEmpty() throws DecoderException
+    {
+        Assert.assertEquals( "ldap:///", new LdapURL( "".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple LdapURL
+     */
+    public void testLdapDNSimple() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://directory.apache.org:80/", new LdapURL( "ldap://directory.apache.org:80/".getBytes()
).toString() );
+    }
+
+    /**
+     * test a LdapURL host 1
+     */
+    public void testLdapDNWithMinus() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://d-a.org:80/", new LdapURL( "ldap://d-a.org:80/".getBytes()
).toString() );
+    }
+
+    /**
+     * test a LdapURL with a bad port
+     */
+    public void testLdapDNBadPort() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad port 2
+     */
+    public void testLdapDNBadPort2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:-1/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad port 3
+     */
+    public void testLdapDNBadPort3() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:abc/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad port 4
+     */
+    public void testLdapDNBadPort4() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:65536/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with no host 
+     */
+    public void testLdapDNBadHost1() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///", new LdapURL( "ldap:///".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with a bad host 2
+     */
+    public void testLdapDNBadHost2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://./".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+    
+    /**
+     * test a LdapURL with a bad host 3
+     */
+    public void testLdapDNBadHost3() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a..b/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 4
+     */
+    public void testLdapDNBadHost4() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://-/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 5
+     */
+    public void testLdapDNBadHost5() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a.b.c-/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 6
+     */
+    public void testLdapDNBadHost6() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a.b.-c/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 7
+     */
+    public void testLdapDNBadHost7() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a.-.c/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL IP host
+     */
+    public void testLdapDNIPHost() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://1.2.3.4/", new LdapURL( "ldap://1.2.3.4/".getBytes()
).toString() );
+    }
+
+    /**
+     * test a LdapURL IP host and port
+     */
+    public void testLdapDNIPHostPort() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://1.2.3.4:80/", new LdapURL( "ldap://1.2.3.4:80/".getBytes()
).toString() );
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 1
+     */
+    public void testLdapDNBadHostIP1() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 2
+     */
+    public void testLdapDNBadHostIP2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1./".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 3
+     */
+    public void testLdapDNBadHostIP3() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1.100000/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 4
+     */
+    public void testLdapDNBadHostIP4() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1.1.1/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a valid host hich is not an IP
+     */
+    public void testLdapDNNotAnIP() throws DecoderException
+    {
+        Assert.assertEquals("ldap://1.1.1.100000.a/", new LdapURL( "ldap://1.1.1.100000.a/".getBytes()
).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid simpleDN
+     */
+    public void testLdapDNSimpleDN() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org/", new LdapURL(
"ldap://directory.apache.org:389/dc=example,dc=org/".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid simpleDN 2
+     */
+    public void testLdapDNSimpleDN2() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org", new LdapURL(
"ldap://directory.apache.org:389/dc=example,dc=org".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with a valid encoded DN
+     */
+    public void testLdapDNSimpleDNEncoded() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example 2,dc=org", new LdapURL(
"ldap://directory.apache.org:389/dc=example%202,dc=org".getBytes() ).toString() );
+    }
+    
+    /**
+     * test a LdapURL with an invalid DN
+     */
+    public void testLdapDNInvalidDN() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/dc=example 2,dc : org".getBytes()
);
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+
+    /**
+     * test a LdapURL with an invalid DN 2
+     */
+    public void testLdapDNInvalidDN2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/dc=example 2,dc = org,".getBytes()
);
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+
+    /**
+     * test a LdapURL with valid unique attributes
+     */
+    public void testLdapDNUniqueAttribute() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou", new LdapURL(
"ldap://directory.apache.org:389/dc=example,dc=org?ou".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid attributes
+     */
+    public void testLdapDNAttributes() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc",
new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc".getBytes()
).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid duplicated attributes
+     */
+    public void testLdapDNDuplicatedAttributes() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,dc", new
LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou".getBytes() ).toString()
);
+    }
+
+    /**
+     * test a LdapURL with invalid attributes
+     */
+    public void testLdapInvalideAttributes() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou=,dc".getBytes()
);
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+    /**
+     * test a LdapURL with attributes but no DN
+     */
+    public void testLdapNoDNAttributes() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/?ou,dc".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+
+    /**
+     * test 1 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_1() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///o=University of Michigan,c=US", new LdapURL( "ldap:///o=University%20of%20Michigan,c=US".getBytes()
).toString() );
+    }
+    
+    /**
+     * test 2 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_2() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University of Michigan,c=US", new
LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US".getBytes() ).toString()
);
+    }
+
+    /**
+     * test 3 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_3() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University of Michigan,c=US?postalAddress",
new LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress".getBytes()
).toString() );
+    }
+
+    /**
+     * test 4 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_4() throws DecoderException
+    {
+        Assert.assertEquals("ldap://host.com:6666/o=University of Michigan,c=US??sub?(cn=Babs
Jensen)", new LdapURL( "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)".getBytes()
).toString() );
+    }
+
+    /**
+     * test 5 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_5() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/c=GB?objectClass?one", new LdapURL(
"ldap://ldap.itd.umich.edu/c=GB?objectClass?one".getBytes() ).toString() );
+    }
+
+    /**
+     * test 6 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_6() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.question.com/o=Question?,c=US?mail", new LdapURL(
"ldap://ldap.question.com/o=Question%3f,c=US?mail".getBytes() ).toString() );
+    }
+
+    /**
+     * test 7 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_7() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.netscape.com/o=Babsco,c=US???(int=\\00\\00\\00\\04)",
new LdapURL( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)".getBytes()
).toString() );
+    }
+
+    /**
+     * test 8 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_8() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///??sub??bindname=cn=Manager,o=Foo", new LdapURL( "ldap:///??sub??bindname=cn=Manager%2co=Foo".getBytes()
).toString() );
+    }
+
+    /**
+     * test 9 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_9() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///??sub??!bindname=cn=Manager,o=Foo", new LdapURL( "ldap:///??sub??!bindname=cn=Manager%2co=Foo".getBytes()
).toString() );
+    }
+}
+



Mime
View raw message