diff options
author | Andinus <andinus@nand.sh> | 2020-03-27 12:01:40 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-03-27 12:31:45 +0530 |
commit | 87832fb2dd6b86494ae79c7a4f5f05db14dd3c4d (patch) | |
tree | 83f9a5c4f4101087593b160958e2a590ffbe666e /auth | |
parent | d5ebc73b84e2c5ea8dc3c4189c087369f08856c8 (diff) | |
download | perseus-87832fb2dd6b86494ae79c7a4f5f05db14dd3c4d.tar.gz |
Add test for hashPass func
Diffstat (limited to 'auth')
-rw-r--r-- | auth/checkpass_test.go | 7 | ||||
-rw-r--r-- | auth/hashpass_test.go | 34 |
2 files changed, 38 insertions, 3 deletions
diff --git a/auth/checkpass_test.go b/auth/checkpass_test.go index 03ff0ad..c8afaee 100644 --- a/auth/checkpass_test.go +++ b/auth/checkpass_test.go @@ -5,7 +5,7 @@ import "testing" // TestCheckPass tests the checkPass function. func TestCheckPass(t *testing.T) { var err error - var passhash = make(map[string]string) + passhash := make(map[string]string) // First we check with static values, these should always pass. passhash["ter4cQ=="] = "$2a$10$ANkaNEFFQ4zxDwTwvAUfoOCqpVIdgtPFopFOTMSrFy39WkaMAYLIC" @@ -27,9 +27,10 @@ func TestCheckPass(t *testing.T) { } // We test the checkPass func by ranging over all values of - // passhash. + // passhash. We assume that hashPass func returns correct + // hashes. for p, h := range passhash { - err := checkPass(p, h) + err = checkPass(p, h) if err != nil { t.Errorf("password: %s, hash: %s didn't match.", p, h) diff --git a/auth/hashpass_test.go b/auth/hashpass_test.go new file mode 100644 index 0000000..7ea9480 --- /dev/null +++ b/auth/hashpass_test.go @@ -0,0 +1,34 @@ +package auth + +import "testing" + +// TestHashPass tests the checkPass function. +func TestHashPass(t *testing.T) { + var err error + passhash := make(map[string]string) + + // We generate random hashes with hashPass, random string is + // generate by genID func. + for i := 1; i <= 8; i++ { + p := genID(8) + passhash[p], err = hashPass(p) + + // Here we test if the hashPass func runs sucessfully. + if err != nil { + t.Errorf("hashPass func failed for password: %s", + p) + } + } + + // Here we are testing if the hashPass func returns correct + // hashes. We assume that checkPass func returns correct + // values. + for p, h := range passhash { + err = checkPass(p, h) + if err != nil { + t.Errorf("password: %s, hash: %s didn't match.", + p, h) + } + } + +} |