64 Commits

Author SHA1 Message Date
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
fdai6352 18f4cc93f9 implemented show credential via name functionality 3 years ago
fdai6352 044d4af707 implemented show credential via ID functionality 3 years ago
fdai6352 f89a4e4af1 implemented add credential functionality 3 years ago
fdai6352 cf0425bc59 added edit credential menu item 3 years ago
fdai6352 5db4d2c1f3 deleted unused line 3 years ago
fdai6352 35a372765d added credential menu item show credential 3 years ago
fdai6352 9b0c21b584 added credential menu item add credential 3 years ago
fdai6352 6b50608ef8 refactored credential menu exit 3 years ago
fdai6352 1d4ec73c19 added credential menu exit 3 years ago
fdai6352 317d500f50 added credential menu 3 years ago
fdai6352 a18ebb7438 temporarily deleted addCredential 3 years ago
fdai6352 34d6de43c7 typo refactor 3 years ago
fdai6352 c9968722c8 implemented set numbers menu item and test refactor 3 years ago
fdai6352 05988f788b implemented set special char menu item and test refactor 3 years ago
fdai6352 881a3234dd menu refactor 3 years ago
fdai6352 6d43a35632 implemented set capitals in configure menu 3 years ago
fdai6352 c2952ab42c setPWLength refactor 3 years ago
fdai6352 ac0ce484d3 implemented setPWLength in configure menu and refactor 3 years ago
fdai6352 6b1d22f773 added vault configure menu wrong input message 3 years ago
fdai6352 cd1e7a85a8 implemented userName for new credentials 3 years ago
fdai6352 db0423a18c added set numbers function 3 years ago
fdai6352 dfffc3c84a added set special characters function and VaultInterface refactor 3 years ago
fdai6352 df02d33f55 added Set Capital function 3 years ago
fdai6352 087e2d6b60 Set PWLength Functionality, proved against wrong input 3 years ago
fdai6352 ee44e3067d added Set PWLength Funtionality 3 years ago
fdai6352 bc1702b935 added setPWLength Option refactor 3 years ago
fdai6352 6572370472 added setPWLength Option 3 years ago
fdai6352 b8ebd3b2f2 VaultTest refactor 3 years ago
fdai6352 46bd7e3f1c Vault and VaultTest refactor 3 years ago
fdai6352 6fa8c74313 added Configuration Menu no Exit after wrong Input 3 years ago
fdai6352 1c6d2148f2 added Configuration Menu exit 3 years ago
fdai6352 091c425ae1 added Configuration Menu 3 years ago
fdai6352 bf3945cef3 made loadFromJson non-static 3 years ago
fdai6352 0bc394a7c3 add basisklassen hinzugefügt 3 years ago
fdai6352 a63314d9f7 add basisklassen hinzugefügt in Vault 3 years ago
fdai6352 b73a9d9377 add menuNavigationOpenVault: assertTrue zu assertFalse geändert 3 years ago
fdai6352 d1652f0443 add vaultinterface 3 years ago
fdai6352 5e4511bcb4 add vaultinterface 3 years ago
fdai6352 0608486ca9 add vault entry class 3 years ago
  1. 171
      src/main/java/Vault.java
  2. 10
      src/main/java/VaultInterface.java
  3. 2
      src/test/java/PasswordManagerTest.java
  4. 238
      src/test/java/VaultTest.java

171
src/main/java/Vault.java

@ -0,0 +1,171 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class Vault implements VaultInterface {
public boolean config;
public int PWLength;
public boolean haveCapitals;
public boolean hasSpecialChars;
public boolean hasNumbers;
public boolean credentialM;
public String userName;
public String password;
public boolean isInt = false;
InputStream inputS = System.in;
OutputStream outputS = System.out;
private void println(String output) {
try {
outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
}
public void configure(){
StringBuilder sbcm = new StringBuilder();
Scanner scan = new Scanner(inputS);
config = true;
sbcm.append("Configure:\n");
sbcm.append("- Password length: l\n");
sbcm.append("- Have capitals: h\n");
sbcm.append("- Have special characters: s\n");
sbcm.append("- Have Numbers: n\n");
sbcm.append("- exit: e\n");
println(sbcm.toString());
String input = scan.nextLine();
if (input.equals("e")) {
config = false;
} else if (input.equals("l")) {
println("Set PW length:");
String inputPw = scan.nextLine();
setPWLength(inputPw);
} else if (input.equals("h")) {
println("Should your PW have capitals? Type in yes or no.");
String inputC = scan.nextLine();
setCapital(inputC);
} else if (input.equals("s")){
println("Should you PW have special characters? Type in yes or no.");
String inputS = scan.nextLine();
setSpecialChar(inputS);
} else if (input.equals("n")) {
println("Should you PW have numbers? Type in yes or no.");
String inputN = scan.nextLine();
setNumbers(inputN);
}
}
public void setPWLength(String pwLength){
try {
PWLength = Integer.parseInt(pwLength);
} catch (NumberFormatException e) {
println("Please enter valid number.");
}
println("\nNew password length is now: ");
}
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 showCredential(){
Scanner scan = new Scanner(inputS);
println("Type in ID or username");
String str = scan.nextLine();
if(str.matches("[0-9]+")) {
isInt = true;
//getCredentialsViaId(Integer.parseInt(str));
} else {
isInt = false;
//getCredentialsViaName(str);
}
}
public void getAsJson(){
}
public void loadFromJson(){
}
public void setCapital(String input) {
if(input.equals("yes")){
haveCapitals = true;
println("Your PWs contain now capitals.");
}else if(input.equals("no")){
haveCapitals = false;
println("Your PWs don´t have capitals anymore.");
}
}
public void setSpecialChar(String input) {
if(input.equals("yes")){
hasSpecialChars = true;
println("Your PWs contain now special characters.");
}else if(input.equals("no")){
hasSpecialChars = false;
println("Your PWs don´t have special characters anymore.");
}
}
public void setNumbers(String input) {
if(input.equals("yes")){
hasNumbers = true;
println("Your PWs contains now numbers.");
}else if(input.equals("no")){
hasNumbers = false;
println("Your PWs don´t have numbers anymore.");
}
}
public void credentialMenu() {
StringBuilder sbcm = new StringBuilder();
Scanner scan = new Scanner(inputS);
credentialM = true;
sbcm.append("Configure credentials:\n");
sbcm.append("- add credential: a\n");
sbcm.append("- show credential: c\n");
sbcm.append("- edit credential: l\n");
sbcm.append("- exit: e\n");
println(sbcm.toString());
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:");
} else if (input.equals("l")) {
println("Type username or ID to select credential:");
}
}
}

10
src/main/java/VaultInterface.java

@ -0,0 +1,10 @@
public interface VaultInterface {
void configure();
void addCredential();
void showCredential();
void getAsJson();
void loadFromJson();
}

2
src/test/java/PasswordManagerTest.java

@ -55,7 +55,7 @@ class PasswordManagerTest {
pm.inputStream = new ByteArrayInputStream("v 0\n".getBytes(StandardCharsets.UTF_8)); pm.inputStream = new ByteArrayInputStream("v 0\n".getBytes(StandardCharsets.UTF_8));
pm.outputStream = outputStream; pm.outputStream = outputStream;
pm.showMenu(); pm.showMenu();
assertTrue(outputStream.toString().endsWith("-- vaults not implemented yet\n"));
assertFalse(outputStream.toString().endsWith("-- vaults not implemented yet\n"));
} }
@Test @Test

238
src/test/java/VaultTest.java

@ -0,0 +1,238 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.*;
public class VaultTest {
//Vault vlt = new Vault();
static Vault vlt;
@BeforeAll
static void init() {
vlt = new Vault();
}
@BeforeEach
void reset() {
vlt.outputS = System.out;
vlt.inputS = System.in;
}
@Test
void openCredentialMenu() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(vlt.credentialM);
assertTrue(outputStream.toString().startsWith("Configure"));
}
@Test
void exitConfigureMenu(){
vlt.inputS = new ByteArrayInputStream("e".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
assertFalse(vlt.credentialM);
}
@Test
void openAddCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("a".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
}
@Test
void openShowCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("c".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
}
@Test
void openEditCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("l".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
}
@Test
void addCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("peter\npassword".getBytes(StandardCharsets.UTF_8));
vlt.addCredential();
assertTrue(outputStream.toString().contains("username"));
assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password);
}
@Test
void showCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
assertTrue(outputStream.toString().contains("Type"));
assertTrue(vlt.isInt);
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("peter".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
assertTrue(outputStream.toString().contains("Type"));
assertFalse(vlt.isInt);
}
@Test
void getAsJson() {vlt.getAsJson();}
@Test
void loadFromJson() {vlt.loadFromJson();}
@Test
void openConfigureMenu() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.configure();
assertTrue(outputStream.toString().startsWith("Configure:"));
}
@Test
void exitConfigurationMenu(){
vlt.inputS = new ByteArrayInputStream("e".getBytes(StandardCharsets.UTF_8));
vlt.configure();
assertFalse(vlt.config);
}
@Test
void doNotExitConfigAfterWrongInput() {
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
vlt.configure();
assertTrue(vlt.config);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = getEmptyStringInputStream();
vlt.outputS = outputStream;
assertThrowsExactly(NoSuchElementException.class, () -> vlt.configure());
assertTrue(outputStream.toString().startsWith("Configure:"));
}
@Test
void openSetPWLengthMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("l\n7".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.configure();
assertEquals(7, vlt.PWLength);
assertTrue(outputStream.toString().contains("Set"));
}
@Test
void setPWLength() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.setPWLength("7");
assertEquals(7, vlt.PWLength);
assertTrue(outputStream.toString().contains("now:"));
}
@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() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.setCapital("yes");
assertTrue(vlt.haveCapitals = true);
assertTrue(outputStream.toString().contains("contain"));
vlt.outputS = outputStream;
vlt.setCapital("no");
assertFalse(vlt.haveCapitals = false);
assertTrue(outputStream.toString().contains("don´t"));
}
@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() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.setSpecialChar("yes");
assertTrue(vlt.hasSpecialChars = true);
vlt.outputS = outputStream;
vlt.setSpecialChar("no");
assertFalse(vlt.hasSpecialChars = false);
assertTrue(outputStream.toString().contains("don´t"));
}
@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() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.setNumbers("yes");
assertTrue(vlt.hasNumbers = true);
assertTrue(outputStream.toString().contains("contain"));
vlt.outputS = outputStream;
vlt.setNumbers("no");
assertFalse(vlt.hasNumbers = false);
assertTrue(outputStream.toString().contains("don´t"));
}
private ByteArrayInputStream getEmptyStringInputStream() {
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
}
}
Loading…
Cancel
Save