Repository navigation
Expand file tree
/
Copy pathfuzz_test.go
More file actions
70 lines (63 loc) · 1.94 KB
/
Copy pathfuzz_test.go
File metadata and controls
70 lines (63 loc) · 1.94 KB
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
package integrity
import "testing"
func FuzzParseSRI(f *testing.F) {
f.Add("")
f.Add("-")
f.Add("sha384")
f.Add(sriEntry(SHA256, "hello"))
f.Add(sriEntry(SHA384, "hello"))
f.Add(sriEntry(SHA512, "hello"))
f.Add(sriEntry(SHA256, "one") + " " + sriEntry(SHA512, "two"))
f.Add("SHA384-" + sriEntry(SHA384, "mixed case")[len("sha384-"):])
f.Add("sha384-!!!!")
f.Add("md5-1B2M2Y8AsgTpgAmY7PhCfg==")
f.Fuzz(func(t *testing.T, value string) {
_, _ = ParseSRI(value)
})
}
func FuzzSRIRoundTrip(f *testing.F) {
f.Add(sriEntry(SHA256, "hello"))
f.Add(sriEntry(SHA384, "hello"))
f.Add(sriEntry(SHA512, "hello"))
f.Add(sriEntry(SHA512, "first") + " " + sriEntry(SHA512, "alternative"))
f.Add(sriEntry(SHA256, "one") + "\t" + sriEntry(SHA384, "two") + "\n" + sriEntry(SHA512, "three"))
f.Fuzz(func(t *testing.T, value string) {
first, err := ParseSRI(value)
if err != nil {
return
}
second, err := ParseSRI(FormatSRI(first))
if err != nil {
t.Fatalf("ParseSRI accepted %q but rejected its canonical form: %v", value, err)
}
if len(first) != len(second) {
t.Fatalf("round trip changed digest count from %d to %d", len(first), len(second))
}
for i := range first {
if first[i].Algorithm() != second[i].Algorithm() || !first[i].Equal(second[i]) {
t.Fatalf("round trip changed digest %d", i)
}
}
})
}
func FuzzParseChecksum(f *testing.F) {
f.Add("")
f.Add("sha1-")
f.Add("md5-" + checksumHex(MD5, "hello"))
f.Add("sha1:" + checksumHex(SHA1, "hello"))
f.Add("SHA512-" + checksumHex(SHA512, "hello"))
f.Add("sha256-" + checksumHex(SHA256, "hello") + " extra")
f.Fuzz(func(t *testing.T, value string) {
digest, err := ParseChecksum(value)
if err != nil {
return
}
again, err := ParseChecksum(digest.Checksum())
if err != nil {
t.Fatalf("ParseChecksum accepted %q but rejected its canonical form: %v", value, err)
}
if !digest.Equal(again) {
t.Fatalf("round trip of %q changed the digest", value)
}
})
}