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