Browse Source

implement listing credentials

feature-showing-passwords
binsky 6 months 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. 14
      src/test/java/VaultTest.java

3
src/main/java/Credential.java

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

4
src/main/java/CredentialRepository.java

@ -193,6 +193,10 @@ public class CredentialRepository implements CredentialRepositoryInterface{
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(){
@ -215,6 +220,7 @@ public class Vault implements VaultInterface {
sbcm.append("- add credential: a\n");
sbcm.append("- show credential: c\n");
sbcm.append("- edit credential: l\n");
sbcm.append("- list credentials: s\n");
sbcm.append("- exit: e\n");
println(sbcm.toString());
@ -238,6 +244,10 @@ public class Vault implements VaultInterface {
case "l":
editCredential();
break;
case "s":
listCredentials();
break;
}
}
}

14
src/test/java/VaultTest.java

@ -82,7 +82,7 @@ public class VaultTest {
assertNotEquals(0, vlt.password.length());
}
@Test
@Test
void showCredentialTest() {
addCredentialTest();
@ -100,6 +100,18 @@ public class VaultTest {
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
void getAsJson() {vlt.getAsJson();}

Loading…
Cancel
Save