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:
2026-11-23 13:15:34 +00:00
parent 7192e4ff3e
commit f0b37ea719
8 changed files with 134 additions and 17 deletions
+24
View File
@@ -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)
}
}
}