Skip to content

Commit 6ac2805

Browse files
committed
feat: support checking packages exist for the Drupal ecosystem
Signed-off-by: Gareth Jones <[email protected]>
1 parent 4464bfb commit 6ac2805

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

tools/osv-linter/internal/checks/packages.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ func PackageExists(json *gjson.Result, config *Config) (findings []CheckError) {
3737
if !maybePackage.Exists() {
3838
return true // keep iterating (over affected entries)
3939
}
40-
// Normalize ecosystems with a colon to their base.
40+
ecosystem := value.Get("package.ecosystem").String()
41+
42+
// Normalize ecosystems with a colon to their base, except for the Drupal ecosystem
43+
// as different repositories are used depending on the suffix
4144
// e.g. "Alpine:v3.5" -> "Alpine"
42-
ecosystem := strings.Split(value.Get("package.ecosystem").String(), ":")[0]
45+
if !strings.HasPrefix(ecosystem, "Drupal") {
46+
ecosystem = strings.Split(ecosystem, ":")[0]
47+
}
4348
// Use config.Ecosystems as an allowlist, if it is set.
4449
if len(config.Ecosystems) > 0 && !slices.Contains(config.Ecosystems, ecosystem) {
4550
return true // keep iterating (over affected entries)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var SupportedEcosystems = []string{
1313
"NuGet",
1414
"RubyGems",
1515
"Packagist",
16+
"Drupal",
1617
"Pub",
1718
"Hackage",
1819
"Maven",
@@ -27,6 +28,7 @@ var EcosystemBaseURLs = map[string]string{
2728
"NuGet": "https://api.nuget.org/v3-flatcontainer",
2829
"RubyGems": "https://rubygems.org/api/v1/gems",
2930
"Packagist": "https://repo.packagist.org/p2",
31+
"Drupal": "https://packages.drupal.org/files/packages/8/p2",
3032
"Pub": "https://pub.dev/api/packages",
3133
"Hackage": "https://hackage.haskell.org/package",
3234
"Maven": "https://search.maven.org/solrsearch/select",
@@ -52,6 +54,8 @@ func ExistsInEcosystem(pkg string, ecosystem string) bool {
5254
case "Debian":
5355
return true
5456
case "Drupal":
57+
return existsInDrupal(pkg)
58+
case "Drupal:7":
5559
return true
5660
case "GIT":
5761
return true
@@ -140,7 +144,6 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
140144
return nil
141145
case "Drupal":
142146
return nil
143-
case "Drupal": return nil
144147
case "GIT":
145148
return nil
146149
case "GitHub Actions":

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ func existsInPackagist(pkg string) bool {
8686
return checkPackageExists(packageInstanceURL)
8787
}
8888

89+
// Validate the existence of a package in Packagist.
90+
func existsInDrupal(pkg string) bool {
91+
packageInstanceURL := fmt.Sprintf("%s/%s.json", EcosystemBaseURLs["Drupal"], pkg)
92+
93+
return checkPackageExists(packageInstanceURL)
94+
}
95+
8996
// Validate the existence of a package in PyPI.
9097
func existsInPyPI(pkg string) bool {
9198
ecosystem := "PyPI"

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,33 @@ func Test_existsInPackagist(t *testing.T) {
144144
}
145145
}
146146

147+
func Test_existsInDrupal(t *testing.T) {
148+
tests := []struct {
149+
name string
150+
pkg string
151+
want bool
152+
ver string
153+
}{
154+
{
155+
name: "existing package",
156+
pkg: "drupal/tfa",
157+
want: true,
158+
},
159+
{
160+
name: "non-existing package",
161+
pkg: "non-existing-package",
162+
want: false,
163+
},
164+
}
165+
for _, tt := range tests {
166+
t.Run(tt.name, func(t *testing.T) {
167+
if got := existsInDrupal(tt.pkg); got != tt.want {
168+
t.Errorf("existsInDrupal() = %v, want %v", got, tt.want)
169+
}
170+
})
171+
}
172+
}
173+
147174
func Test_existsInPub(t *testing.T) {
148175
tests := []struct {
149176
name string

0 commit comments

Comments
 (0)