-
Notifications
You must be signed in to change notification settings - Fork 2
/
fuzz_test.go
78 lines (67 loc) · 1.95 KB
/
fuzz_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build go1.18
// +build go1.18
package imageflux
import (
"reflect"
"strings"
"testing"
"time"
)
func FuzzParseConfig(f *testing.F) {
for _, c := range parseConfigCases {
f.Add(c.input)
}
for _, c := range parseConfigErrorCases {
f.Add(c)
}
f.Fuzz(func(t *testing.T, s string) {
fixTime(t, time.Date(2023, 6, 24, 9, 23, 0, 0, time.UTC))
c0, rest, err := ParseConfig(s)
if err != nil {
return
}
_ = rest
s1 := c0.String()
c1, _, err := ParseConfig(s1)
if err != nil {
t.Error(err)
return
}
// The zero value of Format has same meaning as FormatAuto.
if c0.Format == "" {
c0.Format = FormatAuto
}
if c1.Format == "" {
c1.Format = FormatAuto
}
if !reflect.DeepEqual(c0, c1) {
t.Errorf("%q: c0 != c1: %v != %v", s, c0, c1)
}
})
}
func FuzzProxy_Parse(f *testing.F) {
f.Add("/c!/w=100/images/1.jpg", "", "")
f.Add("/c/sig=1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=,w=200/images/1.jpg", "", "testsigningsecret")
f.Add("/c/w=200,sig=1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=/images/1.jpg", "", "testsigningsecret")
f.Add("/c/w=200%2csig=1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=/images/1.jpg", "", "testsigningsecret")
f.Add("/c/w=200%2Csig=1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=/images/1.jpg", "", "testsigningsecret")
f.Add("/c/w=200/images/1.jpg", "1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=", "testsigningsecret")
f.Add("/c/sig=1.-Yd8m-5pXPihiZdlDATcwkkgjzPIC9gFHmmZ3JMxwS0=/images/1.jpg", "", "testsigningsecret")
f.Add("/images/1.jpg", "1.-Yd8m-5pXPihiZdlDATcwkkgjzPIC9gFHmmZ3JMxwS0=", "testsigningsecret")
f.Fuzz(func(t *testing.T, path, sig, secret string) {
fixTime(t, time.Date(2023, 6, 24, 9, 23, 0, 0, time.UTC))
p := &Proxy{
Host: "example.com",
Secret: secret,
}
img0, err := p.Parse(path, sig)
if err != nil {
return
}
u := img0.SignedURL()
_, err = p.Parse(strings.TrimPrefix(u, "https://example.com"), "")
if err != nil {
t.Error(err)
}
})
}