mirror of
https://github.com/safedep/vet.git
synced 2025-12-10 12:07:30 -06:00
fix: tests, common pkgManifest causing issues due to multiple packages
This commit is contained in:
parent
5840ebd227
commit
9e9abdd162
@ -207,7 +207,6 @@ func TestMalwareAnalyzerDecision(t *testing.T) {
|
||||
|
||||
func TestMalwarePolicyViolationTrigger(t *testing.T) {
|
||||
pkgDetail := models.NewPackageDetail(models.EcosystemNpm, "test", "1.0.0")
|
||||
pkgManifest := models.NewPackageManifestFromLocal("test", models.EcosystemNpm)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
@ -217,18 +216,17 @@ func TestMalwarePolicyViolationTrigger(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "no malware analysis result",
|
||||
expectedPolicyViolation: false,
|
||||
config: MalwareAnalyzerConfig{},
|
||||
pkg: &models.Package{
|
||||
Manifest: pkgManifest,
|
||||
PackageDetails: pkgDetail,
|
||||
},
|
||||
expectedPolicyViolation: false,
|
||||
},
|
||||
{
|
||||
name: "when malware with verification record",
|
||||
expectedPolicyViolation: true,
|
||||
config: MalwareAnalyzerConfig{},
|
||||
pkg: &models.Package{
|
||||
Manifest: pkgManifest,
|
||||
PackageDetails: pkgDetail,
|
||||
MalwareAnalysis: &models.MalwareAnalysisResult{
|
||||
Report: &malysisv1.Report{
|
||||
@ -241,13 +239,12 @@ func TestMalwarePolicyViolationTrigger(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedPolicyViolation: true,
|
||||
},
|
||||
{
|
||||
name: "when malware without verification record",
|
||||
expectedPolicyViolation: false,
|
||||
config: MalwareAnalyzerConfig{},
|
||||
pkg: &models.Package{
|
||||
Manifest: pkgManifest,
|
||||
PackageDetails: pkgDetail,
|
||||
MalwareAnalysis: &models.MalwareAnalysisResult{
|
||||
Report: &malysisv1.Report{
|
||||
@ -257,13 +254,12 @@ func TestMalwarePolicyViolationTrigger(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedPolicyViolation: false,
|
||||
},
|
||||
{
|
||||
name: "when malware without verification record and trusted analysis",
|
||||
expectedPolicyViolation: true,
|
||||
config: MalwareAnalyzerConfig{TrustAutomatedAnalysis: true},
|
||||
pkg: &models.Package{
|
||||
Manifest: pkgManifest,
|
||||
PackageDetails: pkgDetail,
|
||||
MalwareAnalysis: &models.MalwareAnalysisResult{
|
||||
Report: &malysisv1.Report{
|
||||
@ -274,13 +270,12 @@ func TestMalwarePolicyViolationTrigger(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedPolicyViolation: true,
|
||||
},
|
||||
{
|
||||
name: "when malware without verification record and trusted analysis with low confidence",
|
||||
expectedPolicyViolation: false,
|
||||
config: MalwareAnalyzerConfig{TrustAutomatedAnalysis: true},
|
||||
pkg: &models.Package{
|
||||
Manifest: pkgManifest,
|
||||
PackageDetails: pkgDetail,
|
||||
MalwareAnalysis: &models.MalwareAnalysisResult{
|
||||
Report: &malysisv1.Report{
|
||||
@ -291,7 +286,6 @@ func TestMalwarePolicyViolationTrigger(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedPolicyViolation: false,
|
||||
},
|
||||
}
|
||||
|
||||
@ -300,10 +294,17 @@ func TestMalwarePolicyViolationTrigger(t *testing.T) {
|
||||
a, err := NewMalwareAnalyzer(tc.config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
tc.pkg.Manifest.Packages = append(tc.pkg.Manifest.Packages, tc.pkg)
|
||||
pkgManifest := models.NewPackageManifestFromLocal("test", models.EcosystemNpm)
|
||||
|
||||
// add this package in the manifest
|
||||
pkgManifest.Packages = append(pkgManifest.Packages, tc.pkg)
|
||||
tc.pkg.Manifest = pkgManifest
|
||||
|
||||
// verify only one package for testing policy violation
|
||||
assert.Equal(t, len(pkgManifest.Packages), 1)
|
||||
|
||||
policyViolation := false
|
||||
err = a.Analyze(tc.pkg.Manifest, func(event *AnalyzerEvent) error {
|
||||
err = a.Analyze(pkgManifest, func(event *AnalyzerEvent) error {
|
||||
if event.Type == ET_FilterExpressionMatched {
|
||||
policyViolation = true
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user