Add test for hashPass func
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Andinus 2020-03-27 12:01:40 +05:30
parent d5ebc73b84
commit 87832fb2dd
Signed by: andinus
GPG Key ID: B67D55D482A799FD
2 changed files with 38 additions and 3 deletions

View File

@ -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)

34
auth/hashpass_test.go Normal file
View File

@ -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)
}
}
}