feat(lab4): MinIO S3 private bucket, streaming image validation, attachment endpoints, Grade 5 Track 2 reconciler

This commit is contained in:
2026-11-17 02:55:14 +03:00
parent ec540a1a72
commit eaf3963e05
33 changed files with 8458 additions and 21 deletions
+43
View File
@@ -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")
}
}