2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
6 * Modifications Copyright (C) 2020 Nordix Foundation
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ========================LICENSE_END===================================
21 package org.oransc.portal.nonrtric.controlpanel.portalapi;
23 import java.io.IOException;
24 import java.lang.invoke.MethodHandles;
25 import java.lang.reflect.InvocationTargetException;
27 import javax.servlet.ServletException;
28 import javax.servlet.http.Cookie;
30 import org.junit.Assert;
31 import org.junit.jupiter.api.Test;
32 import org.junit.jupiter.api.extension.ExtendWith;
33 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
34 import org.oransc.portal.nonrtric.controlpanel.ControlpanelUserManager;
35 import org.oransc.portal.nonrtric.controlpanel.portalapi.PortalAuthManager;
36 import org.oransc.portal.nonrtric.controlpanel.portalapi.PortalAuthenticationFilter;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Value;
40 import org.springframework.boot.test.context.SpringBootTest;
41 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
42 import org.springframework.mock.web.MockHttpServletRequest;
43 import org.springframework.mock.web.MockHttpServletResponse;
44 import org.springframework.test.context.ActiveProfiles;
45 import org.springframework.test.context.junit.jupiter.SpringExtension;
47 @ExtendWith(SpringExtension.class)
48 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
49 @ActiveProfiles("test")
50 public class PortalAuthManagerTest {
52 @Value("${portalapi.decryptor}")
53 private String decryptor;
55 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
58 public void testPortalStuff() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
59 InvocationTargetException, NoSuchMethodException, IOException, ServletException {
61 PortalAuthManager m = new PortalAuthManager("app", "user", "secret", decryptor, "cookie");
62 Assert.assertNotNull(m.getAppCredentials());
65 MockHttpServletRequest request = new MockHttpServletRequest();
66 s = m.validateEcompSso(request);
67 logger.debug("validateEcompSso answers {}", s);
70 Cookie cookie = new Cookie(PortalApiConstants.EP_SERVICE, "bogus");
71 request.setCookies(cookie);
72 s = m.validateEcompSso(request);
73 logger.debug("validateEcompSso answers {}", s);
76 ControlpanelUserManager dum = new ControlpanelUserManager(true);
77 PortalAuthenticationFilter filter = new PortalAuthenticationFilter(false, m, dum);
80 MockHttpServletResponse response = new MockHttpServletResponse();
82 filter.doFilter(request, response, null);
83 } catch (NullPointerException ex) {
84 logger.debug("chain is null");
87 filter = new PortalAuthenticationFilter(true, m, dum);
89 filter.doFilter(request, response, null);
90 } catch (NullPointerException ex) {
91 logger.debug("chain is null");