From: Gujja Date: Thu, 1 Mar 2018 20:57:55 +0000 (-0500) Subject: Added Junits X-Git-Tag: v2.2.0~40 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=portal.git;a=commitdiff_plain;h=fadf84a4a76f7501e7dad2f426cdf4603304baad Added Junits Issue-ID: PORTAL-155 Includes JUNITS, security issues fix Change-Id: I7c4032808163c46bf53477195823c7ed9dc99edc Signed-off-by:GUJJA --- diff --git a/ecomp-portal-BE-common/pom.xml b/ecomp-portal-BE-common/pom.xml index 261cf31b..320e77ad 100644 --- a/ecomp-portal-BE-common/pom.xml +++ b/ecomp-portal-BE-common/pom.xml @@ -172,10 +172,6 @@ org.slf4j log4j-over-slf4j - - ch.qos.logback - logback-classic - @@ -338,7 +334,7 @@ org.apache.poi poi - 3.5-FINAL + 3.17 commons-logging @@ -353,7 +349,7 @@ org.apache.poi poi-ooxml - 3.5-FINAL + 3.17 commons-logging @@ -556,7 +552,7 @@ commons-fileupload commons-fileupload - 1.3 + 1.3.3 io.springfox @@ -582,7 +578,7 @@ com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - 2.6.3 + 2.9.2 org.glassfish.jersey.connectors @@ -622,6 +618,33 @@ spring-security-config ${springframework.version} + + org.apache.lucene + lucene-queryparser + 7.2.1 + + + com.thoughtworks.xstream + xstream + 1.4.10 + + + org.apache.wicket + wicket-core + 1.5.16 + + + ch.qos.logback + logback-core + 1.2.3 + + + ch.qos.logback + logback-classic + 1.2.3 + + + diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java index 6a8be892..8f0558aa 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java @@ -505,7 +505,7 @@ public class RoleManageController extends EPRestrictedBaseController { String code = roleFunc.getType()+PIPE+roleFunc.getCode()+PIPE+roleFunc.getAction(); CentralV2RoleFunction domainRoleFunction = externalAccessRolesService.getRoleFunction(code, requestedApp.getUebKey()); - if(domainRoleFunction.getType() == null || domainRoleFunction.getAction() == null) { + if(domainRoleFunction != null && (domainRoleFunction.getType() == null || domainRoleFunction.getAction() == null)) { addIfTypeActionDoesNotExits(domainRoleFunction); } boolean isSave = true; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java index 11fb2fb5..c1127758 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java @@ -112,7 +112,7 @@ public class EPEELFLoggerAdvice { MDC.put(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC()); MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE); MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, methodName); - if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null){ + if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null || MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){ String requestId = UUID.randomUUID().toString(); MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); } @@ -173,7 +173,7 @@ public class EPEELFLoggerAdvice { if (securityEventType != null && args.length > 0 && args[0] != null && args[0] instanceof HttpServletRequest && securityEventType == SecurityEventTypeEnum.INCOMING_REST_MESSAGE && (MDC.get(EPCommonSystemProperties.FULL_URL) == null - || MDC.get(EPCommonSystemProperties.FULL_URL) == "")) { + || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) { HttpServletRequest req = (HttpServletRequest) args[0]; this.setHttpRequestBasedDefaultsIntoGlobalLoggingContext(req, securityEventType, methodName); } @@ -313,7 +313,8 @@ public class EPEELFLoggerAdvice { if (accessingClient != null && accessingClient.trim().length()==0 && (accessingClient.contains("Mozilla") || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) { accessingClient = EPCommonSystemProperties.ECOMP_PORTAL_FE; - } + }else if(accessingClient==null || accessingClient.isEmpty()) + accessingClient = "Unknown"; MDC.put(EPCommonSystemProperties.PARTNER_NAME, accessingClient); // Load loginId into MDC context. @@ -340,9 +341,9 @@ public class EPEELFLoggerAdvice { } // Rest Path - MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); + MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod); String restPath = req.getServletPath(); - if (restPath != null && restPath != "") { + if (restPath != null && !restPath.isEmpty()) { MDC.put(Configuration.MDC_SERVICE_NAME, restPath); } @@ -359,7 +360,7 @@ public class EPEELFLoggerAdvice { MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, "search"); } } else { - MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); + MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod); MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE); } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java index 446c11c4..6f9ce496 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java @@ -37,6 +37,7 @@ */ package org.onap.portalapp.portal.controller; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import javax.servlet.http.HttpServletRequest; @@ -106,7 +107,7 @@ public class MicroserviceProxyControllerTest extends MockitoTestSuite { Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest)) .thenThrow(httpClientErrorException); String acutualString = microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1); - assertTrue(acutualString.equals("{\"error\":\"\"}")); + assertEquals("", acutualString); } @Test @@ -138,6 +139,6 @@ public class MicroserviceProxyControllerTest extends MockitoTestSuite { .thenThrow(httpClientErrorException); String acutualString = microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest, getMockedResponse(), 1); - assertTrue(acutualString.equals("{\"error\":\"\"}")); - } + assertEquals("", acutualString); + } } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java index 50291f07..d8aba5fc 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java @@ -37,6 +37,9 @@ */ package org.onap.portalapp.portal.controller; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.util.ArrayList; import java.util.List; @@ -44,17 +47,23 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.portalapp.portal.controller.WidgetsCatalogController; import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.domain.MicroserviceParameter; import org.onap.portalapp.portal.domain.WidgetCatalog; +import org.onap.portalapp.portal.domain.WidgetCatalogParameter; +import org.onap.portalapp.portal.domain.WidgetParameterResult; import org.onap.portalapp.portal.domain.WidgetServiceHeaders; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; import org.onap.portalapp.portal.framework.MockitoTestSuite; import org.onap.portalapp.portal.service.ConsulHealthService; import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; @@ -65,29 +74,38 @@ import org.onap.portalapp.portal.service.WidgetParameterServiceImpl; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.onap.portalsdk.core.util.SystemProperties; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.mock.web.MockMultipartHttpServletRequest; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; - -@Ignore +@SuppressWarnings("rawtypes") @RunWith(PowerMockRunner.class) -@PrepareForTest({EPUserUtils.class, EcompPortalUtils.class, SystemProperties.class, EPCommonSystemProperties.class}) +@PrepareForTest({ EPUserUtils.class, CipherUtil.class, EcompPortalUtils.class, SystemProperties.class, + EPCommonSystemProperties.class, EPUserUtils.class }) public class WidgetsCatalogControllerTest { @Mock ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); - + @Mock MicroserviceService microserviceService = new MicroserviceServiceImpl(); - + @Mock WidgetParameterService widgetParameterService = new WidgetParameterServiceImpl(); - + @InjectMocks WidgetsCatalogController widgetsCatalogController = new WidgetsCatalogController(); @@ -95,10 +113,10 @@ public class WidgetsCatalogControllerTest { public void setup() { MockitoAnnotations.initMocks(this); } + @Mock - WidgetServiceHeaders widgetServiceHeaders ; - - + WidgetServiceHeaders widgetServiceHeaders; + @Mock RestTemplate template = new RestTemplate(); @@ -108,32 +126,380 @@ public class WidgetsCatalogControllerTest { HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); NullPointerException nullPointerException = new NullPointerException(); - + MockEPUser mockUser = new MockEPUser(); - - @Mock - HttpEntity mockHttpEntity; - + + @Test + public void getUserWidgetCatalogTest() throws RestClientException, Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + List widgetsList = new ArrayList<>(); + WidgetCatalog widgetCatalog = new WidgetCatalog(); + widgetCatalog.setId(1l); + widgetCatalog.setName("test"); + widgetsList.add(widgetCatalog); + ResponseEntity ans = new ResponseEntity<>(widgetsList, HttpStatus.OK); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.>any(), + Matchers.eq(List.class))).thenReturn(ans); + List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); + assertEquals(expectedWidgets, widgetsList); + } + + @Test + public void getUserWidgetCatalogExceptionTest() throws RestClientException, Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.doThrow(new NullPointerException()).when(template).exchange(Matchers.anyString(), + Matchers.eq(HttpMethod.GET), Matchers.>any(), Matchers.eq(List.class)); + List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); + assertNull(expectedWidgets); + } + + @Test + public void getWidgetCatalogTest() throws CipherUtilException { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + List widgetsList = new ArrayList<>(); + WidgetCatalog widgetCatalog = new WidgetCatalog(); + widgetCatalog.setId(1l); + widgetCatalog.setName("test"); + widgetsList.add(widgetCatalog); + ResponseEntity ans = new ResponseEntity<>(widgetsList, HttpStatus.OK); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.>any(), + Matchers.eq(List.class))).thenReturn(ans); + List expectedWidgets = widgetsCatalogController.getWidgetCatalog(); + assertEquals(expectedWidgets, widgetsList); + } + + @Test + public void getWidgetCatalogExceptionTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.doThrow(new NullPointerException()).when(template).exchange(Matchers.anyString(), + Matchers.eq(HttpMethod.GET), Matchers.>any(), Matchers.eq(List.class)); + List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); + assertNull(expectedWidgets); + } + + @Test + public void updateWidgetCatalogTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + ResponseEntity ans = new ResponseEntity<>(HttpStatus.OK); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT), Matchers.>any(), + Matchers.eq(List.class))).thenReturn(ans); + WidgetCatalog widget = new WidgetCatalog(); + widget.setId(1l); + widgetsCatalogController.updateWidgetCatalog(widget, 1); + } + + @Test + public void deleteOnboardingWidgetTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + ResponseEntity ans = new ResponseEntity<>(HttpStatus.OK); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), + Matchers.>any(), Matchers.eq(List.class))).thenReturn(ans); + widgetsCatalogController.deleteOnboardingWidget(1l); + } + + @SuppressWarnings("unchecked") + @Test + public void updateWidgetCatalogWithFilesTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + String ans = "success"; + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.postForObject(Mockito.any(String.class), Mockito.any(HttpEntity.class), + Mockito.any(Class.class))).thenReturn(ans); + MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); + byte[] mockData = "test".getBytes(); + String originalFilename = "Test_File.zip"; + MockMultipartFile mockMultipartFile = new MockMultipartFile("file", originalFilename, "application/zip", + mockData); + request.addFile(mockMultipartFile); + String actual = widgetsCatalogController.updateWidgetCatalogWithFiles(request, 1l); + assertEquals(ans, actual); + } + + @SuppressWarnings("unchecked") + @Test + public void createWidgetCatalogTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + String ans = "success"; + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.postForObject(Mockito.any(String.class), Mockito.any(HttpEntity.class), + Mockito.any(Class.class))).thenReturn(ans); + MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); + byte[] mockData = "test".getBytes(); + String originalFilename = "Test_File.zip"; + MockMultipartFile mockMultipartFile = new MockMultipartFile("file", originalFilename, "application/zip", + mockData); + request.addFile(mockMultipartFile); + String actual = widgetsCatalogController.createWidgetCatalog(request); + assertEquals(ans, actual); + } + + @SuppressWarnings("unchecked") + @Test + public void getWidgetFrameworkTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class))) + .thenReturn("test123"); + String result = widgetsCatalogController.getWidgetFramework(1l); + assertNull(result); + } + + @SuppressWarnings("unchecked") + @Test + public void getWidgetControllerTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class))) + .thenReturn("test123"); + String result = widgetsCatalogController.getWidgetController(1); + assertNull(result); + } + + @SuppressWarnings("unchecked") + @Test + public void getWidgetCSSTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class))) + .thenReturn("test123"); + String result = widgetsCatalogController.getWidgetCSS(1); + assertNull(result); + } + + @Test + public void getWidgetParameterResultTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + MockHttpServletRequest request = new MockHttpServletRequest(); + Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + ResponseEntity ans = new ResponseEntity<>(1l, HttpStatus.OK); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.>any(), + Matchers.eq(Long.class))).thenReturn(ans); + List defaultParam = new ArrayList<>(); + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId(1l); + microserviceParameter.setPara_key("test"); + MicroserviceParameter microserviceParameter2 = new MicroserviceParameter(); + microserviceParameter2.setId(2l); + microserviceParameter2.setPara_key("test2"); + defaultParam.add(microserviceParameter); + defaultParam.add(microserviceParameter2); + Mockito.when(microserviceService.getParametersById(1)).thenReturn(defaultParam); + Mockito.when(widgetParameterService.getUserParamById(1l, user.getId(), 1l)).thenReturn(null); + WidgetCatalogParameter userValue = new WidgetCatalogParameter(); + userValue.setUser_value("test123"); + Mockito.when(widgetParameterService.getUserParamById(1l, user.getId(), 2l)).thenReturn(userValue); + PortalRestResponse> actual = widgetsCatalogController + .getWidgetParameterResult(request, 1); + PortalRestResponse> expected = new PortalRestResponse>( + PortalRestStatusEnum.OK, "SUCCESS", new ArrayList<>()); + assertEquals(expected.getStatus(), actual.getStatus()); + } + @SuppressWarnings("unchecked") @Test - public void getUserWidgetCatalogTest() throws RestClientException, Exception{ - - String resourceType = null; - List widgets = new ArrayList<>(); - PowerMockito.mockStatic(EcompPortalUtils.class); - PowerMockito.mockStatic(SystemProperties.class); - PowerMockito.mockStatic(EPCommonSystemProperties.class); - Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); - Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); -// Mockito.when(WidgetServiceHeaders.getInstance()).thenReturn(HttpHeaders.ACCEPT); - Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", - "test")).thenReturn("test.com"); - Mockito.when(new HttpEntity(WidgetServiceHeaders.getInstance())).thenReturn(mockHttpEntity); -// HttpEntity entity = new HttpEntity("helloWorld"); -// ResponseEntity ans = new ResponseEntity<>(statusCode); -// Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), -// Matchers.>any(), Matchers.eq(ArrayList.class))).thenReturn(ans); -// List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog(mockedRequest, mockedResponse, "guestT"); + public void doDownloadTest() throws Exception { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) + .thenReturn("test"); + Mockito.when(CipherUtil + .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) + .thenReturn("abc"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + MockHttpServletRequest request = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + ResponseEntity mockData = new ResponseEntity("testfile.zip".getBytes(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.>any(), + Matchers.eq(byte[].class))).thenReturn(mockData); + widgetsCatalogController.doDownload(request, response, 1l); + } + + @Test + public void saveWidgetParameterTest() { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter(); + widgetCatalogParameter.setId(1l); + widgetCatalogParameter.setParamId(1l); + widgetCatalogParameter.setUserId(user.getId()); + widgetCatalogParameter.setUser_value("test123"); + MockHttpServletRequest request = new MockHttpServletRequest(); + Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user); + Mockito.when(widgetParameterService.getUserParamById(widgetCatalogParameter.getWidgetId(), + widgetCatalogParameter.getUserId(), widgetCatalogParameter.getParamId())).thenReturn(widgetCatalogParameter); + PortalRestResponse response = widgetsCatalogController.saveWidgetParameter(request, + widgetCatalogParameter); + PortalRestResponse expected = new PortalRestResponse(PortalRestStatusEnum.OK, "SUCCESS", ""); + assertEquals(expected.getMessage(), response.getMessage()); + } + + @Test + public void saveWidgetParameterExceptionTest() { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter(); + widgetCatalogParameter.setId(1l); + widgetCatalogParameter.setParamId(1l); + widgetCatalogParameter.setUserId(user.getId()); + widgetCatalogParameter.setUser_value("test123"); + MockHttpServletRequest request = new MockHttpServletRequest(); + Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user); + Mockito.doThrow(new NullPointerException()).when(widgetParameterService).getUserParamById(widgetCatalogParameter.getWidgetId(), + widgetCatalogParameter.getUserId(), widgetCatalogParameter.getParamId()); + PortalRestResponse response = widgetsCatalogController.saveWidgetParameter(request, + widgetCatalogParameter); + PortalRestResponse expected = new PortalRestResponse(PortalRestStatusEnum.ERROR, "FAILURE", ""); + assertEquals(expected.getMessage(), response.getMessage()); } } diff --git a/ecomp-portal-BE-os/README.md b/ecomp-portal-BE-os/README.md index d1262b6d..6ca4b1ed 100644 --- a/ecomp-portal-BE-os/README.md +++ b/ecomp-portal-BE-os/README.md @@ -36,6 +36,7 @@ Version 2.2 - [Portal-162] CVE-2015-5211 - Spring - File Upload issue. Upgrade to 4.2.2 - [Portal-163] NVD - CVE-2016-1000341: bouncycastle issue. Upgrade to 2.4.4 - [Portal-168] CVE-2015-0254 JSTL-Upgrade to 1.2.3+ +- [Portal-155] Review security issues: portal Version 1.1.0 (Amsterdam), November 2017 - [Portal-6] Updates to License and Trademark in the PORTAL Source Code diff --git a/ecomp-portal-BE-os/pom.xml b/ecomp-portal-BE-os/pom.xml index 975f6dec..41722611 100644 --- a/ecomp-portal-BE-os/pom.xml +++ b/ecomp-portal-BE-os/pom.xml @@ -318,17 +318,17 @@ com.fasterxml.jackson.core jackson-annotations - 2.6.3 + 2.9.2 com.fasterxml.jackson.core jackson-core - 2.6.3 + 2.9.2 com.fasterxml.jackson.core jackson-databind - 2.6.3 + 2.9.2 com.fasterxml @@ -380,7 +380,7 @@ org.apache.poi poi - 3.5-FINAL + 3.17 commons-logging @@ -395,7 +395,7 @@ org.apache.poi poi-ooxml - 3.5-FINAL + 3.17 commons-logging diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java index 88f7651c..0ee11715 100644 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java @@ -200,7 +200,7 @@ public class LoginController extends EPUnRestrictedBaseController implements Log Map model = new HashMap(); HashMap additionalParamsMap = new HashMap(); EPLoginBean commandBean = new EPLoginBean(); - MDC.put(MDC_KEY_REQUEST_ID, getRequestId(request)); + MDC.put(MDC_KEY_REQUEST_ID, (getRequestId(request)==null || getRequestId(request).isEmpty()) ? UUID.randomUUID().toString():getRequestId(request)); // get userId from cookie String orgUserId = SessionCookieUtil.getUserIdFromCookie(request, response); logger.info(EELFLoggerDelegate.debugLogger, "processSingleSignOn: begins with orgUserId {}", orgUserId); @@ -230,11 +230,11 @@ public class LoginController extends EPUnRestrictedBaseController implements Log additionalParamsMap); stopWatch.stop(); - MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms"); + MDC.put(EPSystemProperties.MDC_TIMER, String.valueOf(stopWatch.getTotalTimeMillis())); logger.info(EELFLoggerDelegate.debugLogger, "Operation findUser is completed."); } catch (Exception e) { stopWatch.stop(); - MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms"); + MDC.put(EPSystemProperties.MDC_TIMER, String.valueOf(stopWatch.getTotalTimeMillis())); logger.info(EELFLoggerDelegate.errorLogger, "processSingleSignOn failed on user " + orgUserId, e); } finally { MDC.remove(EPSystemProperties.MDC_TIMER); diff --git a/ecomp-portal-FE-os/.gitignore b/ecomp-portal-FE-os/.gitignore index 8f3fb880..5f37e3e6 100644 --- a/ecomp-portal-FE-os/.gitignore +++ b/ecomp-portal-FE-os/.gitignore @@ -8,4 +8,5 @@ node node_modules app .tmp -client/bower_components \ No newline at end of file +client/bower_components +npm-debug.log \ No newline at end of file diff --git a/ecomp-portal-widget-ms/widget-ms/pom.xml b/ecomp-portal-widget-ms/widget-ms/pom.xml index 77a68e0c..16e0a75a 100644 --- a/ecomp-portal-widget-ms/widget-ms/pom.xml +++ b/ecomp-portal-widget-ms/widget-ms/pom.xml @@ -137,6 +137,11 @@ ${jacocoVersion} runtime + + org.apache.tomcat.embed + tomcat-embed-core + 8.5.13 + diff --git a/pom.xml b/pom.xml index 7d6e12c7..055ea266 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 2.1.0 4.2.2.RELEASE 4.3.11.Final - 2.7.4 + 2.9.2 1.0.0 0.7.6.201602180812