-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: string formatting fix and tested
- Loading branch information
1 parent
0f49a6d
commit b693fdd
Showing
3 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"net/url" | ||
"path" | ||
"strings" | ||
"sync" | ||
"testing" | ||
) | ||
|
||
func FuzzParse(f *testing.F) { | ||
var seeds []string = []string { | ||
"https://some-fake-hosting/cdn/v1/app/11-video-id/i1.ts", | ||
"https://fake.cdn.net/##$!qq_eiir482fdd/efev/aa/index-00.ts", | ||
"/vplayer/cc/enus/100_index.ts", | ||
"/hls/stream-11sso-11994/v.1.ts", | ||
"/video-1.ts", | ||
"/50.ts", | ||
"/--308.ts?auth=fake-key-auth&state=permission&quality=1080p&fps=60", | ||
"/stream/6c657347-8eff-473d-97af-3f17266c418c/720p60/v77.ts", | ||
} | ||
|
||
// settings seeds for fuzzing test | ||
for _, seed := range seeds { | ||
f.Add(seed) | ||
} | ||
|
||
var wg sync.WaitGroup | ||
|
||
const defaultEndpoint = "https://fake-cdn-hosting.icnet/file.m3u8" | ||
|
||
var link string | ||
|
||
f.Fuzz(func(t *testing.T, in string) { | ||
parser := NewHlsParser(strings.NewReader(in), path.Dir(defaultEndpoint), DefaultParseValidationFunc, 0, 0) | ||
wg.Add(1) | ||
|
||
go func() { | ||
link = <- parser.UriChan() | ||
<- parser.UriChan() | ||
wg.Done() | ||
}() | ||
|
||
err := parser.Parse() | ||
wg.Wait() | ||
|
||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
uri, _ := url.Parse(defaultEndpoint) | ||
inPath, _ := url.Parse(in) | ||
expected := "https://" + uri.Host + inPath.Path | ||
|
||
if expected != link { | ||
t.Errorf("expected = %v, actual = %v", expected, link) | ||
} | ||
}) | ||
} |