|
|
|
@@ -1507,59 +1507,3 @@ func TestMainSubprocess_DeprecatedGiteaURLEnv(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestMainSubprocess_InvalidDocMapPath confirms that --doc-map with a path
|
|
|
|
|
// traversal attempt (e.g. ../../../etc/passwd) is rejected when the
|
|
|
|
|
// validate-docmap subcommand is used. The validate-docmap subcommand shares
|
|
|
|
|
// the same path validation logic (validateDocmapPath) that is called when
|
|
|
|
|
// --doc-map is provided to the main review-bot command.
|
|
|
|
|
func TestMainSubprocess_InvalidDocMapPath(t *testing.T) {
|
|
|
|
|
if os.Getenv("TEST_SUBPROCESS_MAIN") == "1" {
|
|
|
|
|
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
|
|
|
|
os.Args = []string{"review-bot", "validate-docmap",
|
|
|
|
|
"--docmap", "../../../etc/passwd",
|
|
|
|
|
"--repo-root", "/tmp",
|
|
|
|
|
}
|
|
|
|
|
main()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command(os.Args[0], "-test.run=TestMainSubprocess_InvalidDocMapPath")
|
|
|
|
|
cmd.Env = append(os.Environ(), "TEST_SUBPROCESS_MAIN=1")
|
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("expected non-zero exit for path traversal doc-map, got success")
|
|
|
|
|
}
|
|
|
|
|
combined := string(out)
|
|
|
|
|
if !strings.Contains(combined, "invalid") && !strings.Contains(combined, "repo-root") && !strings.Contains(combined, "traversal") && !strings.Contains(combined, "outside") {
|
|
|
|
|
t.Errorf("expected path confinement error for traversal path, got: %s", combined)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestMainSubprocess_InvalidDocMapFile confirms that --doc-map pointing at a
|
|
|
|
|
// nonexistent file is rejected. The validate-docmap subcommand exercises the
|
|
|
|
|
// same validateDocmapPath that is invoked when --doc-map is provided to the
|
|
|
|
|
// main review-bot command.
|
|
|
|
|
func TestMainSubprocess_InvalidDocMapFile(t *testing.T) {
|
|
|
|
|
if os.Getenv("TEST_SUBPROCESS_MAIN") == "1" {
|
|
|
|
|
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
|
|
|
|
// Create a temp dir to serve as repo-root, then reference a nonexistent file inside it.
|
|
|
|
|
repoDir := os.TempDir()
|
|
|
|
|
os.Args = []string{"review-bot", "validate-docmap",
|
|
|
|
|
"--docmap", "nonexistent-doc-map.yml",
|
|
|
|
|
"--repo-root", repoDir,
|
|
|
|
|
}
|
|
|
|
|
main()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command(os.Args[0], "-test.run=TestMainSubprocess_InvalidDocMapFile")
|
|
|
|
|
cmd.Env = append(os.Environ(), "TEST_SUBPROCESS_MAIN=1")
|
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("expected non-zero exit for nonexistent doc-map file, got success")
|
|
|
|
|
}
|
|
|
|
|
combined := string(out)
|
|
|
|
|
if !strings.Contains(combined, "invalid") && !strings.Contains(combined, "cannot stat") && !strings.Contains(combined, "resolve") {
|
|
|
|
|
t.Errorf("expected file-not-found error for nonexistent doc-map, got: %s", combined)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|