directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [1/4] directory-kerby git commit: DIRKRB-519 Check all the tests to use the NameTest format.
Date Thu, 31 Dec 2015 03:12:40 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk e0ce27d7d -> d06becfd7


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java
deleted file mode 100644
index 8ad721a..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java
+++ /dev/null
@@ -1,49 +0,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. 
- *  
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.CompressedContentInfo;
-import org.apache.kerby.cms.type.CompressedData;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestCompressedData extends CmsTestBase {
-
-    @Test
-    public void testDump1WithCompressedData() throws IOException {
-        byte[] data = readDataFile("/compressed-data.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            CompressedContentInfo contentInfo = new CompressedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            CompressedData compressedData = contentInfo.getCompressedData();
-            Asn1.dump(compressedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java
deleted file mode 100644
index e30007a..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java
+++ /dev/null
@@ -1,86 +0,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.
- *
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.EnvelopedContentInfo;
-import org.apache.kerby.cms.type.EnvelopedData;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestEnvelopedData extends CmsTestBase {
-
-    @Test
-    public void testDecodingKeyTrns() throws IOException {
-        byte[] data = readDataFile("/enveloped-keytrns.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
-            Asn1.dump(envelopedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testDecodingKek() throws IOException {
-        byte[] data = readDataFile("/enveloped-kek.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
-            Asn1.dump(envelopedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testDecodingNestedNDEF() throws IOException {
-        byte[] data = readDataFile("/enveloped-nested-ndef.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
-            Asn1.dump(envelopedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
deleted file mode 100644
index 56c44af..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
+++ /dev/null
@@ -1,54 +0,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.
- *
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
-import org.apache.kerby.x509.type.Extension;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.*;
-
-public class TestExtension {
-
-    @Test
-    public void testUnsetCritical() throws IOException {
-        Extension extension = new Extension();
-        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
-        extension.setExtnValue("value".getBytes());
-        byte[] encodedBytes = extension.encode();
-        Extension decodedExtension = new Extension();
-        decodedExtension.decode(encodedBytes);
-        assertThat(decodedExtension.getCritical()).isFalse();
-    }
-
-    @Test
-    public void testSetCritical() throws IOException {
-        Extension extension = new Extension();
-        extension.setCritical(true);
-        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
-        extension.setExtnValue("value".getBytes());
-        byte[] encodedBytes = extension.encode();
-        Extension decodedExtension = new Extension();
-        decodedExtension.decode(encodedBytes);
-        assertThat(decodedExtension.getCritical()).isTrue();
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
deleted file mode 100644
index 54b60b7..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
+++ /dev/null
@@ -1,50 +0,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.
- *
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.apache.kerby.x509.type.GeneralName;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.*;
-
-public class TestGeneralName {
-    private static final byte[] IPV4 = HexUtil.hex2bytes("87040a090800");
-
-    @Test
-    public void testIpAddress() throws IOException {
-        try {
-            Asn1.parseAndDump(IPV4);
-            GeneralName generalName = new GeneralName();
-            generalName.decode(IPV4);
-            assertThat(generalName.getIPAddress()).isNotNull();
-            byte[] addressBytes = generalName.getIPAddress();
-            // "10.9.8.0"
-            assertThat(addressBytes).isEqualTo(new byte[] {0x0a, 0x09, 0x08, 0x00});
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
deleted file mode 100644
index ab85e93..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
+++ /dev/null
@@ -1,111 +0,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. 
- *  
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.CertificateChoices;
-import org.apache.kerby.cms.type.CertificateSet;
-import org.apache.kerby.cms.type.ContentInfo;
-import org.apache.kerby.cms.type.EncapsulatedContentInfo;
-import org.apache.kerby.cms.type.SignedContentInfo;
-import org.apache.kerby.cms.type.SignedData;
-import org.apache.kerby.x509.type.Certificate;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestSignedData extends CmsTestBase {
-
-    @Test
-    public void testDecoding() throws IOException {
-        byte[] data = readDataFile("/signed-data.txt");
-        try {
-            Asn1.parseAndDump(data);
-            //Asn1.decodeAndDump(data);
-
-            SignedContentInfo contentInfo = new SignedContentInfo();
-            contentInfo.decode(data);
-            //Asn1.dump(contentInfo);
-
-            SignedData signedData = contentInfo.getSignedData();
-            Asn1.dump(signedData);
-
-            Asn1.dump(contentInfo);
-            byte[] encodedData = contentInfo.encode();
-            Asn1.parseAndDump(encodedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testEncoding() throws IOException {
-        SignedContentInfo contentInfo = new SignedContentInfo();
-        contentInfo.setContentType("1.2.840.113549.1.7.2");
-        SignedData signedData = new SignedData();
-        EncapsulatedContentInfo eContentInfo = new EncapsulatedContentInfo();
-        eContentInfo.setContentType("1.3.6.1.5.2.3.1");
-        eContentInfo.setContent("data".getBytes());
-        signedData.setEncapContentInfo(eContentInfo);
-
-        byte[] data = readDataFile("/certificate1.txt");
-        Certificate certificate = new Certificate();
-        certificate.decode(data);
-        CertificateChoices certificateChoices = new CertificateChoices();
-        certificateChoices.setCertificate(certificate);
-        CertificateSet certificateSet = new CertificateSet();
-        certificateSet.addElement(certificateChoices);
-        signedData.setCertificates(certificateSet);
-
-        contentInfo.setSignedData(signedData);
-        Asn1.dump(contentInfo);
-
-        byte[] encodedData = contentInfo.encode();
-        Asn1.parseAndDump(encodedData);
-
-        SignedContentInfo decodedContentInfo = new SignedContentInfo();
-        decodedContentInfo.decode(encodedData);
-        Asn1.dump(decodedContentInfo);
-
-        SignedData decodedSignedData =
-                decodedContentInfo.getSignedData();
-        Asn1.dump(decodedSignedData);
-    }
-
-    @Test
-    public void testContentInfo() throws IOException {
-        byte[] data = readDataFile("/anonymous.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            ContentInfo contentInfo = new ContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-            SignedData signedData =
-                    contentInfo.getContentAs(SignedData.class);
-            Asn1.dump(signedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java b/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java
new file mode 100644
index 0000000..b32e2c7
--- /dev/null
+++ b/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java
@@ -0,0 +1,90 @@
+package org.apache.kerby.util;
+
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.Random;
+
+import static org.junit.Assert.assertTrue;
+
+
+public class Base64Test {
+
+    @Test
+    public void testOrigBase64() throws Exception {
+        Random random = new Random();
+        for (int i = 0; i < 4567; i++) {
+            byte[] buf = new byte[i];
+            random.nextBytes(buf);
+            byte[] enc = Base64.encodeBase64(buf);
+            ByteArrayInputStream in = new ByteArrayInputStream(enc);
+            enc = Util.streamToBytes(in);
+            byte[] dec = Base64.decodeBase64(enc);
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testOrigBase64 Failed on : " + i);
+            }
+            assertTrue(result);
+        }
+        for (int i = 5; i < 50; i++) {
+            int testSize = i * 1000 + 123;
+            byte[] buf = new byte[testSize];
+            random.nextBytes(buf);
+            byte[] enc = Base64.encodeBase64(buf);
+            ByteArrayInputStream in = new ByteArrayInputStream(enc);
+            enc = Util.streamToBytes(in);            
+            byte[] dec = Base64.decodeBase64(enc);
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testOrigBase64 Failed on : " + testSize);
+            }
+            assertTrue(result);
+        }
+    }
+
+    @Test
+    public void testBase64() throws Exception {
+        Random random = new Random();
+        for (int i = 0; i < 4567; i++) {
+            byte[] buf = new byte[i];
+            random.nextBytes(buf);
+
+            ByteArrayInputStream in = new ByteArrayInputStream(buf);
+            Base64InputStream base64 = new Base64InputStream(in, true);
+            byte[] enc = Util.streamToBytes(base64);
+            in = new ByteArrayInputStream(enc);
+            base64 = new Base64InputStream(in);
+            byte[] dec = Util.streamToBytes(base64);
+
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testBase64 Failed on : " + i);
+            }
+            assertTrue(result);
+        }
+        for (int i = 5; i < 50; i++) {
+            int testSize = i * 1000 + 123;
+            byte[] buf = new byte[testSize];
+            random.nextBytes(buf);
+
+            ByteArrayInputStream in = new ByteArrayInputStream(buf);
+            Base64InputStream base64 = new Base64InputStream(in, true);
+            byte[] enc = Util.streamToBytes(base64);
+            in = new ByteArrayInputStream(enc);
+            base64 = new Base64InputStream(in);
+            byte[] dec = Util.streamToBytes(base64);
+
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testBase64 Failed on : " + testSize);
+            }
+            assertTrue(result);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java b/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java
new file mode 100644
index 0000000..6607ccc
--- /dev/null
+++ b/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java
@@ -0,0 +1,80 @@
+package org.apache.kerby.util;
+
+import org.junit.Test;
+
+import static org.apache.kerby.util.IPAddressParser.parseIPv4Literal;
+import static org.apache.kerby.util.IPAddressParser.parseIPv6Literal;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNull;
+
+public class IPAddressParserTest {
+
+    @Test
+    public void theTest() {
+
+        // bad ones
+        assertNull("ip6 invalid", parseIPv6Literal(":::"));
+        assertNull("ip6 too many zero-expanders", parseIPv6Literal("1::1::"));
+        assertNull("ip6 .256 invalid", parseIPv6Literal("1::1:255.254.253.256"));
+        assertNull("ip6 too small", parseIPv6Literal("1:2:3:4"));
+        assertNull("ip6 no zero-expander after ip4", parseIPv6Literal("1:255.254.253.252::"));
+        assertNull("ip6 no zero-expander if 7 colons (end)", parseIPv6Literal("1:2:3:4:5:6:7:8::"));
+        assertNull("ip6 no zero-expander if 7 colons (begin)", parseIPv6Literal("::1:2:3:4:5:6:7:8"));
+        assertNull("ip6 88888 too many digits", parseIPv6Literal("1:2:3:4:5:6:7:88888"));
+        assertNull("ip6 missing colons", parseIPv6Literal("abcd"));
+        assertNull("ip6 umm, no", parseIPv6Literal("cookie monster"));
+        assertNull("ip6 empty string is invalid", parseIPv6Literal(""));
+        assertNull("ip6 null is invalid", parseIPv6Literal(null));
+
+        assertNull("ip4 not enough dots", parseIPv4Literal("abcd"));
+        assertNull("ip4 umm, no", parseIPv4Literal("cookie monster"));
+        assertNull("ip4 empty string is invalid", parseIPv4Literal(""));
+        assertNull("ip4 null is invalid", parseIPv4Literal(null));
+        assertNull("ip4 not enough dots 0", parseIPv4Literal("1"));
+        assertNull("ip4 not enough dots 1", parseIPv4Literal("1.2"));
+        assertNull("ip4 not enough dots 2", parseIPv4Literal("1.2.3"));
+        assertNull("ip4 needs digit after final dot", parseIPv4Literal("1.2.3."));
+        assertNull("ip4 [0-9] digits only", parseIPv4Literal("1.2.3.a"));
+        assertNull("ip4 too many dots", parseIPv4Literal("1.2.3.4.5"));
+        assertNull("ip4 0-255 range", parseIPv4Literal("1.2.3.444"));
+        assertNull("ip4 no negatives", parseIPv4Literal("1.2.-3.4"));
+        assertNull("ip4 no brackets", parseIPv4Literal("[1.2.3.4]"));
+
+        // good ones
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("::"));
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1::"));
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("::1"));
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("1::1"));
+        assertArrayEquals(new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("100::1"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, -3, -4},
+                parseIPv6Literal("1::1:255.254.253.252"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, -4},
+                parseIPv6Literal("::255.254.253.252"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, -1, -2, -3, -4},
+                parseIPv6Literal("1:2:3:4:5:6:255.254.253.252"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("::1:2:3:4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("1::2:3:4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 4}, parseIPv6Literal("1:2::3:4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}, parseIPv6Literal("1:2:3::4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1:2:3:4::"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
+                parseIPv6Literal("1:2:3:4:5:6:7:8"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("[::]"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
+                parseIPv6Literal("[1:2:3:4:5:6:7:8]"));
+
+        assertArrayEquals(new byte[]{17, 17, 34, 34, 51, 51, 68, 68, 85, 85, 102, 102, 119,
119, -120, -120},
+                parseIPv6Literal("1111:2222:3333:4444:5555:6666:7777:8888"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0}, parseIPv4Literal("0.0.0.0"));
+        assertArrayEquals(new byte[]{1, 2, 3, 4}, parseIPv4Literal("1.2.3.4"));
+        assertArrayEquals(new byte[]{-1, -1, -1, -1}, parseIPv4Literal("255.255.255.255"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java b/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java
deleted file mode 100644
index 0eef01d..0000000
--- a/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.apache.kerby.util;
-
-import org.junit.Test;
-
-import java.io.ByteArrayInputStream;
-import java.util.Arrays;
-import java.util.Random;
-
-import static org.junit.Assert.assertTrue;
-
-
-public class TestBase64 {
-
-    @Test
-    public void testOrigBase64() throws Exception {
-        Random random = new Random();
-        for (int i = 0; i < 4567; i++) {
-            byte[] buf = new byte[i];
-            random.nextBytes(buf);
-            byte[] enc = Base64.encodeBase64(buf);
-            ByteArrayInputStream in = new ByteArrayInputStream(enc);
-            enc = Util.streamToBytes(in);
-            byte[] dec = Base64.decodeBase64(enc);
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testOrigBase64 Failed on : " + i);
-            }
-            assertTrue(result);
-        }
-        for (int i = 5; i < 50; i++) {
-            int testSize = i * 1000 + 123;
-            byte[] buf = new byte[testSize];
-            random.nextBytes(buf);
-            byte[] enc = Base64.encodeBase64(buf);
-            ByteArrayInputStream in = new ByteArrayInputStream(enc);
-            enc = Util.streamToBytes(in);            
-            byte[] dec = Base64.decodeBase64(enc);
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testOrigBase64 Failed on : " + testSize);
-            }
-            assertTrue(result);
-        }
-    }
-
-    @Test
-    public void testBase64() throws Exception {
-        Random random = new Random();
-        for (int i = 0; i < 4567; i++) {
-            byte[] buf = new byte[i];
-            random.nextBytes(buf);
-
-            ByteArrayInputStream in = new ByteArrayInputStream(buf);
-            Base64InputStream base64 = new Base64InputStream(in, true);
-            byte[] enc = Util.streamToBytes(base64);
-            in = new ByteArrayInputStream(enc);
-            base64 = new Base64InputStream(in);
-            byte[] dec = Util.streamToBytes(base64);
-
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testBase64 Failed on : " + i);
-            }
-            assertTrue(result);
-        }
-        for (int i = 5; i < 50; i++) {
-            int testSize = i * 1000 + 123;
-            byte[] buf = new byte[testSize];
-            random.nextBytes(buf);
-
-            ByteArrayInputStream in = new ByteArrayInputStream(buf);
-            Base64InputStream base64 = new Base64InputStream(in, true);
-            byte[] enc = Util.streamToBytes(base64);
-            in = new ByteArrayInputStream(enc);
-            base64 = new Base64InputStream(in);
-            byte[] dec = Util.streamToBytes(base64);
-
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testBase64 Failed on : " + testSize);
-            }
-            assertTrue(result);
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java b/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java
deleted file mode 100644
index b132f7d..0000000
--- a/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.apache.kerby.util;
-
-import org.junit.Test;
-
-import static org.apache.kerby.util.IPAddressParser.parseIPv4Literal;
-import static org.apache.kerby.util.IPAddressParser.parseIPv6Literal;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertNull;
-
-public class TestIPAddressParser {
-
-    @Test
-    public void theTest() {
-
-        // bad ones
-        assertNull("ip6 invalid", parseIPv6Literal(":::"));
-        assertNull("ip6 too many zero-expanders", parseIPv6Literal("1::1::"));
-        assertNull("ip6 .256 invalid", parseIPv6Literal("1::1:255.254.253.256"));
-        assertNull("ip6 too small", parseIPv6Literal("1:2:3:4"));
-        assertNull("ip6 no zero-expander after ip4", parseIPv6Literal("1:255.254.253.252::"));
-        assertNull("ip6 no zero-expander if 7 colons (end)", parseIPv6Literal("1:2:3:4:5:6:7:8::"));
-        assertNull("ip6 no zero-expander if 7 colons (begin)", parseIPv6Literal("::1:2:3:4:5:6:7:8"));
-        assertNull("ip6 88888 too many digits", parseIPv6Literal("1:2:3:4:5:6:7:88888"));
-        assertNull("ip6 missing colons", parseIPv6Literal("abcd"));
-        assertNull("ip6 umm, no", parseIPv6Literal("cookie monster"));
-        assertNull("ip6 empty string is invalid", parseIPv6Literal(""));
-        assertNull("ip6 null is invalid", parseIPv6Literal(null));
-
-        assertNull("ip4 not enough dots", parseIPv4Literal("abcd"));
-        assertNull("ip4 umm, no", parseIPv4Literal("cookie monster"));
-        assertNull("ip4 empty string is invalid", parseIPv4Literal(""));
-        assertNull("ip4 null is invalid", parseIPv4Literal(null));
-        assertNull("ip4 not enough dots 0", parseIPv4Literal("1"));
-        assertNull("ip4 not enough dots 1", parseIPv4Literal("1.2"));
-        assertNull("ip4 not enough dots 2", parseIPv4Literal("1.2.3"));
-        assertNull("ip4 needs digit after final dot", parseIPv4Literal("1.2.3."));
-        assertNull("ip4 [0-9] digits only", parseIPv4Literal("1.2.3.a"));
-        assertNull("ip4 too many dots", parseIPv4Literal("1.2.3.4.5"));
-        assertNull("ip4 0-255 range", parseIPv4Literal("1.2.3.444"));
-        assertNull("ip4 no negatives", parseIPv4Literal("1.2.-3.4"));
-        assertNull("ip4 no brackets", parseIPv4Literal("[1.2.3.4]"));
-
-        // good ones
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("::"));
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1::"));
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("::1"));
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("1::1"));
-        assertArrayEquals(new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("100::1"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, -3, -4},
-                parseIPv6Literal("1::1:255.254.253.252"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, -4},
-                parseIPv6Literal("::255.254.253.252"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, -1, -2, -3, -4},
-                parseIPv6Literal("1:2:3:4:5:6:255.254.253.252"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("::1:2:3:4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("1::2:3:4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 4}, parseIPv6Literal("1:2::3:4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}, parseIPv6Literal("1:2:3::4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1:2:3:4::"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
-                parseIPv6Literal("1:2:3:4:5:6:7:8"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("[::]"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
-                parseIPv6Literal("[1:2:3:4:5:6:7:8]"));
-
-        assertArrayEquals(new byte[]{17, 17, 34, 34, 51, 51, 68, 68, 85, 85, 102, 102, 119,
119, -120, -120},
-                parseIPv6Literal("1111:2222:3333:4444:5555:6666:7777:8888"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0}, parseIPv4Literal("0.0.0.0"));
-        assertArrayEquals(new byte[]{1, 2, 3, 4}, parseIPv4Literal("1.2.3.4"));
-        assertArrayEquals(new byte[]{-1, -1, -1, -1}, parseIPv4Literal("255.255.255.255"));
-    }
-}


Mime
View raw message