@@ -318,6 +318,60 @@ func TestUnifiedFindingPresenter_CliOutput(t *testing.T) {
318318 snaps .MatchSnapshot (t , buffer .String ())
319319 })
320320
321+ t .Run ("snapshot test with license without instructions" , func (t * testing.T ) {
322+ config := configuration .New ()
323+ buffer := & bytes.Buffer {}
324+ lipgloss .SetColorProfile (termenv .Ascii )
325+
326+ // Create a license finding without instructions
327+ licenseFinding := testapi.FindingData {
328+ Id : util .Ptr (uuid .MustParse ("55555555-5555-5555-5555-555555555555" )),
329+ Type : util .Ptr (testapi .Findings ),
330+ Attributes : & testapi.FindingAttributes {
331+ Title : "Apache-2.0 license" ,
332+ Rating : testapi.Rating {
333+ Severity : testapi .Severity ("medium" ),
334+ },
335+ Problems : func () []testapi.Problem {
336+ var p testapi.Problem
337+ err := p .FromSnykLicenseProblem (testapi.SnykLicenseProblem {
338+ Id : "snyk:lic:npm:test-pkg:Apache-2.0" ,
339+ License : "Apache-2.0" ,
340+ Instructions : []testapi.SnykvulndbLicenseInstructions {}, // No instructions
341+ })
342+ assert .NoError (t , err )
343+ return []testapi.Problem {p }
344+ }(),
345+ },
346+ }
347+
348+ projectResult := & presenters.UnifiedProjectResult {
349+ Findings : []testapi.FindingData {licenseFinding },
350+ Summary : & json_schemas.TestSummary {
351+ Type : "open-source" ,
352+ Path : "test/path" ,
353+ SeverityOrderAsc : []string {"low" , "medium" , "high" , "critical" },
354+ Results : []json_schemas.TestSummaryResult {
355+ {
356+ Severity : "medium" ,
357+ Open : 1 ,
358+ Total : 1 ,
359+ },
360+ },
361+ },
362+ }
363+
364+ presenter := presenters .NewUnifiedFindingsRenderer (
365+ []* presenters.UnifiedProjectResult {projectResult },
366+ config ,
367+ buffer ,
368+ )
369+
370+ err := presenter .RenderTemplate (presenters .DefaultTemplateFiles , presenters .DefaultMimeType )
371+ assert .NoError (t , err )
372+ snaps .MatchSnapshot (t , buffer .String ())
373+ })
374+
321375 // summary shows security only when there are vulnerability findings and no license findings
322376 t .Run ("summary shows only security when no license issues" , func (t * testing.T ) {
323377 config := configuration .New ()
@@ -553,6 +607,52 @@ func TestUnifiedFindingPresenter_LicenseInstructions(t *testing.T) {
553607 assert .NoError (t , err )
554608
555609 out := buffer .String ()
556- assert .Contains (t , out , "Instructions:" )
557- assert .Contains (t , out , "This license requires you to disclose source code changes." )
610+ assert .Contains (t , out , "Legal instructions:" )
611+ assert .Contains (t , out , "○ for LGPL-3.0: This license requires you to disclose source code changes." )
612+ }
613+
614+ // TestUnifiedFindingPresenter_LicenseWithoutInstructions verifies that license findings without instructions don't show the instructions field.
615+ func TestUnifiedFindingPresenter_LicenseWithoutInstructions (t * testing.T ) {
616+ config := configuration .New ()
617+ buffer := & bytes.Buffer {}
618+ lipgloss .SetColorProfile (termenv .Ascii )
619+
620+ licenseFinding := testapi.FindingData {
621+ Id : util .Ptr (uuid .New ()),
622+ Type : util .Ptr (testapi .Findings ),
623+ Attributes : & testapi.FindingAttributes {
624+ Title : "MIT license" ,
625+ Rating : testapi.Rating {
626+ Severity : testapi .Severity ("low" ),
627+ },
628+ Problems : func () []testapi.Problem {
629+ var p testapi.Problem
630+ err := p .FromSnykLicenseProblem (testapi.SnykLicenseProblem {
631+ Id : "snyk:lic:npm:test-pkg:MIT" ,
632+ License : "MIT" ,
633+ Instructions : []testapi.SnykvulndbLicenseInstructions {},
634+ })
635+ assert .NoError (t , err )
636+ return []testapi.Problem {p }
637+ }(),
638+ },
639+ }
640+
641+ projectResult := & presenters.UnifiedProjectResult {
642+ Findings : []testapi.FindingData {licenseFinding },
643+ Summary : & json_schemas.TestSummary {
644+ Type : "open-source" ,
645+ Path : "test/path" ,
646+ SeverityOrderAsc : []string {"low" , "medium" , "high" , "critical" },
647+ Results : []json_schemas.TestSummaryResult {{Severity : "low" , Open : 1 , Total : 1 }},
648+ },
649+ }
650+
651+ presenter := presenters .NewUnifiedFindingsRenderer ([]* presenters.UnifiedProjectResult {projectResult }, config , buffer )
652+ err := presenter .RenderTemplate (presenters .DefaultTemplateFiles , presenters .DefaultMimeType )
653+ assert .NoError (t , err )
654+
655+ out := buffer .String ()
656+ assert .NotContains (t , out , "Legal instructions:" )
657+ assert .Contains (t , out , "MIT license" )
558658}
0 commit comments