Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/osv-linter/internal/pkgchecker/ecosystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
case "Packagist":
return versionsExistInPackagist(pkg, versions)
case "Pub":
return nil
return versionsExistInPub(pkg, versions)
case "PyPI":
return versionsExistInPyPI(pkg, versions)
case "Red Hat":
Expand Down
56 changes: 56 additions & 0 deletions tools/osv-linter/internal/pkgchecker/ecosystems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,62 @@ func Test_versionsExistInPackagist(t *testing.T) {
}
}

func Test_versionsExistInPub(t *testing.T) {
t.Parallel()

type args struct {
pkg string
versions []string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "multiple_versions_which_all_exist",
args: args{
pkg: "agent_dart",
versions: []string{"0.0.1", "0.1.14+1", "0.1.24", "1.0.0-dev.11"},
},
wantErr: false,
},
{
name: "multiple_versions_with_one_that_does_not_exist",
args: args{
pkg: "agent_dart",
versions: []string{"0.1.1", "0.1.15+4", "1.0.0-dev.17"},
},
wantErr: true,
},
{
name: "an_invalid_version",
args: args{
pkg: "agent_dart",
versions: []string{"!"},
},
wantErr: true,
},
{
name: "a_package_that_does_not_exit",
args: args{
pkg: "not-a-real-package",
versions: []string{"1.0.0"},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if err := versionsExistInPub(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
t.Errorf("versionsExistInPub() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func Test_versionsExistInPyPI(t *testing.T) {
t.Parallel()

Expand Down
12 changes: 12 additions & 0 deletions tools/osv-linter/internal/pkgchecker/version_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ func versionsExistInPackagist(pkg string, versions []string) error {
)
}

// Confirm that all specified versions of a package exist in Pub.
func versionsExistInPub(pkg string, versions []string) error {
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["Pub"], pkg)

return versionsExistInGeneric(
pkg, versions,
"Pub",
packageInstanceURL,
"versions.#.version",
)
}

// Confirm that all specified versions of a package exist in PyPI.
func versionsExistInPyPI(pkg string, versions []string) error {
// https://packaging.python.org/en/latest/specifications/name-normalization/
Expand Down
Loading