Browse Source

implement showing saved password when the option show credential was selected

feature-showing-passwords
binsky 3 years ago
parent
commit
dc61f16b26
  1. 9
      src/main/java/Vault.java
  2. 3
      src/test/java/VaultTest.java

9
src/main/java/Vault.java

@ -118,14 +118,19 @@ public class Vault implements VaultInterface {
println("Type in ID or username"); println("Type in ID or username");
String str = scan.nextLine(); String str = scan.nextLine();
Credential credential = null;
if(str.matches("[0-9]+")) { if(str.matches("[0-9]+")) {
println("Getting credential via ID"); println("Getting credential via ID");
credentialRepository.getCredentialsViaId(Integer.parseInt(str));
credential = credentialRepository.getCredentialsViaId(Integer.parseInt(str));
} else { } else {
println("Getting credential via name"); println("Getting credential via name");
credentialRepository.getCredentialsViaName(str);
credential = credentialRepository.getCredentialsViaName(str);
}
if (credential != null) {
println(credential.getName() + ": " + credential.getPassword());
} }
} }

3
src/test/java/VaultTest.java

@ -84,6 +84,8 @@ public class VaultTest {
@Test @Test
void showCredentialTest() { void showCredentialTest() {
addCredentialTest();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8)); vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8));
@ -95,6 +97,7 @@ public class VaultTest {
vlt.credentialMenu(); vlt.credentialMenu();
assertTrue(outputStream.toString().contains("name")); assertTrue(outputStream.toString().contains("name"));
assertTrue(outputStream.toString().contains("peter: " + vlt.password));
} }
@Test @Test

Loading…
Cancel
Save