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") } }