You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by xi...@apache.org on 2016/08/10 23:28:40 UTC
hadoop git commit: HADOOP-13461. NPE in KeyProvider.rollNewVersion.
Contributed by Colm O hEigeartaigh.
Repository: hadoop
Updated Branches:
refs/heads/trunk ec289bbec -> e83be44af
HADOOP-13461. NPE in KeyProvider.rollNewVersion. Contributed by Colm O hEigeartaigh.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e83be44a
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e83be44a
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e83be44a
Branch: refs/heads/trunk
Commit: e83be44af530d57d9c49cd989d030052548a068b
Parents: ec289bb
Author: Xiao Chen <xi...@apache.org>
Authored: Wed Aug 10 16:26:16 2016 -0700
Committer: Xiao Chen <xi...@apache.org>
Committed: Wed Aug 10 16:28:02 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/e83be44a/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 0845a5f..c99a7bf 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/e83be44a/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 c3335a3..9c01175 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