Align bundle path validation coverage

This commit is contained in:
2026-06-04 00:40:17 +00:00
parent 5a3fd2b8ac
commit 2ac2bbdf79
6 changed files with 146 additions and 11 deletions

View File

@@ -90,17 +90,33 @@ func TestBuildManifestRequiresOneFileMode(t *testing.T) {
}
}
func TestBuildManifestRejectsUnsafePath(t *testing.T) {
func TestBuildManifestRejectsUnsafeExplicitPaths(t *testing.T) {
root := t.TempDir()
writeFile(t, root, "report.txt", "report")
_, err := BuildManifest(BuildOptions{
Root: root,
ID: "reports.unsafe",
Files: []string{"../report.txt"},
})
if err == nil {
t.Fatal("BuildManifest() error = nil, want unsafe path error")
tests := []string{
"",
"../report.txt",
"/report.txt",
"nested/../report.txt",
"nested/./report.txt",
`nested\report.txt`,
ManifestName,
distributorStateName,
"nested/" + ManifestName,
"nested/" + distributorStateName,
}
for _, sourcePath := range tests {
t.Run(sourcePath, func(t *testing.T) {
_, err := BuildManifest(BuildOptions{
Root: root,
ID: "reports.unsafe",
Files: []string{sourcePath},
})
if err == nil {
t.Fatal("BuildManifest() error = nil, want unsafe path error")
}
})
}
}
@@ -330,7 +346,21 @@ func TestValidateSourcePath(t *testing.T) {
t.Fatalf("ValidateSourcePath(%q) error = %v", path, err)
}
}
invalid := []string{"", "../report.md", "/report.md", "nested/../report.md", `nested\report.md`, ManifestName, distributorStateName}
invalid := []string{
"",
".",
"./report.md",
"../report.md",
"/report.md",
"nested/../report.md",
"nested/./report.md",
"nested//report.md",
`nested\report.md`,
ManifestName,
distributorStateName,
"nested/" + ManifestName,
"nested/" + distributorStateName,
}
for _, path := range invalid {
if err := ValidateSourcePath(path); err == nil {
t.Fatalf("ValidateSourcePath(%q) error = nil, want error", path)

View File

@@ -23,8 +23,7 @@ func ValidateSourcePath(value string) error {
return fmt.Errorf("source path %q must be a clean relative slash-separated path", value)
}
}
switch value {
case ManifestName, distributorStateName:
if path.Base(value) == ManifestName || path.Base(value) == distributorStateName {
return fmt.Errorf("%q is reserved", value)
}
return nil