@@ -260,6 +260,89 @@ func TestScanArchive(t *testing.T) {
260260 }
261261}
262262
263+ func extractError (e error ) error {
264+ if strings .Contains (e .Error (), "not a valid gzip archive" ) {
265+ return nil
266+ }
267+ return e
268+ }
269+
270+ func TestScanInvalidArchive (t * testing.T ) {
271+ t .Parallel ()
272+ ctx := slogtest .Context (t )
273+ clog .FromContext (ctx ).With ("test" , "scan_archive" )
274+
275+ var out bytes.Buffer
276+ r , err := render .New ("json" , & out )
277+ if err != nil {
278+ t .Fatalf ("render: %v" , err )
279+ }
280+
281+ rfs := []fs.FS {rules .FS , thirdparty .FS }
282+ yrs , err := CachedRules (ctx , rfs )
283+ if err != nil {
284+ t .Fatalf ("rules: %v" , err )
285+ }
286+
287+ mc := malcontent.Config {
288+ Concurrency : runtime .NumCPU (),
289+ ExitExtraction : true ,
290+ IgnoreSelf : false ,
291+ MinFileRisk : 0 ,
292+ MinRisk : 0 ,
293+ Renderer : r ,
294+ Rules : yrs ,
295+ ScanPaths : []string {"testdata/joblib_0.9.4.dev0_compressed_cache_size_pickle_py35_np19.gz" },
296+ }
297+ _ , err = Scan (ctx , mc )
298+ err = extractError (err )
299+ if err != nil {
300+ t .Fatal (err )
301+ }
302+ }
303+
304+ func TestScanInvalidArchiveIgnore (t * testing.T ) {
305+ t .Parallel ()
306+ ctx := slogtest .Context (t )
307+ clog .FromContext (ctx ).With ("test" , "scan_archive" )
308+
309+ var out bytes.Buffer
310+ r , err := render .New ("json" , & out )
311+ if err != nil {
312+ t .Fatalf ("render: %v" , err )
313+ }
314+
315+ rfs := []fs.FS {rules .FS , thirdparty .FS }
316+ yrs , err := CachedRules (ctx , rfs )
317+ if err != nil {
318+ t .Fatalf ("rules: %v" , err )
319+ }
320+
321+ mc := malcontent.Config {
322+ Concurrency : runtime .NumCPU (),
323+ ExitExtraction : false ,
324+ IgnoreSelf : false ,
325+ MinFileRisk : 0 ,
326+ MinRisk : 0 ,
327+ Renderer : r ,
328+ Rules : yrs ,
329+ ScanPaths : []string {"testdata/joblib_0.9.4.dev0_compressed_cache_size_pickle_py35_np19.gz" },
330+ }
331+ res , err := Scan (ctx , mc )
332+ if err != nil {
333+ t .Fatal (err )
334+ }
335+ if err := r .Full (ctx , nil , res ); err != nil {
336+ t .Fatalf ("full: %v" , err )
337+ }
338+
339+ got := out .String ()
340+ want := "{}\n "
341+ if diff := cmp .Diff (want , got ); diff != "" {
342+ t .Errorf ("output mismatch: (-want +got):\n %s" , diff )
343+ }
344+ }
345+
263346func TestGetExt (t * testing.T ) {
264347 tests := []struct {
265348 path string
0 commit comments