MCPcopy Create free account
hub / github.com/github/gh-aw / TestRunnerGuardPathTraversalGuard

Function TestRunnerGuardPathTraversalGuard

pkg/cli/runner_guard_test.go:290–353  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

288}
289
290func TestRunnerGuardPathTraversalGuard(t *testing.T) {
291 tests := []struct {
292 name string
293 filePath string
294 skip bool // whether the finding should be skipped (outside git root)
295 }{
296 {
297 name: "normal workflow file",
298 filePath: ".github/workflows/test.lock.yml",
299 skip: false,
300 },
301 {
302 name: "file outside git root via ..",
303 filePath: "../outside/file.yml",
304 skip: true,
305 },
306 {
307 name: "file with .. prefix but inside root",
308 filePath: "..foo/file.yml", // should NOT be skipped — not a parent traversal
309 skip: false,
310 },
311 }
312
313 for _, tt := range tests {
314 t.Run(tt.name, func(t *testing.T) {
315 tmpDir := t.TempDir()
316
317 stdout := `{"findings":[{"rule_id":"RGS-TEST","name":"Test","severity":"high","file":"` +
318 tt.filePath + `","line":1}]}`
319
320 oldStderr := os.Stderr
321 r, w, _ := os.Pipe()
322 os.Stderr = w
323
324 count, err := parseAndDisplayRunnerGuardOutput(stdout, false, tmpDir)
325
326 w.Close()
327 os.Stderr = oldStderr
328
329 var buf bytes.Buffer
330 buf.ReadFrom(r)
331 output := buf.String()
332
333 if err != nil {
334 t.Errorf("Unexpected error: %v", err)
335 }
336
337 if tt.skip {
338 // Skipped findings still count toward totalFindings but won't appear in output
339 // The finding is parsed (count=1) but display is skipped
340 if count != 1 {
341 t.Errorf("Expected count 1 (finding parsed even if skipped for display), got %d", count)
342 }
343 if strings.Contains(output, "RGS-TEST") {
344 t.Errorf("Expected skipped finding not to appear in output, got:\n%s", output)
345 }
346 } else {
347 if count != 1 {

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.65
RunMethod · 0.45
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected