Skip to content

Commit 6b64f7b

Browse files
committed
Fix empty Target JAS Results
1 parent 898cae8 commit 6b64f7b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

utils/results/common.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ func CheckIfFailBuild(auditResults *SecurityCommandResults) (bool, error) {
7878
}
7979

8080
func checkIfFailBuildConsideringApplicability(target *TargetResults, entitledForJas bool, shouldFailBuild *bool) error {
81+
if target == nil {
82+
log.Debug("checkIfFailBuildConsideringApplicability: target is nil, returning early")
83+
return nil
84+
}
85+
if target.JasResults == nil {
86+
log.Debug(fmt.Sprintf("checkIfFailBuildConsideringApplicability: JasResults is nil for target %s, falling back to check without applicability", target.ScanTarget.Target))
87+
*shouldFailBuild = checkIfFailBuildWithoutConsideringApplicability(target)
88+
return nil
89+
}
90+
8191
jasApplicabilityResults := target.JasResults.GetApplicabilityScanResults()
8292

8393
if target.ScaResults == nil {

utils/results/common_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@ func TestViolationFailBuild(t *testing.T) {
183183
},
184184
expectedResult: false,
185185
},
186+
{
187+
name: "nil JasResults with violations - should fallback to check without applicability",
188+
auditResults: &SecurityCommandResults{
189+
EntitledForJas: true,
190+
Targets: []*TargetResults{
191+
{
192+
ScanTarget: ScanTarget{Target: "test-target"},
193+
ScaResults: &ScaScanResults{
194+
Violations: []services.Violation{
195+
{
196+
Components: map[string]services.Component{"gav://antparent:ant:1.6.5": {}},
197+
ViolationType: utils.ViolationTypeSecurity.String(),
198+
FailBuild: true,
199+
Cves: []services.Cve{{Id: "CVE-2024-1234"}},
200+
Severity: "High",
201+
},
202+
},
203+
},
204+
JasResults: nil,
205+
},
206+
},
207+
},
208+
expectedResult: true, // Should fail because violation has FailBuild=true
209+
},
186210
}
187211

188212
for _, test := range tests {

0 commit comments

Comments
 (0)