2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 package org.oransc.ric.portal.dashboard.portalapi;
22 import java.io.IOException;
23 import java.lang.invoke.MethodHandles;
24 import java.lang.reflect.InvocationTargetException;
26 import javax.servlet.ServletException;
27 import javax.servlet.http.Cookie;
29 import org.junit.Assert;
30 import org.junit.jupiter.api.Assertions;
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.ric.portal.dashboard.DashboardUserManager;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Value;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
40 import org.springframework.mock.web.MockHttpServletRequest;
41 import org.springframework.mock.web.MockHttpServletResponse;
42 import org.springframework.test.context.ActiveProfiles;
43 import org.springframework.test.context.junit.jupiter.SpringExtension;
45 @ExtendWith(SpringExtension.class)
46 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
47 @ActiveProfiles("test")
48 public class PortalAuthManagerTest {
50 @Value("${portalapi.decryptor}")
51 private String decryptor;
53 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
56 public void testPortalStuff() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
57 InvocationTargetException, NoSuchMethodException, IOException, ServletException {
59 PortalAuthManager m = new PortalAuthManager("app", "user", "secret", decryptor, "cookie");
60 Assert.assertNotNull(m.getAppCredentials());
63 MockHttpServletRequest request = new MockHttpServletRequest();
64 s = m.validateEcompSso(request);
65 logger.debug("validateEcompSso answers {}", s);
68 Cookie cookie = new Cookie(PortalApiConstants.EP_SERVICE, "bogus");
69 request.setCookies(cookie);
70 s = m.validateEcompSso(request);
71 logger.debug("validateEcompSso answers {}", s);
74 DashboardUserManager dum = new DashboardUserManager(true);
75 final PortalAuthenticationFilter filter = new PortalAuthenticationFilter(false, m, dum);
78 MockHttpServletResponse response = new MockHttpServletResponse();
79 Assertions.assertThrows(NullPointerException.class, () -> {
80 filter.doFilter(request, response, null);
83 PortalAuthenticationFilter filter2 = new PortalAuthenticationFilter(true, m, dum);
84 filter2.doFilter(request, response, null);