From 27d0fd4f8789280a2c6eedb20860fca4b2417712 Mon Sep 17 00:00:00 2001 From: Teodora Sandu Date: Mon, 10 Jun 2024 15:21:08 +0100 Subject: [PATCH] fix: store bundle hash for ai fix --- infrastructure/code/code.go | 1 + infrastructure/code/code_test.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/infrastructure/code/code.go b/infrastructure/code/code.go index b068ca4db..3a34e776e 100644 --- a/infrastructure/code/code.go +++ b/infrastructure/code/code.go @@ -409,6 +409,7 @@ func (sc *Scanner) UploadAndAnalyzeWithIgnores(ctx context.Context, if err != nil { return []snyk.Issue{}, err } + sc.BundleHashes[path] = bundleHash converter := SarifConverter{sarif: *sarif, c: sc.c} issues, err = converter.toIssues(path) diff --git a/infrastructure/code/code_test.go b/infrastructure/code/code_test.go index c10e83033..0d855719f 100644 --- a/infrastructure/code/code_test.go +++ b/infrastructure/code/code_test.go @@ -400,6 +400,7 @@ func TestUploadAndAnalyzeWithIgnores(t *testing.T) { scanner := New( NewBundler(c, snykCodeMock, NewCodeInstrumentor()), + &snyk_api.FakeApiClient{CodeEnabled: true}, newTestCodeErrorReporter(), ux2.NewTestAnalytics(c), @@ -408,6 +409,7 @@ func TestUploadAndAnalyzeWithIgnores(t *testing.T) { fakeCodeScanner, ) issues, _ := scanner.UploadAndAnalyzeWithIgnores(context.Background(), "", sliceToChannel(files), map[string]bool{}) + assert.True(t, fakeCodeScanner.UploadAndAnalyzeWasCalled) assert.False(t, issues[0].IsIgnored) assert.Nil(t, issues[0].IgnoreDetails) @@ -417,6 +419,10 @@ func TestUploadAndAnalyzeWithIgnores(t *testing.T) { assert.Equal(t, "13 days", issues[1].IgnoreDetails.Expiration) assert.Equal(t, 2024, issues[1].IgnoreDetails.IgnoredOn.Year()) assert.Equal(t, "Neil M", issues[1].IgnoreDetails.IgnoredBy) + + // verify that bundle hash has been saved + assert.Equal(t, 1, len(scanner.BundleHashes)) + assert.Equal(t, snykCodeMock.Options.bundleHash, scanner.BundleHashes[path]) } func Test_Scan(t *testing.T) {