2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.auth.cm.data;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Mockito.when;
26 import static org.mockito.MockitoAnnotations.initMocks;
28 import java.io.IOException;
29 import java.security.GeneralSecurityException;
30 import java.security.KeyPair;
31 import java.security.PrivateKey;
32 import java.security.PublicKey;
33 import java.security.cert.X509Certificate;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Answers;
38 import org.mockito.Mock;
39 import org.onap.aaf.auth.cm.ca.CA;
40 import org.onap.aaf.auth.cm.cert.CSRMeta;
41 import org.onap.aaf.cadi.configure.CertException;
42 import org.onap.aaf.misc.env.Trans;
44 public class JU_CertRespTest {
49 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
59 public void setUp() throws Exception {
61 CertDrop drop = new CertDrop();
62 CertRenew renew = new CertRenew();
64 PublicKey publicKey = new PublicKey() {
67 public String getFormat() {
68 // TODO Auto-generated method stub
73 public byte[] getEncoded() {
74 // TODO Auto-generated method stub
79 public String getAlgorithm() {
80 // TODO Auto-generated method stub
84 PrivateKey privateKey = new PrivateKey() {
87 public String getFormat() {
88 // TODO Auto-generated method stub
93 public byte[] getEncoded() {
94 // TODO Auto-generated method stub
95 return "privatekey".getBytes();
99 public String getAlgorithm() {
100 // TODO Auto-generated method stub
104 KeyPair keypair = new KeyPair(publicKey, privateKey);
106 when(csrMeta.keypair(trans)).thenReturn(keypair);
107 when(csrMeta.challenge()).thenReturn("challenge");
108 when(x509.getSubjectDN()).thenReturn(null);
109 when(x509.getEncoded()).thenReturn("x509Certificate".getBytes());
114 public void testCertResp() throws IOException, GeneralSecurityException, CertException {
115 CertResp resp = new CertResp("CERT");
117 assertEquals("CERT", resp.asCertString());
118 assertEquals("", resp.challenge());
120 String[] trustChain = { "trustChain" };
121 String[] notes = { "notes" };
123 String[] caIssureDNs = { "caIssuer" };
124 String[] trustedCAs = { "trustedCAs" };
126 when(ca.getCaIssuerDNs()).thenReturn(caIssureDNs);
127 when(ca.getEnv()).thenReturn("Env");
128 when(ca.getTrustedCAs()).thenReturn(trustedCAs);
130 resp = new CertResp(trans, ca, x509, csrMeta, trustChain, notes);
132 assertNotNull(resp.privateString());
133 assertEquals("challenge", resp.challenge());
134 assertEquals("notes", resp.notes()[0]);
135 assertEquals("trustChain", resp.trustChain()[0]);
136 assertEquals("caIssuer", resp.caIssuerDNs()[0]);
137 assertEquals("trustedCAs", resp.trustCAs()[0]);
138 assertEquals("Env", resp.env());