6
6
"testing"
7
7
"time"
8
8
9
+ "github.com/aquasecurity/fanal/artifact"
10
+
9
11
depTypes "github.com/aquasecurity/go-dep-parser/pkg/types"
10
12
"golang.org/x/xerrors"
11
13
@@ -15,6 +17,7 @@ import (
15
17
16
18
_ "github.com/aquasecurity/fanal/analyzer/command/apk"
17
19
_ "github.com/aquasecurity/fanal/analyzer/library/composer"
20
+ _ "github.com/aquasecurity/fanal/analyzer/library/pipenv"
18
21
_ "github.com/aquasecurity/fanal/analyzer/os/alpine"
19
22
_ "github.com/aquasecurity/fanal/analyzer/os/debian"
20
23
_ "github.com/aquasecurity/fanal/analyzer/os/ubuntu"
@@ -29,7 +32,7 @@ import (
29
32
30
33
func TestArtifact_Inspect (t * testing.T ) {
31
34
type args struct {
32
- ctx context. Context
35
+ inspectOption artifact. InspectOption
33
36
}
34
37
tests := []struct {
35
38
name string
@@ -203,6 +206,132 @@ func TestArtifact_Inspect(t *testing.T) {
203
206
},
204
207
},
205
208
},
209
+ {
210
+ name : "happy path: include a fake lock file" ,
211
+ imagePath : "../../test/testdata/fake-lockfile.tar.gz" ,
212
+ args : args {
213
+ inspectOption : artifact.InspectOption {
214
+ SkipDirectories : []string {"/dep/" },
215
+ },
216
+ },
217
+ missingBlobsExpectation : cache.ArtifactCacheMissingBlobsExpectation {
218
+ Args : cache.ArtifactCacheMissingBlobsArgs {
219
+ ArtifactID : "sha256:c4a9737d9fb3671d19691e767bd4ff04f1185e45c6256462af82127703a05904" ,
220
+ BlobIDs : []string {
221
+ "sha256:de1602ca36c9aa319d4bff5df192859c300d0c66975a1762d4564c145d0c5bd1" ,
222
+ "sha256:1d3b68b6972f1721420b414849e7a08ed732fe05a89427296ffa3b89d885f372" ,
223
+ "sha256:5f4707793820b85c490763fc4e0b344015825f86e3500357b0422e218db4f6a7" ,
224
+ "sha256:f93dc29b4a9e546654f3d3c3e874fe21009a0862be3e1bea1ebd7dcc955e137a" ,
225
+ },
226
+ },
227
+ Returns : cache.ArtifactCacheMissingBlobsReturns {
228
+ MissingBlobIDs : []string {
229
+ "sha256:de1602ca36c9aa319d4bff5df192859c300d0c66975a1762d4564c145d0c5bd1" ,
230
+ "sha256:1d3b68b6972f1721420b414849e7a08ed732fe05a89427296ffa3b89d885f372" ,
231
+ "sha256:5f4707793820b85c490763fc4e0b344015825f86e3500357b0422e218db4f6a7" ,
232
+ "sha256:f93dc29b4a9e546654f3d3c3e874fe21009a0862be3e1bea1ebd7dcc955e137a" ,
233
+ },
234
+ },
235
+ },
236
+ putBlobExpectations : []cache.ArtifactCachePutBlobExpectation {
237
+ {
238
+ Args : cache.ArtifactCachePutBlobArgs {
239
+ BlobID : "sha256:de1602ca36c9aa319d4bff5df192859c300d0c66975a1762d4564c145d0c5bd1" ,
240
+ BlobInfo : types.BlobInfo {
241
+ SchemaVersion : 1 ,
242
+ Digest : "" ,
243
+ DiffID : "sha256:de1602ca36c9aa319d4bff5df192859c300d0c66975a1762d4564c145d0c5bd1" ,
244
+ OS : & types.OS {Family : "debian" , Name : "10.1" },
245
+ PackageInfos : []types.PackageInfo {
246
+ {
247
+ FilePath : "var/lib/dpkg/status.d/base" ,
248
+ Packages : []types.Package {
249
+ {Name : "base-files" , Version : "10.3+deb10u1" , SrcName : "base-files" , SrcVersion : "10.3+deb10u1" },
250
+ },
251
+ },
252
+ {
253
+ FilePath : "var/lib/dpkg/status.d/netbase" ,
254
+ Packages : []types.Package {
255
+ {Name : "netbase" , Version : "5.6" , SrcName : "netbase" , SrcVersion : "5.6" },
256
+ },
257
+ },
258
+ {
259
+ FilePath : "var/lib/dpkg/status.d/tzdata" ,
260
+ Packages : []types.Package {
261
+ {Name : "tzdata" , Version : "2019b-0+deb10u1" , SrcName : "tzdata" , SrcVersion : "2019b-0+deb10u1" },
262
+ },
263
+ },
264
+ },
265
+ },
266
+ },
267
+ },
268
+ {
269
+ Args : cache.ArtifactCachePutBlobArgs {
270
+ BlobID : "sha256:1d3b68b6972f1721420b414849e7a08ed732fe05a89427296ffa3b89d885f372" ,
271
+ BlobInfo : types.BlobInfo {
272
+ SchemaVersion : 1 ,
273
+ Digest : "" ,
274
+ DiffID : "sha256:1d3b68b6972f1721420b414849e7a08ed732fe05a89427296ffa3b89d885f372" ,
275
+ PackageInfos : []types.PackageInfo {
276
+ {
277
+ FilePath : "var/lib/dpkg/status.d/libc6" ,
278
+ Packages : []types.Package {{Name : "libc6" , Version : "2.28-10" , SrcName : "glibc" , SrcVersion : "2.28-10" }},
279
+ },
280
+ {
281
+ FilePath : "var/lib/dpkg/status.d/libssl1" ,
282
+ Packages : []types.Package {
283
+ {Name : "libssl1.1" , Version : "1.1.1d-0+deb10u1" , SrcName : "openssl" , SrcVersion : "1.1.1d-0+deb10u1" },
284
+ },
285
+ },
286
+ {
287
+ FilePath : "var/lib/dpkg/status.d/openssl" ,
288
+ Packages : []types.Package {
289
+ {Name : "openssl" , Version : "1.1.1d-0+deb10u1" , SrcName : "openssl" , SrcVersion : "1.1.1d-0+deb10u1" },
290
+ },
291
+ },
292
+ },
293
+ },
294
+ },
295
+ },
296
+ {
297
+ Args : cache.ArtifactCachePutBlobArgs {
298
+ BlobID : "sha256:5f4707793820b85c490763fc4e0b344015825f86e3500357b0422e218db4f6a7" ,
299
+ BlobInfo : types.BlobInfo {
300
+ SchemaVersion : 1 ,
301
+ Digest : "" ,
302
+ DiffID : "sha256:5f4707793820b85c490763fc4e0b344015825f86e3500357b0422e218db4f6a7" ,
303
+ Applications : []types.Application {{Type : "pipenv" , FilePath : "app/Pipfile.lock" ,
304
+ Libraries : []types.LibraryInfo {
305
+ {Library : depTypes.Library {Name : "pyyaml" , Version : "5.3.1" }},
306
+ },
307
+ }},
308
+ OpaqueDirs : []string {"app/" },
309
+ },
310
+ },
311
+ },
312
+ {
313
+ Args : cache.ArtifactCachePutBlobArgs {
314
+ BlobID : "sha256:f93dc29b4a9e546654f3d3c3e874fe21009a0862be3e1bea1ebd7dcc955e137a" ,
315
+ BlobInfo : types.BlobInfo {
316
+ SchemaVersion : 1 ,
317
+ Digest : "" ,
318
+ DiffID : "sha256:f93dc29b4a9e546654f3d3c3e874fe21009a0862be3e1bea1ebd7dcc955e137a" ,
319
+ OpaqueDirs : []string {"dep/" },
320
+ },
321
+ },
322
+ },
323
+ },
324
+ want : types.ArtifactReference {
325
+ Name : "../../test/testdata/fake-lockfile.tar.gz" ,
326
+ ID : "sha256:c4a9737d9fb3671d19691e767bd4ff04f1185e45c6256462af82127703a05904" ,
327
+ BlobIDs : []string {
328
+ "sha256:de1602ca36c9aa319d4bff5df192859c300d0c66975a1762d4564c145d0c5bd1" ,
329
+ "sha256:1d3b68b6972f1721420b414849e7a08ed732fe05a89427296ffa3b89d885f372" ,
330
+ "sha256:5f4707793820b85c490763fc4e0b344015825f86e3500357b0422e218db4f6a7" ,
331
+ "sha256:f93dc29b4a9e546654f3d3c3e874fe21009a0862be3e1bea1ebd7dcc955e137a" ,
332
+ },
333
+ },
334
+ },
206
335
{
207
336
name : "sad path, MissingBlobs returns an error" ,
208
337
imagePath : "../../test/testdata/alpine-311.tar.gz" ,
@@ -363,7 +492,7 @@ func TestArtifact_Inspect(t *testing.T) {
363
492
require .NoError (t , err )
364
493
365
494
a := image2 .NewArtifact (img , mockCache )
366
- got , err := a .Inspect (context .Background ())
495
+ got , err := a .Inspect (context .Background (), tt . args . inspectOption )
367
496
if tt .wantErr != "" {
368
497
require .NotNil (t , err )
369
498
assert .Contains (t , err .Error (), tt .wantErr , tt .name )
0 commit comments