feat: update licenses to including license content when SPDX expressions are unable to be determined (#3366)

---------
Signed-off-by: HeyeOpenSource <opensource@heye-international.com>
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Co-authored-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
HeyeOpenSource
2025-01-28 18:05:27 +00:00
committed by GitHub
co-authored by Christopher Phillips
parent 58dc43de86
commit f7e767fc25
21 changed files with 3291 additions and 43 deletions
+31 -4
View File
@@ -14,6 +14,7 @@ import (
"strings"
"testing"
"github.com/google/licensecheck"
"github.com/stretchr/testify/require"
"github.com/anchore/syft/internal/licenses"
@@ -70,7 +71,7 @@ func Test_LicenseSearch(t *testing.T) {
localVendorDir := filepath.Join(wd, "test-fixtures", "licenses-vendor")
licenseScanner := licenses.TestingOnlyScanner()
licenseScanner := licenses.NewScanner(licensecheck.Scan, float64(75))
tests := []struct {
name string
@@ -295,7 +296,7 @@ func Test_findVersionPath(t *testing.T) {
func Test_walkDirErrors(t *testing.T) {
resolver := newGoLicenseResolver("", CatalogerConfig{})
_, err := resolver.findLicensesInFS(context.Background(), licenses.TestingOnlyScanner(), "somewhere", badFS{})
_, err := resolver.findLicensesInFS(context.Background(), licenses.NewScanner(licensecheck.Scan, float64(75)), "somewhere", badFS{})
require.Error(t, err)
}
@@ -313,8 +314,7 @@ func Test_noLocalGoModDir(t *testing.T) {
validTmp := t.TempDir()
require.NoError(t, os.MkdirAll(filepath.Join(validTmp, "mod@ver"), 0700|os.ModeDir))
licenseScanner := licenses.TestingOnlyScanner()
licenseScanner := licenses.NewScanner(licensecheck.Scan, float64(75))
tests := []struct {
name string
dir string
@@ -353,3 +353,30 @@ func Test_noLocalGoModDir(t *testing.T) {
})
}
}
func TestLicenseConversion(t *testing.T) {
inputLicenses := []pkg.License{
{
Value: "Apache-2.0",
SPDXExpression: "Apache-2.0",
Type: "concluded",
URLs: nil,
Locations: file.NewLocationSet(file.NewLocation("LICENSE")),
Contents: "",
},
{
Value: "UNKNOWN",
SPDXExpression: "UNKNOWN_4d1cffe420916f2b706300ab63fcafaf35226a0ad3725cb9f95b26036cefae32",
Type: "declared",
URLs: nil,
Locations: file.NewLocationSet(file.NewLocation("LICENSE2")),
Contents: "NVIDIA Software License Agreement and CUDA Supplement to Software License Agreement",
},
}
goLicenses := toGoLicenses(inputLicenses)
result := toPkgLicenses(goLicenses)
require.Equal(t, inputLicenses, result)
}