Skip to content

Commit

Permalink
Fixes anchore#1179 Deprecated SPDX license (anchore#1263)
Browse files Browse the repository at this point in the history
  • Loading branch information
vargenau authored Oct 14, 2022
1 parent f984843 commit 33c845c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 65 deletions.
72 changes: 36 additions & 36 deletions internal/spdxlicense/generate/generate_license_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ func TestReplaceDeprecatedLicenses(t *testing.T) {
}

expected := map[string]string{
"abc-1": "ABC-1.0-Only",
"abc-1-only": "ABC-1.0-Only",
"abc-1.0": "ABC-1.0-Only",
"abc-1.0.0": "ABC-1.0-Only",
"abc-1.0-only": "ABC-1.0-Only",
"abc-1.0.0-only": "ABC-1.0-Only",
"abc-1+": "ABC-1.0-Or-later",
"abc-1.0+": "ABC-1.0-Or-later",
"abc-1.0.0+": "ABC-1.0-Or-later",
"abc-1-or-later": "ABC-1.0-Or-later",
"abc-1.0-or-later": "ABC-1.0-Or-later",
"abc-1.0.0-or-later": "ABC-1.0-Or-later",
"abc-1": "ABC-1.0-only",
"abc-1-only": "ABC-1.0-only",
"abc-1.0": "ABC-1.0-only",
"abc-1.0.0": "ABC-1.0-only",
"abc-1.0-only": "ABC-1.0-only",
"abc-1.0.0-only": "ABC-1.0-only",
"abc-1+": "ABC-1.0-or-later",
"abc-1.0+": "ABC-1.0-or-later",
"abc-1.0.0+": "ABC-1.0-or-later",
"abc-1-or-later": "ABC-1.0-or-later",
"abc-1.0-or-later": "ABC-1.0-or-later",
"abc-1.0.0-or-later": "ABC-1.0-or-later",
"duh-1": "Duh-1.0",
"duh-1.0": "Duh-1.0",
"duh-1.0.0": "Duh-1.0",
Expand Down Expand Up @@ -79,22 +79,22 @@ func Test_processSPDXLicense(t *testing.T) {
"afl-3.0": "AFL-3.0",
"afl-3.0.0": "AFL-3.0",
"afmparse": "Afmparse",
"agpl-1": "AGPL-1.0",
"agpl-1": "AGPL-1.0-only",
"agpl-1-only": "AGPL-1.0-only",
"agpl-1-or-later": "AGPL-1.0-or-later",
"agpl-1.0": "AGPL-1.0",
"agpl-1.0": "AGPL-1.0-only",
"agpl-1.0-only": "AGPL-1.0-only",
"agpl-1.0-or-later": "AGPL-1.0-or-later",
"agpl-1.0.0": "AGPL-1.0",
"agpl-1.0.0": "AGPL-1.0-only",
"agpl-1.0.0-only": "AGPL-1.0-only",
"agpl-1.0.0-or-later": "AGPL-1.0-or-later",
"agpl-3": "AGPL-3.0",
"agpl-3": "AGPL-3.0-only",
"agpl-3-only": "AGPL-3.0-only",
"agpl-3-or-later": "AGPL-3.0-or-later",
"agpl-3.0": "AGPL-3.0",
"agpl-3.0": "AGPL-3.0-only",
"agpl-3.0-only": "AGPL-3.0-only",
"agpl-3.0-or-later": "AGPL-3.0-or-later",
"agpl-3.0.0": "AGPL-3.0",
"agpl-3.0.0": "AGPL-3.0-only",
"agpl-3.0.0-only": "AGPL-3.0-only",
"agpl-3.0.0-or-later": "AGPL-3.0-or-later",
"aladdin": "Aladdin",
Expand Down Expand Up @@ -160,18 +160,18 @@ func Test_processSPDXLicense(t *testing.T) {
"bsd-1.0-clause": "BSD-1-Clause",
"bsd-1.0.0-clause": "BSD-1-Clause",
"bsd-2-clause": "BSD-2-Clause",
"bsd-2-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2-clause-netbsd": "BSD-2-Clause",
"bsd-2-clause-patent": "BSD-2-Clause-Patent",
"bsd-2-clause-views": "BSD-2-Clause-Views",
"bsd-2.0-clause": "BSD-2-Clause",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0-clause-views": "BSD-2-Clause-Views",
"bsd-2.0.0-clause": "BSD-2-Clause",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0.0-clause-views": "BSD-2-Clause-Views",
"bsd-3-clause": "BSD-3-Clause",
Expand Down Expand Up @@ -221,9 +221,9 @@ func Test_processSPDXLicense(t *testing.T) {
"busl-1": "BUSL-1.1",
"busl-1.1": "BUSL-1.1",
"busl-1.1.0": "BUSL-1.1",
"bzip2-1": "bzip2-1.0.5",
"bzip2-1.0": "bzip2-1.0.5",
"bzip2-1.0.5": "bzip2-1.0.5",
"bzip2-1": "bzip2-1.0.6",
"bzip2-1.0": "bzip2-1.0.6",
"bzip2-1.0.5": "bzip2-1.0.6",
"bzip2-1.0.6": "bzip2-1.0.6",
"c-uda-1": "C-UDA-1.0",
"c-uda-1.0": "C-UDA-1.0",
Expand Down Expand Up @@ -520,49 +520,49 @@ func Test_processSPDXLicense(t *testing.T) {
"fsfullr": "FSFULLR",
"ftl": "FTL",
"gd": "GD",
"gfdl-1": "GFDL-1.1",
"gfdl-1": "GFDL-1.1-only",
"gfdl-1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1-only": "GFDL-1.1-only",
"gfdl-1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1": "GFDL-1.1",
"gfdl-1.1": "GFDL-1.1-only",
"gfdl-1.1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1-only": "GFDL-1.1-only",
"gfdl-1.1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1.0": "GFDL-1.1",
"gfdl-1.1.0": "GFDL-1.1-only",
"gfdl-1.1.0-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1.0-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1.0-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1.0-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1.0-only": "GFDL-1.1-only",
"gfdl-1.1.0-or-later": "GFDL-1.1-or-later",
"gfdl-1.2": "GFDL-1.2",
"gfdl-1.2": "GFDL-1.2-only",
"gfdl-1.2-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2-only": "GFDL-1.2-only",
"gfdl-1.2-or-later": "GFDL-1.2-or-later",
"gfdl-1.2.0": "GFDL-1.2",
"gfdl-1.2.0": "GFDL-1.2-only",
"gfdl-1.2.0-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2.0-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2.0-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2.0-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2.0-only": "GFDL-1.2-only",
"gfdl-1.2.0-or-later": "GFDL-1.2-or-later",
"gfdl-1.3": "GFDL-1.3",
"gfdl-1.3": "GFDL-1.3-only",
"gfdl-1.3-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3-no-invariants-only": "GFDL-1.3-no-invariants-only",
"gfdl-1.3-no-invariants-or-later": "GFDL-1.3-no-invariants-or-later",
"gfdl-1.3-only": "GFDL-1.3-only",
"gfdl-1.3-or-later": "GFDL-1.3-or-later",
"gfdl-1.3.0": "GFDL-1.3",
"gfdl-1.3.0": "GFDL-1.3-only",
"gfdl-1.3.0-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3.0-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3.0-no-invariants-only": "GFDL-1.3-no-invariants-only",
Expand Down Expand Up @@ -686,11 +686,11 @@ func Test_processSPDXLicense(t *testing.T) {
"lgpl-2.0.0-only": "LGPL-2.0-only",
"lgpl-2.0.0-or-later": "LGPL-2.0-or-later",
"lgpl-2.1": "LGPL-2.1-only",
"lgpl-2.1+": "LGPL-2.1+",
"lgpl-2.1+": "LGPL-2.1-or-later",
"lgpl-2.1-only": "LGPL-2.1-only",
"lgpl-2.1-or-later": "LGPL-2.1-or-later",
"lgpl-2.1.0": "LGPL-2.1-only",
"lgpl-2.1.0+": "LGPL-2.1+",
"lgpl-2.1.0+": "LGPL-2.1-or-later",
"lgpl-2.1.0-only": "LGPL-2.1-only",
"lgpl-2.1.0-or-later": "LGPL-2.1-or-later",
"lgpl-3": "LGPL-3.0-only",
Expand Down
19 changes: 18 additions & 1 deletion internal/spdxlicense/generate/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ func (l License) canReplace(other License) bool {
return false
}

// We want to replace deprecated licenses with non-deprecated counterparts
// For more information, see: https://github.com/spdx/license-list-XML/issues/1676
if other.Deprecated {
switch {
case strings.ReplaceAll(l.ID, "-only", "") == other.ID:
return true
case strings.ReplaceAll(l.ID, "-or-later", "+") == other.ID:
return true
case l.ID == "BSD-2-Clause" && other.ID == "BSD-2-Clause-NetBSD":
return true
case l.ID == "BSD-2-Clause-Views" && other.ID == "BSD-2-Clause-FreeBSD":
return true
case l.ID == "bzip2-1.0.6" && other.ID == "bzip2-1.0.5":
return true
}
}

if l.Name != other.Name {
return false
}
Expand All @@ -43,7 +60,7 @@ func (l License) canReplace(other License) bool {
}
}

return l.ID != other.ID
return l.ID == other.ID
}

func (ll LicenseList) findReplacementLicense(deprecated License) *License {
Expand Down
8 changes: 5 additions & 3 deletions internal/spdxlicense/generate/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
}

license2 = License{
ID: "ABC-1.0-Or-later",
ID: "ABC-1.0-or-later",
Name: "The ABC License 1.0",
}

Expand All @@ -26,7 +26,7 @@ var (
}

license4 = License{
ID: "ABC-1.0-Only",
ID: "ABC-1.0-only",
Name: "The ABC License 1.0 Only",
}
license5 = License{
Expand All @@ -53,7 +53,9 @@ func TestLicense_canReplace(t *testing.T) {
}

for _, tt := range tests {
assert.Equal(t, tt.expected, tt.l1.canReplace(tt.l2))
t.Run(tt.l1.ID+" - "+tt.l2.ID, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.l1.canReplace(tt.l2))
})
}
}

Expand Down
Loading

0 comments on commit 33c845c

Please sign in to comment.