forked from anchore/syft
-
Notifications
You must be signed in to change notification settings - Fork 0
Populate SPDX copyrightText from PE binary LegalCopyright field #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/update-copyright-text-in-spdx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
81162a8
Initial plan
Copilot 9d59d39
Add PE copyright support for SPDX generation with tests
Copilot d3b2816
Fix indentation in test file
Copilot 16c94f7
Implementation complete - all checks passed
Copilot d2d3fca
Revert unintended go.mod and go.sum changes
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 0 additions & 4 deletions
4
cmd/syft/internal/test/integration/test-fixtures/image-pkg-coverage/pkgs/go/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,3 @@ | ||
| module github.com/anchore/syft | ||
|
|
||
| go 1.14 | ||
|
|
||
| require ( | ||
| github.com/bmatcuk/doublestar v1.3.1 | ||
| ) | ||
5 changes: 0 additions & 5 deletions
5
cmd/syft/internal/test/integration/test-fixtures/image-sbom-cataloger/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,3 @@ | ||
| module github.com/anchore/syft | ||
|
|
||
| go 1.14 | ||
|
|
||
| require ( | ||
| github.com/anchore/packageurl-go v0.1.1-0.20220428202044-a072fa3cb6d7 | ||
| github.com/bmatcuk/doublestar v1.3.1 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package helpers | ||
|
|
||
| import "github.com/anchore/syft/syft/pkg" | ||
|
|
||
| // Copyright extracts copyright text from package metadata. | ||
| // For PE binaries, it returns the LegalCopyright field from version resources. | ||
| // Returns NOASSERTION if no copyright information is available. | ||
| func Copyright(p pkg.Package) string { | ||
| if hasMetadata(p) { | ||
| switch metadata := p.Metadata.(type) { | ||
| case pkg.PEBinary: | ||
| if copyright, ok := metadata.VersionResources.Get("LegalCopyright"); ok && copyright != "" { | ||
| return copyright | ||
| } | ||
| } | ||
| } | ||
| return NOASSERTION | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package helpers | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/anchore/syft/syft/pkg" | ||
| ) | ||
|
|
||
| func TestCopyright(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| pkg pkg.Package | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "PE binary with LegalCopyright", | ||
| pkg: pkg.Package{ | ||
| Name: "test", | ||
| Metadata: pkg.PEBinary{ | ||
| VersionResources: pkg.KeyValues{ | ||
| {Key: "LegalCopyright", Value: "Copyright (c) 2024 Test Company"}, | ||
| {Key: "ProductName", Value: "Test Product"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: "Copyright (c) 2024 Test Company", | ||
| }, | ||
| { | ||
| name: "PE binary without LegalCopyright", | ||
| pkg: pkg.Package{ | ||
| Name: "test", | ||
| Metadata: pkg.PEBinary{ | ||
| VersionResources: pkg.KeyValues{ | ||
| {Key: "ProductName", Value: "Test Product"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: NOASSERTION, | ||
| }, | ||
| { | ||
| name: "PE binary with empty LegalCopyright", | ||
| pkg: pkg.Package{ | ||
| Name: "test", | ||
| Metadata: pkg.PEBinary{ | ||
| VersionResources: pkg.KeyValues{ | ||
| {Key: "LegalCopyright", Value: ""}, | ||
| {Key: "ProductName", Value: "Test Product"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: NOASSERTION, | ||
| }, | ||
| { | ||
| name: "non-PE binary package", | ||
| pkg: pkg.Package{ | ||
| Name: "test", | ||
| Metadata: pkg.NpmPackage{ | ||
| Name: "test-package", | ||
| }, | ||
| }, | ||
| expected: NOASSERTION, | ||
| }, | ||
| { | ||
| name: "package with no metadata", | ||
| pkg: pkg.Package{ | ||
| Name: "test", | ||
| }, | ||
| expected: NOASSERTION, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := Copyright(tt.pkg) | ||
| assert.Equal(t, tt.expected, result) | ||
| }) | ||
| } | ||
| } |
4 changes: 0 additions & 4 deletions
4
syft/pkg/cataloger/golang/test-fixtures/go-mod-fixtures/one-package/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,3 @@ | ||
| module github.com/anchore/syft | ||
|
|
||
| go 1.14 | ||
|
|
||
| require ( | ||
| github.com/bmatcuk/doublestar v1.3.1 | ||
| ) |
1 change: 0 additions & 1 deletion
1
syft/pkg/cataloger/golang/test-fixtures/go-mod-fixtures/one-package/go.sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +0,0 @@ | ||
| github.com/bmatcuk/doublestar v1.3.1/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
syft/pkg/cataloger/golang/test-fixtures/go-sum-hashes/go.sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +0,0 @@ | ||
| github.com/CycloneDX/cyclonedx-go v0.6.0/go.mod h1:nQCiF4Tvrg5Ieu8qPhYMvzPGMu5I7fANZkrSsJjl5mg= | ||
| github.com/CycloneDX/cyclonedx-go v0.7.0 h1:jNxp8hL7UpcvPDFXjY+Y1ibFtsW+e5zyF9QoSmhK/zg= | ||
| github.com/CycloneDX/cyclonedx-go v0.7.0/go.mod h1:W5Z9w8pTTL+t+yG3PCiFRGlr8PUlE0pGWzKSJbsyXkg= | ||
| github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= | ||
| github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= | ||
| github.com/bradleyjkemp/cupaloy/v2 v2.7.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0= | ||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= | ||
| github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= | ||
| github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= | ||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
| github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't modify the go.mod files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted the go.mod and go.sum changes in commit d2d3fca.