Local CA to use Keystores
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / aaf / v2_0 / JU_AAFAuthnTest.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
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.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;
26
27 import javax.net.ssl.HttpsURLConnection;
28
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;
40
41 public class JU_AAFAuthnTest {
42         
43         @Mock(answer = Answers.RETURNS_DEEP_STUBS)
44         private AAFCon<HttpsURLConnection> con;
45
46         @Mock(answer = Answers.RETURNS_DEEP_STUBS)
47         private Future<String> fp;
48
49         @Mock(answer = Answers.RETURNS_DEEP_STUBS)
50         private AbsUserCache<AAFPermission> cache;
51
52         
53         @Before
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);
57         }
58         /*TODO broken JUNIT with MOCKITO
59          * 
60          * reduce size of this test file by looping thru conOfClient instead of copy pasta?
61          * 
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?
64          *
65          */
66         @Test
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"));;
73         }
74
75         @Test
76         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission() throws Exception {
77                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
78                 assertNotNull(auth);
79         }
80         //TODO broken JUNIT with MOCKITO
81         @Test
82         public void testAAFAuthnAAFConOfCLIENT1() throws Exception {
83                 when(fp.get(anyInt())).thenReturn(false);
84                 when(fp.code()).thenReturn(401);
85                 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
86                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
87                 
88                 assertNotNull(auth.validate("NewUser1", "New Password1"));;
89         }
90
91         @Test
92         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission1() throws Exception {
93                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
94                 assertNotNull(auth);
95         }
96         //TODO broken JUNIT with MOCKITO
97         @Test
98         public void testAAFAuthnAAFConOfCLIENT2() throws Exception {
99                 when(fp.get(anyInt())).thenReturn(false);
100                 when(fp.code()).thenReturn(401);
101                 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
102                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
103                 
104                 assertNotNull(auth.validate("NewUser2", "New Password2"));;
105         }
106
107         @Test
108         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission2() throws Exception {
109                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
110                 assertNotNull(auth);
111
112         }
113         //TODO broken JUNIT with MOCKITO
114         @Test
115         public void testAAFAuthnAAFConOfCLIENT3() throws Exception {
116                 when(fp.get(anyInt())).thenReturn(false);
117                 when(fp.code()).thenReturn(401);
118                 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
119                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
120                 
121                 assertNotNull(auth.validate("NewUser3", "New Password3"));;
122         }
123
124         @Test
125         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission3() throws Exception {
126                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
127                 assertNotNull(auth);
128
129         }
130         //TODO broken JUNIT with MOCKITO
131         @Test
132         public void testAAFAuthnAAFConOfCLIENT4() throws Exception {
133                 when(fp.get(anyInt())).thenReturn(false);
134                 when(fp.code()).thenReturn(401);
135                 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
136                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
137                 
138                 assertNotNull(auth.validate("NewUser4", "New Password4"));;
139         }
140
141         @Test
142         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission4() throws Exception {
143                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
144                 assertNotNull(auth);
145
146         }
147         //TODO broken JUNIT with MOCKITO
148         @Test
149         public void testAAFAuthnAAFConOfCLIENT5() throws Exception {
150                 when(fp.get(anyInt())).thenReturn(false);
151                 when(fp.code()).thenReturn(401);
152                 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
153                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn();
154                 
155                 assertNotNull(auth.validate("NewUser5", "New Password5"));;
156         }
157
158         @Test
159         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission5() throws Exception {
160                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
161                 assertNotNull(auth);
162
163         }
164 }