Files
mygo/internal/auth/password_test.go
Huxley 3eeb9f6d26 Implement JWT authentication and app passkey support
- Add JWT token generation and validation
- Implement bcrypt password hashing
- Create auth service with register/login/refresh/logout
- Add app passkey generation and management
- Implement protected routes and auth middleware
- Add comprehensive tests for new functionality
2026-04-29 11:50:09 +08:00

49 lines
1.0 KiB
Go

package auth
import (
"testing"
)
func TestHashPassword(t *testing.T) {
hash, err := HashPassword("mypassword")
if err != nil {
t.Fatalf("HashPassword = %v", err)
}
if hash == "" {
t.Fatal("hash is empty")
}
if hash == "mypassword" {
t.Fatal("hash should not equal the plaintext password")
}
}
func TestVerifyPasswordCorrect(t *testing.T) {
hash, err := HashPassword("mypassword")
if err != nil {
t.Fatalf("HashPassword = %v", err)
}
if err := VerifyPassword(hash, "mypassword"); err != nil {
t.Fatalf("VerifyPassword = %v", err)
}
}
func TestVerifyPasswordWrong(t *testing.T) {
hash, err := HashPassword("mypassword")
if err != nil {
t.Fatalf("HashPassword = %v", err)
}
if err := VerifyPassword(hash, "wrongpassword"); err == nil {
t.Fatal("expected error for wrong password, got nil")
}
}
func TestHashPasswordUnique(t *testing.T) {
hash1, _ := HashPassword("mypassword")
hash2, _ := HashPassword("mypassword")
if hash1 == hash2 {
t.Fatal("bcrypt should produce different hashes for the same password")
}
}