harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r433520 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10: CertificationRequestInfoTest.java CertificationRequestTest.java
Date Tue, 22 Aug 2006 05:01:27 GMT
Author: mloenko
Date: Mon Aug 21 22:01:27 2006
New Revision: 433520

URL: http://svn.apache.org/viewvc?rev=433520&view=rev
Log:
integrating new tests from HARMONY-1234
Tests for org.apache.harmony.security.pkcs10

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java?rev=433520&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java
Mon Aug 21 22:01:27 2006
@@ -0,0 +1,85 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.harmony.security.tests.pkcs10;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.security.auth.x500.X500Principal;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.pkcs10.CertificationRequestInfo;
+import org.apache.harmony.security.x501.AttributeTypeAndValue;
+import org.apache.harmony.security.x501.AttributeValue;
+import org.apache.harmony.security.x501.Name;
+import org.apache.harmony.security.x509.AlgorithmIdentifier;
+import org.apache.harmony.security.x509.SubjectPublicKeyInfo;
+
+
+public class CertificationRequestInfoTest extends TestCase {
+
+    /**
+     * Test method for CertificationRequestInfo. Creates
+     * CertificationRequestInfo, gets its values, encodes and decodes the
+     * encoded form.
+     * 
+     */
+    public void testCertificationRequestInfo() throws IOException {
+        int version = 2;// X.509 v3
+        Name subject = new Name("O=subject");
+        SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo(
+                new AlgorithmIdentifier("1.2.840.113549.1.1.2"), new byte[4]);
+        List attributes = new ArrayList();
+        // 1.2.840.113549.1.9.1 is OID of EMAILADDRESS
+        attributes.add(new AttributeTypeAndValue("1.2.840.113549.1.9.1",
+                new AttributeValue("a@b.com", false)));
+
+        CertificationRequestInfo certReqInfo = new CertificationRequestInfo(
+                version, subject, spki, attributes);
+
+        // check what we have constructed
+        assertEquals(version, certReqInfo.getVersion());
+        assertEquals(subject.getName(X500Principal.RFC1779), certReqInfo
+                .getSubject().getName(X500Principal.RFC1779));
+        assertTrue(Arrays.equals(spki.getEncoded(), certReqInfo
+                .getSubjectPublicKeyInfo().getEncoded()));
+        assertEquals(attributes, certReqInfo.getAttributes());
+
+        // decode the encoded CertificationRequestInfo 
+        byte[] encoding = certReqInfo.getEncoded();
+        CertificationRequestInfo decoded = 
+                (CertificationRequestInfo) CertificationRequestInfo.ASN1
+                        .decode(encoding);
+
+        // check what was decoded
+        assertEquals(certReqInfo.getVersion(), decoded.getVersion());
+        assertEquals(certReqInfo.getSubject().getName(X500Principal.CANONICAL),
+                decoded.getSubject().getName(X500Principal.CANONICAL));
+        assertTrue(Arrays.equals(certReqInfo.getSubjectPublicKeyInfo()
+                .getEncoded(), decoded.getSubjectPublicKeyInfo().getEncoded()));
+        
+        AttributeTypeAndValue certReqInfoATaV = (AttributeTypeAndValue) certReqInfo
+                .getAttributes().get(0); 
+        AttributeTypeAndValue decodedATaV = (AttributeTypeAndValue) decoded
+                .getAttributes().get(0);
+        assertEquals(certReqInfoATaV.getType(), decodedATaV.getType());
+    }
+}
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java?rev=433520&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java
Mon Aug 21 22:01:27 2006
@@ -0,0 +1,86 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.harmony.security.tests.pkcs10;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.pkcs10.CertificationRequest;
+import org.apache.harmony.security.pkcs10.CertificationRequestInfo;
+import org.apache.harmony.security.x501.AttributeTypeAndValue;
+import org.apache.harmony.security.x501.AttributeValue;
+import org.apache.harmony.security.x501.Name;
+import org.apache.harmony.security.x509.AlgorithmIdentifier;
+import org.apache.harmony.security.x509.SubjectPublicKeyInfo;
+
+
+
+public class CertificationRequestTest extends TestCase {
+
+    /**
+     * Test method for 'com.openintel.drl.security.pkcs10.CertificationRequest'.
+     * Creates CertificationRequest, gets its values, encodes and decodes the
+     * encoded form.
+     * 
+     */
+    public void testCertificationRequest() throws IOException {
+        int version = 2;// v3
+        Name subject = new Name("O=subject");
+        SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo(
+                new AlgorithmIdentifier("1.2.840.113549.1.1.2"), new byte[4]);
+        List attributes = new ArrayList();
+        // 1.2.840.113549.1.9.1 is OID of EMAILADDRESS
+        attributes.add(new AttributeTypeAndValue("1.2.840.113549.1.9.1",
+                new AttributeValue("a@b.com", false)));
+        CertificationRequestInfo certReqInfo = new CertificationRequestInfo(
+                version, subject, spki, attributes);
+        AlgorithmIdentifier signatureAlgId = new AlgorithmIdentifier(
+                "1.2.3.44.555");
+        byte[] signature = { (byte) 0x01, (byte) 0x02, (byte) 0x03,
+                (byte) 0x04, (byte) 0x05 };
+
+        CertificationRequest certReq = new CertificationRequest(certReqInfo,
+                signatureAlgId, signature);
+
+        // check what we have constructed
+        assertEquals(certReqInfo, certReq.getInfo());
+        assertEquals(signatureAlgId, certReq.getAlgId());
+        assertTrue(Arrays.equals(signature, certReq.getSignature()));
+
+        // decode the encoded CSR 
+        byte[] encoding = certReq.getEncoded();
+        CertificationRequest decoded = (CertificationRequest) CertificationRequest.ASN1
+                .decode(encoding);
+
+        // check what was decoded
+        CertificationRequestInfo decodedCRinfo = certReq.getInfo();
+        
+        assertEquals(certReqInfo.getSubject(), decodedCRinfo.getSubject());
+        assertEquals(certReqInfo.getSubjectPublicKeyInfo(), decodedCRinfo
+                .getSubjectPublicKeyInfo());
+        assertEquals(certReqInfo.getVersion(), decodedCRinfo.getVersion());
+        assertEquals(certReqInfo.getAttributes(), decodedCRinfo.getAttributes());
+        
+        assertEquals(certReq.getAlgId(), decoded.getAlgId());
+        assertTrue(Arrays.equals(certReq.getSignature(), decoded.getSignature()));
+    }
+}
+



Mime
View raw message