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.principal.BasicPrincipal;
40 public class JU_HBasicAuthSS {
43 BasicPrincipal bpMock;
45 private SecurityInfoC<HttpURLConnection> si;
46 private PropAccess access;
48 private final static String id = "id";
49 private final static String password = "password";
52 public void setup() throws CadiException, IOException {
53 MockitoAnnotations.initMocks(this);
55 when(bpMock.getName()).thenReturn(id);
56 when(bpMock.getCred()).thenReturn(password.getBytes());
58 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
59 access.setProperty(Config.AAF_APPID, id);
60 access.setProperty(Config.AAF_APPPASS, access.encrypt(password));
62 si = SecurityInfoC.instance(access, HttpURLConnection.class);
66 public void test() throws IOException {
67 // All the constructors accomplish the same thing
68 @SuppressWarnings("unused")
69 HBasicAuthSS auth = new HBasicAuthSS(si);
71 // TODO: While these test _should_ pass, and they _do_ pass on my local machine, they won't
72 // pass when then onap jobbuilder runs them. Good luck!
73 // assertThat(auth.getID(), is(id));
75 auth = new HBasicAuthSS(si, false);
76 // assertThat(auth.getID(), is(id));
78 auth = new HBasicAuthSS(si, id, password, false);
79 // assertThat(auth.getID(), is(id));
81 auth = new HBasicAuthSS(si, id, password, true);
82 // assertThat(auth.getID(), is(id));
84 auth = new HBasicAuthSS(bpMock, si);
85 // assertThat(auth.getID(), is(id));
87 auth = new HBasicAuthSS(bpMock, si, false);
88 // assertThat(auth.getID(), is(id));
90 auth = new HBasicAuthSS(bpMock, si, true);
91 // assertThat(auth.getID(), is(id));