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====================================================
22 package org.onap.aaf.cadi.http.test;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.PrintStream;
27 import java.net.HttpURLConnection;
29 import static org.mockito.Mockito.*;
33 import org.onap.aaf.cadi.CadiException;
34 import org.onap.aaf.cadi.PropAccess;
35 import org.onap.aaf.cadi.config.Config;
36 import org.onap.aaf.cadi.config.SecurityInfoC;
37 import org.onap.aaf.cadi.http.HBasicAuthSS;
38 import org.onap.aaf.cadi.http.HSecurityInfoInit;
39 import org.onap.aaf.cadi.principal.BasicPrincipal;
41 public class JU_HBasicAuthSS {
44 BasicPrincipal bpMock;
46 private SecurityInfoC<HttpURLConnection> si;
47 private PropAccess access;
49 private final static String id = "id";
50 private final static String password = "password";
53 public void setup() throws CadiException, IOException {
54 MockitoAnnotations.initMocks(this);
56 when(bpMock.getName()).thenReturn(id);
57 when(bpMock.getCred()).thenReturn(password.getBytes());
59 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
60 access.setProperty(Config.AAF_APPID, id);
61 access.setProperty(Config.AAF_APPPASS, access.encrypt(password));
63 si = SecurityInfoC.instance(access, HttpURLConnection.class);
67 public void test() throws IOException {
68 // All the constructors accomplish the same thing
69 @SuppressWarnings("unused")
70 HBasicAuthSS auth = new HBasicAuthSS(si);
72 // TODO: While these test _should_ pass, and they _do_ pass on my local machine, they won't
73 // pass when then onap jobbuilder runs them. Good luck!
74 // assertThat(auth.getID(), is(id));
76 auth = new HBasicAuthSS(si, false);
77 // assertThat(auth.getID(), is(id));
79 auth = new HBasicAuthSS(si, id, password, false);
80 // assertThat(auth.getID(), is(id));
82 auth = new HBasicAuthSS(si, id, password, true);
83 // assertThat(auth.getID(), is(id));
85 auth = new HBasicAuthSS(bpMock, si);
86 // assertThat(auth.getID(), is(id));
88 auth = new HBasicAuthSS(bpMock, si, false);
89 // assertThat(auth.getID(), is(id));
91 auth = new HBasicAuthSS(bpMock, si, true);
92 // assertThat(auth.getID(), is(id));