Skip to content

Commit

Permalink
Merge pull request #190 from openeuropa/OEL-3187
Browse files Browse the repository at this point in the history
OEL-3187: Upgrade to Drupal 11
  • Loading branch information
sergepavle authored Dec 18, 2024
2 parents 5ea0f71 + 84383ef commit 31d8a7e
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 103 deletions.
12 changes: 5 additions & 7 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ services:
- DOCUMENT_ROOT=/test/oe_authentication
- COMPOSERVER=--2
mysql:
image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/percona:5.7
command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3
image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/percona:8.0
command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 --skip-log-bin --innodb-flush-log-at-trx-commit=2 --innodb-read-io-threads=16 --innodb-write-io-threads=16
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
selenium:
Expand Down Expand Up @@ -75,11 +75,9 @@ pipeline:

matrix:
include:
- CORE_VERSION: 10.2.0
PHP_VERSION: 8.1
- CORE_VERSION: 10.2.0
PHP_VERSION: 8.2
- CORE_VERSION: 10.3.0
PHP_VERSION: 8.1
- CORE_VERSION: 10.3.0
PHP_VERSION: 8.2
PHP_VERSION: 8.3
- CORE_VERSION: 11.0
PHP_VERSION: 8.3
30 changes: 19 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
"prefer-stable": true,
"require": {
"php": ">=8.1",
"drupal/cas": "^2.3",
"drupal/core": "^10"
"drupal/cas": "^3.0",
"drupal/core": "^10.3 || ^11.0"
},
"require-dev": {
"composer/installers": "^1.11",
"drupal/cas_mock_server": "^2.0.1",
"drupal/core-composer-scaffold": "^10",
"drupal/core-composer-scaffold": "^10.3 || ^11.0",
"drupal/drupal-extension": "^5.0",
"drush/drush": "^12",
"drush/drush": "^12 || ^13",
"mikey179/vfsstream": "^1.6.10",
"nikic/php-parser": "^4",
"openeuropa/behat-transformation-context": "^0.2",
"openeuropa/code-review": "^2.0.0-alpha6",
"openeuropa/task-runner-drupal-project-symlink": "^1.0-beta6",
"openeuropa/code-review-drupal": "^1.0.0-alpha",
"openeuropa/task-runner-drupal-project-symlink": "^1.0",
"phpspec/prophecy-phpunit": "^2",
"symfony/phpunit-bridge": "^6.2"
},
Expand All @@ -39,12 +39,20 @@
"Drupal\\Tests\\cas_mock_server\\": "./build/modules/contrib/cas_mock_server/tests/src/"
}
},
"repositories": {
"drupal": {
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "git",
"url": "https://github.com/openeuropa/DrupalDriver.git"
},
{
"type": "git",
"url": "https://github.com/openeuropa/code-review-drupal.git"
}
},
],
"extra": {
"composer-exit-on-patch-failure": true,
"enable-patching": true,
Expand All @@ -69,10 +77,10 @@
"sort-packages": true,
"allow-plugins": {
"composer/installers": true,
"cweagans/composer-patches": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"drupal/core-composer-scaffold": true,
"phpro/grumphp": true
"phpro/grumphp-shim": true,
"phpstan/extension-installer": true
}
}
}
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '2'
services:
web:
image: fpfis/httpd-php-dev:8.1
image: fpfis/httpd-php-dev:8.3
working_dir: /var/www/html
ports:
- 8080:8080
Expand All @@ -18,8 +17,8 @@ services:
# Enable step debugging for all PHP request. See ./README.md#step-debugging for more information.
# XDEBUG_SESSION: 1
mysql:
image: percona/percona-server:5.7
command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3
image: percona/percona-server:8.0
command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 --skip-log-bin --innodb-flush-log-at-trx-commit=2 --innodb-read-io-threads=16 --innodb-write-io-threads=16
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
# ports:
Expand Down
35 changes: 7 additions & 28 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
imports:
- { resource: vendor/openeuropa/code-review/dist/drupal-conventions.yml }
- { resource: ./vendor/openeuropa/code-review-drupal/dist/oe-component-conventions.yml }
grumphp:
extensions:
- OpenEuropa\CodeReview\ExtraTasksExtension
git_hook_variables:
EXEC_GRUMPHP_COMMAND: 'docker-compose exec -T web'
parameters:
tasks.phpcs.ignore_patterns:
- vendor/
- node_modules/
- build/
tasks.phpcs.triggered_by:
- php
- module
- inc
- theme
- install

extra_tasks:
tasks:
phpparser:
ignore_patterns:
- vendor/
- node_modules/
- build/
visitors:
declare_strict_types: ~
triggered_by:
- php
- module
- inc
- theme
- install
git_hook_variables:
EXEC_GRUMPHP_COMMAND: 'docker-compose exec -T web'

parameters:
tasks.phpstan.configuration: phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: OE Authentication EU Login mock
description: EU Login mock server implementation.
package: OpenEuropa
type: module
core_version_requirement: ^10
core_version_requirement: ^10.3 || ^11
dependencies:
- cas:cas
- cas_mock_server:cas_mock_server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ oe_authentication_eulogin_mock.register:
_title: 'Register'
requirements:
_access: 'TRUE'

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Drupal\oe_authentication_eulogin_mock\EventSubscriber;

use Drupal\cas\Event\CasPreRedirectEvent;
use Drupal\cas\Service\CasHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand All @@ -32,7 +31,7 @@ public function onCasPreRedirect(CasPreRedirectEvent $event) {
*/
public static function getSubscribedEvents() {
return [
CasHelper::EVENT_PRE_REDIRECT => ['onCasPreRedirect'],
CasPreRedirectEvent::class => ['onCasPreRedirect'],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: OE Authentication User Fields
description: Provides some user basic fields and map them with EU Login attributes.
package: OpenEuropa
type: module
core_version_requirement: ^10
core_version_requirement: ^10.3 || ^11
dependencies:
- oe_authentication:oe_authentication
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;
use Drush\Drupal\Commands\sql\SanitizeCommands;
use Drush\Drupal\Commands\sql\SanitizePluginInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -66,7 +65,7 @@ public static function create(ContainerInterface $container) {
/**
* {@inheritdoc}
*/
#[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: SanitizeCommands::SANITIZE)]
#[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: 'sql:sanitize')]
public function sanitize($result, CommandData $commandData) {
$this->connection->update('users_field_data')
->expression('field_oe_firstname', 'CONCAT(:fn_dummy_string, uid)', [
Expand All @@ -92,9 +91,10 @@ public function sanitize($result, CommandData $commandData) {
/**
* {@inheritdoc}
*/
#[CLI\Hook(type: HookManager::ON_EVENT, target: SanitizeCommands::CONFIRMS)]
#[CLI\Hook(type: HookManager::ON_EVENT, target: 'sql-sanitize-confirms')]
public function messages(&$messages, InputInterface $input) {
$messages[] = dt('Sanitise user fields.');
return $messages;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Drupal\cas\Event\CasPostLoginEvent;
use Drupal\cas\Event\CasPreRegisterEvent;
use Drupal\cas\Service\CasHelper;
use Drupal\oe_authentication_user_fields\EuLoginAttributesHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -20,8 +19,8 @@ class EuLoginAttributesToUserFieldsSubscriber implements EventSubscriberInterfac
*/
public static function getSubscribedEvents() {
return [
CasHelper::EVENT_POST_LOGIN => 'updateUserData',
CasHelper::EVENT_PRE_REGISTER => 'processUserProperties',
CasPostLoginEvent::class => 'updateUserData',
CasPreRegisterEvent::class => 'processUserProperties',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ public function testEuLoginUsersDataSanitization() {
// We need to write in session table to trigger the table creation.
\Drupal::service('session_handler.storage')->write('some-id', 'serialized-session-data');

$this->drush('sql:sanitize');
$version = $this->drushMajorVersion();
$expected = 'The following operations will be performed:' . PHP_EOL;
$expected .= '* Truncate sessions table.' . PHP_EOL;
$expected .= '* Sanitize text fields associated with users.' . PHP_EOL;
$expected .= '* Sanitize user passwords.' . PHP_EOL;
$expected .= '* Sanitize user emails.' . PHP_EOL;
$expected .= '* Preserve user emails and passwords for the specified roles.' . PHP_EOL;
$expected .= '* Sanitise user fields.';

if ($version > 12) {
$expected = 'The following operations will be performed:' . PHP_EOL;
$expected .= '* Sanitize user passwords.' . PHP_EOL;
$expected .= '* Sanitize user emails.' . PHP_EOL;
$expected .= '* Preserve user emails and passwords for the specified roles.' . PHP_EOL;
$expected .= '* Sanitize text fields associated with users.' . PHP_EOL;
$expected .= '* Truncate sessions table.' . PHP_EOL;
$expected .= '* Sanitise user fields.';
}

$this->drush('sql:sanitize');
$this->assertOutputEquals($expected);

$user = \Drupal::entityTypeManager()->getStorage('user')->load($user->id());
Expand Down
2 changes: 1 addition & 1 deletion oe_authentication.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: OE Authentication
description: Authentication against the OpenEuropa Authentication service.
package: OpenEuropa
type: module
core_version_requirement: ^10
core_version_requirement: ^10.3 || ^11
dependencies:
- cas:cas
4 changes: 2 additions & 2 deletions oe_authentication.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

declare(strict_types=1);

use Drupal\cas\Service\CasUserManager;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\cas\Model\EmailAssignment;

/**
* Implements hook_install().
Expand All @@ -32,7 +32,7 @@ function oe_authentication_install(): void {
->set('user_accounts.auto_register_follow_registration_policy', TRUE)
// We need to add a default email domain so that we can trigger
// the appropriate event to handle emails.
->set('user_accounts.email_assignment_strategy', CasUserManager::EMAIL_ASSIGNMENT_STANDARD)
->set('user_accounts.email_assignment_strategy', EmailAssignment::Standard->value)
->set('user_accounts.email_hostname', 'example.com')
->set('login_link_enabled', TRUE)
->set('login_link_label', 'EU Login')
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- ./vendor/openeuropa/code-review-drupal/dist/phpstan.drupal.neon

parameters:
ignoreErrors:
- identifier: class.implementsDeprecatedInterface
2 changes: 1 addition & 1 deletion runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ commands:
// Enable the option 'Initialize this client as a proxy'
// $config['cas.settings']['proxy']['initialize'] = TRUE;
// SSL Configuration to not verify CAS server. DO NOT USE IN PRODUCTION!
$config['cas.settings']['server']['verify'] = '2';
$config['cas.settings']['server']['verify'] = 2;
$config['oe_authentication.settings']['protocol'] = 'eulogin';
$config['oe_authentication.settings']['validation_path'] = 'TicketValidationService';
- { task: "run", command: "setup:phpunit" }
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/ProxyCallbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Drupal\oe_authentication\Controller;

use Drupal\cas\Controller\ProxyCallbackController as CASProxyCallbackController;
use Drupal\cas\Service\CasHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Connection;
use Drupal\cas\Controller\ProxyCallbackController as CASProxyCallbackController;
use Drupal\cas\Service\CasHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -59,7 +59,7 @@ public static function create(ContainerInterface $container) {
* This function stores the incoming PGTIOU and pgtId parameters so that
* the incoming response from the EULogin Server can be looked up.
*/
public function callback() {
public function callback(): Response {
$config = $this->configFactory->get('oe_authentication.settings');
if ($config->get('protocol') !== 'eulogin') {
parent::callback();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Drupal\oe_authentication\Controller;

use Drupal\cas\CasServerConfig;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Url;
use Drupal\cas\CasServerConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

Expand Down
14 changes: 7 additions & 7 deletions src/Event/EuLoginEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace Drupal\oe_authentication\Event;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\cas\Event\CasPostValidateEvent;
use Drupal\cas\Event\CasPreRedirectEvent;
use Drupal\cas\Event\CasPreRegisterEvent;
use Drupal\cas\Event\CasPreValidateEvent;
use Drupal\cas\Service\CasHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\oe_authentication\CasProcessor;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -60,13 +59,14 @@ public static function create(ContainerInterface $container) {
*/
public static function getSubscribedEvents(): array {
$events = [];
$events[CasHelper::EVENT_PRE_REGISTER] = [
$events[CasPreRegisterEvent::class] = [
['checkUserMailExists', 1000],
['processUserProperties'],
];
$events[CasHelper::EVENT_PRE_REDIRECT] = 'forceTwoFactorAuthentication';
$events[CasHelper::EVENT_POST_VALIDATE] = 'processCasAttributes';
$events[CasHelper::EVENT_PRE_VALIDATE] = 'alterValidationPath';
$events[CasPreRedirectEvent::class] = 'forceTwoFactorAuthentication';
$events[CasPostValidateEvent::class] = 'processCasAttributes';
$events[CasPreValidateEvent::class] = 'alterValidationPath';

return $events;
}

Expand Down
Loading

0 comments on commit 31d8a7e

Please sign in to comment.