@@ -3,48 +3,270 @@ package rust
3
3
import (
4
4
"testing"
5
5
6
+ "github.com/anchore/syft/syft/artifact"
6
7
"github.com/anchore/syft/syft/file"
7
8
"github.com/anchore/syft/syft/pkg"
8
9
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
9
10
)
10
11
11
12
func TestNewAuditBinaryCataloger (t * testing.T ) {
13
+ locations := file .NewLocationSet (file .NewVirtualLocation ("/usr/local/bin/hello_world" , "/usr/local/bin/hello_world" ))
14
+
15
+ argh := pkg.Package {
16
+ Name : "argh" ,
17
+ Version : "0.1.12" ,
18
+ PURL :
"pkg:cargo/[email protected] " ,
19
+ FoundBy : "cargo-auditable-binary-cataloger" ,
20
+ Locations : locations ,
21
+ Language : pkg .Rust ,
22
+ Type : pkg .RustPkg ,
23
+ Metadata : pkg.RustBinaryAuditEntry {
24
+ Name : "argh" ,
25
+ Version : "0.1.12" ,
26
+ Source : "crates.io" ,
27
+ },
28
+ }
29
+
30
+ arghDerive := pkg.Package {
31
+ Name : "argh_derive" ,
32
+ Version : "0.1.12" ,
33
+ PURL :
"pkg:cargo/[email protected] " ,
34
+ FoundBy : "cargo-auditable-binary-cataloger" ,
35
+ Locations : locations ,
36
+ Language : pkg .Rust ,
37
+ Type : pkg .RustPkg ,
38
+ Metadata : pkg.RustBinaryAuditEntry {
39
+ Name : "argh_derive" ,
40
+ Version : "0.1.12" ,
41
+ Source : "crates.io" ,
42
+ },
43
+ }
44
+
45
+ arghShared := pkg.Package {
46
+ Name : "argh_shared" ,
47
+ Version : "0.1.12" ,
48
+ PURL :
"pkg:cargo/[email protected] " ,
49
+ FoundBy : "cargo-auditable-binary-cataloger" ,
50
+ Locations : locations ,
51
+ Language : pkg .Rust ,
52
+ Type : pkg .RustPkg ,
53
+ Metadata : pkg.RustBinaryAuditEntry {
54
+ Name : "argh_shared" ,
55
+ Version : "0.1.12" ,
56
+ Source : "crates.io" ,
57
+ },
58
+ }
59
+
60
+ helloWorld := pkg.Package {
61
+ Name : "hello_world" ,
62
+ Version : "0.1.0" ,
63
+ PURL :
"pkg:cargo/[email protected] " ,
64
+ FoundBy : "cargo-auditable-binary-cataloger" ,
65
+ Locations : locations ,
66
+ Language : pkg .Rust ,
67
+ Type : pkg .RustPkg ,
68
+ Metadata : pkg.RustBinaryAuditEntry {
69
+ Name : "hello_world" ,
70
+ Version : "0.1.0" ,
71
+ Source : "local" ,
72
+ },
73
+ }
74
+
75
+ procMacro2 := pkg.Package {
76
+ Name : "proc-macro2" ,
77
+ Version : "1.0.92" ,
78
+ PURL :
"pkg:cargo/[email protected] " ,
79
+ FoundBy : "cargo-auditable-binary-cataloger" ,
80
+ Locations : locations ,
81
+ Language : pkg .Rust ,
82
+ Type : pkg .RustPkg ,
83
+ Metadata : pkg.RustBinaryAuditEntry {
84
+ Name : "proc-macro2" ,
85
+ Version : "1.0.92" ,
86
+ Source : "crates.io" ,
87
+ },
88
+ }
89
+
90
+ quote := pkg.Package {
91
+ Name : "quote" ,
92
+ Version : "1.0.37" ,
93
+ PURL :
"pkg:cargo/[email protected] " ,
94
+ FoundBy : "cargo-auditable-binary-cataloger" ,
95
+ Locations : locations ,
96
+ Language : pkg .Rust ,
97
+ Type : pkg .RustPkg ,
98
+ Metadata : pkg.RustBinaryAuditEntry {
99
+ Name : "quote" ,
100
+ Version : "1.0.37" ,
101
+ Source : "crates.io" ,
102
+ },
103
+ }
104
+
105
+ serde := pkg.Package {
106
+ Name : "serde" ,
107
+ Version : "1.0.215" ,
108
+ PURL :
"pkg:cargo/[email protected] " ,
109
+ FoundBy : "cargo-auditable-binary-cataloger" ,
110
+ Locations : locations ,
111
+ Language : pkg .Rust ,
112
+ Type : pkg .RustPkg ,
113
+ Metadata : pkg.RustBinaryAuditEntry {
114
+ Name : "serde" ,
115
+ Version : "1.0.215" ,
116
+ Source : "crates.io" ,
117
+ },
118
+ }
119
+
120
+ serdeDerive := pkg.Package {
121
+ Name : "serde_derive" ,
122
+ Version : "1.0.215" ,
123
+ PURL :
"pkg:cargo/[email protected] " ,
124
+ FoundBy : "cargo-auditable-binary-cataloger" ,
125
+ Locations : locations ,
126
+ Language : pkg .Rust ,
127
+ Type : pkg .RustPkg ,
128
+ Metadata : pkg.RustBinaryAuditEntry {
129
+ Name : "serde_derive" ,
130
+ Version : "1.0.215" ,
131
+ Source : "crates.io" ,
132
+ },
133
+ }
134
+
135
+ syn := pkg.Package {
136
+ Name : "syn" ,
137
+ Version : "2.0.90" ,
138
+ PURL :
"pkg:cargo/[email protected] " ,
139
+ FoundBy : "cargo-auditable-binary-cataloger" ,
140
+ Locations : locations ,
141
+ Language : pkg .Rust ,
142
+ Type : pkg .RustPkg ,
143
+ Metadata : pkg.RustBinaryAuditEntry {
144
+ Name : "syn" ,
145
+ Version : "2.0.90" ,
146
+ Source : "crates.io" ,
147
+ },
148
+ }
149
+
150
+ unicodeIdent := pkg.Package {
151
+ Name : "unicode-ident" ,
152
+ Version : "1.0.14" ,
153
+ PURL :
"pkg:cargo/[email protected] " ,
154
+ FoundBy : "cargo-auditable-binary-cataloger" ,
155
+ Locations : locations ,
156
+ Language : pkg .Rust ,
157
+ Type : pkg .RustPkg ,
158
+ Metadata : pkg.RustBinaryAuditEntry {
159
+ Name : "unicode-ident" ,
160
+ Version : "1.0.14" ,
161
+ Source : "crates.io" ,
162
+ },
163
+ }
12
164
13
165
expectedPkgs := []pkg.Package {
166
+ argh ,
167
+ arghDerive ,
168
+ arghShared ,
169
+ helloWorld ,
170
+ procMacro2 ,
171
+ quote ,
172
+ serde ,
173
+ serdeDerive ,
174
+ syn ,
175
+ unicodeIdent ,
176
+ }
177
+
178
+ expectedRelationships := []artifact.Relationship {
14
179
{
15
- Name : "auditable" ,
16
- Version : "0.1.0" ,
17
- PURL :
"pkg:cargo/[email protected] " ,
18
- FoundBy : "cargo-auditable-binary-cataloger" ,
19
- Locations : file .NewLocationSet (file .NewVirtualLocation ("/hello-auditable" , "/hello-auditable" )),
20
- Language : pkg .Rust ,
21
- Type : pkg .RustPkg ,
22
- Metadata : pkg.RustBinaryAuditEntry {
23
- Name : "auditable" ,
24
- Version : "0.1.0" ,
25
- Source : "local" ,
26
- },
180
+ From : argh ,
181
+ To : helloWorld ,
182
+ Type : artifact .DependencyOfRelationship ,
27
183
},
28
184
{
29
- Name : "hello-auditable" ,
30
- Version : "0.1.0" ,
31
- PURL :
"pkg:cargo/[email protected] " ,
32
- FoundBy : "cargo-auditable-binary-cataloger" ,
33
- Locations : file .NewLocationSet (file .NewVirtualLocation ("/hello-auditable" , "/hello-auditable" )),
34
- Language : pkg .Rust ,
35
- Type : pkg .RustPkg ,
36
- Metadata : pkg.RustBinaryAuditEntry {
37
- Name : "hello-auditable" ,
38
- Version : "0.1.0" ,
39
- Source : "local" ,
40
- },
185
+ From : arghDerive ,
186
+ To : argh ,
187
+ Type : artifact .DependencyOfRelationship ,
188
+ },
189
+ {
190
+ From : arghShared ,
191
+ To : argh ,
192
+ Type : artifact .DependencyOfRelationship ,
193
+ },
194
+ {
195
+ From : arghShared ,
196
+ To : arghDerive ,
197
+ Type : artifact .DependencyOfRelationship ,
198
+ },
199
+ {
200
+ From : procMacro2 ,
201
+ To : arghDerive ,
202
+ Type : artifact .DependencyOfRelationship ,
203
+ },
204
+ {
205
+ From : procMacro2 ,
206
+ To : quote ,
207
+ Type : artifact .DependencyOfRelationship ,
208
+ },
209
+ {
210
+ From : procMacro2 ,
211
+ To : serdeDerive ,
212
+ Type : artifact .DependencyOfRelationship ,
213
+ },
214
+ {
215
+ From : procMacro2 ,
216
+ To : syn ,
217
+ Type : artifact .DependencyOfRelationship ,
218
+ },
219
+ {
220
+ From : quote ,
221
+ To : arghDerive ,
222
+ Type : artifact .DependencyOfRelationship ,
223
+ },
224
+ {
225
+ From : quote ,
226
+ To : serdeDerive ,
227
+ Type : artifact .DependencyOfRelationship ,
228
+ },
229
+ {
230
+ From : quote ,
231
+ To : syn ,
232
+ Type : artifact .DependencyOfRelationship ,
233
+ },
234
+ {
235
+ From : serde ,
236
+ To : arghShared ,
237
+ Type : artifact .DependencyOfRelationship ,
238
+ },
239
+ {
240
+ From : serdeDerive ,
241
+ To : serde ,
242
+ Type : artifact .DependencyOfRelationship ,
243
+ },
244
+ {
245
+ From : syn ,
246
+ To : arghDerive ,
247
+ Type : artifact .DependencyOfRelationship ,
248
+ },
249
+ {
250
+ From : syn ,
251
+ To : serdeDerive ,
252
+ Type : artifact .DependencyOfRelationship ,
253
+ },
254
+ {
255
+ From : unicodeIdent ,
256
+ To : procMacro2 ,
257
+ Type : artifact .DependencyOfRelationship ,
258
+ },
259
+ {
260
+ From : unicodeIdent ,
261
+ To : syn ,
262
+ Type : artifact .DependencyOfRelationship ,
41
263
},
42
264
}
43
265
44
266
pkgtest .NewCatalogTester ().
45
267
WithImageResolver (t , "image-audit" ).
46
268
IgnoreLocationLayer (). // this fixture can be rebuilt, thus the layer ID will change
47
- Expects (expectedPkgs , nil ).
269
+ Expects (expectedPkgs , expectedRelationships ).
48
270
TestCataloger (t , NewAuditBinaryCataloger ())
49
271
}
50
272
0 commit comments