Add initial shared code packages
This commit is contained in:
commit
838a97d344
54 files changed
+6265
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func TestPasswordRoundTrip(t *testing.T) {
|
||||
hash, err := HashPassword("correct horse battery staple")
|
||||
if err != nil {
|
||||
t.Fatalf("HashPassword() error = %v", err)
|
||||
}
|
||||
if !VerifyPassword(hash, "correct horse battery staple") {
|
||||
t.Fatal("VerifyPassword() rejected the original password")
|
||||
}
|
||||
if VerifyPassword(hash, "wrong password") {
|
||||
t.Fatal("VerifyPassword() accepted the wrong password")
|
||||
}
|
||||
if cost, err := bcrypt.Cost([]byte(hash)); err != nil || cost != BcryptCost {
|
||||
t.Fatalf("bcrypt cost = %d, error = %v; want %d", cost, err, BcryptCost)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewSessionToken(t *testing.T) {
|
||||
raw, hash, err := NewSessionToken()
|
||||
if err != nil {
|
||||
t.Fatalf("NewSessionToken() error = %v", err)
|
||||
}
|
||||
if raw == "" || hash == "" {
|
||||
t.Fatal("NewSessionToken() returned an empty token or hash")
|
||||
}
|
||||
if got := HashToken(raw); got != hash {
|
||||
diff := got
|
||||
t.Fatalf("HashToken(raw) = %q, want %q", diff, hash)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user