Skip to content

Commit

Permalink
fix: drop runtime relationship
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Apr 26, 2024
1 parent 1e1fe20 commit 5e620b0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 29 deletions.
12 changes: 6 additions & 6 deletions pkg/dependency/parser/golang/binary/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,

libs := make([]types.Library, 0, len(info.Deps)+2)
libs = append(libs, []types.Library{
{
// Add the Go version used to build this binary.
Name: "stdlib",
Version: strings.TrimPrefix(info.GoVersion, "go"),
Relationship: types.RelationshipRuntime,
},
{
// Add main module
Name: info.Main.Path,
Expand All @@ -65,6 +59,12 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,
Version: p.checkVersion(info.Main.Path, info.Main.Version),
Relationship: types.RelationshipRoot,
},
{
// Add the Go version used to build this binary.
Name: "stdlib",
Version: strings.TrimPrefix(info.GoVersion, "go"),
Relationship: types.RelationshipDirect, // Considered a direct dependency as the main module depends on the standard packages.
},
}...)

for _, dep := range info.Deps {
Expand Down
30 changes: 15 additions & 15 deletions pkg/dependency/parser/golang/binary/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (

func TestParse(t *testing.T) {
wantLibs := []types.Library{
{
Name: "stdlib",
Version: "1.15.2",
Relationship: types.RelationshipRuntime,
},
{
Name: "github.com/aquasecurity/test",
Version: "",
Relationship: types.RelationshipRoot,
},
{
Name: "stdlib",
Version: "1.15.2",
Relationship: types.RelationshipDirect,
},
{
Name: "github.com/aquasecurity/go-pep440-version",
Version: "v0.0.0-20210121094942-22b2f8951d46",
Expand Down Expand Up @@ -62,16 +62,16 @@ func TestParse(t *testing.T) {
name: "with replace directive",
inputFile: "testdata/replace.elf",
want: []types.Library{
{
Name: "stdlib",
Version: "1.16.4",
Relationship: types.RelationshipRuntime,
},
{
Name: "github.com/ebati/trivy-mod-parse",
Version: "",
Relationship: types.RelationshipRoot,
},
{
Name: "stdlib",
Version: "1.16.4",
Relationship: types.RelationshipDirect,
},
{
Name: "github.com/davecgh/go-spew",
Version: "v1.1.1",
Expand All @@ -86,16 +86,16 @@ func TestParse(t *testing.T) {
name: "with semver main module version",
inputFile: "testdata/semver-main-module-version.macho",
want: []types.Library{
{
Name: "stdlib",
Version: "1.20.6",
Relationship: types.RelationshipRuntime,
},
{
Name: "go.etcd.io/bbolt",
Version: "v1.3.5",
Relationship: types.RelationshipRoot,
},
{
Name: "stdlib",
Version: "1.20.6",
Relationship: types.RelationshipDirect,
},
},
},
{
Expand Down
2 changes: 0 additions & 2 deletions pkg/dependency/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,13 @@ type Relationship int

const (
RelationshipUnknown Relationship = iota
RelationshipRuntime
RelationshipRoot
RelationshipDirect
RelationshipIndirect
)

var relationshipNames = [...]string{
"unknown",
"runtime",
"root",
"direct",
"indirect",
Expand Down
10 changes: 5 additions & 5 deletions pkg/fanal/analyzer/language/golang/binary/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func Test_gobinaryLibraryAnalyzer_Analyze(t *testing.T) {
Type: types.GoBinary,
FilePath: "testdata/executable_gobinary",
Libraries: types.Packages{
{
Name: "stdlib",
Version: "1.15.2",
Relationship: types.RelationshipRuntime,
},
{
Name: "github.com/aquasecurity/test",
Version: "",
Relationship: types.RelationshipRoot,
},
{
Name: "stdlib",
Version: "1.15.2",
Relationship: types.RelationshipDirect,
},
{
Name: "github.com/aquasecurity/go-pep440-version",
Version: "v0.0.0-20210121094942-22b2f8951d46",
Expand Down
1 change: 0 additions & 1 deletion pkg/fanal/types/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ type Relationship = godeptypes.Relationship

const (
RelationshipUnknown = godeptypes.RelationshipUnknown
RelationshipRuntime = godeptypes.RelationshipRuntime
RelationshipRoot = godeptypes.RelationshipRoot
RelationshipDirect = godeptypes.RelationshipDirect
RelationshipIndirect = godeptypes.RelationshipIndirect
Expand Down
42 changes: 42 additions & 0 deletions pkg/sbom/io/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,19 @@ func TestEncoder_Encode(t *testing.T) {
},
Relationship: ftypes.RelationshipIndirect,
},
{
ID: "[email protected]",
Name: "stdlib",
Version: "1.22.1",
Identifier: ftypes.PkgIdentifier{
PURL: &packageurl.PackageURL{
Type: packageurl.TypeGolang,
Name: "stdlib",
Version: "1.22.1",
},
},
Relationship: ftypes.RelationshipDirect,
},
},
},
},
Expand Down Expand Up @@ -460,6 +473,30 @@ func TestEncoder_Encode(t *testing.T) {
BOMRef: "pkg:golang/github.com/org/[email protected]",
},
},
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"): {
Type: core.TypeLibrary,
Name: "stdlib",
Version: "1.22.1",
SrcFile: "test",
Properties: []core.Property{
{
Name: core.PropertyPkgID,
Value: "[email protected]",
},
{
Name: core.PropertyPkgType,
Value: "gobinary",
},
},
PkgID: core.PkgID{
PURL: &packageurl.PackageURL{
Type: packageurl.TypeGolang,
Name: "stdlib",
Version: "1.22.1",
},
BOMRef: "pkg:golang/[email protected]",
},
},
},
wantRels: map[uuid.UUID][]core.Relationship{
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000001"): {
Expand All @@ -479,6 +516,10 @@ func TestEncoder_Encode(t *testing.T) {
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"),
Type: core.RelationshipDependsOn,
},
{
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"),
Type: core.RelationshipDependsOn,
},
},
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"): {
{
Expand All @@ -487,6 +528,7 @@ func TestEncoder_Encode(t *testing.T) {
},
},
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000005"): nil,
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"): nil,
},
wantVulns: map[uuid.UUID][]core.Vulnerability{},
},
Expand Down

0 comments on commit 5e620b0

Please sign in to comment.