From 34400eeebc299cbf8e4335a7bee937753554bed5 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 16 Nov 2017 13:22:49 +0100 Subject: Rework CryptoUtils CryptoUtils now takes the key from a file located in the resource not in spring file Change-Id: I002978d292550e6173efb4324cbb977f35d7e753 Issue-ID: CLAMP-74 Signed-off-by: Determe, Sebastien (sd378r) --- .../org/onap/clamp/clds/it/CryptoUtilsItCase.java | 76 -------------------- .../org/onap/clamp/clds/util/CryptoUtilsTest.java | 80 ++++++++++++++++++++++ .../resources/application-no-camunda.properties | 6 +- src/test/resources/clds/clds-reference.properties | 3 +- src/test/resources/clds/key.properties | 1 + src/test/resources/https/https-test.properties | 5 +- 6 files changed, 88 insertions(+), 83 deletions(-) delete mode 100644 src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java create mode 100644 src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java create mode 100644 src/test/resources/clds/key.properties (limited to 'src/test') diff --git a/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java b/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java deleted file mode 100644 index f03fe83c7..000000000 --- a/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.security.GeneralSecurityException; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.util.CryptoUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test Crypto Utils with Spring. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class CryptoUtilsItCase { - @Autowired - private CryptoUtils cryptoUtils; - - /** - * This method tests encryption. - * - * @throws GeneralSecurityException - */ - @Test - public final void testEncryption() throws GeneralSecurityException { - final String testData = "This is a test string"; - final String encodedStringExpected = "A5CB112C9F608A220B35AFED08024D98B9653333AF4C9527C2E934DE473F6145"; - String encodedString = cryptoUtils.encrypt(testData); - assertNotNull(encodedString); - assertEquals(encodedStringExpected, encodedString); - } - - /** - * This method tests decryption. - * - * @throws GeneralSecurityException - */ - @Test - public final void testDecryption() throws GeneralSecurityException { - final String decodedStringExpected = "This is a test string"; - final String encodedString = "A5CB112C9F608A220B35AFED08024D98B9653333AF4C9527C2E934DE473F6145"; - String decryptedString = cryptoUtils.decrypt(encodedString); - assertNotNull(decryptedString); - assertEquals(decodedStringExpected, decryptedString); - } -} \ No newline at end of file diff --git a/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java new file mode 100644 index 000000000..6fe447556 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; + +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Hex; +import org.apache.commons.lang3.ArrayUtils; +import org.junit.Test; + +/** + * Test Crypto Utils with Spring. + */ +public class CryptoUtilsTest { + private CryptoUtils cryptoUtils = new CryptoUtils(); + final String data = "This is a test string"; + + /** + * This method tests encryption. + * + * @throws GeneralSecurityException + * @throws DecoderException + * @throws UnsupportedEncodingException + */ + @Test + public final void testEncryption() throws GeneralSecurityException, DecoderException, UnsupportedEncodingException { + String encodedString = cryptoUtils.encrypt(data); + assertNotNull(encodedString); + assertEquals(data, cryptoUtils.decrypt(encodedString)); + } + + /** + * This method tests encryption. + * + * @throws GeneralSecurityException + * @throws DecoderException + * @throws UnsupportedEncodingException + */ + @Test + public final void testEncryptedStringIsDifferent() + throws GeneralSecurityException, DecoderException, UnsupportedEncodingException { + String encodedString1 = cryptoUtils.encrypt(data); + String encodedString2 = cryptoUtils.encrypt(data); + byte[] encryptedMessage1 = Hex.decodeHex(encodedString1.toCharArray()); + byte[] encryptedMessage2 = Hex.decodeHex(encodedString2.toCharArray()); + assertNotNull(encryptedMessage1); + assertNotNull(encryptedMessage2); + assertNotEquals(encryptedMessage1, encryptedMessage2); + byte[] subData1 = ArrayUtils.subarray(encryptedMessage1, 16, encryptedMessage1.length); + byte[] subData2 = ArrayUtils.subarray(encryptedMessage2, 16, encryptedMessage2.length); + assertNotEquals(subData1, subData2); + } +} \ No newline at end of file diff --git a/src/test/resources/application-no-camunda.properties b/src/test/resources/application-no-camunda.properties index f8727946d..ece42484e 100644 --- a/src/test/resources/application-no-camunda.properties +++ b/src/test/resources/application-no-camunda.properties @@ -97,7 +97,7 @@ kubernetes.namespace=com-att-ajsc spring.datasource.camunda.driverClassName=org.mariadb.jdbc.Driver spring.datasource.camunda.url=jdbc:mariadb:sequential://localhost:${docker.mariadb.port.host}/camundabpm?autoReconnect=true&retriesAllDown=2147483647&failoverLoopRetries=2147483647 spring.datasource.camunda.username=camunda -spring.datasource.camunda.password=D75B89195FD913848EA11416F755390E +spring.datasource.camunda.password=e1bb2a8381d1aa6c09879bd627db3bb560ad29e8a3343fe6aa7e6a7ba622da4e spring.datasource.camunda.validationQuery=SELECT 1 spring.datasource.camunda.validationQueryTimeout=20000 spring.datasource.camunda.validationInterval=30000 @@ -122,7 +122,7 @@ camunda.bpm.metrics.enabled=false spring.datasource.cldsdb.driverClassName=org.mariadb.jdbc.Driver spring.datasource.cldsdb.url=jdbc:mariadb:sequential://localhost:${docker.mariadb.port.host}/cldsdb4?autoReconnect=true&retriesAllDown=2147483647&failoverLoopRetries=2147483647 spring.datasource.cldsdb.username=clds -spring.datasource.cldsdb.password=035F8819FEBB754F3C99ECCCC1259850 +spring.datasource.cldsdb.password=4c90a0b48204383f4283448d23e0b885a47237b2a23588e7c4651604f51c1067 spring.datasource.cldsdb.validationQuery=SELECT 1 spring.datasource.cldsdb.validationQueryTimeout=20000 spring.datasource.cldsdb.validationInterval=30000 @@ -149,7 +149,7 @@ org.onap.clamp.config.files.cldsReference=classpath:/clds/clds-reference.propert org.onap.clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties org.onap.clamp.config.files.cldsUsers=classpath:/clds/clds-users.json org.onap.clamp.config.files.globalClds=classpath:/clds/globalClds.properties -org.onap.clamp.encryption.aes.key=aa3871669d893c7fb8abbcda31b88b4f + #Define user permission related parameters, the permission type can be changed but MUST be redefined in clds-users.properties in that case ! CLDS_PERMISSION_TYPE_CL=permission-type-cl diff --git a/src/test/resources/clds/clds-reference.properties b/src/test/resources/clds/clds-reference.properties index 0657fe7ba..83f7351a6 100644 --- a/src/test/resources/clds/clds-reference.properties +++ b/src/test/resources/clds/clds-reference.properties @@ -81,13 +81,14 @@ sdc.catalog.url=http://127.0.0.1:8080/sdc/v1/catalog/ sdc.hostUrl=http://127.0.0.1:8080 sdc.serviceUrl=http://127.0.0.1:8080/sdc/v1/catalog/services sdc.serviceUsername=test -sdc.servicePassword=123456 +sdc.servicePassword=aa2871669d793c7fb7abbcda31b88b4c29bf2982755b25f08f8d0130539c11b0 sdc.artifactLabel=blueprintclampcockpit sdc.sdcX-InstanceID=CLAMP sdc.artifactType=DCAE_INVENTORY_BLUEPRINT sdc.locationArtifactLabel=LocationClampCockpit sdc.locationArtifactType=DCAE_INVENTORY_JSON sdc.InstanceID=X-ONAP-InstanceID +sdc.header.requestId = X-ECOMP-RequestID # # # diff --git a/src/test/resources/clds/key.properties b/src/test/resources/clds/key.properties new file mode 100644 index 000000000..dda811040 --- /dev/null +++ b/src/test/resources/clds/key.properties @@ -0,0 +1 @@ +org.onap.clamp.encryption.aes.key=aa3871669d893c7fb8abbcda31b88b4f \ No newline at end of file diff --git a/src/test/resources/https/https-test.properties b/src/test/resources/https/https-test.properties index 58345d06a..bd84242ef 100644 --- a/src/test/resources/https/https-test.properties +++ b/src/test/resources/https/https-test.properties @@ -96,7 +96,7 @@ kubernetes.namespace=com-att-ajsc spring.datasource.camunda.driverClassName=org.mariadb.jdbc.Driver spring.datasource.camunda.url=jdbc:mariadb:sequential://localhost:${docker.mariadb.port.host}/camundabpm?autoReconnect=true&retriesAllDown=2147483647&failoverLoopRetries=2147483647 spring.datasource.camunda.username=camunda -spring.datasource.camunda.password=D75B89195FD913848EA11416F755390E +spring.datasource.camunda.password=e1bb2a8381d1aa6c09879bd627db3bb560ad29e8a3343fe6aa7e6a7ba622da4e spring.datasource.camunda.validationQuery=SELECT 1 spring.datasource.camunda.validationQueryTimeout=20000 spring.datasource.camunda.validationInterval=30000 @@ -122,7 +122,7 @@ camunda.bpm.metrics.enabled=false spring.datasource.cldsdb.driverClassName=org.mariadb.jdbc.Driver spring.datasource.cldsdb.url=jdbc:mariadb:sequential://localhost:${docker.mariadb.port.host}/cldsdb4?autoReconnect=true&retriesAllDown=2147483647&failoverLoopRetries=2147483647 spring.datasource.cldsdb.username=clds -spring.datasource.cldsdb.password=035F8819FEBB754F3C99ECCCC1259850 +spring.datasource.cldsdb.password=4c90a0b48204383f4283448d23e0b885a47237b2a23588e7c4651604f51c1067 spring.datasource.cldsdb.validationQuery=SELECT 1 spring.datasource.cldsdb.validationQueryTimeout=20000 spring.datasource.cldsdb.validationInterval=30000 @@ -149,7 +149,6 @@ org.onap.clamp.config.files.cldsReference=classpath:/clds/clds-reference.propert org.onap.clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties org.onap.clamp.config.files.cldsUsers=classpath:/clds/clds-users.json org.onap.clamp.config.files.globalClds=classpath:/clds/globalClds.properties -org.onap.clamp.encryption.aes.key=aa3871669d893c7fb8abbcda31b88b4f #Define user permission related parameters, the permission type can be changed but MUST be redefined in clds-users.properties in that case ! CLDS_PERMISSION_TYPE_CL=permission-type-cl -- cgit 1.2.3-korg