2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 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
21 package org.onap.aaf.auth.locate;
\r
23 import static org.junit.Assert.assertEquals;
\r
24 import static org.mockito.Mockito.verify;
\r
25 import static org.mockito.Mockito.when;
\r
26 import static org.mockito.MockitoAnnotations.initMocks;
\r
28 import javax.servlet.http.HttpServletRequest;
\r
29 import javax.servlet.http.HttpServletResponse;
\r
31 import org.eclipse.jetty.http.HttpStatus;
\r
32 import org.junit.Before;
\r
33 import org.junit.Test;
\r
34 import org.mockito.Answers;
\r
35 import org.mockito.Mock;
\r
36 import org.onap.aaf.auth.env.AuthzTrans;
\r
37 import org.onap.aaf.auth.locate.facade.LocateFacade;
\r
38 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
\r
39 import org.onap.aaf.cadi.principal.BasicPrincipal;
\r
40 import org.onap.aaf.cadi.principal.X509Principal;
\r
41 import org.onap.aaf.misc.env.LogTarget;
\r
43 public class JU_BasicAuthCodeTest {
\r
48 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
52 HttpServletRequest req;
\r
55 HttpServletResponse resp;
\r
61 LocateFacade facade;
\r
64 BasicPrincipal basicPrincipal;
\r
66 X509Principal x509Principal;
\r
69 public void setUp() throws Exception {
\r
74 public void testWithNullUserPrincipal() throws Exception {
\r
75 BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
\r
76 LocateCode locateCode = basicAuthCode.clone(facade, false);
\r
78 assertEquals(locateCode.desc(), basicAuthCode.desc());
\r
80 when(trans.getUserPrincipal()).thenReturn(null);
\r
81 when(trans.error()).thenReturn(error);
\r
83 basicAuthCode.handle(trans, req, resp);
\r
87 public void testWithBasicUserPrincipal() throws Exception {
\r
88 BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
\r
89 LocateCode locateCode = basicAuthCode.clone(facade, false);
\r
91 assertEquals(locateCode.desc(), basicAuthCode.desc());
\r
93 when(trans.getUserPrincipal()).thenReturn(basicPrincipal);
\r
95 basicAuthCode.handle(trans, req, resp);
\r
97 verify(resp).setStatus(HttpStatus.OK_200);
\r
101 public void testWithX509UserPrincipal() throws Exception {
\r
102 BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
\r
103 LocateCode locateCode = basicAuthCode.clone(facade, false);
\r
105 assertEquals(locateCode.desc(), basicAuthCode.desc());
\r
107 when(trans.getUserPrincipal()).thenReturn(x509Principal);
\r
108 when(req.getHeader("Authorization")).thenReturn("Basic 76//76");
\r
110 basicAuthCode.handle(trans, req, resp);
\r
112 verify(resp).setStatus(HttpStatus.FORBIDDEN_403);
\r