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.test;
23 import java.io.InputStream;
24 import java.net.HttpURLConnection;
25 import java.net.InetAddress;
27 import java.security.cert.CertificateException;
29 import javax.security.auth.x500.X500Principal;
31 import org.junit.After;
32 import org.junit.AfterClass;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import static org.junit.Assert.*;
37 import org.onap.aaf.auth.env.AuthzEnv;
38 import org.onap.aaf.cadi.CadiException;
39 import org.onap.aaf.cadi.Locator;
40 import org.onap.aaf.cadi.Locator.Item;
41 import org.onap.aaf.cadi.client.Future;
42 import org.onap.aaf.cadi.client.Rcli;
43 import org.onap.aaf.cadi.client.Retryable;
44 import org.onap.aaf.cadi.cm.Factory;
45 import org.onap.aaf.cadi.config.SecurityInfoC;
46 import org.onap.aaf.cadi.http.HBasicAuthSS;
47 import org.onap.aaf.cadi.http.HMangr;
48 import org.onap.aaf.cadi.locator.DNSLocator;
49 import org.onap.aaf.misc.env.APIException;
50 import org.onap.aaf.misc.env.Data;
51 import org.onap.aaf.misc.env.Data.TYPE;
52 import org.onap.aaf.misc.env.util.Chrono;
53 import org.onap.aaf.misc.rosetta.env.RosettaDF;
55 import certman.v1_0.CertInfo;
56 import certman.v1_0.CertificateRequest;
57 import junit.framework.Assert;
59 public class CertmanTest {
61 private static HMangr hman;
62 private static AuthzEnv env;
63 private static HBasicAuthSS ss;
64 private static RosettaDF<CertificateRequest> reqDF;
65 private static RosettaDF<CertInfo> certDF;
68 public static void setUpBeforeClass() throws Exception {
70 // InputStream ris = env.classLoader().getResource("certman.props").openStream();
77 // Locator<URI> loc = new DNSLocator(env, "https", "aaf.it.att.com", "8150");
78 // for(Item item = loc.first(); item!=null; item=loc.next(item)) {
79 // System.out.println(loc.get(item));
83 // SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(env, HttpURLConnection.class);
84 // ss = new HBasicAuthSS(si,"m12345@aaf.att.com",
85 // env.decrypt("enc:gvptdJyo0iKdVZw2rzMb0woxa7YKMdqLuhfQ4OQfZ8k",false));
86 // env.decrypt("enc:jFfAnO3mOKb9Gzm2OFysslmXpbnyuAxuoNJK",false), si);
87 // SecuritySetter<HttpURLConnection> ss = new X509SS(si, "aaf");
89 // hman = new HMangr(env,loc);
91 // reqDF = env.newDataFactory(CertificateRequest.class);
92 // reqDF.out(TYPE.JSON);
93 // certDF = env.newDataFactory(CertInfo.class);
97 // public static void tearDownAfterClass() throws Exception {
102 public void setUp() throws Exception {
107 public void tearDown() throws Exception {
111 // public void testX500Name() throws Exception {
113 // for( InetAddress ia : InetAddress.getAllByName("aaf.dev.att.com")) {
114 // System.out.printf("%s - %s\n", ia.getHostName(), ia.getHostAddress());
115 // InetAddress ia1 = InetAddress.getByName(ia.getHostAddress());
116 // System.out.printf("%s - %s\n", ia1.getHostName(), ia1.getHostAddress());
119 // hman.best(ss, new Retryable<Void>() {
121 // public Void code(Rcli<?> client) throws APIException, CadiException {
122 // CertificateRequest cr = new CertificateRequest();
123 // cr.setMechid("a12345@org.osaaf.org");
124 // cr.setSponsor("something");
125 // cr.getFqdns().add("mithrilcsp.sbc.com");
126 // cr.getFqdns().add("zld01907.vci.att.com");
127 // cr.getFqdns().add("aaftest.test.att.com");
129 // String path = "/cert/local"; // Local Test
130 //// String path = "/cert/aaf"; // Official CA
131 // long end=0,start = System.nanoTime();
133 // System.out.println(reqDF.newData().option(Data.PRETTY).load(cr).asString());
134 // Future<String> f = client.updateRespondString(path, reqDF, cr);
135 // if(f.get(10000)) {
136 // end = System.nanoTime();
137 // System.out.println(f.body());
138 // CertInfo capi = certDF.newData().in(Data.TYPE.JSON).load(f.body()).asObject();
139 // for(String c :capi.getCerts()) {
140 // for( java.security.cert.Certificate x509 : Factory.toX509Certificate(c)) {
141 // System.out.println(x509.toString());
145 // end = System.nanoTime();
146 // String msg = "Client returned " + f.code() + ": " + f.body();
147 // System.out.println(msg);
150 // } catch (CertificateException e) {
151 // throw new CadiException(e);
153 // System.out.println(Chrono.millisFromNanos(start,end) + " ms");
162 // public X500Principal ephemeral() {
166 @Test //TODO: Temporary fix AAF-111
167 public void netYetTested() {
168 fail("Tests not yet implemented");