summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-27 11:46:00 +0530
committerAndinus <andinus@nand.sh>2020-03-27 11:46:00 +0530
commitd5ebc73b84e2c5ea8dc3c4189c087369f08856c8 (patch)
tree922cbd4e489201daea6a91cb61f6c61bfd409bfa
parentb01aaa498865b97d486b3da34c087a539e2a1c8a (diff)
downloadperseus-d5ebc73b84e2c5ea8dc3c4189c087369f08856c8.tar.gz
Improve checkPass func tests
-rw-r--r--auth/checkpass_test.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/auth/checkpass_test.go b/auth/checkpass_test.go
index d22bf48..03ff0ad 100644
--- a/auth/checkpass_test.go
+++ b/auth/checkpass_test.go
@@ -1,14 +1,33 @@
 package auth
 
-import (
-	"testing"
-)
+import "testing"
 
 // TestCheckPass tests the checkPass function.
 func TestCheckPass(t *testing.T) {
+	var err error
 	var passhash = make(map[string]string)
-	passhash["password"] = "$2a$10$hyV9vtsYXX88wz1rmA1x0.tcdkyvd6QsmV6gLOcR5wtYBE2GaSqT."
 
+	// First we check with static values, these should always pass.
+	passhash["ter4cQ=="] = "$2a$10$ANkaNEFFQ4zxDwTwvAUfoOCqpVIdgtPFopFOTMSrFy39WkaMAYLIC"
+	passhash["G29J6A=="] = "$2a$10$1oH1PyhncIHcHJWbLt3Gv.OjClUoFoaEDaFpQ9E9atfRbIrVxsbwm"
+	passhash["Z1S/kQ=="] = "$2a$10$fZ05kKmb7bh4vBLebpK1u.3bUNQ6eeX5ghT/GZaekgS.5bx4.Ru1e"
+	passhash["J861dQ=="] = "$2a$10$nXb6Btn6n3AWMAUkDh9bFObvQw5V9FLKhfX.E1EzRWgVDuqIp99u2"
+
+	// We also check with values generated with hashPass, this may
+	// fail if hashPass itself fails in that case it's not
+	// checkPass error so the test shouldn't fail but warning
+	// should be sent. We use genID func to generate random inputs
+	// for this test.
+	for i := 1; i <= 4; i++ {
+		p := genID(8)
+		passhash[p], err = hashPass(p)
+		if err != nil {
+			t.Log("hashPass func failed")
+		}
+	}
+
+	// We test the checkPass func by ranging over all values of
+	// passhash.
 	for p, h := range passhash {
 		err := checkPass(p, h)
 		if err != nil {
@@ -16,4 +35,5 @@ func TestCheckPass(t *testing.T) {
 				p, h)
 		}
 	}
+
 }