diff options
11 files changed, 215 insertions, 43 deletions
diff --git a/.gitignore b/.gitignore index 7df831f3b..dbc83afef 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,12 @@ .classpath .jupiter .pydevproject -.idea + +# IntelliJ files +.idea/ +**/*.iml +overlays/ + target .metadata/ ASTRAGateway/policyEngineLog.log diff --git a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java index 45f65851e..8826d5697 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java @@ -256,8 +256,8 @@ public class BrmsPush { repUrlList = new ArrayList<>(); repUrlList.add(repUrl); } - repUserName = config.getProperty("repositoryUsername"); - repPassword = PeCryptoUtils.decrypt(config.getProperty("repositoryPassword")); + repUserName = getValue(config.getProperty("repositoryUsername")); + repPassword = PeCryptoUtils.decrypt(getValue(config.getProperty("repositoryPassword"))); if (repUserName == null || repPassword == null) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repostoryUserName and respositoryPassword properties are required."); @@ -367,6 +367,13 @@ public class BrmsPush { } + private String getValue(final String value) { + if (value != null && value.matches("[$][{].*[}]$")) { + return System.getenv(value.substring(2, value.length() - 1)); + } + return value; + } + private static void setBackupMonitor(final BackUpMonitor instance) { bm = instance; } diff --git a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java index f12522af6..77aafdf7a 100644 --- a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java +++ b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java @@ -884,11 +884,11 @@ public class ParseLog { setLogFileProperties(splitString); jdbcUrl = config.getProperty("JDBC_URL").replace("'", ""); - jdbcUser = config.getProperty("JDBC_USER"); + jdbcUser = getValue(config.getProperty("JDBC_USER")); jdbcDriver = config.getProperty("JDBC_DRIVER"); PeCryptoUtils.initAesKey(config.getProperty(PROP_AES_KEY)); - jdbcPassword = PeCryptoUtils.decrypt(config.getProperty("JDBC_PASSWORD")); + jdbcPassword = PeCryptoUtils.decrypt(getValue(config.getProperty("JDBC_PASSWORD"))); config.setProperty("javax.persistence.jdbc.password", jdbcPassword); return config; @@ -902,6 +902,13 @@ public class ParseLog { return null; } + private static String getValue(final String value) { + if (value != null && value.matches("[$][{].*[}]$")) { + return System.getenv(value.substring(2, value.length() - 1)); + } + return value; + } + public static Connection getDbConnection() { return dbConnection(jdbcDriver, jdbcUrl, jdbcUser, jdbcPassword); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java index 67214acf2..e694f7e0b 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -549,6 +549,9 @@ public class PolicyDbDaoTransactionInstance implements PolicyDbDaoTransaction { IOUtils.closeQuietly(policyXmlStream); if (PolicyDbDao.isJunit()) { + if (policyDataString != null) { + logger.warn("isJUnit will overwrite policyDataString"); + } // Using parentPath object to set policy data. policyDataString = policy.policyAdapter.getParentPath(); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java index 29b244046..f2f2e8dbc 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -618,7 +618,13 @@ public class PolicyCreation extends AbstractPolicyCreation { } catch (Exception e) { LOGGER.error("Exception Occured : " + e.getMessage(), e); body = ERROR; - response.addHeader(ERROR, e.getMessage()); + // + // Because we are catching any old exception instead of a dedicated exception, + // its possible the e.getMessage() returns a null value. You cannot add a header + // to the response with a null value, it will throw an exception. This is something + // this is undesirable. + // + response.addHeader(ERROR, (e.getMessage() == null ? "missing exception message" : e.getMessage())); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } return new ResponseEntity<>(body, status); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java index 0c029b433..953fff35c 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java @@ -20,26 +20,33 @@ package org.onap.policy.pap.xacml.rest.policycontroller; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; - -import com.mockrunner.mock.web.MockHttpServletRequest; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; import org.junit.Test; import org.mockito.Mockito; +import org.onap.policy.pap.xacml.rest.components.PolicyDbDao; +import org.onap.policy.pap.xacml.rest.components.PolicyDbDaoTransaction; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.dao.CommonClassDao; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; import org.onap.policy.rest.jpa.PolicyVersion; +import org.powermock.reflect.Whitebox; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.mock.web.MockHttpServletResponse; +import com.mockrunner.mock.web.MockHttpServletRequest; public class PolicyCreationTest { @Test @@ -57,7 +64,7 @@ public class PolicyCreationTest { Exception cause = new Exception("oops"); HttpMessageNotReadableException exception = new HttpMessageNotReadableException("oops", cause); assertEquals(HttpStatus.BAD_REQUEST, - creation.messageNotReadableExceptionHandler(req, exception).getStatusCode()); + creation.messageNotReadableExceptionHandler(req, exception).getStatusCode()); HttpServletResponse response = new MockHttpServletResponse(); PolicyRestAdapter policyData = new PolicyRestAdapter(); @@ -65,53 +72,81 @@ public class PolicyCreationTest { policyData.setConfigPolicyType("ClosedLoop_Fault"); policyData.setDomainDir("domain"); policyData.setPolicyName("policyname"); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + ResponseEntity<String> responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); version.setHigherVersion(1); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); policyData.setEditPolicy(true); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); policyData.setEditPolicy(false); version.setHigherVersion(0); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); policyData.setEditPolicy(true); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); version.setHigherVersion(1); policyData.setConfigPolicyType("Firewall Config"); - assertThatThrownBy(() -> creation.savePolicy(policyData, response)) - .isInstanceOf(IllegalArgumentException.class); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); policyData.setConfigPolicyType("BRMS_Raw"); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); + policyData.setConfigPolicyType("BRMS_Param"); - assertThatThrownBy(() -> creation.savePolicy(policyData, response)) - .isInstanceOf(IllegalArgumentException.class); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); + policyData.setConfigPolicyType("Base"); Mockito.when(policyData.getRuleData()).thenReturn(new LinkedHashMap<>()); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + + SessionFactory mockSessionFactory = Mockito.mock(SessionFactory.class); + Session mockSession = Mockito.mock(Session.class); + Criteria mockCriteria = Mockito.mock(Criteria.class); + List<?> policyDbDaoEntityList = new LinkedList<>(); + + Mockito.when(mockSessionFactory.openSession()).thenReturn(mockSession); + Mockito.when(mockSession.createCriteria(PolicyDbDaoEntity.class)).thenReturn(mockCriteria); + Mockito.when(mockCriteria.list()).thenReturn(policyDbDaoEntityList); + Whitebox.setInternalState(PolicyDbDao.class, "sessionfactory", mockSessionFactory); + + PolicyDbDao mockPolicyDbDao = Mockito.mock(PolicyDbDao.class); + PolicyDbDaoTransaction mockTransaction = Mockito.mock(PolicyDbDaoTransaction.class); + Mockito.when(mockPolicyDbDao.getNewTransaction()).thenReturn(mockTransaction); + + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); + policyData.setConfigPolicyType("ClosedLoop_PM"); - assertThatThrownBy(() -> creation.savePolicy(policyData, response)) - .isInstanceOf(IllegalArgumentException.class); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); + policyData.setConfigPolicyType("Micro Service"); - assertThatThrownBy(() -> creation.savePolicy(policyData, response)) - .isInstanceOf(IllegalArgumentException.class); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); + policyData.setConfigPolicyType("Optimization"); - assertThatThrownBy(() -> creation.savePolicy(policyData, response)) - .isInstanceOf(IllegalArgumentException.class); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); policyData.setPolicyType("Action"); - List<Object> choices = new ArrayList<Object>(); + List<Object> choices = new ArrayList<>(); policyData.setRuleAlgorithmschoices(choices); - assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); policyData.setPolicyType("Decision"); - List<Object> settings = new ArrayList<Object>(); + List<Object> settings = new ArrayList<>(); policyData.setSettings(settings); - assertThatThrownBy(() -> creation.savePolicy(policyData, response)) - .isInstanceOf(IllegalArgumentException.class); + responseEntity = creation.savePolicy(policyData, response); + assertThat(responseEntity).isNotNull(); } } diff --git a/ONAP-SDK-APP/pom.xml b/ONAP-SDK-APP/pom.xml index c3c595c53..45d105a06 100644 --- a/ONAP-SDK-APP/pom.xml +++ b/ONAP-SDK-APP/pom.xml @@ -214,6 +214,10 @@ <groupId>org.onap.portal.sdk</groupId> <artifactId>epsdk-core</artifactId> </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + </exclusion> </exclusions> </dependency> <dependency> @@ -283,6 +287,16 @@ <version>3.2.2</version> </dependency> <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${springframework.version}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${springframework.version}</version> + </dependency> + <dependency> <groupId>org.onap.portal.sdk</groupId> <artifactId>epsdk-core</artifactId> <version>${epsdk.version}</version> @@ -313,9 +327,25 @@ <artifactId>spring-webmvc</artifactId> </exclusion> <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + </exclusion> + <exclusion> <groupId>xalan</groupId> <artifactId>xalan</artifactId> </exclusion> + <exclusion> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + </exclusion> + <exclusion> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + </exclusion> </exclusions> </dependency> <dependency> @@ -369,6 +399,21 @@ <!-- Spring --> <!-- Added dependencies to fix issue with duplicate jars of different versions --> <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>1.8.14</version> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>1.8.14</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + <version>${springframework.version}</version> + </dependency> + <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${springframework.version}</version> @@ -383,11 +428,23 @@ <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${springframework.version}</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${springframework.version}</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + </exclusion> + </exclusions> </dependency> <!-- bridge to implement commons-logging using slf4j --> <dependency> diff --git a/POLICY-SDK-APP/pom.xml b/POLICY-SDK-APP/pom.xml index 14179fafc..6c66bd7d2 100644 --- a/POLICY-SDK-APP/pom.xml +++ b/POLICY-SDK-APP/pom.xml @@ -108,6 +108,10 @@ <artifactId>spring-webmvc</artifactId> </exclusion> <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + </exclusion> + <exclusion> <groupId>xalan</groupId> <artifactId>xalan</artifactId> </exclusion> @@ -123,12 +127,40 @@ <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> + <exclusion> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + </exclusion> + <exclusion> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + </exclusion> + <exclusion> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + <version>${springframework.version}</version> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>1.8.14</version> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>1.8.14</version> + </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> + <version>${springframework.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> @@ -144,10 +176,24 @@ <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> + <version>${springframework.version}</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> + <version>${springframework.version}</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> @@ -259,6 +305,14 @@ <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + </exclusion> </exclusions> </dependency> <dependency> @@ -274,12 +328,12 @@ <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> - <version>3.17</version> + <version>4.1.1</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> - <version>3.17</version> + <version>4.1.1</version> <exclusions> <exclusion> <groupId>org.apache.xmlbeans</groupId> diff --git a/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties b/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties index a12eac3ce..4831802ca 100644 --- a/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties +++ b/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties @@ -44,9 +44,9 @@ decryption_key = AGLDdG4D04BKm2IxIWEr8o== ########################################################################## #Mysql db.driver = org.mariadb.jdbc.Driver -db.connectionURL = jdbc:mariadb://localhost:3306/onapsdk1707 +db.connectionURL = jdbc:mariadb://localhost:3306/onap_sdk db.userName = root -db.password = +db.password = db.hib.dialect = org.hibernate.dialect.MySQLDialect db.min_pool_size = 5 db.max_pool_size = 10 diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java index b2e1b9228..6c47b3955 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java @@ -69,7 +69,7 @@ import org.powermock.reflect.Whitebox; import org.springframework.mock.web.MockHttpServletResponse; @RunWith(PowerMockRunner.class) -@PowerMockIgnore({"com.sun.org.apache.xerces.*", "jdk.internal.reflect.*", "javax.xml.*", "org.xml.*", "org.w3c.*"}) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "com.sun.org.apache.xalan.*"}) public class PolicyRestControllerTest { private String clRequestString; diff --git a/packages/docker/src/main/docker/Dockerfile b/packages/docker/src/main/docker/Dockerfile index d59e9d70e..c257fd301 100644 --- a/packages/docker/src/main/docker/Dockerfile +++ b/packages/docker/src/main/docker/Dockerfile @@ -13,9 +13,7 @@ RUN apt update && \ apt-get install -y netcat && \ apt-get install -y cron && \ mkdir -p /tmp/policy-install ${POLICY_LOGS} && \ - chown policy:policy /tmp/policy-install ${POLICY_LOGS} && \ - rmdir ${POLICY_HOME}/etc/ssl && \ - rmdir ${POLICY_HOME}/etc + chown policy:policy /tmp/policy-install ${POLICY_LOGS} WORKDIR /tmp/policy-install |