-
Notifications
You must be signed in to change notification settings - Fork 3
/
rustaudit_test.go
58 lines (52 loc) · 1.59 KB
/
rustaudit_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
package rustaudit
import (
"bytes"
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLinuxRustDependencies(t *testing.T) {
// Generate this with `DOCKER_BUILDKIT=1 docker build -f test/Dockerfile -o . .`
r, err := os.Open("crate_with_features_bin")
if err != nil {
log.Fatal(err)
}
versionInfo, err := GetDependencyInfo(r)
if err != nil {
log.Fatal(err)
}
assert.Equal(t, 2, len(versionInfo.Packages))
assert.Equal(t, Package{Name: "crate_with_features", Version: "0.1.0", Source: "local", Kind: "runtime", Dependencies: []uint{1}, Root: true}, versionInfo.Packages[0])
assert.Equal(t, false, versionInfo.Packages[1].Root)
}
func TestWasmRustDependencies(t *testing.T) {
// Generate this with `DOCKER_BUILDKIT=1 docker build -f test/Dockerfile -o . .`
r, err := os.Open("wasm_crate.wasm")
if err != nil {
log.Fatal(err)
}
versionInfo, err := GetDependencyInfo(r)
if err != nil {
log.Fatal(err)
}
assert.Equal(t, 18, len(versionInfo.Packages))
assert.Equal(t, Package{Name: "bumpalo", Version: "3.16.0", Source: "crates.io", Kind: "runtime", Dependencies: nil, Root: false}, versionInfo.Packages[0])
assert.Equal(t, false, versionInfo.Packages[1].Root)
}
func FuzzWasm(f *testing.F) {
// Use the test fixture as a seed
data, err := os.ReadFile("wasm_crate.wasm")
if err != nil {
log.Fatal(err)
}
f.Add(data)
f.Fuzz(func(t *testing.T, input []byte) {
r := bytes.NewReader(input)
w := wasmReader{r}
_, err := w.ReadRustDepSection()
if err != ErrNoRustDepInfo && err != ErrUnknownFileFormat && err != nil {
t.Errorf("Unexpected error: %v", err)
}
})
}