1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.aaf.v2_0;
\r
24 import static org.junit.Assert.*;
\r
26 import org.junit.Test;
\r
30 import static org.junit.Assert.*;
\r
31 import static org.mockito.Matchers.anyInt;
\r
32 import static org.mockito.Mockito.when;
\r
35 import org.junit.Before;
\r
36 import org.junit.Test;
\r
37 import org.mockito.Answers;
\r
38 import org.mockito.Mock;
\r
39 import org.mockito.MockitoAnnotations;
\r
40 import org.onap.aaf.cadi.AbsUserCache;
\r
41 import org.onap.aaf.cadi.CadiException;
\r
42 import org.onap.aaf.cadi.aaf.AAFPermission;
\r
43 import org.onap.aaf.cadi.client.Future;
\r
44 import org.onap.aaf.inno.env.APIException;
\r
46 import com.att.aft.dme2.internal.jersey.api.client.Client;
\r
48 public class AAFAuthnTest {
\r
50 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
51 private AAFCon<Client> con;
\r
53 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
54 private Future<String> fp;
\r
56 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
57 private AbsUserCache<AAFPermission> cache;
\r
61 public void setup() throws APIException, CadiException {
\r
62 MockitoAnnotations.initMocks(this);
\r
63 when(con.client(AAFCon.AAF_LATEST_VERSION).read("/authn/basicAuth", "text/plain")).thenReturn(fp);
\r
67 public void testAAFAuthnAAFConOfCLIENT() throws Exception {
\r
68 when(fp.get(anyInt())).thenReturn(false);
\r
69 when(fp.code()).thenReturn(401);
\r
70 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
\r
71 AAFAuthn<Client> auth = new AAFAuthn<Client>(con);
\r
73 assertNotNull(auth.validate("NewUser", "New Password"));;
\r
77 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission() throws Exception {
\r
78 AAFAuthn<Client> auth = new AAFAuthn<Client>(con,cache);
\r
82 public void testAAFAuthnAAFConOfCLIENT1() throws Exception {
\r
83 when(fp.get(anyInt())).thenReturn(false);
\r
84 when(fp.code()).thenReturn(401);
\r
85 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
\r
86 AAFAuthn<Client> auth = new AAFAuthn<Client>(con);
\r
88 assertNotNull(auth.validate("NewUser1", "New Password1"));;
\r
92 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission1() throws Exception {
\r
93 AAFAuthn<Client> auth = new AAFAuthn<Client>(con,cache);
\r
97 public void testAAFAuthnAAFConOfCLIENT2() throws Exception {
\r
98 when(fp.get(anyInt())).thenReturn(false);
\r
99 when(fp.code()).thenReturn(401);
\r
100 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
\r
101 AAFAuthn<Client> auth = new AAFAuthn<Client>(con);
\r
103 assertNotNull(auth.validate("NewUser2", "New Password2"));;
\r
107 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission2() throws Exception {
\r
108 AAFAuthn<Client> auth = new AAFAuthn<Client>(con,cache);
\r
112 public void testAAFAuthnAAFConOfCLIENT3() throws Exception {
\r
113 when(fp.get(anyInt())).thenReturn(false);
\r
114 when(fp.code()).thenReturn(401);
\r
115 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
\r
116 AAFAuthn<Client> auth = new AAFAuthn<Client>(con);
\r
118 assertNotNull(auth.validate("NewUser3", "New Password3"));;
\r
122 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission3() throws Exception {
\r
123 AAFAuthn<Client> auth = new AAFAuthn<Client>(con,cache);
\r
127 public void testAAFAuthnAAFConOfCLIENT4() throws Exception {
\r
128 when(fp.get(anyInt())).thenReturn(false);
\r
129 when(fp.code()).thenReturn(401);
\r
130 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
\r
131 AAFAuthn<Client> auth = new AAFAuthn<Client>(con);
\r
133 assertNotNull(auth.validate("NewUser4", "New Password4"));;
\r
137 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission4() throws Exception {
\r
138 AAFAuthn<Client> auth = new AAFAuthn<Client>(con,cache);
\r
142 public void testAAFAuthnAAFConOfCLIENT5() throws Exception {
\r
143 when(fp.get(anyInt())).thenReturn(false);
\r
144 when(fp.code()).thenReturn(401);
\r
145 when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\"");
\r
146 AAFAuthn<Client> auth = new AAFAuthn<Client>(con);
\r
148 assertNotNull(auth.validate("NewUser5", "New Password5"));;
\r
152 public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission5() throws Exception {
\r
153 AAFAuthn<Client> auth = new AAFAuthn<Client>(con,cache);
\r