mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(cache): scan npm and PyPI packages named like Go metadata
IsMetadataEntry treated any name ending in .mod or .info as metadata. An npm or PyPI package with such a name skipped the vulnerability scan and was never blocked. The suffix rule now applies to the go registry only.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package metadata
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIsMetadataEntry(t *testing.T) {
|
||||
tests := []struct {
|
||||
registry, name, version string
|
||||
want bool
|
||||
}{
|
||||
{"npm", "lodash", "metadata", true},
|
||||
{"pypi", "foo", "page", true},
|
||||
{"go", "example.com/m/@v/list", "list", true},
|
||||
{"go", "example.com/m/@v/v1.0.0.mod", "v1.0.0", true},
|
||||
{"go", "example.com/m/@v/v1.0.0.info", "v1.0.0", true},
|
||||
{"go", "example.com/m/@v/v1.0.0.zip", "v1.0.0", false},
|
||||
{"npm", "left.info", "1.0.0", false},
|
||||
{"pypi", "foo.mod", "foo.mod-1.0.tar.gz", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := IsMetadataEntry(tt.registry, tt.name, tt.version); got != tt.want {
|
||||
t.Errorf("IsMetadataEntry(%q, %q, %q) = %v, want %v", tt.registry, tt.name, tt.version, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user