Mass whitespace changes (Style Warnings)
[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
22 package org.onap.aaf.auth.cm.test;
23
24 import java.io.InputStream;
25 import java.net.HttpURLConnection;
26 import java.net.InetAddress;
27 import java.net.URI;
28 import java.security.cert.CertificateException;
29
30 import javax.security.auth.x500.X500Principal;
31
32 import org.junit.After;
33 import org.junit.AfterClass;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import static org.junit.Assert.*;
38 import org.onap.aaf.auth.env.AuthzEnv;
39 import org.onap.aaf.cadi.CadiException;
40 import org.onap.aaf.cadi.Locator;
41 import org.onap.aaf.cadi.Locator.Item;
42 import org.onap.aaf.cadi.client.Future;
43 import org.onap.aaf.cadi.client.Rcli;
44 import org.onap.aaf.cadi.client.Retryable;
45 import org.onap.aaf.cadi.config.SecurityInfoC;
46 import org.onap.aaf.cadi.configure.Factory;
47 import org.onap.aaf.cadi.http.HBasicAuthSS;
48 import org.onap.aaf.cadi.http.HMangr;
49 import org.onap.aaf.cadi.locator.DNSLocator;
50 import org.onap.aaf.misc.env.APIException;
51 import org.onap.aaf.misc.env.Data;
52 import org.onap.aaf.misc.env.Data.TYPE;
53 import org.onap.aaf.misc.env.util.Chrono;
54 import org.onap.aaf.misc.rosetta.env.RosettaDF;
55
56 import certman.v1_0.CertInfo;
57 import certman.v1_0.CertificateRequest;
58 import junit.framework.Assert;
59
60 public class CertmanTest {
61
62     private static HMangr hman;
63     private static AuthzEnv env;
64     private static HBasicAuthSS ss;
65     private static RosettaDF<CertificateRequest> reqDF;
66     private static RosettaDF<CertInfo> certDF;
67
68     @BeforeClass
69     public static void setUpBeforeClass() throws Exception {
70         env = new AuthzEnv();
71 //        InputStream ris = env.classLoader().getResource("certman.props").openStream();
72 //        try {
73 //            env.load(ris);
74 //        } finally {
75 //            ris.close();
76 //        }
77 //
78 //        Locator<URI> loc = new DNSLocator(env, "https", "aaf.it.att.com", "8150");
79 //        for (Item item = loc.first(); item!=null; item=loc.next(item)) {
80 //            System.out.println(loc.get(item));
81 //        }
82 //        
83 //        
84 //        SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(env, HttpURLConnection.class);
85 //        ss = new HBasicAuthSS(si,"m12345@aaf.att.com", 
86 //                env.decrypt("enc:gvptdJyo0iKdVZw2rzMb0woxa7YKMdqLuhfQ4OQfZ8k",false));
87 //                env.decrypt("enc:jFfAnO3mOKb9Gzm2OFysslmXpbnyuAxuoNJK",false), si);
88 //                    SecuritySetter<HttpURLConnection> ss = new X509SS(si, "aaf");
89         
90 //        hman = new HMangr(env,loc);
91 //
92 //        reqDF = env.newDataFactory(CertificateRequest.class);
93 //        reqDF.out(TYPE.JSON);
94 //        certDF = env.newDataFactory(CertInfo.class);
95     }
96
97 //    @AfterClass
98 //    public static void tearDownAfterClass() throws Exception {
99 //        hman.close();
100 //    }
101
102     @Before
103     public void setUp() throws Exception {
104
105     }
106
107     @After
108     public void tearDown() throws Exception {
109     }
110
111 //    @Test
112 //    public void testX500Name() throws Exception {
113 //        
114 //        for ( InetAddress ia : InetAddress.getAllByName("aaf.dev.att.com")) {
115 //            System.out.printf("%s - %s\n", ia.getHostName(), ia.getHostAddress());
116 //            InetAddress ia1 = InetAddress.getByName(ia.getHostAddress());
117 //            System.out.printf("%s - %s\n", ia1.getHostName(), ia1.getHostAddress());
118 //        }
119 //        
120 //        hman.best(ss, new Retryable<Void>() {
121 //            @Override
122 //            public Void code(Rcli<?> client) throws APIException, CadiException {
123 //                CertificateRequest cr = new CertificateRequest();
124 //                cr.setMechid("a12345@org.osaaf.org");
125 //                cr.setSponsor("something");
126 //                cr.getFqdns().add("mithrilcsp.sbc.com");
127 //                cr.getFqdns().add("zld01907.vci.att.com");
128 //                cr.getFqdns().add("aaftest.test.att.com");
129 //                
130 //                String path = "/cert/local"; // Local Test
131 ////                String path = "/cert/aaf"; // Official CA
132 //                long end=0,start = System.nanoTime();
133 //                try {
134 //                    System.out.println(reqDF.newData().option(Data.PRETTY).load(cr).asString());
135 //                    Future<String> f = client.updateRespondString(path, reqDF, cr);
136 //                    if (f.get(10000)) {
137 //                        end = System.nanoTime();
138 //                        System.out.println(f.body());
139 //                        CertInfo capi = certDF.newData().in(Data.TYPE.JSON).load(f.body()).asObject();
140 //                        for (String c :capi.getCerts()) {
141 //                            for ( java.security.cert.Certificate x509 : Factory.toX509Certificate(c)) {
142 //                                System.out.println(x509.toString());
143 //                            }
144 //                        }
145 //                    } else {
146 //                        end = System.nanoTime();
147 //                        String msg = "Client returned " + f.code() + ": " + f.body();
148 //                        System.out.println(msg);
149 //                        Assert.fail(msg);
150 //                    }
151 //                } catch (CertificateException e) {
152 //                    throw new CadiException(e);
153 //                } finally {
154 //                    System.out.println(Chrono.millisFromNanos(start,end) + " ms");
155 //                }
156 //                return null;
157 //            }
158 //        });
159 //        
160 //        
161 //    }
162 //
163 //    public X500Principal ephemeral() {
164 //        return null;
165 //    }
166     
167 }