@@ -3,6 +3,7 @@ package normalize
33import (
44 "bytes"
55 "encoding/json"
6+ "slices"
67 "testing"
78
89 cdx "github.com/CycloneDX/cyclonedx-go"
@@ -326,7 +327,7 @@ func TestInvalidComponentTypeValidation(t *testing.T) {
326327
327328// TestSchemaBreakers tests various ways to break CycloneDX 1.6 schema validation
328329func TestSchemaBreakers (t * testing.T ) {
329- t .Run ("missing required component name returns error when trying to construct sbom graph" , func (t * testing.T ) {
330+ t .Run ("missing component name defaults to bomRef and does not break graph construction " , func (t * testing.T ) {
330331 bom := & cdx.BOM {
331332 SpecVersion : cdx .SpecVersion1_6 ,
332333 BOMFormat : "CycloneDX" ,
@@ -341,16 +342,29 @@ func TestSchemaBreakers(t *testing.T) {
341342 Components : & []cdx.Component {
342343 {
343344 BOMRef : "pkg:npm/test@1.0.0" ,
344- // Name field is empty - should cause error in graph construction
345- Type : cdx .ComponentTypeLibrary ,
345+ // Name field is empty, so name would be bomRef
346+ Type : cdx .ComponentTypeLibrary ,
347+ Version : "1.0.0" ,
348+ PackageURL : "pkg:npm/test@1.0.0" ,
349+ },
350+ },
351+ Dependencies : & []cdx.Dependency {
352+ {
353+ Ref : "root" ,
354+ Dependencies : & []string {"pkg:npm/test@1.0.0" },
346355 },
347356 },
348357 }
349358
350- // SBOMGraphFromCycloneDX should return error for missing component name
359+ // SBOMGraphFromCycloneDX should handle this gracefully by using bomRef as the name if name is missing
351360 graph , err := SBOMGraphFromCycloneDX (bom , "test-artifact" , "test-source" , false )
352- assert .NotNil (t , err , "Should return error for component with missing name" )
353- assert .Nil (t , graph , "Graph should be nil when error occurs" )
361+ assert .NoError (t , err )
362+
363+ component := slices .Collect (graph .Components ())[0 ]
364+ assert .Equal (t , "pkg:npm/test@1.0.0" , component .Component .Name , "Component name should default to bomRef when name is missing" )
365+
366+ assert .NoError (t , err )
367+ assert .NotNil (t , graph , "Graph should be created even with missing component name (bomRef will be used as name)" )
354368 })
355369
356370 t .Run ("invalid scope value returns error when building sbom graph" , func (t * testing.T ) {
0 commit comments