diff --git a/src/Composer/Repository/FilterRepository.php b/src/Composer/Repository/FilterRepository.php index 7419cd1a8..bd9b54d9a 100644 --- a/src/Composer/Repository/FilterRepository.php +++ b/src/Composer/Repository/FilterRepository.php @@ -21,7 +21,7 @@ use Composer\Pcre\Preg; * * @author Jordi Boggiano */ -class FilterRepository implements RepositoryInterface +class FilterRepository implements RepositoryInterface, AdvisoryProviderInterface { /** @var ?string */ private $only = null; @@ -188,6 +188,33 @@ class FilterRepository implements RepositoryInterface 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 { if (!$this->only && !$this->exclude) { diff --git a/tests/Composer/Test/Repository/FilterRepositoryTest.php b/tests/Composer/Test/Repository/FilterRepositoryTest.php index 33db52c6b..111d58431 100644 --- a/tests/Composer/Test/Repository/FilterRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilterRepositoryTest.php @@ -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 { $repo = new FilterRepository($this->arrayRepo, []);