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
This commit is contained in:
48
internal/auth/password_test.go
Normal file
48
internal/auth/password_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user