(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func 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 | |
| 99 | func TestMutableSafeURLString(t *testing.T) { |
| 100 | tests := []struct { |
nothing calls this directly
no test coverage detected