Browse Source

Merge commit '698cc4ae0063aab03758d622f4ded66f75939c4b' into HEAD

development projektabgabe
jenkins 3 years ago
parent
commit
650d1b875c
  1. 3
      src/main/java/Credential.java
  2. 4
      src/main/java/CredentialRepository.java
  3. 19
      src/main/java/Vault.java
  4. 19
      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;
}
}

19
src/main/java/Vault.java

@ -118,14 +118,19 @@ public class Vault implements VaultInterface {
println("Type in ID or username");
String str = scan.nextLine();
Credential credential = null;
if(str.matches("[0-9]+")) {
println("Getting credential via ID");
credentialRepository.getCredentialsViaId(Integer.parseInt(str));
credential = credentialRepository.getCredentialsViaId(Integer.parseInt(str));
} else {
println("Getting credential via name");
credentialRepository.getCredentialsViaName(str);
credential = credentialRepository.getCredentialsViaName(str);
}
if (credential != null) {
println(credential.getName() + ": " + credential.getPassword());
}
}
@ -158,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(){
@ -210,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());
@ -233,6 +244,10 @@ public class Vault implements VaultInterface {
case "l":
editCredential();
break;
case "s":
listCredentials();
break;
}
}
}

19
src/test/java/VaultTest.java

@ -82,8 +82,10 @@ public class VaultTest {
assertNotEquals(0, vlt.password.length());
}
@Test
@Test
void showCredentialTest() {
addCredentialTest();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8));
@ -94,7 +96,20 @@ public class VaultTest {
vlt.inputS = new ByteArrayInputStream("peter".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("name"));
assertTrue(outputStream.toString().contains("name"));
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

Loading…
Cancel
Save