Skip to content
Snippets Groups Projects

Issue #3285631: Make it impossible to call CronUpdater::begin() directly

1 file
+ 14
105
Compare changes
  • Side-by-side
  • Inline
@@ -205,7 +205,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -205,7 +205,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
return [
return [
'valid target, dev snapshot installed' => [
'valid target, dev snapshot installed' => [
['automatic_updates.updater', 'automatic_updates.cron_updater'],
'9.8.0-dev',
'9.8.0-dev',
"$metadata_dir/drupal.9.8.1-security.xml",
"$metadata_dir/drupal.9.8.1-security.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
@@ -219,7 +218,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -219,7 +218,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
// The following cases can only happen by explicitly supplying the updater
// The following cases can only happen by explicitly supplying the updater
// with an invalid target version.
// with an invalid target version.
'downgrade' => [
'downgrade' => [
['automatic_updates.updater', 'automatic_updates.cron_updater'],
'9.8.1',
'9.8.1',
"$metadata_dir/drupal.9.8.2.xml",
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
@@ -231,7 +229,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -231,7 +229,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
],
],
],
],
'major version upgrade' => [
'major version upgrade' => [
['automatic_updates.updater', 'automatic_updates.cron_updater'],
'8.9.1',
'8.9.1',
"$metadata_dir/drupal.9.8.2.xml",
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
@@ -243,7 +240,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -243,7 +240,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
],
],
],
],
'unsupported target version' => [
'unsupported target version' => [
['automatic_updates.updater', 'automatic_updates.cron_updater'],
'9.8.0',
'9.8.0',
"$metadata_dir/drupal.9.8.2-unsupported_unpublished.xml",
"$metadata_dir/drupal.9.8.2-unsupported_unpublished.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
@@ -255,55 +251,18 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -255,55 +251,18 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
],
],
],
],
// This case proves that an attended update to a normal non-security
// This case proves that an attended update to a normal non-security
// release is allowed regardless of how cron is configured...
// release is allowed regardless of how cron is configured.
'attended update to normal release' => [
'attended update to normal release' => [
['automatic_updates.updater'],
'9.8.1',
'9.8.1',
"$metadata_dir/drupal.9.8.2.xml",
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
['drupal' => '9.8.2'],
['drupal' => '9.8.2'],
[],
[],
],
],
// ...and these two cases prove that an unattended update to a normal
// These two cases prove that updating across minor versions of Drupal
// non-security release is only allowed if cron is configured to allow
// all updates.
'unattended update to normal release, security only in cron' => [
['automatic_updates.cron_updater'],
'9.8.1',
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::SECURITY],
['drupal' => '9.8.2'],
[
$this->createValidationResult('9.8.1', '9.8.2', [
'Drupal cannot be automatically updated during cron from 9.8.1 to 9.8.2 because 9.8.2 is not a security release.',
]),
],
],
'unattended update to normal release, all allowed in cron' => [
['automatic_updates.cron_updater'],
'9.8.1',
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::ALL],
['drupal' => '9.8.2'],
[],
],
// These three cases prove that updating across minor versions of Drupal
// core is only allowed for attended updates when a specific configuration
// core is only allowed for attended updates when a specific configuration
// flag is set.
// flag is set.
'unattended update to next minor' => [
['automatic_updates.cron_updater'],
'9.7.9',
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
['drupal' => '9.8.2'],
[
$this->createValidationResult('9.7.9', '9.8.2', [
'Drupal cannot be automatically updated from 9.7.9 to 9.8.2 because automatic updates from one minor version to another are not supported during cron.',
]),
],
],
'attended update to next minor not allowed' => [
'attended update to next minor not allowed' => [
['automatic_updates.updater'],
'9.7.9',
'9.7.9',
"$metadata_dir/drupal.9.8.2.xml",
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
@@ -315,7 +274,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -315,7 +274,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
],
],
],
],
'attended update to next minor allowed' => [
'attended update to next minor allowed' => [
['automatic_updates.updater'],
'9.7.9',
'9.7.9',
"$metadata_dir/drupal.9.8.2.xml",
"$metadata_dir/drupal.9.8.2.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
@@ -326,7 +284,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -326,7 +284,6 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
// If attended updates across minor versions are allowed, it's okay to
// If attended updates across minor versions are allowed, it's okay to
// update from an unsupported minor version.
// update from an unsupported minor version.
'attended update from unsupported minor allowed' => [
'attended update from unsupported minor allowed' => [
['automatic_updates.updater'],
'9.7.9',
'9.7.9',
"$metadata_dir/drupal.9.8.1-security.xml",
"$metadata_dir/drupal.9.8.1-security.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
[CronUpdater::SECURITY, CronUpdater::ALL],
@@ -334,58 +291,12 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -334,58 +291,12 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
[],
[],
TRUE,
TRUE,
],
],
// Unattended updates to unstable versions are not allowed.
'unattended update to unstable version' => [
['automatic_updates.cron_updater'],
'9.8.0',
"$metadata_dir/drupal.9.8.2-older-sec-release.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
['drupal' => '9.8.1-beta1'],
[
$this->createValidationResult('9.8.0', '9.8.1-beta1', [
'Drupal cannot be automatically updated during cron to 9.8.1-beta1, because Automatic Updates only supports updating to stable versions during cron.',
]),
],
],
// Unattended updates from an unsupported minor are never allowed, but
// the messaging will vary depending on whether attended updates across
// minor versions are allowed.
'unattended update from unsupported minor, minor updates forbidden' => [
['automatic_updates.cron_updater'],
'9.7.9',
"$metadata_dir/drupal.9.8.1-security.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
['drupal' => '9.8.1'],
[
$this->createValidationResult('9.7.9', '9.8.1', [
'The currently installed version of Drupal core, 9.7.9, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.',
'See the <a href="/admin/reports/updates">available updates page</a> for available updates.',
]),
],
FALSE,
],
'unattended update from unsupported minor, minor updates allowed' => [
['automatic_updates.cron_updater'],
'9.7.9',
"$metadata_dir/drupal.9.8.1-security.xml",
[CronUpdater::SECURITY, CronUpdater::ALL],
['drupal' => '9.8.1'],
[
$this->createValidationResult('9.7.9', '9.8.1', [
'The currently installed version of Drupal core, 9.7.9, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.',
'Use the <a href="/admin/modules/automatic-update">update form</a> to update to a supported version.',
]),
],
TRUE,
],
];
];
}
}
/**
/**
* Tests validation of explicitly specified target versions.
* Tests validation of explicitly specified target versions.
*
*
* @param string[] $updaters
* The IDs of the updater services to test.
* @param string $installed_version
* @param string $installed_version
* The installed version of Drupal core.
* The installed version of Drupal core.
* @param string $release_metadata
* @param string $release_metadata
@@ -404,7 +315,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -404,7 +315,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
*
*
* @dataProvider providerApi
* @dataProvider providerApi
*/
*/
public function testApi(array $updaters, string $installed_version, string $release_metadata, array $cron_modes, array $project_versions, array $expected_results, bool $allow_minor_updates = FALSE): void {
public function testApi(string $installed_version, string $release_metadata, array $cron_modes, array $project_versions, array $expected_results, bool $allow_minor_updates = FALSE): void {
$this->setCoreVersion($installed_version);
$this->setCoreVersion($installed_version);
$this->setReleaseMetadata(['drupal' => $release_metadata]);
$this->setReleaseMetadata(['drupal' => $release_metadata]);
@@ -414,20 +325,18 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
@@ -414,20 +325,18 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
->set('allow_core_minor_updates', $allow_minor_updates)
->set('allow_core_minor_updates', $allow_minor_updates)
->save();
->save();
foreach ($updaters as $updater) {
/** @var \Drupal\automatic_updates\Updater $updater */
/** @var \Drupal\automatic_updates\Updater $updater */
$updater = $this->container->get('automatic_updates.updater');
$updater = $this->container->get($updater);
try {
try {
$updater->begin($project_versions);
$updater->begin($project_versions);
// Ensure that we did not, in fact, expect any errors.
// Ensure that we did not, in fact, expect any errors.
$this->assertEmpty($expected_results);
$this->assertEmpty($expected_results);
// Reset the updater for the next iteration of the loop.
// Reset the updater for the next iteration of the loop.
$updater->destroy();
$updater->destroy();
}
}
catch (StageValidationException $e) {
catch (StageValidationException $e) {
$this->assertValidationResultsEqual($expected_results, $e->getResults());
$this->assertValidationResultsEqual($expected_results, $e->getResults());
}
}
}
}
}
}
}
Loading