Skip to content

Commit

Permalink
fix(hooks): exclude go from filtering (#332)
Browse files Browse the repository at this point in the history
* fix(hooks): exclude go from filtering

* Limited scope to individual packages

Co-authored-by: Teppei Fukuda <[email protected]>
  • Loading branch information
AndreyLevchenko and knqyf263 authored Nov 29, 2021
1 parent d4a9fe5 commit ea3982a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hook/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ var (
"/usr/lib/python2.7/lib-dynload/Python-2.7.egg-info",
"/usr/lib/python2.7/wsgiref.egg-info",
}

affectedTypes = []string{
// ruby
types.GemSpec,

// python
types.PythonPkg,

// node.js
types.NodePkg,
}
)

type systemFileFilterHook struct{}
Expand All @@ -38,7 +49,7 @@ func (h systemFileFilterHook) Hook(blob *types.BlobInfo) error {
for _, app := range blob.Applications {
// If the lang-specific package was installed by OS package manager, it should not be taken.
// Otherwise, the package version will be wrong, then it will lead to false positive.
if utils.StringInSlice(app.FilePath, systemFiles) {
if utils.StringInSlice(app.FilePath, systemFiles) && utils.StringInSlice(app.Type, affectedTypes) {
continue
}

Expand Down
35 changes: 35 additions & 0 deletions hook/filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func Test_systemFileFilterHook_Hook(t *testing.T) {
blob: &types.BlobInfo{
Applications: []types.Application{
{
Type: types.PythonPkg,
FilePath: "usr/lib/python2.7/lib-dynload/Python-2.7.egg-info",
Libraries: []types.Package{
{
Expand All @@ -151,6 +152,40 @@ func Test_systemFileFilterHook_Hook(t *testing.T) {
},
want: &types.BlobInfo{},
},
{
name: "go is not affected",
blob: &types.BlobInfo{
Applications: []types.Application{
{
Type: "gobinary",
FilePath: "usr/local/bin/goreleaser",
Libraries: []types.Package{
{
Name: "github.com/sassoftware/go-rpmutils",
Version: "v0.0.0-20190420191620-a8f1baeba37b",
},
},
},
},
SystemFiles: []string{
"usr/local/bin/goreleaser",
},
},
want: &types.BlobInfo{
Applications: []types.Application{
{
Type: "gobinary",
FilePath: "usr/local/bin/goreleaser",
Libraries: []types.Package{
{
Name: "github.com/sassoftware/go-rpmutils",
Version: "v0.0.0-20190420191620-a8f1baeba37b",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit ea3982a

Please sign in to comment.