TestIsSafeScriptName verifies path traversal detection in script names
(t *testing.T)
| 392 | |
| 393 | // TestIsSafeScriptName verifies path traversal detection in script names |
| 394 | func 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 |
| 423 | func TestBuildCustomSafeOutputScriptsJSONPathTraversal(t *testing.T) { |
nothing calls this directly
no test coverage detected