hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x...@apache.org
Subject hadoop git commit: HADOOP-13461. NPE in KeyProvider.rollNewVersion. Contributed by Colm O hEigeartaigh.
Date Wed, 10 Aug 2016 23:31:56 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 de6eafc69 -> 01fc975ed


HADOOP-13461. NPE in KeyProvider.rollNewVersion. Contributed by Colm O hEigeartaigh.

(cherry picked from commit e83be44af530d57d9c49cd989d030052548a068b)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/01fc975e
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/01fc975e
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/01fc975e

Branch: refs/heads/branch-2
Commit: 01fc975ed9e8e8bb2fa6bf15ef0aaa08d71eb3dd
Parents: de6eafc
Author: Xiao Chen <xiao@apache.org>
Authored: Wed Aug 10 16:26:16 2016 -0700
Committer: Xiao Chen <xiao@apache.org>
Committed: Wed Aug 10 16:28:34 2016 -0700

----------------------------------------------------------------------
 .../apache/hadoop/crypto/key/KeyProvider.java   |  4 +++
 .../hadoop/crypto/key/TestKeyProvider.java      | 28 +++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/01fc975e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java
index fc8b46a..c3717eb 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java
@@ -557,6 +557,10 @@ public abstract class KeyProvider {
   public KeyVersion rollNewVersion(String name) throws NoSuchAlgorithmException,
                                                        IOException {
     Metadata meta = getMetadata(name);
+    if (meta == null) {
+      throw new IOException("Can't find Metadata for key " + name);
+    }
+
     byte[] material = generateKey(meta.getBitLength(), meta.getCipher());
     return rollNewVersion(name, material);
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/01fc975e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProvider.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProvider.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProvider.java
index eec80c2..8a298b1 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProvider.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProvider.java
@@ -22,6 +22,7 @@ import org.apache.hadoop.conf.Configuration;
 
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.security.ProviderUtils;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.junit.Test;
 
 import java.io.IOException;
@@ -38,6 +39,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.fail;
 
 public class TestKeyProvider {
 
@@ -182,7 +184,10 @@ public class TestKeyProvider {
 
     @Override
     public Metadata getMetadata(String name) throws IOException {
-      return new Metadata(CIPHER, 128, "description", null, new Date(), 0);
+      if (!"unknown".equals(name)) {
+        return new Metadata(CIPHER, 128, "description", null, new Date(), 0);
+      }
+      return null;
     }
 
     @Override
@@ -237,6 +242,27 @@ public class TestKeyProvider {
   }
 
   @Test
+  public void testRolloverUnknownKey() throws Exception {
+    MyKeyProvider kp = new MyKeyProvider(new Configuration());
+    KeyProvider.Options options = new KeyProvider.Options(new Configuration());
+    options.setCipher(CIPHER);
+    options.setBitLength(128);
+    kp.createKey("hello", options);
+    Assert.assertEquals(128, kp.size);
+    Assert.assertEquals(CIPHER, kp.algorithm);
+    Assert.assertNotNull(kp.material);
+
+    kp = new MyKeyProvider(new Configuration());
+    try {
+      kp.rollNewVersion("unknown");
+      fail("should have thrown");
+    } catch (IOException e) {
+      String expectedError = "Can't find Metadata for key";
+      GenericTestUtils.assertExceptionContains(expectedError, e);
+    }
+  }
+
+  @Test
   public void testConfiguration() throws Exception {
     Configuration conf = new Configuration(false);
     conf.set("a", "A");


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message