Add fuzzing for webseed path escaping
This commit is contained in:
parent
291c428016
commit
df126fcace
@ -10,21 +10,51 @@ import (
|
|||||||
func TestDefaultPathEscaper(t *testing.T) {
|
func TestDefaultPathEscaper(t *testing.T) {
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
test := func(unescaped string, parts ...string) {
|
test := func(unescaped string, parts ...string) {
|
||||||
escaped := defaultPathEscaper(parts)
|
assertPartsUnescape(c, unescaped, parts...)
|
||||||
pathUnescaped, err := url.PathUnescape(escaped)
|
}
|
||||||
c.Assert(err, qt.IsNil)
|
for _, tc := range defaultPathEscapeTestCases {
|
||||||
c.Assert(pathUnescaped, qt.Equals, unescaped)
|
test(tc.escaped, tc.parts...)
|
||||||
queryUnescaped, err := url.QueryUnescape(escaped)
|
|
||||||
c.Assert(err, qt.IsNil)
|
|
||||||
c.Assert(queryUnescaped, qt.Equals, unescaped)
|
|
||||||
}
|
}
|
||||||
test("a_b-c/d + e.f", "a_b-c", "d + e.f")
|
}
|
||||||
test("a_1-b_c2/d 3. (e, f).g", "a_1-b_c2", "d 3. (e, f).g")
|
|
||||||
test("a_b-c/d + e.f", "a_b-c", "d + e.f")
|
// So we can manually check, and use these to seed fuzzing.
|
||||||
test("a_1-b_c2/d 3. (e, f).g", "a_1-b_c2", "d 3. (e, f).g")
|
var defaultPathEscapeTestCases = []struct {
|
||||||
test("war/and/peace", "war", "and", "peace")
|
escaped string
|
||||||
test("hello/world", "hello", "world")
|
parts []string
|
||||||
test(`ノ┬─┬ノ ︵ ( \o°o)\`, `ノ┬─┬ノ ︵ ( \o°o)\`)
|
}{
|
||||||
test(`%aa + %bb/Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`,
|
{"/", []string{"", ""}},
|
||||||
`%aa + %bb`, `Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`)
|
{"a_b-c/d + e.f", []string{"a_b-c", "d + e.f"}},
|
||||||
|
{"a_1-b_c2/d 3. (e, f).g", []string{"a_1-b_c2", "d 3. (e, f).g"}},
|
||||||
|
{"a_b-c/d + e.f", []string{"a_b-c", "d + e.f"}},
|
||||||
|
{"a_1-b_c2/d 3. (e, f).g", []string{"a_1-b_c2", "d 3. (e, f).g"}},
|
||||||
|
{"war/and/peace", []string{"war", "and", "peace"}},
|
||||||
|
{"he//o#world/world", []string{"he//o#world", "world"}},
|
||||||
|
{`ノ┬─┬ノ ︵ ( \o°o)\`, []string{`ノ┬─┬ノ ︵ ( \o°o)\`}},
|
||||||
|
{
|
||||||
|
`%aa + %bb/Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`,
|
||||||
|
[]string{`%aa + %bb`, `Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertPartsUnescape(c *qt.C, unescaped string, parts ...string) {
|
||||||
|
escaped := defaultPathEscaper(parts)
|
||||||
|
pathUnescaped, err := url.PathUnescape(escaped)
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
c.Assert(pathUnescaped, qt.Equals, unescaped)
|
||||||
|
queryUnescaped, err := url.QueryUnescape(escaped)
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
c.Assert(queryUnescaped, qt.Equals, unescaped)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FuzzDefaultPathEscaper(f *testing.F) {
|
||||||
|
for _, tc := range defaultPathEscapeTestCases {
|
||||||
|
if len(tc.parts) == 2 {
|
||||||
|
f.Add(tc.parts[0], tc.parts[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// I think a single separator is enough to test special handling around /. Also fuzzing doesn't
|
||||||
|
// let us take []string as an input.
|
||||||
|
f.Fuzz(func(t *testing.T, first, second string) {
|
||||||
|
assertPartsUnescape(qt.New(t), first+"/"+second, first, second)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user