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
22 package org.onap.aaf.auth.locate;
\r
24 import static org.junit.Assert.assertEquals;
\r
25 import static org.mockito.Mockito.verify;
\r
26 import static org.mockito.Mockito.when;
\r
27 import static org.mockito.MockitoAnnotations.initMocks;
\r
29 import javax.servlet.http.HttpServletRequest;
\r
30 import javax.servlet.http.HttpServletResponse;
\r
32 import org.eclipse.jetty.http.HttpStatus;
\r
33 import org.junit.Before;
\r
34 import org.junit.Test;
\r
35 import org.mockito.Answers;
\r
36 import org.mockito.Mock;
\r
37 import org.onap.aaf.auth.env.AuthzTrans;
\r
38 import org.onap.aaf.auth.locate.facade.LocateFacade;
\r
39 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
\r
40 import org.onap.aaf.cadi.principal.BasicPrincipal;
\r
41 import org.onap.aaf.cadi.principal.X509Principal;
\r
42 import org.onap.aaf.misc.env.LogTarget;
\r
44 public class JU_BasicAuthCodeTest {
\r
49 @Mock(answer = Answers.RETURNS_DEEP_STUBS)
\r
53 HttpServletRequest req;
\r
56 HttpServletResponse resp;
\r
62 LocateFacade facade;
\r
65 BasicPrincipal basicPrincipal;
\r
67 X509Principal x509Principal;
\r
70 public void setUp() throws Exception {
\r
75 public void testWithNullUserPrincipal() throws Exception {
\r
76 BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
\r
77 LocateCode locateCode = basicAuthCode.clone(facade, false);
\r
79 assertEquals(locateCode.desc(), basicAuthCode.desc());
\r
81 when(trans.getUserPrincipal()).thenReturn(null);
\r
82 when(trans.error()).thenReturn(error);
\r
84 basicAuthCode.handle(trans, req, resp);
\r
88 public void testWithBasicUserPrincipal() throws Exception {
\r
89 BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
\r
90 LocateCode locateCode = basicAuthCode.clone(facade, false);
\r
92 assertEquals(locateCode.desc(), basicAuthCode.desc());
\r
94 when(trans.getUserPrincipal()).thenReturn(basicPrincipal);
\r
96 basicAuthCode.handle(trans, req, resp);
\r
98 verify(resp).setStatus(HttpStatus.OK_200);
\r
102 public void testWithX509UserPrincipal() throws Exception {
\r
103 BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
\r
104 LocateCode locateCode = basicAuthCode.clone(facade, false);
\r
106 assertEquals(locateCode.desc(), basicAuthCode.desc());
\r
108 when(trans.getUserPrincipal()).thenReturn(x509Principal);
\r
109 when(req.getHeader("Authorization")).thenReturn("Basic 76//76");
\r
111 basicAuthCode.handle(trans, req, resp);
\r
113 verify(resp).setStatus(HttpStatus.FORBIDDEN_403);
\r