@@ -149,7 +149,7 @@ func TestIsCustomState(t *testing.T) {
149149 }
150150}
151151func TestRunTriageUpdateWithNotFoundCustomState (t * testing.T ) {
152- mockResultsPredicatesWrapper := & mock.ResultsPredicatesMockWrapper {}
152+ mockResultsPredicatesWrapper := & mock.ResultsPredicatesWrapper {}
153153 mockFeatureFlagsWrapper := & mock.FeatureFlagsMockWrapper {}
154154 mockCustomStatesWrapper := & mock.CustomStatesMockWrapper {}
155155 clearFlags ()
@@ -171,7 +171,7 @@ func TestRunTriageUpdateWithNotFoundCustomState(t *testing.T) {
171171}
172172
173173func TestRunTriageUpdateWithCustomState (t * testing.T ) {
174- mockResultsPredicatesWrapper := & mock.ResultsPredicatesMockWrapper {}
174+ mockResultsPredicatesWrapper := & mock.ResultsPredicatesWrapper {}
175175 mockFeatureFlagsWrapper := & mock.FeatureFlagsMockWrapper {}
176176 mockCustomStatesWrapper := & mock.CustomStatesMockWrapper {}
177177 clearFlags ()
@@ -193,7 +193,7 @@ func TestRunTriageUpdateWithCustomState(t *testing.T) {
193193}
194194
195195func TestRunTriageUpdateWithSystemState (t * testing.T ) {
196- mockResultsPredicatesWrapper := & mock.ResultsPredicatesMockWrapper {}
196+ mockResultsPredicatesWrapper := & mock.ResultsPredicatesWrapper {}
197197 mockFeatureFlagsWrapper := & mock.FeatureFlagsMockWrapper {}
198198 mockCustomStatesWrapper := & mock.CustomStatesMockWrapper {}
199199
@@ -339,3 +339,139 @@ func TestDetermineSystemOrCustomState(t *testing.T) {
339339 })
340340 }
341341}
342+
343+ func TestPrepareScaTriagePayload (t * testing.T ) {
344+ tests := []struct {
345+ name string
346+ vulnerabilityDetails []string
347+ comment string
348+ state string
349+ projectId string
350+ expectedError string
351+ }{
352+ {
353+ name : "Valid SCA triage payload" ,
354+ vulnerabilityDetails : []string {
355+ "packageName=lodash" ,
356+ "packageVersion=4.17.20" ,
357+ "packageManager=npm" ,
358+ "vulnerabilityId=CVE-2021-23337" ,
359+ },
360+ comment : "Testing SCA triage" ,
361+ state : "NOT_EXPLOITABLE" ,
362+ projectId : "test-project-123" ,
363+ expectedError : "" ,
364+ },
365+ {
366+ name : "Missing packageName" ,
367+ vulnerabilityDetails : []string {
368+ "packageVersion=4.17.20" ,
369+ "packageManager=npm" ,
370+ "vulnerabilityId=CVE-2021-23337" ,
371+ },
372+ comment : "Testing missing package name" ,
373+ state : "NOT_EXPLOITABLE" ,
374+ projectId : "test-project-123" ,
375+ expectedError : "Package name is required" ,
376+ },
377+ {
378+ name : "Missing packageVersion" ,
379+ vulnerabilityDetails : []string {
380+ "packageName=lodash" ,
381+ "packageManager=npm" ,
382+ "vulnerabilityId=CVE-2021-23337" ,
383+ },
384+ comment : "Testing missing package version" ,
385+ state : "NOT_EXPLOITABLE" ,
386+ projectId : "test-project-123" ,
387+ expectedError : "Package version is required" ,
388+ },
389+ {
390+ name : "Missing packageManager" ,
391+ vulnerabilityDetails : []string {
392+ "packageName=lodash" ,
393+ "packageVersion=4.17.20" ,
394+ "vulnerabilityId=CVE-2021-23337" ,
395+ },
396+ comment : "Testing missing package manager" ,
397+ state : "NOT_EXPLOITABLE" ,
398+ projectId : "test-project-123" ,
399+ expectedError : "Package manager is required" ,
400+ },
401+ {
402+ name : "Invalid vulnerability format - no equals sign" ,
403+ vulnerabilityDetails : []string {
404+ "packageNamelodash" ,
405+ "packageVersion=4.17.20" ,
406+ "packageManager=npm" ,
407+ },
408+ comment : "Testing invalid format" ,
409+ state : "NOT_EXPLOITABLE" ,
410+ projectId : "test-project-123" ,
411+ expectedError : "Invalid vulnerabilities. It should be in a KEY=VALUE format" ,
412+ },
413+ {
414+ name : "Case insensitive package name" ,
415+ vulnerabilityDetails : []string {
416+ "packagename=lodash" ,
417+ "packageversion=4.17.20" ,
418+ "packagemanager=npm" ,
419+ "vulnerabilityId=CVE-2021-23337" ,
420+ },
421+ comment : "Testing case insensitive" ,
422+ state : "CONFIRMED" ,
423+ projectId : "test-project-123" ,
424+ expectedError : "" ,
425+ },
426+ }
427+
428+ for _ , tt := range tests {
429+ tt := tt
430+ t .Run (tt .name , func (t * testing.T ) {
431+ payload , err := prepareScaTriagePayload (tt .vulnerabilityDetails , tt .comment , tt .state , tt .projectId )
432+ if tt .expectedError != "" {
433+ assert .ErrorContains (t , err , tt .expectedError )
434+ } else {
435+ assert .NilError (t , err )
436+ assert .Assert (t , payload != nil , "Expected payload to be non-nil" )
437+ }
438+ })
439+ }
440+ }
441+
442+ func TestRunUpdateTriageCommandForSCA (t * testing.T ) {
443+ execCmdNilAssertion (
444+ t ,
445+ "triage" ,
446+ "update" ,
447+ "--project-id" ,
448+ "MOCK" ,
449+ "--state" ,
450+ "not_exploitable" ,
451+ "--comment" ,
452+ "Testing SCA triage commands." ,
453+ "--scan-type" ,
454+ "sca" ,
455+ "--vulnerabilities" ,
456+ "packageName=lodash,packageVersion=4.17.20,packageManager=npm,vulnerabilityId=CVE-2021-23337" ,
457+ )
458+ }
459+
460+ func TestRunUpdateTriageCommandForSCAWithMissingPackageDetails (t * testing.T ) {
461+ err := execCmdNotNilAssertion (
462+ t ,
463+ "triage" ,
464+ "update" ,
465+ "--project-id" ,
466+ "MOCK" ,
467+ "--state" ,
468+ "not_exploitable" ,
469+ "--comment" ,
470+ "Testing SCA triage with missing details." ,
471+ "--scan-type" ,
472+ "sca" ,
473+ "--vulnerabilities" ,
474+ "packageVersion=4.17.20" ,
475+ )
476+ assert .ErrorContains (t , err , "Package name is required" )
477+ }
0 commit comments