From a88d718ed352859d97d111efe88171453a7262b5 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 3 May 2015 10:38:40 +0200 Subject: [PATCH] Added test for password generation --- lib/generator_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/generator_test.go b/lib/generator_test.go index ac50c13..ad731b2 100644 --- a/lib/generator_test.go +++ b/lib/generator_test.go @@ -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)