diff options
author | 2018-01-30 17:29:36 -0500 | |
---|---|---|
committer | 2018-02-01 15:10:02 -0500 | |
commit | 21a8761f684745bb300e075c7e98ad897ace9eed (patch) | |
tree | 6d585c3fe39fbb42a314941dbc8646e6ccf188cf /ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java | |
parent | 3af8af1310d5a27cb58be29505573f0bbdc1717c (diff) |
Security/ Package Name changes
Issue-ID: PORTAL-174, PORTAL-157, PORTAL-156, PORTAL-148, PORTAL-145,
PORTAL-140, PORTAL-133, PORTAL-121, PORTAL-111, PORTAL-88
Includes security fixes, Role Centralization, replace certain ECOMP
occurrences etc
Change-Id: I3c8b706709c6b92e646e3cbe50c2d660e8a46ef4
Signed-off-by: st782s <statta@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java')
-rw-r--r-- | ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java new file mode 100644 index 00000000..58e596ae --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.authentication; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.authentication.OpenIdConnectLoginStrategy; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalapp.util.SessionCookieUtil; +import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; +import org.onap.portalsdk.core.util.SystemProperties; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mitre.openid.connect.model.DefaultUserInfo; +import org.mitre.openid.connect.model.UserInfo; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.util.StringUtils; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({StringUtils.class, EPUserUtils.class , SessionCookieUtil.class,SystemProperties.class}) +public class OpenIdConnectLoginStrategyTest { + + @InjectMocks + OpenIdConnectLoginStrategy OpenIdConnectLoginStrategy = new OpenIdConnectLoginStrategy(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void loginTest() throws Exception + { + PowerMockito.mockStatic(StringUtils.class); + PowerMockito.mockStatic(EPUserUtils.class); + PowerMockito.mockStatic(SessionCookieUtil.class); + + UserInfo userInfo = new DefaultUserInfo(); + userInfo.setPreferredUsername("Test"); + userInfo.setEmail("test@gmail.com"); + userInfo.setName("first_name"); + userInfo.setFamilyName("last_name"); + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + assertTrue(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserNullTest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); +// Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("auth"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserIfAuthIsOIDCTest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("OIDC"); + Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserIfAuthNotNullTest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("test"); + Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserExceptionest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenThrow(nullPointerException); + Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + @Test(expected = Exception.class) + public void doLoginTest() throws Exception + { + OpenIdConnectLoginStrategy.doLogin(mockedRequest, mockedResponse); + } + + @Test(expected = PortalAPIException.class) + public void getUserIdTest() throws Exception + { + OpenIdConnectLoginStrategy.getUserId(mockedRequest); + } + +} |