ЛР 6 — БПИ2302 — Нурлыгаянова — на 3

This commit is contained in:
Nurlygayanova Ekaterina
2026-11-13 11:32:45 +03:00
parent 470d9d6f1e
commit 69a190be0e
164 changed files with 25947 additions and 29 deletions
+39
View File
@@ -0,0 +1,39 @@
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")
}
}