feat(lab4): MinIO S3 private bucket, streaming image validation, attachment endpoints, Grade 5 Track 2 reconciler
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHashAndVerifyPassword(t *testing.T) {
|
||||
pw := "Сложный:Пароль:С:Двоеточиями:2026!🚀"
|
||||
hash, err := HashPassword(pw)
|
||||
if err != nil {
|
||||
t.Fatalf("HashPassword failed: %v", err)
|
||||
}
|
||||
if !strings.HasPrefix(hash, "$argon2id$v=19$") {
|
||||
t.Fatalf("expected Argon2id PHC prefix, got: %s", hash)
|
||||
}
|
||||
|
||||
ok, err := VerifyPassword(pw, hash)
|
||||
if err != nil || !ok {
|
||||
t.Fatalf("expected password verification to succeed, err=%v, ok=%v", err, ok)
|
||||
}
|
||||
|
||||
okWrong, err := VerifyPassword("WrongPassword-12345!", hash)
|
||||
if err != nil || okWrong {
|
||||
t.Fatalf("expected wrong password to fail verification")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateSessionToken(t *testing.T) {
|
||||
raw, hash, err := GenerateSessionToken()
|
||||
if err != nil {
|
||||
t.Fatalf("GenerateSessionToken failed: %v", err)
|
||||
}
|
||||
if len(raw) != 64 {
|
||||
t.Fatalf("expected 64-char hex raw token (256-bit), got len=%d", len(raw))
|
||||
}
|
||||
if len(hash) != 64 {
|
||||
t.Fatalf("expected 64-char SHA-256 hex digest, got len=%d", len(hash))
|
||||
}
|
||||
if HashToken(raw) != hash {
|
||||
t.Fatalf("HashToken mismatch")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user