|
| 1 | +/* |
| 2 | + * © 2024 Snyk Limited All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package sbom |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + cdx "github.com/CycloneDX/cyclonedx-go" |
| 23 | + "github.com/spdx/tools-golang/spdx" |
| 24 | + "github.com/stretchr/testify/assert" |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | +) |
| 27 | + |
| 28 | +func TestAddParlayWatermark_CycloneDX(t *testing.T) { |
| 29 | + doc, err := DecodeSBOMDocument([]byte(`{ |
| 30 | + "bomFormat": "CycloneDX", |
| 31 | + "specVersion": "1.6" |
| 32 | + }`)) |
| 33 | + require.NoError(t, err) |
| 34 | + |
| 35 | + AddParlayWatermark(doc, "parlay", "0.0.0") |
| 36 | + |
| 37 | + bom, ok := doc.BOM.(*cdx.BOM) |
| 38 | + require.True(t, ok) |
| 39 | + |
| 40 | + require.NotNil(t, bom.Metadata.Tools.Components) |
| 41 | + require.Len(t, *bom.Metadata.Tools.Components, 1) |
| 42 | + tool := (*bom.Metadata.Tools.Components)[0] |
| 43 | + assert.Equal(t, "application", string(tool.Type)) |
| 44 | + assert.Equal(t, "parlay", tool.Name) |
| 45 | + assert.Equal(t, "0.0.0", tool.Version) |
| 46 | + assert.Equal(t, "Snyk", tool.Publisher) |
| 47 | +} |
| 48 | + |
| 49 | +func TestAddParlayWatermark_SPDX(t *testing.T) { |
| 50 | + doc, err := DecodeSBOMDocument([]byte(`{ |
| 51 | + "spdxVersion": "SPDX-2.3", |
| 52 | + "SPDXID": "SPDXRef-DOCUMENT" |
| 53 | + }`)) |
| 54 | + require.NoError(t, err) |
| 55 | + |
| 56 | + AddParlayWatermark(doc, "parlay", "0.0.0") |
| 57 | + |
| 58 | + bom, ok := doc.BOM.(*spdx.Document) |
| 59 | + require.True(t, ok) |
| 60 | + |
| 61 | + assert.Contains(t, bom.CreationInfo.Creators, spdx.Creator{Creator: "parlay", CreatorType: "Tool"}) |
| 62 | +} |
0 commit comments