|
@@ -29,6 +29,7 @@ import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
@@ -37,18 +38,23 @@ public class TestCredShell {
|
|
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
|
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
|
private static final File tmpDir =
|
|
private static final File tmpDir =
|
|
new File(System.getProperty("test.build.data", "/tmp"), "creds");
|
|
new File(System.getProperty("test.build.data", "/tmp"), "creds");
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /* The default JCEKS provider - for testing purposes */
|
|
|
|
+ private String jceksProvider;
|
|
|
|
+
|
|
@Before
|
|
@Before
|
|
public void setup() throws Exception {
|
|
public void setup() throws Exception {
|
|
System.setOut(new PrintStream(outContent));
|
|
System.setOut(new PrintStream(outContent));
|
|
System.setErr(new PrintStream(errContent));
|
|
System.setErr(new PrintStream(errContent));
|
|
|
|
+ final Path jksPath = new Path(tmpDir.toString(), "keystore.jceks");
|
|
|
|
+ jceksProvider = "jceks://file" + jksPath.toUri();
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testCredentialSuccessfulLifecycle() throws Exception {
|
|
public void testCredentialSuccessfulLifecycle() throws Exception {
|
|
outContent.reset();
|
|
outContent.reset();
|
|
String[] args1 = {"create", "credential1", "-value", "p@ssw0rd", "-provider",
|
|
String[] args1 = {"create", "credential1", "-value", "p@ssw0rd", "-provider",
|
|
- "jceks://file" + tmpDir + "/credstore.jceks"};
|
|
|
|
|
|
+ jceksProvider};
|
|
int rc = 0;
|
|
int rc = 0;
|
|
CredentialShell cs = new CredentialShell();
|
|
CredentialShell cs = new CredentialShell();
|
|
cs.setConf(new Configuration());
|
|
cs.setConf(new Configuration());
|
|
@@ -59,14 +65,14 @@ public class TestCredShell {
|
|
|
|
|
|
outContent.reset();
|
|
outContent.reset();
|
|
String[] args2 = {"list", "-provider",
|
|
String[] args2 = {"list", "-provider",
|
|
- "jceks://file" + tmpDir + "/credstore.jceks"};
|
|
|
|
|
|
+ jceksProvider};
|
|
rc = cs.run(args2);
|
|
rc = cs.run(args2);
|
|
assertEquals(0, rc);
|
|
assertEquals(0, rc);
|
|
assertTrue(outContent.toString().contains("credential1"));
|
|
assertTrue(outContent.toString().contains("credential1"));
|
|
|
|
|
|
outContent.reset();
|
|
outContent.reset();
|
|
String[] args4 = {"delete", "credential1", "-provider",
|
|
String[] args4 = {"delete", "credential1", "-provider",
|
|
- "jceks://file" + tmpDir + "/credstore.jceks"};
|
|
|
|
|
|
+ jceksProvider};
|
|
rc = cs.run(args4);
|
|
rc = cs.run(args4);
|
|
assertEquals(0, rc);
|
|
assertEquals(0, rc);
|
|
assertTrue(outContent.toString().contains("credential1 has been successfully " +
|
|
assertTrue(outContent.toString().contains("credential1 has been successfully " +
|
|
@@ -74,7 +80,7 @@ public class TestCredShell {
|
|
|
|
|
|
outContent.reset();
|
|
outContent.reset();
|
|
String[] args5 = {"list", "-provider",
|
|
String[] args5 = {"list", "-provider",
|
|
- "jceks://file" + tmpDir + "/credstore.jceks"};
|
|
|
|
|
|
+ jceksProvider};
|
|
rc = cs.run(args5);
|
|
rc = cs.run(args5);
|
|
assertEquals(0, rc);
|
|
assertEquals(0, rc);
|
|
assertFalse(outContent.toString(), outContent.toString().contains("credential1"));
|
|
assertFalse(outContent.toString(), outContent.toString().contains("credential1"));
|
|
@@ -132,7 +138,7 @@ public class TestCredShell {
|
|
@Test
|
|
@Test
|
|
public void testPromptForCredentialWithEmptyPasswd() throws Exception {
|
|
public void testPromptForCredentialWithEmptyPasswd() throws Exception {
|
|
String[] args1 = {"create", "credential1", "-provider",
|
|
String[] args1 = {"create", "credential1", "-provider",
|
|
- "jceks://file" + tmpDir + "/credstore.jceks"};
|
|
|
|
|
|
+ jceksProvider};
|
|
ArrayList<String> passwords = new ArrayList<String>();
|
|
ArrayList<String> passwords = new ArrayList<String>();
|
|
passwords.add(null);
|
|
passwords.add(null);
|
|
passwords.add("p@ssw0rd");
|
|
passwords.add("p@ssw0rd");
|
|
@@ -148,7 +154,7 @@ public class TestCredShell {
|
|
@Test
|
|
@Test
|
|
public void testPromptForCredential() throws Exception {
|
|
public void testPromptForCredential() throws Exception {
|
|
String[] args1 = {"create", "credential1", "-provider",
|
|
String[] args1 = {"create", "credential1", "-provider",
|
|
- "jceks://file" + tmpDir + "/credstore.jceks"};
|
|
|
|
|
|
+ jceksProvider};
|
|
ArrayList<String> passwords = new ArrayList<String>();
|
|
ArrayList<String> passwords = new ArrayList<String>();
|
|
passwords.add("p@ssw0rd");
|
|
passwords.add("p@ssw0rd");
|
|
passwords.add("p@ssw0rd");
|
|
passwords.add("p@ssw0rd");
|
|
@@ -162,7 +168,7 @@ public class TestCredShell {
|
|
"created."));
|
|
"created."));
|
|
|
|
|
|
String[] args2 = {"delete", "credential1", "-provider",
|
|
String[] args2 = {"delete", "credential1", "-provider",
|
|
- "jceks://file" + tmpDir + "/credstore.jceks"};
|
|
|
|
|
|
+ jceksProvider};
|
|
rc = shell.run(args2);
|
|
rc = shell.run(args2);
|
|
assertEquals(0, rc);
|
|
assertEquals(0, rc);
|
|
assertTrue(outContent.toString().contains("credential1 has been successfully " +
|
|
assertTrue(outContent.toString().contains("credential1 has been successfully " +
|