Skip to content

Commit adcb07e

Browse files
committed
feat: support checking versions exist in Pub
Signed-off-by: Gareth Jones <3151613+G-Rath@users.noreply.github.com>
1 parent 4599421 commit adcb07e

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

tools/osv-linter/internal/pkgchecker/ecosystems.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
177177
case "Packagist":
178178
return versionsExistInPackagist(pkg, versions)
179179
case "Pub":
180-
return nil
180+
return versionsExistInPub(pkg, versions)
181181
case "PyPI":
182182
return versionsExistInPyPI(pkg, versions)
183183
case "Red Hat":

tools/osv-linter/internal/pkgchecker/ecosystems_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,62 @@ func Test_versionsExistInPackagist(t *testing.T) {
422422
}
423423
}
424424

425+
func Test_versionsExistInPub(t *testing.T) {
426+
t.Parallel()
427+
428+
type args struct {
429+
pkg string
430+
versions []string
431+
}
432+
tests := []struct {
433+
name string
434+
args args
435+
wantErr bool
436+
}{
437+
{
438+
name: "multiple_versions_which_all_exist",
439+
args: args{
440+
pkg: "agent_dart",
441+
versions: []string{"0.0.1", "0.1.14+1", "0.1.24", "1.0.0-dev.11"},
442+
},
443+
wantErr: false,
444+
},
445+
{
446+
name: "multiple_versions_with_one_that_does_not_exist",
447+
args: args{
448+
pkg: "agent_dart",
449+
versions: []string{"0.1.1", "0.1.15+4", "1.0.0-dev.17"},
450+
},
451+
wantErr: true,
452+
},
453+
{
454+
name: "an_invalid_version",
455+
args: args{
456+
pkg: "agent_dart",
457+
versions: []string{"!"},
458+
},
459+
wantErr: true,
460+
},
461+
{
462+
name: "a_package_that_does_not_exit",
463+
args: args{
464+
pkg: "not-a-real-package",
465+
versions: []string{"1.0.0"},
466+
},
467+
wantErr: true,
468+
},
469+
}
470+
for _, tt := range tests {
471+
t.Run(tt.name, func(t *testing.T) {
472+
t.Parallel()
473+
474+
if err := versionsExistInPub(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
475+
t.Errorf("versionsExistInPub() error = %v, wantErr %v", err, tt.wantErr)
476+
}
477+
})
478+
}
479+
}
480+
425481
func Test_versionsExistInPyPI(t *testing.T) {
426482
t.Parallel()
427483

tools/osv-linter/internal/pkgchecker/version_check.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ func versionsExistInPackagist(pkg string, versions []string) error {
264264
)
265265
}
266266

267+
// Confirm that all specified versions of a package exist in Pub.
268+
func versionsExistInPub(pkg string, versions []string) error {
269+
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["Pub"], pkg)
270+
271+
return versionsExistInGeneric(
272+
pkg, versions,
273+
"Pub",
274+
packageInstanceURL,
275+
"versions.#.version",
276+
)
277+
}
278+
267279
// Confirm that all specified versions of a package exist in PyPI.
268280
func versionsExistInPyPI(pkg string, versions []string) error {
269281
// https://packaging.python.org/en/latest/specifications/name-normalization/

0 commit comments

Comments
 (0)