1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.cadi.aaf.v2_0;
23 import static org.junit.Assert.assertNotNull;
24 import static org.mockito.Matchers.anyInt;
25 import static org.mockito.Mockito.when;
27 import javax.net.ssl.HttpsURLConnection;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Answers;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.aaf.cadi.AbsUserCache;
35 import org.onap.aaf.cadi.CadiException;
36 import org.onap.aaf.cadi.aaf.AAFPermission;
37 import org.onap.aaf.cadi.client.Future;
38 import org.onap.aaf.cadi.config.Config;
39 import org.onap.aaf.misc.env.APIException;
41 public class JU_AAFAuthnTest {
43 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
44 private AAFCon<HttpsURLConnection> con;
46 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
47 private Future<String> fp;
49 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
50 private AbsUserCache<AAFPermission> cache;
54 public void setup() throws APIException, CadiException {
55 MockitoAnnotations.initMocks(this);
56 when(con.client(Config.AAF_DEFAULT_VERSION).read("/authn/basicAuth", "text/plain")).thenReturn(fp);
58 /*TODO broken JUNIT with MOCKITO
60 * reduce size of this test file by looping thru conOfClient instead of copy pasta?
62 * These appear to receive data but cannot validate them. Maybe due to @before
63 * Possible fixes for tomorrow: look into auth,validate, @before mockito, @mock issues?
67 public void testAAFAuthnAAFConOfCLIENT() throws Exception {
68 when(fp.get(anyInt())).thenReturn(false);
69 when(fp.code()).thenReturn(401);
70 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
71 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
72 assertNotNull(auth.validate("NewUser", "New Password"));;
76 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission() throws Exception {
77 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
79 //TODO broken JUNIT with MOCKITO
81 public void testAAFAuthnAAFConOfCLIENT1() throws Exception {
82 when(fp.get(anyInt())).thenReturn(false);
83 when(fp.code()).thenReturn(401);
84 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
85 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
87 assertNotNull(auth.validate("NewUser1", "New Password1"));;
91 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission1() throws Exception {
92 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
94 //TODO broken JUNIT with MOCKITO
96 public void testAAFAuthnAAFConOfCLIENT2() throws Exception {
97 when(fp.get(anyInt())).thenReturn(false);
98 when(fp.code()).thenReturn(401);
99 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
100 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
102 assertNotNull(auth.validate("NewUser2", "New Password2"));;
106 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission2() throws Exception {
107 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
109 //TODO broken JUNIT with MOCKITO
111 public void testAAFAuthnAAFConOfCLIENT3() throws Exception {
112 when(fp.get(anyInt())).thenReturn(false);
113 when(fp.code()).thenReturn(401);
114 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
115 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
117 assertNotNull(auth.validate("NewUser3", "New Password3"));;
121 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission3() throws Exception {
122 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
124 //TODO broken JUNIT with MOCKITO
126 public void testAAFAuthnAAFConOfCLIENT4() throws Exception {
127 when(fp.get(anyInt())).thenReturn(false);
128 when(fp.code()).thenReturn(401);
129 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
130 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
132 assertNotNull(auth.validate("NewUser4", "New Password4"));;
136 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission4() throws Exception {
137 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
139 //TODO broken JUNIT with MOCKITO
141 public void testAAFAuthnAAFConOfCLIENT5() throws Exception {
142 when(fp.get(anyInt())).thenReturn(false);
143 when(fp.code()).thenReturn(401);
144 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
145 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
147 assertNotNull(auth.validate("NewUser5", "New Password5"));;
151 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission5() throws Exception {
152 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);