Update Certificate for all FQDNs
[aaf/authz.git] / auth / auth-certman / src / test / java / org / onap / aaf / auth / cm / test / CertmanTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21 package org.onap.aaf.auth.cm.test;
22
23 import java.io.InputStream;
24 import java.net.HttpURLConnection;
25 import java.net.InetAddress;
26 import java.net.URI;
27 import java.security.cert.CertificateException;
28
29 import javax.security.auth.x500.X500Principal;
30
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;
54
55 import certman.v1_0.CertInfo;
56 import certman.v1_0.CertificateRequest;
57 import junit.framework.Assert;
58
59 public class CertmanTest {
60
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;
66
67         @BeforeClass
68         public static void setUpBeforeClass() throws Exception {
69                 env = new AuthzEnv();
70 //              InputStream ris = env.classLoader().getResource("certman.props").openStream();
71 //              try {
72 //                      env.load(ris);
73 //              } finally {
74 //                      ris.close();
75 //              }
76 //
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));
80 //              }
81 //              
82 //              
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");
88                 
89 //              hman = new HMangr(env,loc);
90 //
91 //              reqDF = env.newDataFactory(CertificateRequest.class);
92 //              reqDF.out(TYPE.JSON);
93 //              certDF = env.newDataFactory(CertInfo.class);
94         }
95
96 //      @AfterClass
97 //      public static void tearDownAfterClass() throws Exception {
98 //              hman.close();
99 //      }
100
101         @Before
102         public void setUp() throws Exception {
103
104         }
105
106         @After
107         public void tearDown() throws Exception {
108         }
109
110 //      @Test
111 //      public void testX500Name() throws Exception {
112 //              
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());
117 //              }
118 //              
119 //              hman.best(ss, new Retryable<Void>() {
120 //                      @Override
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");
128 //                              
129 //                              String path = "/cert/local"; // Local Test
130 ////                            String path = "/cert/aaf"; // Official CA
131 //                              long end=0,start = System.nanoTime();
132 //                              try {
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());
142 //                                                      }
143 //                                              }
144 //                                      } else {
145 //                                              end = System.nanoTime();
146 //                                              String msg = "Client returned " + f.code() + ": " + f.body();
147 //                                              System.out.println(msg);
148 //                                              Assert.fail(msg);
149 //                                      }
150 //                              } catch (CertificateException e) {
151 //                                      throw new CadiException(e);
152 //                              } finally {
153 //                                      System.out.println(Chrono.millisFromNanos(start,end) + " ms");
154 //                              }
155 //                              return null;
156 //                      }
157 //              });
158 //              
159 //              
160 //      }
161 //
162 //      public X500Principal ephemeral() {
163 //              return null;
164 //      }
165         
166         @Test                                           //TODO: Temporary fix AAF-111
167         public void netYetTested() {
168                 fail("Tests not yet implemented");
169         }
170 }