accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmil...@apache.org
Subject [accumulo] branch master updated: Fix crypto tests writing to /tmp (#641)
Date Tue, 11 Sep 2018 19:10:13 GMT
This is an automated email from the ASF dual-hosted git repository.

mmiller pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new e88ba2f   Fix crypto tests writing to /tmp (#641)
e88ba2f is described below

commit e88ba2fd4e7f8219bcd33f6b5c60620ceae2dcce
Author: Mike Miller <mmiller@apache.org>
AuthorDate: Tue Sep 11 15:10:10 2018 -0400

     Fix crypto tests writing to /tmp (#641)
---
 .../apache/accumulo/core/file/rfile/RFileTest.java | 20 +++++++++++---------
 .../accumulo/core/security/crypto/CryptoTest.java  | 22 ++++++----------------
 .../test/resources/crypto-on-accumulo.properties   | 18 ------------------
 3 files changed, 17 insertions(+), 43 deletions(-)

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 2ed8620..ad61f2e 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.AccumuloConfiguration;
 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.FileSystem;
 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 class RFileTest {
     CryptoTest.setupKeyFile();
   }
 
-  @AfterClass
-  public static void removeCryptoKeyFile() throws Exception {
-    CryptoTest.cleanupKeyFile();
-  }
-
   static class SeekableByteArrayInputStream extends ByteArrayInputStream
       implements Seekable, PositionedReadable {
 
@@ -1787,8 +1781,16 @@ public class RFileTest {
     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 e5e3e53..4eb6b2f 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.conf.Configuration;
 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 class CryptoTest {
 
   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 @@ public class CryptoTest {
   @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 class CryptoTest {
 
   @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 52100c7..0000000
--- 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


Mime
View raw message