Fix security advisory parsing when filter repo is used, fixes #11281
parent
f6f972a699
commit
5165792f9c
|
@ -21,7 +21,7 @@ use Composer\Pcre\Preg;
|
||||||
*
|
*
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*/
|
*/
|
||||||
class FilterRepository implements RepositoryInterface
|
class FilterRepository implements RepositoryInterface, AdvisoryProviderInterface
|
||||||
{
|
{
|
||||||
/** @var ?string */
|
/** @var ?string */
|
||||||
private $only = null;
|
private $only = null;
|
||||||
|
@ -188,6 +188,33 @@ class FilterRepository implements RepositoryInterface
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasSecurityAdvisories(): bool
|
||||||
|
{
|
||||||
|
if (!$this->repo instanceof AdvisoryProviderInterface) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->repo->hasSecurityAdvisories();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getSecurityAdvisories(array $packageConstraintMap, bool $allowPartialAdvisories = false): array
|
||||||
|
{
|
||||||
|
if (!$this->repo instanceof AdvisoryProviderInterface) {
|
||||||
|
return ['namesFound' => [], 'advisories' => []];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($packageConstraintMap as $name => $constraint) {
|
||||||
|
if (!$this->isAllowed($name)) {
|
||||||
|
unset($packageConstraintMap[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->repo->getSecurityAdvisories($packageConstraintMap, $allowPartialAdvisories);
|
||||||
|
}
|
||||||
|
|
||||||
private function isAllowed(string $name): bool
|
private function isAllowed(string $name): bool
|
||||||
{
|
{
|
||||||
if (!$this->only && !$this->exclude) {
|
if (!$this->only && !$this->exclude) {
|
||||||
|
|
|
@ -62,6 +62,14 @@ class FilterRepositoryTest extends TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSecurityAdvisoriesDisabledInChild(): void
|
||||||
|
{
|
||||||
|
$repo = new FilterRepository($this->arrayRepo, ['only' => ['foo/*']]);
|
||||||
|
|
||||||
|
self::assertFalse($repo->hasSecurityAdvisories());
|
||||||
|
self::assertSame(['namesFound' => [], 'advisories' => []], $repo->getSecurityAdvisories(['foo/aaa' => new MatchAllConstraint()], true));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCanonicalDefaultTrue(): void
|
public function testCanonicalDefaultTrue(): void
|
||||||
{
|
{
|
||||||
$repo = new FilterRepository($this->arrayRepo, []);
|
$repo = new FilterRepository($this->arrayRepo, []);
|
||||||
|
|
Loading…
Reference in New Issue