fix: use "contents" field and remove "fullText" license field (#3857)

---------
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
Christopher Angelo Phillips
2025-05-05 21:40:09 +00:00
committed by GitHub
parent 6db60c5975
commit 1ba1186410
15 changed files with 64 additions and 40 deletions
+4 -5
View File
@@ -27,17 +27,16 @@ var _ sort.Interface = (*Licenses)(nil)
// of where a license was declared/concluded for a given package
// If a license is given as it's full text in the metadata rather than it's value or SPDX expression
// The FullText field is used to represent this data
// The Contents field is used to represent this data
// A Concluded License type is the license the SBOM creator believes governs the package (human crafted or altered SBOM)
// The Declared License is what the authors of a project believe govern the package. This is the default type syft declares.
type License struct {
SPDXExpression string
Value string
FullText string
Type license.Type
Contents string
URLs []string `hash:"ignore"`
Locations file.LocationSet `hash:"ignore"`
Contents string `hash:"ignore"` // The optional binary contents of the license file
}
type Licenses []License
@@ -93,7 +92,7 @@ func NewLicenseFromType(value string, t license.Type) License {
if fullText != "" {
return License{
FullText: fullText,
Contents: fullText,
Type: t,
Locations: file.NewLocationSet(),
}
@@ -180,7 +179,7 @@ func NewLicenseFromFields(value, url string, location *file.Location) License {
}
func (s License) Empty() bool {
return s.Value == "" && s.SPDXExpression == "" && s.FullText == ""
return s.Value == "" && s.SPDXExpression == "" && s.Contents == ""
}
// Merge two licenses into a new license object. If the merge is not possible due to unmergeable fields
+26
View File
@@ -1,6 +1,7 @@
package pkg
import (
"os"
"testing"
"github.com/google/go-cmp/cmp"
@@ -125,6 +126,23 @@ func TestLicenseSet_Add(t *testing.T) {
},
},
},
{
name: "licenses that are unknown with different contents can exist in the same set",
licenses: []License{
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/nvidia-software-and-cuda-supplement")),
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/apache-license-2.0")),
},
want: []License{
{
Contents: readFileAsString("../../internal/licenses/test-fixtures/apache-license-2.0"),
Type: license.Declared,
},
{
Contents: readFileAsString("../../internal/licenses/test-fixtures/nvidia-software-and-cuda-supplement"),
Type: license.Declared,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -160,3 +178,11 @@ func defaultLicenseComparer(x, y License) bool {
},
))
}
func readFileAsString(filepath string) string {
data, err := os.ReadFile(filepath)
if err != nil {
panic(err)
}
return string(data)
}
+1 -1
View File
@@ -240,7 +240,7 @@ func TestFullText(t *testing.T) {
want: License{
Value: "",
Type: license.Declared,
FullText: fullText,
Contents: fullText,
},
},
}