1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18/**
19 * @author Alexander Y. Kleymenov
20 */
21
22package org.apache.harmony.security.tests.provider.cert;
23
24import java.math.BigInteger;
25import java.util.Date;
26import javax.security.auth.x500.X500Principal;
27
28import org.apache.harmony.security.provider.cert.X509CRLEntryImpl;
29import org.apache.harmony.security.x509.Extension;
30import org.apache.harmony.security.x509.Extensions;
31import org.apache.harmony.security.x509.ReasonCode;
32import org.apache.harmony.security.x509.TBSCertList;
33
34import junit.framework.Test;
35import junit.framework.TestCase;
36import junit.framework.TestSuite;
37
38/**
39 * X509CRLEntryImplTest test
40 */
41public class X509CRLEntryImplTest extends TestCase {
42
43    /**
44     * getExtensionValue(String oid) method testing.
45     */
46    public void testGetExtensionValue() throws Exception {
47        // revoked certificate issuer
48        X500Principal issuer =
49            new X500Principal("O=Certificate Issuer");
50        // revoked certificate serial number
51        BigInteger serialNumber = BigInteger.valueOf(555);
52        // crl entry extensions
53        Extensions crlEntryExtensions = new Extensions();
54        // add reason code extension which OID is 2.5.29.21
55        // see RFC 3280 http://www.ietf.org/rfc/rfc3280.txt
56        crlEntryExtensions.addExtension(
57                new Extension("2.5.29.21", Extension.NON_CRITICAL,
58                    new ReasonCode(ReasonCode.KEY_COMPROMISE)));
59        // crl entry
60        X509CRLEntryImpl crlEntry = new X509CRLEntryImpl(
61                new TBSCertList.RevokedCertificate(
62                        serialNumber,
63                        new Date(),
64                        crlEntryExtensions
65                    ),
66                issuer
67            );
68        assertNotNull(crlEntry.getExtensionValue("2.5.29.21"));
69        assertNull("Null value should be returned in the case of "
70                + "nonexisting extension",
71                // demand absent Invalidity Date extension
72                // which OID is 2.5.29.24 (RFC 3280)
73                crlEntry.getExtensionValue("2.5.29.24"));
74    }
75
76    public static Test suite() {
77        return new TestSuite(X509CRLEntryImplTest.class);
78    }
79
80}
81