Merge branch v2.11 into v3.3
This commit is contained in:
commit
f6fb240eb6
44 changed files with 940 additions and 597 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -382,3 +383,44 @@ func TestKeepAliveH2c(t *testing.T) {
|
|||
// to change.
|
||||
require.Contains(t, err.Error(), "use of closed network connection")
|
||||
}
|
||||
|
||||
func TestSanitizePath(t *testing.T) {
|
||||
tests := []struct {
|
||||
path string
|
||||
expected string
|
||||
}{
|
||||
{path: "/b", expected: "/b"},
|
||||
{path: "/b/", expected: "/b/"},
|
||||
{path: "/../../b/", expected: "/b/"},
|
||||
{path: "/../../b", expected: "/b"},
|
||||
{path: "/a/b/..", expected: "/a"},
|
||||
{path: "/a/b/../", expected: "/a/"},
|
||||
{path: "/a/../../b", expected: "/b"},
|
||||
{path: "/..///b///", expected: "/b/"},
|
||||
{path: "/a/../b", expected: "/b"},
|
||||
{path: "/a/./b", expected: "/a/b"},
|
||||
{path: "/a//b", expected: "/a/b"},
|
||||
{path: "/a/../../b", expected: "/b"},
|
||||
{path: "/a/../c/../b", expected: "/b"},
|
||||
{path: "/a/../../../c/../b", expected: "/b"},
|
||||
{path: "/a/../c/../../b", expected: "/b"},
|
||||
{path: "/a/..//c/.././b", expected: "/b"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("Testing case: "+test.path, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var callCount int
|
||||
clean := sanitizePath(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
callCount++
|
||||
assert.Equal(t, test.expected, r.URL.Path)
|
||||
}))
|
||||
|
||||
request := httptest.NewRequest(http.MethodGet, "http://foo"+test.path, http.NoBody)
|
||||
clean.ServeHTTP(httptest.NewRecorder(), request)
|
||||
|
||||
assert.Equal(t, 1, callCount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue