diff --git a/cloudflare.info.yml b/cloudflare.info.yml index 493b30d..760d050 100644 --- a/cloudflare.info.yml +++ b/cloudflare.info.yml @@ -1,7 +1,7 @@ name: CloudFlare type: module description: CloudFlare CDN integration. -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 package: Web services configure: cloudflare.admin_settings_form diff --git a/cloudflare.install b/cloudflare.install index 6760f65..c0c32a2 100644 --- a/cloudflare.install +++ b/cloudflare.install @@ -6,6 +6,10 @@ */ use Drupal\Core\Url; +use Drupal\Core\Entity\EntityStorageException; +use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; +use Drupal\Core\Utility\UpdateException; /** * Implements hook_requirements(). diff --git a/modules/cloudflarepurger/cloudflarepurger.info.yml b/modules/cloudflarepurger/cloudflarepurger.info.yml index 5dd455c..400695d 100644 --- a/modules/cloudflarepurger/cloudflarepurger.info.yml +++ b/modules/cloudflarepurger/cloudflarepurger.info.yml @@ -1,7 +1,7 @@ name: CloudFlare Purger type: module description: CloudFlare CDN integration. -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 package: Purge - reverse proxies & CDNs configure: cloudflare.admin_settings_form dependencies: diff --git a/modules/cloudflarepurger/src/EventSubscriber/CloudFlareCacheTagHeaderGenerator.php b/modules/cloudflarepurger/src/EventSubscriber/CloudFlareCacheTagHeaderGenerator.php index d398a9c..f5d1aad 100644 --- a/modules/cloudflarepurger/src/EventSubscriber/CloudFlareCacheTagHeaderGenerator.php +++ b/modules/cloudflarepurger/src/EventSubscriber/CloudFlareCacheTagHeaderGenerator.php @@ -3,7 +3,7 @@ namespace Drupal\cloudflarepurger\EventSubscriber; use Drupal\Core\Cache\CacheableResponseInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -33,11 +33,11 @@ class CloudFlareCacheTagHeaderGenerator implements EventSubscriberInterface { /** * Generates a 'Cache-Tag' header in the format expected by CloudFlare. * - * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event + * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * The event to process. */ - public function onResponse(FilterResponseEvent $event) { - if (!$event->isMasterRequest()) { + public function onResponse(ResponseEvent $event) { + if (!$event->isMainRequest()) { return; } diff --git a/modules/cloudflarepurger/src/Plugin/Purge/Purger/CloudFlarePurger.php b/modules/cloudflarepurger/src/Plugin/Purge/Purger/CloudFlarePurger.php index dce8a9e..a721645 100644 --- a/modules/cloudflarepurger/src/Plugin/Purge/Purger/CloudFlarePurger.php +++ b/modules/cloudflarepurger/src/Plugin/Purge/Purger/CloudFlarePurger.php @@ -165,6 +165,8 @@ class CloudFlarePurger extends PurgerBase implements PurgerInterface { // via a service. Purging should only ever happen through the purge module // which is why this is NOT in a service. $auth_using = $this->config->get('auth_using'); + $key = ''; // Default value of key in case it does not go into any of below if conditions + if ($auth_using === 'key') { $api_key = $this->config->get('apikey'); $email = $this->config->get('email'); diff --git a/modules/cloudflarepurger/tests/src/Unit/DiagnosticCheckTestBase.php b/modules/cloudflarepurger/tests/src/Unit/DiagnosticCheckTestBase.php index 593015d..3f0d530 100644 --- a/modules/cloudflarepurger/tests/src/Unit/DiagnosticCheckTestBase.php +++ b/modules/cloudflarepurger/tests/src/Unit/DiagnosticCheckTestBase.php @@ -26,7 +26,7 @@ abstract class DiagnosticCheckTestBase extends UnitTestCase { /** * Tracks Drupal states. * - * @var \Drupal\Core\state\StateInterface + * @var \Drupal\Core\State\StateInterface */ protected $drupalState; @@ -54,7 +54,7 @@ abstract class DiagnosticCheckTestBase extends UnitTestCase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp() : void { parent::setUp(); $this->drupalState = new CoreState(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend()); $this->timestampStub = new Timestamp(); diff --git a/src/CloudFlareMiddleware.php b/src/CloudFlareMiddleware.php index 75ae075..fc4a711 100644 --- a/src/CloudFlareMiddleware.php +++ b/src/CloudFlareMiddleware.php @@ -12,6 +12,7 @@ use GuzzleHttp\Exception\RequestException; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\IpUtils; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -79,6 +80,8 @@ class CloudFlareMiddleware implements HttpKernelInterface { */ protected $remoteAddrValidate; + protected $bypassHost; + /** * Constructs the CloudflareMiddleware object. * @@ -107,7 +110,7 @@ class CloudFlareMiddleware implements HttpKernelInterface { /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { if ($type !== self::MASTER_REQUEST) { return $this->httpKernel->handle($request, $type, $catch); } @@ -212,6 +215,7 @@ class CloudFlareMiddleware implements HttpKernelInterface { catch (RequestException $exception) { $this->logger->error("Unable to get a listing of CloudFlare IPs. " . $exception->getMessage()); } + return []; } } diff --git a/src/Form/ZoneSelectionForm.php b/src/Form/ZoneSelectionForm.php index f75ac0f..14c9e50 100644 --- a/src/Form/ZoneSelectionForm.php +++ b/src/Form/ZoneSelectionForm.php @@ -27,6 +27,13 @@ class ZoneSelectionForm extends FormBase implements ContainerInjectionInterface */ protected $configFactory; + /** + * The configuration object. + * + * @var \Drupal\Core\Config\Config + */ + protected $config; + /** * Wrapper to access the CloudFlare zone api. * @@ -48,6 +55,20 @@ class ZoneSelectionForm extends FormBase implements ContainerInjectionInterface */ protected $zones; + /** + * Boolean indicates if zone id is set or not. + * + * @var bool + */ + protected $hasZoneId; + + /** + * Boolean indicates if valid_credentials property set to true or not. + * + * @var bool + */ + protected $hasValidCredentials; + /** * Boolean indicates if CloudFlare dependencies have been met. * @@ -62,6 +83,13 @@ class ZoneSelectionForm extends FormBase implements ContainerInjectionInterface */ protected $hasMultipleZones; + /** + * Store the zone name. + * + * @var string + */ + protected $zone_name; + /** * {@inheritdoc} */ diff --git a/src/State.php b/src/State.php index 0a5eb78..c07169f 100644 --- a/src/State.php +++ b/src/State.php @@ -17,14 +17,14 @@ class State implements CloudFlareStateInterface { /** * Tracks rate limits associated with CloudFlare Api. * - * @var \Drupal\cloudflare\CloudFlareStateInterface + * @var \Drupal\Core\State\StateInterface */ protected $state; /** * Timestamp service. * - * @var \Drupal\CloudFlare\CloudFlareTimestampInterface + * @var \Drupal\cloudflare\CloudFlareTimestampInterface */ protected $timestamper; @@ -33,7 +33,7 @@ class State implements CloudFlareStateInterface { * * @param \Drupal\Core\State\StateInterface $state * The drupal state service. - * @param \Drupal\CloudFlare\CloudFlareTimestampInterface $timestamper + * @param \Drupal\cloudflare\CloudFlareTimestampInterface $timestamper * Cloudflare timestamp service. */ public function __construct(StateInterface $state, CloudFlareTimestampInterface $timestamper) { diff --git a/src/Zone.php b/src/Zone.php index c660246..54067e1 100644 --- a/src/Zone.php +++ b/src/Zone.php @@ -88,6 +88,9 @@ class Zone implements CloudFlareZoneInterface { public static function create(ConfigFactoryInterface $config_factory, LoggerInterface $logger, CacheBackendInterface $cache, CloudFlareStateInterface $state, CloudFlareComposerDependenciesCheckInterface $check_interface) { $config = $config_factory->get('cloudflare.settings'); $auth_using = $config->get('auth_using'); + // Setting default value for email, api_key, token and key. + $email = $api_key = $token = $key = ''; + if ($auth_using === 'key') { $api_key = $config->get('apikey'); $email = $config->get('email'); diff --git a/tests/modules/cloudflare_form_tester/cloudflare_form_tester.info.yml b/tests/modules/cloudflare_form_tester/cloudflare_form_tester.info.yml index 00ef0d7..42bc4e4 100644 --- a/tests/modules/cloudflare_form_tester/cloudflare_form_tester.info.yml +++ b/tests/modules/cloudflare_form_tester/cloudflare_form_tester.info.yml @@ -1,7 +1,7 @@ name: CloudFlare Form Tester type: module description: Adds replacement services used for testing CloudFlare forms -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 package: Web services dependencies: diff --git a/tests/src/Functional/CloudFlareAdminSettingsFormTest.php b/tests/src/Functional/CloudFlareAdminSettingsFormTest.php index 6444000..6cc7512 100644 --- a/tests/src/Functional/CloudFlareAdminSettingsFormTest.php +++ b/tests/src/Functional/CloudFlareAdminSettingsFormTest.php @@ -17,7 +17,7 @@ class CloudFlareAdminSettingsFormTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['cloudflare', 'cloudflare_form_tester', 'ctools']; + protected static $modules = ['cloudflare', 'cloudflare_form_tester', 'ctools']; /** * {@inheritdoc} @@ -31,6 +31,13 @@ class CloudFlareAdminSettingsFormTest extends BrowserTestBase { */ protected $adminUser; + /** + * Stores the cloudflare form url. + * + * @var \Drupal\Core\Url + */ + protected $formUrl; + /** * Route providing the main configuration form of the cloudflare module. * @@ -41,7 +48,7 @@ class CloudFlareAdminSettingsFormTest extends BrowserTestBase { /** * Setup the test. */ - public function setUp() { + public function setUp() : void { parent::setUp(); $this->adminUser = $this->drupalCreateUser(['administer cloudflare']); diff --git a/tests/src/Functional/CloudFlareAdminSettingsInvalidFormTest.php b/tests/src/Functional/CloudFlareAdminSettingsInvalidFormTest.php index 1721304..2cd16c0 100644 --- a/tests/src/Functional/CloudFlareAdminSettingsInvalidFormTest.php +++ b/tests/src/Functional/CloudFlareAdminSettingsInvalidFormTest.php @@ -19,7 +19,7 @@ class CloudFlareAdminSettingsInvalidFormTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['cloudflare', 'ctools']; + protected static $modules = ['cloudflare', 'ctools']; /** * {@inheritdoc} @@ -33,6 +33,13 @@ class CloudFlareAdminSettingsInvalidFormTest extends BrowserTestBase { */ protected $adminUser; + /** + * Stores the cloudflare form url. + * + * @var \Drupal\Core\Url + */ + protected $formUrl; + /** * Route providing the main configuration form of the cloudflare module. * @@ -43,7 +50,7 @@ class CloudFlareAdminSettingsInvalidFormTest extends BrowserTestBase { /** * Setup the test. */ - public function setUp() { + public function setUp() : void { parent::setUp(); $this->adminUser = $this->drupalCreateUser(['administer cloudflare']); @@ -57,7 +64,7 @@ class CloudFlareAdminSettingsInvalidFormTest extends BrowserTestBase { public function testConfigFormDisplay() { $this->drupalLogin($this->adminUser); $this->drupalGet($this->formUrl); - $this->assertSession()->pageTextContains('This will help suppress log warnings regarding requests bypassing CloudFlare', 'Helper Text'); + $this->assertSession()->pageTextContains('This will help suppress log warnings regarding requests bypassing CloudFlare'); $this->assertSession()->fieldExists('auth_using'); $this->assertSession()->fieldExists('api_token'); $this->assertSession()->fieldExists('apikey'); diff --git a/tests/src/Functional/ComposerDependencyTest.php b/tests/src/Functional/ComposerDependencyTest.php index 69aa6ea..5dab03d 100644 --- a/tests/src/Functional/ComposerDependencyTest.php +++ b/tests/src/Functional/ComposerDependencyTest.php @@ -16,7 +16,7 @@ class ComposerDependencyTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['cloudflare', 'cloudflare_form_tester', 'ctools']; + protected static $modules = ['cloudflare', 'cloudflare_form_tester', 'ctools']; /** * {@inheritdoc} @@ -40,7 +40,7 @@ class ComposerDependencyTest extends BrowserTestBase { /** * Setup the test. */ - public function setUp() { + public function setUp() : void { parent::setUp(); $this->adminUser = $this->drupalCreateUser(['administer cloudflare']); $this->route = Url::fromRoute('cloudflare.admin_settings_form'); diff --git a/tests/src/Unit/ClientIpRestoreTest.php b/tests/src/Unit/ClientIpRestoreTest.php index 717d43a..56882b6 100644 --- a/tests/src/Unit/ClientIpRestoreTest.php +++ b/tests/src/Unit/ClientIpRestoreTest.php @@ -30,10 +30,17 @@ class ClientIpRestoreTest extends UnitTestCase { */ protected $container; + /** + * Mock object of URL generator. + * + * @var \PHPUnit\Framework\MockObject\MockObject + */ + protected $urlGenerator; + /** * {@inheritdoc} */ - public function setUp() { + public function setUp() : void { parent::setUp(); $this->container = new ContainerBuilder(); $this->container->set('string_translation', $this->getStringTranslationStub());