MCPcopy Create free account
hub / github.com/cli/cli / TestJoinPathRejectsTraversal

Function TestJoinPathRejectsTraversal

internal/safeurl/safeurl_test.go:75–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestJoinPathRejectsTraversal(t *testing.T) {
76 tests := []struct {
77 name string
78 components []string
79 }{
80 {
81 name: "only a .. component",
82 components: []string{".."},
83 },
84 {
85 name: "a .. component in the middle",
86 components: []string{"repos", "octocat", "..", "hello-world"},
87 },
88 }
89 for _, tt := range tests {
90 t.Run(tt.name, func(t *testing.T) {
91 _, errJoinPath := safeurl.JoinPath(tt.components...)
92 require.Error(t, errJoinPath)
93 _, errJoinPathWithHostPrefix := safeurl.JoinPathWithHostPrefix("https://api.github.com", tt.components...)
94 require.Error(t, errJoinPathWithHostPrefix)
95 })
96 }
97}
98
99func TestMutableSafeURLString(t *testing.T) {
100 tests := []struct {

Callers

nothing calls this directly

Calls 4

JoinPathFunction · 0.92
JoinPathWithHostPrefixFunction · 0.92
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected