Browse Source

implement listing credentials

feature-showing-passwords
binsky 3 years ago
parent
commit
698cc4ae00
  1. 3
      src/main/java/Credential.java
  2. 4
      src/main/java/CredentialRepository.java
  3. 10
      src/main/java/Vault.java
  4. 12
      src/test/java/VaultTest.java

3
src/main/java/Credential.java

@ -3,7 +3,7 @@ import java.io.Serializable;
public class Credential implements Serializable { public class Credential implements Serializable {
private String name, password; private String name, password;
private int id;
private final int id;
public Credential(String name, String password, int id) throws Exception { public Credential(String name, String password, int id) throws Exception {
@ -12,6 +12,7 @@ public class Credential implements Serializable {
this.name = name; this.name = name;
this.password = password; this.password = password;
this.id = id;
} }
public String getName() public String getName()

4
src/main/java/CredentialRepository.java

@ -193,6 +193,10 @@ public class CredentialRepository implements CredentialRepositoryInterface{
return System.getProperty("user.dir"); return System.getProperty("user.dir");
} }
public CredentialList getCredentialList() {
return credentials;
}
} }

10
src/main/java/Vault.java

@ -163,6 +163,11 @@ public class Vault implements VaultInterface {
} }
} }
public void listCredentials() {
for (Credential credential : credentialRepository.getCredentialList()) {
println(String.format("ID: %d - Username: %s", credential.getId(), credential.getName()));
}
}
public void getAsJson(){ public void getAsJson(){
@ -215,6 +220,7 @@ public class Vault implements VaultInterface {
sbcm.append("- add credential: a\n"); sbcm.append("- add credential: a\n");
sbcm.append("- show credential: c\n"); sbcm.append("- show credential: c\n");
sbcm.append("- edit credential: l\n"); sbcm.append("- edit credential: l\n");
sbcm.append("- list credentials: s\n");
sbcm.append("- exit: e\n"); sbcm.append("- exit: e\n");
println(sbcm.toString()); println(sbcm.toString());
@ -238,6 +244,10 @@ public class Vault implements VaultInterface {
case "l": case "l":
editCredential(); editCredential();
break; break;
case "s":
listCredentials();
break;
} }
} }
} }

12
src/test/java/VaultTest.java

@ -100,6 +100,18 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("peter: " + vlt.password)); assertTrue(outputStream.toString().contains("peter: " + vlt.password));
} }
@Test
void listCredentialsTest() {
addCredentialTest();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("s\n".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("ID: 0 - Username: peter"));
}
@Test @Test
void getAsJson() {vlt.getAsJson();} void getAsJson() {vlt.getAsJson();}

Loading…
Cancel
Save