Files
mtusi2026lab6/app/internal/validate/attachment_test.go
T

40 lines
1.2 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package validate
import (
"strings"
"testing"
)
func TestFilename(t *testing.T) {
valid := []string{"photo.png", "фото отпуска.jpeg", "a", strings.Repeat("я", 255), "👋.png", "..hidden.png"}
for _, s := range valid {
if err := Filename(s); err != nil {
t.Errorf("Filename(%q) = %v", s, err)
}
}
invalid := []string{"", " ", ".", "..", "../etc/passwd", `a\b.png`, "a/b.png", "a\x00.png", "a\nb.png", "a\x7f.png",
"\xff.png", "evil‮gnp.exe", "a
b", strings.Repeat("я", 256)}
for _, s := range invalid {
if err := Filename(s); err == nil {
t.Errorf("Filename(%q) accepted", s)
}
}
}
func TestAttachmentIDs(t *testing.T) {
const a = "11111111-1111-4111-8111-111111111111"
got, err := AttachmentIDs([]string{strings.ToUpper(a)})
if err != nil || got[0] != a {
t.Errorf("canonical form: %v, %v", got, err)
}
if _, err := AttachmentIDs([]string{a, strings.ToUpper(a)}); err == nil {
t.Error("duplicates accepted after canonicalization")
}
if _, err := AttachmentIDs([]string{"not-a-uuid"}); err == nil {
t.Error("invalid UUID accepted")
}
if _, err := AttachmentIDs(make([]string, AttachmentIDsMax+1)); err == nil {
t.Error("too many IDs accepted")
}
}