From c93cd351724bfe7d4baa48b0d6690e9ddc9a35bb Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 8 May 2020 12:41:58 +0200 Subject: [PATCH] Fixed code to generate DB Key --- .../DatabaseEnvironmentTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java index e258c2f..faac2cf 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java @@ -1,5 +1,14 @@ package org.gcube.informationsystem.resourceregistry.dbinitialization; +import java.io.File; +import java.io.InputStream; +import java.net.URL; +import java.security.Key; +import java.util.Properties; + +import org.gcube.common.encryption.KeyFactory; +import org.gcube.common.encryption.KeySerialization; +import org.gcube.common.encryption.SymmetricKey; import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; @@ -35,7 +44,7 @@ public class DatabaseEnvironmentTest { @Test public void generateDBKey() throws Exception { Properties properties = new Properties(); - InputStream input = DatabaseEnvironmentTest.class.getClassLoader().getResourceAsStream("config.properties"); + InputStream input = DatabaseEnvironmentTest.class.getClassLoader().getResourceAsStream("config.properties.prod"); // load a properties file properties.load(input); @@ -44,10 +53,11 @@ public class DatabaseEnvironmentTest { String keyAlgorithm = properties.getProperty("DB_KEY_ALGORITHM_VARNAME"); URL url = SymmetricKey.class.getResource(keyFileName); + File keyFile = new File("src/test/resources", keyFileName); Key key = null; if(url!=null) { try { - key = SymmetricKey.loadKeyFromFile(keyFileName, keyAlgorithm); + key = SymmetricKey.loadKeyFromFile(keyFile, keyAlgorithm); } catch(Exception e) { } @@ -55,8 +65,7 @@ public class DatabaseEnvironmentTest { if(key==null){ key = KeyFactory.newAESKey(); - File file = new File("src/test/resources", keyFileName); - KeySerialization.store(key, file); + KeySerialization.store(key, keyFile); } } */