Map the downloadLocation field for PHP Composer packages (#3011)

Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
This commit is contained in:
Laurent Goderre 2024-07-09 12:01:58 -04:00 committed by GitHub
parent de3313cfb6
commit b101f44aba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 0 deletions

View file

@ -22,6 +22,10 @@ func DownloadLocation(p pkg.Package) string {
return NoneIfEmpty(metadata.URL)
case pkg.NpmPackageLockEntry:
return NoneIfEmpty(metadata.Resolved)
case pkg.PhpComposerLockEntry:
return NoneIfEmpty(metadata.Dist.URL)
case pkg.PhpComposerInstalledEntry:
return NoneIfEmpty(metadata.Dist.URL)
}
}
return NOASSERTION

View file

@ -64,6 +64,50 @@ func Test_DownloadLocation(t *testing.T) {
},
expected: NONE,
},
{
name: "from php installed.json",
input: pkg.Package{
Metadata: pkg.PhpComposerInstalledEntry{
Dist: pkg.PhpComposerExternalReference{
URL: "http://package-lock.test",
},
},
},
expected: "http://package-lock.test",
},
{
name: "empty",
input: pkg.Package{
Metadata: pkg.PhpComposerInstalledEntry{
Dist: pkg.PhpComposerExternalReference{
URL: "",
},
},
},
expected: "NONE",
},
{
name: "from php composer.lock",
input: pkg.Package{
Metadata: pkg.PhpComposerLockEntry{
Dist: pkg.PhpComposerExternalReference{
URL: "http://package-lock.test",
},
},
},
expected: "http://package-lock.test",
},
{
name: "empty",
input: pkg.Package{
Metadata: pkg.PhpComposerLockEntry{
Dist: pkg.PhpComposerExternalReference{
URL: "",
},
},
},
expected: "NONE",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {