Align bundle path validation coverage
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user