Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 49BC1200B6B for ; Thu, 11 Aug 2016 01:31:58 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 48652160AB1; Wed, 10 Aug 2016 23:31:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 91A3E160AA4 for ; Thu, 11 Aug 2016 01:31:57 +0200 (CEST) Received: (qmail 81853 invoked by uid 500); 10 Aug 2016 23:31:56 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 81844 invoked by uid 99); 10 Aug 2016 23:31:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Aug 2016 23:31:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 64C51E04AF; Wed, 10 Aug 2016 23:31:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: xiao@apache.org To: common-commits@hadoop.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HADOOP-13461. NPE in KeyProvider.rollNewVersion. Contributed by Colm O hEigeartaigh. Date: Wed, 10 Aug 2016 23:31:56 +0000 (UTC) archived-at: Wed, 10 Aug 2016 23:31:58 -0000 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 Authored: Wed Aug 10 16:26:16 2016 -0700 Committer: Xiao Chen 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