1
0
mirror of https://github.com/Luzifer/password.git synced 2024-09-19 10:22:56 +00:00

Added test for password generation

This commit is contained in:
Knut Ahlers 2015-05-03 10:38:40 +02:00
parent fe235ab869
commit a88d718ed3

View File

@ -80,6 +80,36 @@ func TestSecurePasswordWithSpecialCharacter(t *testing.T) {
}
}
func TestPasswordGeneration(t *testing.T) {
password, _ := NewSecurePassword().GeneratePassword(20, false)
if len(password) != 20 {
t.Error("Password did not match requested length")
}
if !NewSecurePassword().CheckPasswordSecurity(password, false) {
t.Error("Password did not pass security test")
}
if NewSecurePassword().CheckPasswordSecurity(password, true) {
t.Error("Password without special characters passed security test for passwords with special characters")
}
password, _ = NewSecurePassword().GeneratePassword(32, true)
if len(password) != 32 {
t.Error("Password did not match requested length")
}
if !NewSecurePassword().CheckPasswordSecurity(password, false) {
t.Error("Password did not pass security test for passwords without special characters")
}
if !NewSecurePassword().CheckPasswordSecurity(password, true) {
t.Error("Password without special characters did not security test for passwords with special characters")
}
}
func TestImpossiblePasswords(t *testing.T) {
for i := 0; i < 4; i++ {
_, err := NewSecurePassword().GeneratePassword(i, false)