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