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

Function TestIsSafeScriptName

pkg/workflow/safe_scripts_test.go:394–420  ·  view source on GitHub ↗

TestIsSafeScriptName verifies path traversal detection in script names

(t *testing.T)

Source from the content-addressed store, hash-verified

392
393// TestIsSafeScriptName verifies path traversal detection in script names
394func TestIsSafeScriptName(t *testing.T) {
395 tests := []struct {
396 name string
397 input string
398 want bool
399 }{
400 // Valid names
401 {"plain name", "my_handler", true},
402 {"name with numbers", "handler_v2", true},
403 {"single word", "handler", true},
404 {"dot in name", "handler.name", true},
405 // Invalid — path separators and traversal sequences
406 {"forward slash", "sub/handler", false},
407 {"backslash", `sub\handler`, false},
408 {"double dot", "handler..", false},
409 {"leading dot-dot", "../evil", false},
410 {"double dot only", "..", false},
411 {"traversal chain", "../../etc/shadow", false},
412 {"dot-dot at end", "handler/../../", false},
413 }
414 for _, tt := range tests {
415 t.Run(tt.name, func(t *testing.T) {
416 got := isSafeScriptName(tt.input)
417 assert.Equal(t, tt.want, got, "isSafeScriptName(%q) should be %v", tt.input, tt.want)
418 })
419 }
420}
421
422// TestBuildCustomSafeOutputScriptsJSONPathTraversal verifies path traversal names are rejected
423func TestBuildCustomSafeOutputScriptsJSONPathTraversal(t *testing.T) {

Callers

nothing calls this directly

Calls 2

isSafeScriptNameFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected