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.junit.Assert.*;
30 import static org.mockito.Mockito.*;
31 import static org.hamcrest.CoreMatchers.*;
35 import org.onap.aaf.cadi.CadiException;
36 import org.onap.aaf.cadi.PropAccess;
37 import org.onap.aaf.cadi.config.Config;
38 import org.onap.aaf.cadi.config.SecurityInfoC;
39 import org.onap.aaf.cadi.http.HBasicAuthSS;
40 import org.onap.aaf.cadi.principal.BasicPrincipal;
42 public class JU_HBasicAuthSS {
45 BasicPrincipal bpMock;
47 private SecurityInfoC<HttpURLConnection> si;
48 private PropAccess access;
50 private final static String id = "id";
51 private final static String password = "password";
54 public void setup() throws CadiException, IOException {
55 MockitoAnnotations.initMocks(this);
57 when(bpMock.getName()).thenReturn(id);
58 when(bpMock.getCred()).thenReturn(password.getBytes());
60 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
61 access.setProperty(Config.AAF_APPID, id);
62 access.setProperty(Config.AAF_APPPASS, access.encrypt(password));
64 si = SecurityInfoC.instance(access, HttpURLConnection.class);
68 public void test() throws IOException {
69 // All the constructors accomplish the same thing
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));