Search in sources :

Example 96 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestKeyProviderFactory method testJksProviderPasswordViaConfig.

@Test
public void testJksProviderPasswordViaConfig() throws Exception {
    Configuration conf = new Configuration();
    final Path jksPath = new Path(testRootDir.toString(), "test.jks");
    final String ourUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();
    File file = new File(testRootDir, "test.jks");
    file.delete();
    try {
        conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, ourUrl);
        conf.set(JavaKeyStoreProvider.KEYSTORE_PASSWORD_FILE_KEY, "javakeystoreprovider.password");
        KeyProvider provider = KeyProviderFactory.getProviders(conf).get(0);
        provider.createKey("key3", new byte[16], KeyProvider.options(conf));
        provider.flush();
    } catch (Exception ex) {
        Assert.fail("could not create keystore with password file");
    }
    KeyProvider provider = KeyProviderFactory.getProviders(conf).get(0);
    Assert.assertNotNull(provider.getCurrentKey("key3"));
    try {
        conf.set(JavaKeyStoreProvider.KEYSTORE_PASSWORD_FILE_KEY, "bar");
        KeyProviderFactory.getProviders(conf).get(0);
        Assert.fail("using non existing password file, it should fail");
    } catch (IOException ex) {
    //NOP
    }
    try {
        conf.set(JavaKeyStoreProvider.KEYSTORE_PASSWORD_FILE_KEY, "core-site.xml");
        KeyProviderFactory.getProviders(conf).get(0);
        Assert.fail("using different password file, it should fail");
    } catch (IOException ex) {
    //NOP
    }
    try {
        conf.unset(JavaKeyStoreProvider.KEYSTORE_PASSWORD_FILE_KEY);
        KeyProviderFactory.getProviders(conf).get(0);
        Assert.fail("No password file property, env not set, it should fail");
    } catch (IOException ex) {
    //NOP
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 97 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestKeyProviderFactory method testUserProvider.

@Test
public void testUserProvider() throws Exception {
    Configuration conf = new Configuration();
    final String ourUrl = UserProvider.SCHEME_NAME + ":///";
    conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, ourUrl);
    checkSpecificProvider(conf, ourUrl);
    // see if the credentials are actually in the UGI
    Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials();
    assertArrayEquals(new byte[] { 1 }, credentials.getSecretKey(new Text("key4@0")));
    assertArrayEquals(new byte[] { 2 }, credentials.getSecretKey(new Text("key4@1")));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

Example 98 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestKeyShell method testTransientProviderWarning.

@Test
public void testTransientProviderWarning() throws Exception {
    final String[] args1 = { "create", "key1", "-cipher", "AES", "-provider", "user:///" };
    int rc = 0;
    KeyShell ks = new KeyShell();
    ks.setConf(new Configuration());
    rc = ks.run(args1);
    assertEquals(0, rc);
    assertTrue(outContent.toString().contains("WARNING: you are modifying a " + "transient provider."));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Example 99 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestKeyShell method testInvalidProvider.

@Test
public void testInvalidProvider() throws Exception {
    final String[] args1 = { "create", "key1", "-cipher", "AES", "-provider", "sdff://file/tmp/keystore.jceks" };
    int rc = 0;
    KeyShell ks = new KeyShell();
    ks.setConf(new Configuration());
    rc = ks.run(args1);
    assertEquals(1, rc);
    assertTrue(outContent.toString().contains(KeyShell.NO_VALID_PROVIDERS));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Example 100 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestKeyShell method testAttributes.

@Test
public void testAttributes() throws Exception {
    int rc;
    KeyShell ks = new KeyShell();
    ks.setConf(new Configuration());
    /* Simple creation test */
    final String[] args1 = { "create", "keyattr1", "-provider", jceksProvider, "-attr", "foo=bar" };
    rc = ks.run(args1);
    assertEquals(0, rc);
    assertTrue(outContent.toString().contains("keyattr1 has been " + "successfully created"));
    /* ...and list to see that we have the attr */
    String listOut = listKeys(ks, true);
    assertTrue(listOut.contains("keyattr1"));
    assertTrue(listOut.contains("attributes: [foo=bar]"));
    /* Negative tests: no attribute */
    outContent.reset();
    final String[] args2 = { "create", "keyattr2", "-provider", jceksProvider, "-attr", "=bar" };
    rc = ks.run(args2);
    assertEquals(1, rc);
    /* Not in attribute = value form */
    outContent.reset();
    args2[5] = "foo";
    rc = ks.run(args2);
    assertEquals(1, rc);
    /* No attribute or value */
    outContent.reset();
    args2[5] = "=";
    rc = ks.run(args2);
    assertEquals(1, rc);
    /* Legal: attribute is a, value is b=c */
    outContent.reset();
    args2[5] = "a=b=c";
    rc = ks.run(args2);
    assertEquals(0, rc);
    listOut = listKeys(ks, true);
    assertTrue(listOut.contains("keyattr2"));
    assertTrue(listOut.contains("attributes: [a=b=c]"));
    /* Test several attrs together... */
    outContent.reset();
    final String[] args3 = { "create", "keyattr3", "-provider", jceksProvider, "-attr", "foo = bar", "-attr", " glarch =baz  ", "-attr", "abc=def" };
    rc = ks.run(args3);
    assertEquals(0, rc);
    /* ...and list to ensure they're there. */
    listOut = listKeys(ks, true);
    assertTrue(listOut.contains("keyattr3"));
    assertTrue(listOut.contains("[foo=bar]"));
    assertTrue(listOut.contains("[glarch=baz]"));
    assertTrue(listOut.contains("[abc=def]"));
    /* Negative test - repeated attributes should fail */
    outContent.reset();
    final String[] args4 = { "create", "keyattr4", "-provider", jceksProvider, "-attr", "foo=bar", "-attr", "foo=glarch" };
    rc = ks.run(args4);
    assertEquals(1, rc);
    /* Clean up to be a good citizen */
    deleteKey(ks, "keyattr1");
    deleteKey(ks, "keyattr2");
    deleteKey(ks, "keyattr3");
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)5973 Test (org.junit.Test)3243 Path (org.apache.hadoop.fs.Path)1602 FileSystem (org.apache.hadoop.fs.FileSystem)903 IOException (java.io.IOException)850 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)727 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)517 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)502 File (java.io.File)499 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)388 ArrayList (java.util.ArrayList)360 URI (java.net.URI)319 BeforeClass (org.junit.BeforeClass)275 Job (org.apache.hadoop.mapreduce.Job)272 Before (org.junit.Before)264 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)219 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)203 HashMap (java.util.HashMap)192 FileStatus (org.apache.hadoop.fs.FileStatus)190 Properties (java.util.Properties)187