milleruntime closed pull request #641:  Fix crypto tests writing to /tmp
URL: https://github.com/apache/accumulo/pull/641
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java 
b/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java
index 2ed8620f40..ad61f2e62b 100644
--- a/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.core.file.rfile;
 
+import static org.apache.accumulo.core.conf.Property.INSTANCE_CRYPTO_PREFIX;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -54,7 +55,6 @@
 import org.apache.accumulo.core.conf.ConfigurationCopy;
 import org.apache.accumulo.core.conf.DefaultConfiguration;
 import org.apache.accumulo.core.conf.Property;
-import org.apache.accumulo.core.conf.SiteConfiguration;
 import org.apache.accumulo.core.data.ArrayByteSequence;
 import org.apache.accumulo.core.data.ByteSequence;
 import org.apache.accumulo.core.data.Key;
@@ -89,7 +89,6 @@
 import org.apache.hadoop.fs.PositionedReadable;
 import org.apache.hadoop.fs.Seekable;
 import org.apache.hadoop.io.Text;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
@@ -132,11 +131,6 @@ public static void setupCryptoKeyFile() throws Exception {
     CryptoTest.setupKeyFile();
   }
 
-  @AfterClass
-  public static void removeCryptoKeyFile() throws Exception {
-    CryptoTest.cleanupKeyFile();
-  }
-
   static class SeekableByteArrayInputStream extends ByteArrayInputStream
       implements Seekable, PositionedReadable {
 
@@ -1787,8 +1781,16 @@ private void runVersionTest(int version, 
AccumuloConfiguration aconf) throws IOE
     reader.close();
   }
 
-  public static AccumuloConfiguration getAccumuloConfig(String 
cryptoConfSetting) {
-    return new 
SiteConfiguration(CryptoTest.class.getClassLoader().getResource(cryptoConfSetting));
+  public static AccumuloConfiguration getAccumuloConfig(String cryptoOn) {
+    ConfigurationCopy cfg = new 
ConfigurationCopy(DefaultConfiguration.getInstance());
+    switch (cryptoOn) {
+      case CryptoTest.CRYPTO_ON_CONF:
+        cfg.set(Property.INSTANCE_CRYPTO_SERVICE,
+            "org.apache.accumulo.core.security.crypto.impl.AESCryptoService");
+        cfg.set(INSTANCE_CRYPTO_PREFIX.getKey() + "key.location", 
CryptoTest.keyPath);
+        cfg.set(INSTANCE_CRYPTO_PREFIX.getKey() + "key.provider", "uri");
+    }
+    return cfg;
   }
 
   @Test
diff --git 
a/core/src/test/java/org/apache/accumulo/core/security/crypto/CryptoTest.java 
b/core/src/test/java/org/apache/accumulo/core/security/crypto/CryptoTest.java
index e5e3e53442..4eb6b2fe25 100644
--- 
a/core/src/test/java/org/apache/accumulo/core/security/crypto/CryptoTest.java
+++ 
b/core/src/test/java/org/apache/accumulo/core/security/crypto/CryptoTest.java
@@ -66,7 +66,6 @@
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
@@ -76,8 +75,10 @@
 
   public static final int MARKER_INT = 0xCADEFEDD;
   public static final String MARKER_STRING = "1 2 3 4 5 6 7 8 a b c d e f g h 
";
-  public static final String CRYPTO_ON_CONF = "crypto-on-accumulo.properties";
-  public static final String CRYPTO_OFF_CONF = "accumulo.properties";
+  public static final String CRYPTO_ON_CONF = "ON";
+  public static final String CRYPTO_OFF_CONF = "OFF";
+  public static final String keyPath = System.getProperty("user.dir")
+      + "/target/CryptoTest-testkeyfile";
 
   @Rule
   public ExpectedException exception = ExpectedException.none();
@@ -85,23 +86,12 @@
   @BeforeClass
   public static void setupKeyFile() throws Exception {
     FileSystem fs = FileSystem.getLocal(CachedConfiguration.getInstance());
-    String file = "/tmp/testAESFile";
-    Path aesPath = new Path(file);
-    fs.delete(aesPath, true);
-    fs.createNewFile(aesPath);
+    Path aesPath = new Path(keyPath);
     try (FSDataOutputStream out = fs.create(aesPath)) {
       out.writeUTF("sixteenbytekey"); // 14 + 2 from writeUTF
     }
   }
 
-  @AfterClass
-  public static void cleanupKeyFile() throws Exception {
-    FileSystem fs = FileSystem.getLocal(CachedConfiguration.getInstance());
-    String file = "/tmp/testAESFile";
-    Path aesPath = new Path(file);
-    fs.delete(aesPath, true);
-  }
-
   @Test
   public void simpleGCMTest() throws Exception {
     AccumuloConfiguration conf = getAccumuloConfig(CRYPTO_ON_CONF);
@@ -297,7 +287,7 @@ public void testKeyManagerWrapAndUnwrap()
 
   @Test
   public void testKeyManagerLoadKekFromUri() throws IOException {
-    SecretKeySpec fileKey = 
AESKeyUtils.loadKekFromUri("file:///tmp/testAESFile");
+    SecretKeySpec fileKey = AESKeyUtils.loadKekFromUri(keyPath);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream dos = new DataOutputStream(baos);
     dos.writeUTF("sixteenbytekey");
diff --git a/core/src/test/resources/crypto-on-accumulo.properties 
b/core/src/test/resources/crypto-on-accumulo.properties
deleted file mode 100644
index 52100c706f..0000000000
--- a/core/src/test/resources/crypto-on-accumulo.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-
-instance.crypto.service=org.apache.accumulo.core.security.crypto.impl.AESCryptoService
-instance.crypto.opts.key.location=file:///tmp/testAESFile
-instance.crypto.opts.key.provider=uri


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to