Browse Source

Merge commit 'e445d046b2e7cdae91a5aba947abc3ead398c78e' into HEAD

development
jenkins 3 years ago
parent
commit
c5bf848e4f
  1. 39
      src/test/java/PasswordValidatorTest.java

39
src/test/java/PasswordValidatorTest.java

@ -1,15 +1,21 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class PasswordValidatorTest {
static PasswordValidator passwordValidator = new PasswordValidator();
@BeforeAll
static void init() {
passwordValidator = new PasswordValidator();
}
@Test
void validate() {
PasswordValidator passwordValidator = new PasswordValidator();
void testMinimumPasswordLength() {
assertFalse(passwordValidator.validate(""));
// test minimum password length
passwordValidator.setMinLength(6);
passwordValidator.setRequireUppercase(false);
passwordValidator.setRequireLowercase(false);
@ -19,8 +25,10 @@ class PasswordValidatorTest {
assertFalse(passwordValidator.validate("abcde"));
assertTrue(passwordValidator.validate("abcdef"));
assertTrue(passwordValidator.validate("abcdefg"));
}
// test uppercase requirement
@Test
void testUppercasePasswordRequirement() {
passwordValidator.setRequireUppercase(true);
passwordValidator.setRequireLowercase(false);
passwordValidator.setRequireDigit(false);
@ -29,8 +37,10 @@ class PasswordValidatorTest {
assertFalse(passwordValidator.validate("abcdef"));
assertTrue(passwordValidator.validate("abCdef"));
assertTrue(passwordValidator.validate("ABCDEF"));
}
// test lowercase requirement
@Test
void testLowercasePasswordRequirement() {
passwordValidator.setRequireUppercase(true);
passwordValidator.setRequireLowercase(true);
passwordValidator.setRequireDigit(false);
@ -39,8 +49,10 @@ class PasswordValidatorTest {
assertFalse(passwordValidator.validate("abcdef"));
assertTrue(passwordValidator.validate("abCdef"));
assertFalse(passwordValidator.validate("ABCDEF"));
}
// test digits requirement
@Test
void testDigitsPasswordRequirement() {
passwordValidator.setRequireUppercase(true);
passwordValidator.setRequireLowercase(true);
passwordValidator.setRequireDigit(true);
@ -54,8 +66,10 @@ class PasswordValidatorTest {
assertFalse(passwordValidator.validate("ABCDEF"));
assertFalse(passwordValidator.validate("ABCDEF8"));
assertTrue(passwordValidator.validate("abCDE8F"));
}
// test special chars requirement
@Test
void testSpecialCharsPasswordRequirement() {
passwordValidator.setRequireUppercase(true);
passwordValidator.setRequireLowercase(true);
passwordValidator.setRequireDigit(true);
@ -65,8 +79,13 @@ class PasswordValidatorTest {
assertFalse(passwordValidator.validate("abCDE8F"));
assertTrue(passwordValidator.validate("abCDE8_F"));
assertTrue(passwordValidator.validate("abCDE*/8_F"));
}
// test password pwned check
/**
* Requires a network connection and DNS to be set up.
*/
@Test
void testPasswordPwnedCheck() {
passwordValidator.setRequireUppercase(true);
passwordValidator.setRequireLowercase(true);
passwordValidator.setRequireDigit(true);
@ -74,8 +93,10 @@ class PasswordValidatorTest {
assertFalse(passwordValidator.validate("8"));
assertFalse(passwordValidator.validate("asdf12"));
assertTrue(passwordValidator.validate("=phan0johB4aisae6Mie0jeip9Saejahc0iuvuth7ahv9uoni6o*_.+"));
}
// test password wordlist check
@Test
void testPasswordWordlistCheck() {
passwordValidator.setRequireUppercase(true);
passwordValidator.setRequireLowercase(true);
passwordValidator.setRequireDigit(true);

Loading…
Cancel
Save