4 Commits

  1. 2
      src/main/java/CredentialRepository.java
  2. 77
      src/main/java/Vault.java
  3. 4
      src/main/java/VaultInterface.java
  4. 42
      src/test/java/VaultTest.java

2
src/main/java/CredentialRepository.java

@ -106,7 +106,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{
return -1;
}
*/
private int getListSize()
public int getListSize()
{
return this.credentials.size();
}

77
src/main/java/Vault.java

@ -14,9 +14,18 @@ public class Vault implements VaultInterface {
public boolean credentialM;
public String userName;
public String password;
public boolean isInt = false;
public int newID;
public String newString;
public boolean decision;
InputStream inputS = System.in;
OutputStream outputS = System.out;
private CredentialRepository credentialRepository = new CredentialRepository();
public static void main (String args[]) {
Vault vault = new Vault();
vault.credentialMenu();
}
private void println(String output) {
try {
@ -63,7 +72,7 @@ public class Vault implements VaultInterface {
}
}
public void setPWLength(String pwLength){
public void setPWLength(String pwLength) {
try {
PWLength = Integer.parseInt(pwLength);
} catch (NumberFormatException e) {
@ -74,33 +83,23 @@ public class Vault implements VaultInterface {
}
public void addCredential(){
Scanner scan = new Scanner(inputS);
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
//createNewCredential(userName, password);
public void addCredential(String userName, String password){
credentialRepository.createNewCredential(userName, password);
}
public void showCredential(){
Scanner scan = new Scanner(inputS);
println("Type in ID or username");
String str = scan.nextLine();
public void showCredential(String str) {
if(str.matches("[0-9]+")) {
isInt = true;
//getCredentialsViaId(Integer.parseInt(str));
println("Getting credential via ID");
credentialRepository.getCredentialsViaId(Integer.parseInt(str));
} else {
isInt = false;
//getCredentialsViaName(str);
}
println("Getting credential via name");
credentialRepository.getCredentialsViaName(str);
}
}
public void getAsJson(){
}
@ -158,14 +157,40 @@ public class Vault implements VaultInterface {
String input = scan.nextLine();
if (input.equals("e")) {
credentialM = false;
} else if (input.equals("a")) {
println("Type username:");
} else if (input.equals("c")) {
println("Type username or ID to show credential:");
}
if (input.equals("a")) {
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
addCredential(userName, password);
}
if (input.equals("c")) {
println("Type in ID or username");
String str = scan.nextLine();
showCredential(str);
} else if (input.equals("l")) {
println("Type username or ID to select credential:");
println("Type ID to select credential:");
newID = Integer.parseInt(scan.nextLine());
println("-change username: u\n-change password: p");
input = scan.nextLine();
if (input.equals("u")) {
decision = true;
}else{
decision = false;
}
println("Type new:");
newString = scan.nextLine();
//editCredential(newID, newString, decision);
}
}
}

4
src/main/java/VaultInterface.java

@ -3,8 +3,8 @@
public interface VaultInterface {
void configure();
void addCredential();
void showCredential();
void addCredential(String userName, String password);
void showCredential(String str);
void getAsJson();
void loadFromJson();
}

42
src/test/java/VaultTest.java

@ -47,16 +47,20 @@ public class VaultTest {
@Test
void openAddCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("a".getBytes(StandardCharsets.UTF_8));
vlt.inputS = new ByteArrayInputStream("a\npeter\npassword".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertTrue(outputStream.toString().contains("username"));
assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password);
}
@Test
void openShowCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("c".getBytes(StandardCharsets.UTF_8));
vlt.inputS = new ByteArrayInputStream("c\n1".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
@ -65,13 +69,21 @@ public class VaultTest {
@Test
void openEditCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("l".getBytes(StandardCharsets.UTF_8));
vlt.inputS = new ByteArrayInputStream("l\n1\nu\npeter".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertEquals(1,vlt.newID);
assertEquals(true,vlt.decision);
assertEquals("peter",vlt.newString);
}
@Test
/*@Test
void editCredentialTest() {
}*/
/*@Test
void addCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
@ -82,25 +94,21 @@ public class VaultTest {
assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password);
}
}*/
@Test
/*@Test
void showCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
vlt.inputS = new ByteArrayInputStream("l\n1".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertTrue(vlt.isInt);
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("peter".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
vlt.inputS = new ByteArrayInputStream("l\npeter".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertFalse(vlt.isInt);
}
}*/
@Test
void getAsJson() {vlt.getAsJson();}

Loading…
Cancel
Save