5bea198153a81d8eeb5303c036809155256a21f4
[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         }
79         //TODO broken JUNIT with MOCKITO
80         @Test
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();
86                 
87                 assertNotNull(auth.validate("NewUser1", "New Password1"));;
88         }
89
90         @Test
91         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission1() throws Exception {
92                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
93         }
94         //TODO broken JUNIT with MOCKITO
95         @Test
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();
101                 
102                 assertNotNull(auth.validate("NewUser2", "New Password2"));;
103         }
104
105         @Test
106         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission2() throws Exception {
107                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
108         }
109         //TODO broken JUNIT with MOCKITO
110         @Test
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();
116                 
117                 assertNotNull(auth.validate("NewUser3", "New Password3"));;
118         }
119
120         @Test
121         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission3() throws Exception {
122                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
123         }
124         //TODO broken JUNIT with MOCKITO
125         @Test
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();
131                 
132                 assertNotNull(auth.validate("NewUser4", "New Password4"));;
133         }
134
135         @Test
136         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission4() throws Exception {
137                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
138         }
139         //TODO broken JUNIT with MOCKITO
140         @Test
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();
146                 
147                 assertNotNull(auth.validate("NewUser5", "New Password5"));;
148         }
149
150         @Test
151         public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission5() throws Exception {
152                 AAFAuthn<HttpsURLConnection> auth = con.newAuthn(cache);
153         }
154 }