|
@@ -42,6 +42,7 @@ import static org.junit.Assert.assertArrayEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
+import static org.junit.Assert.fail;
|
|
|
|
|
|
public class TestKeyProviderFactory {
|
|
public class TestKeyProviderFactory {
|
|
|
|
|
|
@@ -430,4 +431,51 @@ public class TestKeyProviderFactory {
|
|
Assert.assertNull(kp);
|
|
Assert.assertNull(kp);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testJksProviderWithKeytoolKeys() throws Exception {
|
|
|
|
+ final Configuration conf = new Configuration();
|
|
|
|
+ final String keystoreDirAbsolutePath =
|
|
|
|
+ conf.getResource("hdfs7067.keystore").getPath();
|
|
|
|
+ final String ourUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file@/" +
|
|
|
|
+ keystoreDirAbsolutePath;
|
|
|
|
+
|
|
|
|
+ conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, ourUrl);
|
|
|
|
+
|
|
|
|
+ final KeyProvider provider = KeyProviderFactory.getProviders(conf).get(0);
|
|
|
|
+
|
|
|
|
+ // Sanity check that we are using the right keystore
|
|
|
|
+ @SuppressWarnings("unused")
|
|
|
|
+ final KeyProvider.KeyVersion keyVersion =
|
|
|
|
+ provider.getKeyVersion("testkey5@0");
|
|
|
|
+ try {
|
|
|
|
+ @SuppressWarnings("unused")
|
|
|
|
+ final KeyProvider.KeyVersion keyVersionWrongKeyNameFormat =
|
|
|
|
+ provider.getKeyVersion("testkey2");
|
|
|
|
+ fail("should have thrown an exception");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // No version in key path testkey2/
|
|
|
|
+ GenericTestUtils.assertExceptionContains("No version in key path", e);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ @SuppressWarnings("unused")
|
|
|
|
+ final KeyProvider.KeyVersion keyVersionCurrentKeyNotWrongKeyNameFormat =
|
|
|
|
+ provider.getCurrentKey("testkey5@0");
|
|
|
|
+ fail("should have thrown an exception getting testkey5@0");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // javax.crypto.spec.SecretKeySpec cannot be cast to
|
|
|
|
+ // org.apache.hadoop.crypto.key.JavaKeyStoreProvider$KeyMetadata
|
|
|
|
+ GenericTestUtils.assertExceptionContains("other non-Hadoop method", e);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ @SuppressWarnings("unused")
|
|
|
|
+ KeyProvider.KeyVersion keyVersionCurrentKeyNotReally =
|
|
|
|
+ provider.getCurrentKey("testkey2");
|
|
|
|
+ fail("should have thrown an exception getting testkey2");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // javax.crypto.spec.SecretKeySpec cannot be cast to
|
|
|
|
+ // org.apache.hadoop.crypto.key.JavaKeyStoreProvider$KeyMetadata
|
|
|
|
+ GenericTestUtils.assertExceptionContains("other non-Hadoop method", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|