Smail/backend/controllers/attachments_test.go
smail f60d3b0880
Some checks are pending
Security Checks / security (push) Waiting to run
整理前后端与测试构建目录并完善配置和安全引导
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
2026-09-05 19:19:52 +08:00

31 lines
872 B
Go

package controllers
import (
"strings"
"testing"
)
func TestSafeDownloadName(t *testing.T) {
for input, expected := range map[string]string{
"report.txt": "report.txt",
"../report.txt": ".._report.txt",
"report\r\nX-Test: value": "report__X-Test: value",
"": "attachment",
"..": "attachment",
} {
if got := safeDownloadName(input); got != expected {
t.Fatalf("safeDownloadName(%q) = %q, want %q", input, got, expected)
}
}
}
func TestSafeDownloadNameLength(t *testing.T) {
input := strings.Repeat("a", 300)
if got := safeDownloadName(input); len([]rune(got)) != 180 {
t.Fatalf("unexpected filename length: %d", len([]rune(got)))
}
if got := safeDownloadName("\u4e2d\u6587-report.txt"); got != "\u4e2d\u6587-report.txt" {
t.Fatalf("unicode filename changed: %q", got)
}
}