Skip to content
Snippets Groups Projects
Commit b0222f84 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3416768: For testing purposes, allow PhpTufValidator to validate...

Issue #3416768: For testing purposes, allow PhpTufValidator to validate repositories other than packages.drupal.org
parent de142aac
No related branches found
No related tags found
1 merge request!1021Allow base URL to be injected
Pipeline #84641 failed
...@@ -54,6 +54,8 @@ variables: ...@@ -54,6 +54,8 @@ variables:
# Always test against the previous minor version of core. # Always test against the previous minor version of core.
OPT_IN_TEST_PREVIOUS_MINOR: '1' OPT_IN_TEST_PREVIOUS_MINOR: '1'
# SKIP_ESLINT: '1' # SKIP_ESLINT: '1'
# @todo Remove this line when https://drupal.org/i/3414093 is fixed.
CI_DEBUG_SERVICES: "true"
################################################################################### ###################################################################################
......
...@@ -167,7 +167,9 @@ services: ...@@ -167,7 +167,9 @@ services:
- { name: event_subscriber } - { name: event_subscriber }
# @todo Tag this service as an event subscriber in https://drupal.org/i/3358504, # @todo Tag this service as an event subscriber in https://drupal.org/i/3358504,
# once packages.drupal.org supports TUF. # once packages.drupal.org supports TUF.
Drupal\package_manager\Validator\PhpTufValidator: {} Drupal\package_manager\Validator\PhpTufValidator:
arguments:
$baseUrl: 'https://packages.drupal.org'
Drupal\package_manager\PackageManagerUpdateProcessor: Drupal\package_manager\PackageManagerUpdateProcessor:
arguments: arguments:
# @todo Autowire $update_fetcher when https://drupal.org/i/3325557 lands. # @todo Autowire $update_fetcher when https://drupal.org/i/3325557 lands.
......
...@@ -59,11 +59,15 @@ final class PhpTufValidator implements EventSubscriberInterface { ...@@ -59,11 +59,15 @@ final class PhpTufValidator implements EventSubscriberInterface {
* The Composer inspector service. * The Composer inspector service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service. * The module handler service.
* @param string $baseUrl
* The base URL of the repository, or repositories, defined in
* `composer.json`that must be protected by TUF.
*/ */
public function __construct( public function __construct(
private readonly PathLocator $pathLocator, private readonly PathLocator $pathLocator,
private readonly ComposerInspector $composerInspector, private readonly ComposerInspector $composerInspector,
private readonly ModuleHandlerInterface $moduleHandler private readonly ModuleHandlerInterface $moduleHandler,
private readonly string $baseUrl,
) {} ) {}
/** /**
...@@ -147,13 +151,12 @@ final class PhpTufValidator implements EventSubscriberInterface { ...@@ -147,13 +151,12 @@ final class PhpTufValidator implements EventSubscriberInterface {
$messages[] = $message; $messages[] = $message;
} }
// Get the defined repositories that use packages.drupal.org. // Get the defined repositories that live at the base URL, and confirm that
// they have all opted into TUF protection.
$repositories = array_filter( $repositories = array_filter(
Json::decode($this->composerInspector->getConfig('repositories', $dir)), Json::decode($this->composerInspector->getConfig('repositories', $dir)),
fn (array $r): bool => str_starts_with($r['url'], 'https://packages.drupal.org') fn (array $r): bool => str_starts_with($r['url'], $this->baseUrl)
); );
// All packages.drupal.org repositories must have TUF protection.
foreach ($repositories as $repository) { foreach ($repositories as $repository) {
if (empty($repository['tuf'])) { if (empty($repository['tuf'])) {
$messages[] = $this->t('TUF is not enabled for the @url repository.', [ $messages[] = $this->t('TUF is not enabled for the @url repository.', [
...@@ -162,10 +165,11 @@ final class PhpTufValidator implements EventSubscriberInterface { ...@@ -162,10 +165,11 @@ final class PhpTufValidator implements EventSubscriberInterface {
} }
} }
// There must be at least one repository using packages.drupal.org, since // There must be at least one repository using the base URL.
// that's the only repository which supports TUF right now.
if (empty($repositories)) { if (empty($repositories)) {
$message = $this->t('The <code>https://packages.drupal.org</code> Composer repository must be defined in <code>composer.json</code>.'); $message = $this->t('The <code>@url</code> Composer repository must be defined in <code>composer.json</code>.', [
'@url' => $this->baseUrl,
]);
if (isset($help_url)) { if (isset($help_url)) {
$message = $this->t('@message See <a href=":url">the help page</a> for more information on how to set up this repository.', [ $message = $this->t('@message See <a href=":url">the help page</a> for more information on how to set up this repository.', [
'@message' => $message, '@message' => $message,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment