Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dce8e4454 |
@@ -9,8 +9,6 @@
|
||||
### Tests
|
||||
|
||||
- **`TestValidateDocmapPath_DirSymlinkBypass`**: verifies that a directory symlink inside the repo pointing outside cannot be used to bypass path confinement ([#150](https://gitea.weiker.me/rodin/review-bot/issues/150)).
|
||||
- **`TestMainSubprocess_InvalidDocMapPath`**: verifies that a path-traversal `--docmap` argument (`../../../etc/passwd`) is rejected by the validate-docmap subcommand ([#146](https://gitea.weiker.me/rodin/review-bot/issues/146)).
|
||||
- **`TestMainSubprocess_InvalidDocMapFile`**: verifies that a nonexistent `--docmap` file is rejected by the validate-docmap subcommand ([#146](https://gitea.weiker.me/rodin/review-bot/issues/146)).
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user