32 Commits

Author SHA1 Message Date
jenkins 380d31bca4 Merge commit 'eb3439281fe93753a321aedcf3baf7e75bd318fc' into HEAD 3 years ago
binsky eb3439281f fix merge conflicts 3 years ago
fdai6352 9d255f29f5 debug testcommit 3 years ago
fdai6352 92d763d836 refactored edit credential menu and test 3 years ago
fdai6352 b7a44828cf refactored show credential method and test 3 years ago
fdai6352 c511951af0 refactored show credential method and test 3 years ago
fdai6352 f014afbf83 refactored add credential Method and Test 3 years ago
fdai6352 3a3f5f4e5a Merge remote-tracking branch 'origin/feature-credential' into feature-credential 3 years ago
fdai5728 85ea30ccb7 erneuter commit, löscht hoffentlich datei 3 years ago
fdai5728 ffdbc80dfe Reverts some mistakes 3 years ago
fdai5728 57ae190c63 Implements Unittest and function to delete credential from arraylist 3 years ago
fdai5728 b0730d1003 Adds error printing for indexoutofbound case 3 years ago
fdai5728 2ad4ea87c4 Implements function for Username Update 3 years ago
fdai5728 2d2d1bd527 Implements Unittest for Username Update 3 years ago
fdai5728 90cb65377c Implements function for Password Update 3 years ago
fdai5728 b95899aa56 Implements Unittest for Password Update 3 years ago
fdai5728 d485b04678 Updates Interface and function signatures 3 years ago
fdai5728 b6e33cd520 Rewrite ValueObject to DTO since we don't want to destroy the old object each time it gets updated 3 years ago
fdai5728 729f80d09d Restructures repository class and interface 3 years ago
fdai5728 028267642f Removes unused functions 3 years ago
fdai5728 cf2ec72c26 Fix counter error in arrayList 3 years ago
fdai5728 c131eac34a Implements search function and test for search via index 3 years ago
fdai5728 a914453294 Implements search function and test for search 3 years ago
fdai5728 aff9a8f70e Implements test for search function over repository 3 years ago
fdai5728 b0fca310de Implements testable function signature and first unit test 3 years ago
fdai5728 93d7dc776c Creates Testclass for CredentialRepository 3 years ago
fdai5728 978c79d3ae Implements a Value Object to hold user information 3 years ago
fdai5728 cd340772ab Implements Skeleton for CredentialRepository 3 years ago
fdai5728 4e91f37a40 Implements an Interface with basic functions 3 years ago
fdai5728 f6ad637c4f added skeleton of credentials class 3 years ago
fdai5728 2f4de90121 add credential entry class 3 years ago
fdai5728 8ee050401a add credential interface 3 years ago
  1. 2
      src/main/java/CredentialRepository.java
  2. 85
      src/main/java/Vault.java
  3. 4
      src/main/java/VaultInterface.java
  4. 2
      src/test/java/PasswordManagerTest.java
  5. 64
      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();
}

85
src/main/java/Vault.java

@ -14,10 +14,22 @@ public class Vault implements VaultInterface {
public boolean credentialM;
public String userName;
public String password;
public int newID;
public String newString;
public boolean decision;
public boolean isInt = false;
//InputStream inputS = System.in;
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 {
outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8));
@ -28,7 +40,7 @@ public class Vault implements VaultInterface {
public void configure(){
StringBuilder sbcm = new StringBuilder();
Scanner scan = new Scanner(System.in);
Scanner scan = new Scanner(inputS);
config = true;
sbcm.append("Configure:\n");
@ -63,7 +75,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 +86,22 @@ public class Vault implements VaultInterface {
}
public void addCredential(){
Scanner scan = new Scanner(System.in);
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(System.in);
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(){
}
@ -145,7 +146,7 @@ public class Vault implements VaultInterface {
public void credentialMenu() {
StringBuilder sbcm = new StringBuilder();
Scanner scan = new Scanner(System.in);
Scanner scan = new Scanner(inputS);
credentialM = true;
sbcm.append("Configure credentials:\n");
@ -158,14 +159,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();
}

2
src/test/java/PasswordManagerTest.java

@ -80,9 +80,11 @@ class PasswordManagerTest {
pm.inputStream = new ByteArrayInputStream("v 0\n".getBytes(StandardCharsets.UTF_8));
pm.outputStream = new ByteArrayOutputStream();
pm.showMenu();
System.out.println(pm.outputStream.toString());
pm.inputStream = new ByteArrayInputStream("o 0\n".getBytes(StandardCharsets.UTF_8));
pm.outputStream = outputStream;
pm.vaults.get(0).inputS = new ByteArrayInputStream("e\n".getBytes(StandardCharsets.UTF_8));
pm.showMenu();
assertTrue(outputStream.toString().contains("Run selected operation"));

64
src/test/java/VaultTest.java

@ -24,10 +24,10 @@ public class VaultTest {
@BeforeEach
void reset() {
vlt.outputS = System.out;
//vlt.inputS = System.in;
vlt.inputS = getEmptyStringInputStream();
}
/* @Test
@Test
void openCredentialMenu() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
@ -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;
@ -86,19 +98,14 @@ public class VaultTest {
@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);
}*/
@ -108,7 +115,7 @@ public class VaultTest {
@Test
void loadFromJson() {vlt.loadFromJson();}
/* @Test
@Test
void openConfigureMenu() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
@ -122,9 +129,9 @@ public class VaultTest {
vlt.inputS = new ByteArrayInputStream("e".getBytes(StandardCharsets.UTF_8));
vlt.configure();
assertFalse(vlt.config);
}*/
}
/* @Test
@Test
void doNotExitConfigAfterWrongInput() {
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
vlt.configure();
@ -136,9 +143,9 @@ public class VaultTest {
assertThrowsExactly(NoSuchElementException.class, () -> vlt.configure());
assertTrue(outputStream.toString().startsWith("Configure:"));
}*/
}
/* @Test
@Test
void openSetPWLengthMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("l\n7".getBytes(StandardCharsets.UTF_8));
@ -146,7 +153,7 @@ public class VaultTest {
vlt.configure();
assertEquals(7, vlt.PWLength);
assertTrue(outputStream.toString().contains("Set"));
}*/
}
@Test
void setPWLength() {
@ -158,14 +165,14 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("now:"));
}
/*@Test
@Test
void openSetCapitalsMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("h\nyes".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.configure();
assertTrue(vlt.haveCapitals = true);
}*/
}
@Test
void setCapitals() {
@ -181,17 +188,16 @@ public class VaultTest {
assertFalse(vlt.haveCapitals = false);
assertTrue(outputStream.toString().contains("don't"));
System.out.println(outputStream.toString());
}
/*@Test
@Test
void openSetSpecialCharsMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("h\nyes".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.configure();
assertTrue(vlt.hasSpecialChars = true);
}*/
}
@Test
void setSpecialCharTest() {
@ -208,14 +214,14 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("don't"));
}
/*@Test
@Test
void openSetNumbersMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("h\nyes".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.configure();
assertTrue(vlt.hasNumbers = true);
}*/
}
@Test
void setNumbersTest() {

Loading…
Cancel
Save