Skip to content

Commit

Permalink
Add jasrunner_cves tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guyshe-jfrog committed Dec 7, 2023
1 parent cf9deab commit 17ca3fe
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions xray/commands/scan/jasrunner_cves_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package scan

import (
"os"
"testing"

rtutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit/jas"
"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/stretchr/testify/assert"
)

func TestGetExtendedScanResults_AnalyzerManagerDoesntExist(t *testing.T) {
tmpDir, err := fileutils.CreateTempDir()
defer func() {
assert.NoError(t, fileutils.RemoveTempDir(tmpDir))
}()
assert.NoError(t, err)
assert.NoError(t, os.Setenv(coreutils.HomeDir, tmpDir))
defer func() {
assert.NoError(t, os.Unsetenv(coreutils.HomeDir))
}()
scanResults := &utils.Results{ScaResults: []utils.ScaScanResult{{Technology: coreutils.Yarn, XrayResults: jas.FakeBasicXrayResults}}, ExtendedScanResults: &utils.ExtendedScanResults{}}
err = runJasScannersAndSetResults(scanResults, []string{"CVE-12345", "CVE-54321"}, &jas.FakeServerDetails, nil, "", false)
// Expect error:
assert.Error(t, err)
}

func TestGetExtendedScanResults_ServerNotValid(t *testing.T) {
scanResults := &utils.Results{ScaResults: []utils.ScaScanResult{{Technology: coreutils.Pip, XrayResults: jas.FakeBasicXrayResults}}, ExtendedScanResults: &utils.ExtendedScanResults{}}
err := runJasScannersAndSetResults(scanResults, []string{"CVE-12345", "CVE-54321"}, nil, nil, "", false)
assert.NoError(t, err)
}

func TestGetExtendedScanResults_AnalyzerManagerReturnsError(t *testing.T) {
assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded())

scanResults := &utils.Results{ScaResults: []utils.ScaScanResult{{Technology: coreutils.Yarn, XrayResults: jas.FakeBasicXrayResults}}, ExtendedScanResults: &utils.ExtendedScanResults{}}
err := runJasScannersAndSetResults(scanResults, []string{"CVE-12345", "CVE-54321"}, &jas.FakeServerDetails, nil, "", false)

// Expect error:
assert.ErrorContains(t, err, "failed to run Applicability scan")
}

0 comments on commit 17ca3fe

Please sign in to comment.