Skip to content
Snippets Groups Projects
Commit fb54cfed authored by Ankit Pathak's avatar Ankit Pathak Committed by Kim Pepper
Browse files

Issue #3433678 by kim.pepper, ankitv18: Automated Drupal 11 compatibility...

Issue #3433678 by kim.pepper, ankitv18: Automated Drupal 11 compatibility fixes for one_time_password
parent bc948bba
No related branches found
Tags 8.x-1.1
1 merge request!6Issue #3433678 "Automated drupal 11"
Pipeline #244980 passed
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
# "ref" value can be:
# - Recommended (default) - `ref: $_GITLAB_TEMPLATES_REF` - The Drupal Association will update this value to the recommended tag for contrib.
# - Latest - `ref: main` - Get the latest additions and bug fixes as they are merged into the templates.
# - Minor or Major latests - `ref: 1.x-latest` or `ref: 1.0.x-latest` - Get the latest additions within a minor (mostly bugfixes) or major (bugs and new features).
# - Fixed tag - `ref: 1.0.1` - Set the value to a known tag. This will not get any updates.
# If you change the default value of ref, you should set the _CURL_TEMPLATES_REF variable in the variables section to be the same as set here.
ref: $_GITLAB_TEMPLATES_REF
file:
- "/includes/include.drupalci.main.yml"
# For Drupal 7, remove the above line and uncomment the below.
# - "/includes/include.drupalci.main-d7.yml"
- "/includes/include.drupalci.variables.yml"
- "/includes/include.drupalci.workflows.yml"
#
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
################
variables:
_CSPELL_WORDS: 'endroid,hotp,otpauth,otphp,totp'
# SKIP_ESLINT: '1'
# OPT_IN_TEST_NEXT_MAJOR: '1'
# _CURL_TEMPLATES_REF: 'main'
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
_CSPELL_WORDS: 'endroid, hotp, otpauth, otphp, totp'
OPT_IN_TEST_PREVIOUS_MINOR: 1
OPT_IN_TEST_NEXT_MINOR: 1
OPT_IN_TEST_NEXT_MAJOR: 1
......@@ -4,7 +4,7 @@
"type": "drupal-module",
"require": {
"spomky-labs/otphp": "^v10.0.1",
"endroid/qr-code": "^3.9.7"
"endroid/qr-code": "^3.9.7 || ^5.0.9"
},
"authors": [
{
......
name: One Time Password
description: An integration for one time passwords according to RFC 4226 (HOTP) and the RFC 6238 (TOTP).
type: module
core_version_requirement: ^9.1 || ^10 || ^11
core_version_requirement: ^10.1 || ^11
dependencies:
- drupal:user
......@@ -25,7 +25,7 @@ function one_time_password_entity_base_field_info_alter(&$fields, EntityTypeInte
/**
* Implements hook_entity_field_access().
*/
function one_time_password_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
function one_time_password_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, ?FieldItemListInterface $items = NULL) {
return \Drupal::classResolver()
->getInstanceFromDefinition(UserFieldAttach::class)
->entityFieldAccess($operation, $field_definition, $account, $items);
......
......@@ -25,6 +25,11 @@ parameters:
count: 1
path: one_time_password.module
-
message: "#^Function one_time_password_entity_field_access\\(\\) has parameter \\$items with no value type specified in iterable type Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\.$#"
count: 1
path: one_time_password.module
-
message: "#^Function one_time_password_entity_field_access\\(\\) has parameter \\$operation with no type specified\\.$#"
count: 1
......@@ -51,18 +56,18 @@ parameters:
path: src/Form/PasswordSetupForm.php
-
message: "#^Cannot access property \\$one_time_password on Drupal\\\\user\\\\Entity\\\\User\\|null\\.$#"
count: 2
message: "#^Call to function method_exists\\(\\) with 'Endroid\\\\\\\\QrCode\\\\\\\\QrCode' and 'writeDataUri' will always evaluate to false\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Cannot access property \\$one_time_password on mixed\\.$#"
count: 2
message: "#^Method Drupal\\\\one_time_password\\\\Form\\\\PasswordSetupForm\\:\\:buildForm\\(\\) has parameter \\$form with no value type specified in iterable type array\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Cannot call method save\\(\\) on mixed\\.$#"
count: 2
message: "#^Method Drupal\\\\one_time_password\\\\Form\\\\PasswordSetupForm\\:\\:buildForm\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
......@@ -70,33 +75,53 @@ parameters:
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Method Drupal\\\\one_time_password\\\\Form\\\\PasswordSetupForm\\:\\:disableTwoFactorAuth\\(\\) has parameter \\$form with no value type specified in iterable type array\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Method Drupal\\\\one_time_password\\\\Form\\\\PasswordSetupForm\\:\\:enableTwoFactorAuth\\(\\) has no return type specified\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Method Drupal\\\\one_time_password\\\\Form\\\\PasswordSetupForm\\:\\:enableTwoFactorAuth\\(\\) has parameter \\$form with no value type specified in iterable type array\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Method Drupal\\\\one_time_password\\\\Form\\\\PasswordSetupForm\\:\\:submitForm\\(\\) has no return type specified\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Method Drupal\\\\one_time_password\\\\Form\\\\PasswordSetupForm\\:\\:submitForm\\(\\) has parameter \\$form with no value type specified in iterable type array\\.$#"
count: 1
path: src/Form/PasswordSetupForm.php
-
message: "#^Method Drupal\\\\one_time_password\\\\Plugin\\\\Field\\\\FieldType\\\\ProvisioningUriItem\\:\\:getOneTimePassword\\(\\) should return OTPHP\\\\TOTPInterface but returns OTPHP\\\\OTPInterface\\.$#"
count: 1
path: src/Plugin/Field/FieldType/ProvisioningUriItem.php
-
message: "#^Class Drupal\\\\one_time_password\\\\Plugin\\\\Field\\\\FieldType\\\\ProvisioningUriItemList extends generic class Drupal\\\\Core\\\\Field\\\\FieldItemList but does not specify its types\\: T$#"
message: "#^Method Drupal\\\\one_time_password\\\\Plugin\\\\Field\\\\FieldType\\\\ProvisioningUriItem\\:\\:schema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Plugin/Field/FieldType/ProvisioningUriItem.php
-
message: "#^Call to function method_exists\\(\\) with 'OTPHP\\\\\\\\TOTP' and 'generate' will always evaluate to false\\.$#"
count: 1
path: src/Plugin/Field/FieldType/ProvisioningUriItemList.php
-
message: "#^Method Drupal\\\\one_time_password\\\\Plugin\\\\Field\\\\FieldType\\\\ProvisioningUriItemList\\:\\:regenerateOneTimePassword\\(\\) has no return type specified\\.$#"
message: "#^Class Drupal\\\\one_time_password\\\\Plugin\\\\Field\\\\FieldType\\\\ProvisioningUriItemList extends generic class Drupal\\\\Core\\\\Field\\\\FieldItemList but does not specify its types\\: T$#"
count: 1
path: src/Plugin/Field/FieldType/ProvisioningUriItemList.php
-
message: "#^Parameter \\#1 \\$label of method OTPHP\\\\OTPInterface\\:\\:setLabel\\(\\) expects string, Drupal\\\\Core\\\\StringTranslation\\\\TranslatableMarkup\\|string\\|null given\\.$#"
message: "#^Method Drupal\\\\one_time_password\\\\Plugin\\\\Field\\\\FieldType\\\\ProvisioningUriItemList\\:\\:regenerateOneTimePassword\\(\\) has no return type specified\\.$#"
count: 1
path: src/Plugin/Field/FieldType/ProvisioningUriItemList.php
......@@ -131,17 +156,17 @@ parameters:
path: src/UserFieldAttach.php
-
message: "#^Method Drupal\\\\one_time_password\\\\UserFieldAttach\\:\\:entityFieldAccess\\(\\) has parameter \\$operation with no type specified\\.$#"
message: "#^Method Drupal\\\\one_time_password\\\\UserFieldAttach\\:\\:entityFieldAccess\\(\\) has parameter \\$items with no value type specified in iterable type Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\.$#"
count: 1
path: src/UserFieldAttach.php
-
message: "#^Method Drupal\\\\one_time_password\\\\UserFieldAttach\\:\\:installFieldDefinition\\(\\) has no return type specified\\.$#"
message: "#^Method Drupal\\\\one_time_password\\\\UserFieldAttach\\:\\:entityFieldAccess\\(\\) has parameter \\$operation with no type specified\\.$#"
count: 1
path: src/UserFieldAttach.php
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
message: "#^Method Drupal\\\\one_time_password\\\\UserFieldAttach\\:\\:installFieldDefinition\\(\\) has no return type specified\\.$#"
count: 1
path: src/UserFieldAttach.php
......@@ -150,16 +175,6 @@ parameters:
count: 1
path: src/UserLoginEnforce.php
-
message: "#^Cannot access property \\$one_time_password on Drupal\\\\user\\\\Entity\\\\User\\|null\\.$#"
count: 2
path: src/UserLoginEnforce.php
-
message: "#^Cannot call method getClientIp\\(\\) on Symfony\\\\Component\\\\HttpFoundation\\\\Request\\|null\\.$#"
count: 1
path: src/UserLoginEnforce.php
-
message: "#^Method Drupal\\\\one_time_password\\\\UserLoginEnforce\\:\\:formUserLoginFormAlter\\(\\) has no return type specified\\.$#"
count: 1
......@@ -180,43 +195,23 @@ parameters:
count: 1
path: src/UserLoginEnforce.php
-
message: "#^Parameter \\#1 \\$otp of method OTPHP\\\\TOTP\\:\\:verify\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/UserLoginEnforce.php
-
message: "#^Parameter \\#3 \\$identifier of method Drupal\\\\Core\\\\Flood\\\\FloodInterface\\:\\:register\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/UserLoginEnforce.php
-
message: "#^Parameter \\#4 \\$identifier of method Drupal\\\\Core\\\\Flood\\\\FloodInterface\\:\\:isAllowed\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/UserLoginEnforce.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\:\\:regenerateOneTimePassword\\(\\)\\.$#"
count: 1
path: tests/src/Functional/InstallationTest.php
-
message: "#^Cannot access property \\$one_time_password on Drupal\\\\user\\\\Entity\\\\User\\|null\\.$#"
count: 1
path: tests/src/Functional/InstallationTest.php
-
message: "#^Cannot call method save\\(\\) on Drupal\\\\user\\\\Entity\\\\User\\|null\\.$#"
message: "#^Method Drupal\\\\Tests\\\\one_time_password\\\\Functional\\\\InstallationTest\\:\\:testInstallUninstall\\(\\) has no return type specified\\.$#"
count: 1
path: tests/src/Functional/InstallationTest.php
-
message: "#^Method Drupal\\\\Tests\\\\one_time_password\\\\Functional\\\\InstallationTest\\:\\:testInstallUninstall\\(\\) has no return type specified\\.$#"
message: "#^PHPDoc type array of property Drupal\\\\Tests\\\\one_time_password\\\\Functional\\\\InstallationTest\\:\\:\\$modules is not covariant with PHPDoc type array\\<string\\> of overridden property Drupal\\\\Tests\\\\BrowserTestBase\\:\\:\\$modules\\.$#"
count: 1
path: tests/src/Functional/InstallationTest.php
-
message: "#^PHPDoc type array of property Drupal\\\\Tests\\\\one_time_password\\\\Functional\\\\InstallationTest\\:\\:\\$modules is not covariant with PHPDoc type array\\<string\\> of overridden property Drupal\\\\Tests\\\\BrowserTestBase\\:\\:\\$modules\\.$#"
message: "#^Property Drupal\\\\Tests\\\\one_time_password\\\\Functional\\\\InstallationTest\\:\\:\\$modules type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/src/Functional/InstallationTest.php
......@@ -255,6 +250,11 @@ parameters:
count: 1
path: tests/src/Functional/PasswordSetupFormTest.php
-
message: "#^Property Drupal\\\\Tests\\\\one_time_password\\\\Functional\\\\PasswordSetupFormTest\\:\\:\\$modules type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/src/Functional/PasswordSetupFormTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\:\\:getOneTimePassword\\(\\)\\.$#"
count: 3
......@@ -330,6 +330,11 @@ parameters:
count: 3
path: tests/src/Functional/UserLoginEnforceTest.php
-
message: "#^Property Drupal\\\\Tests\\\\one_time_password\\\\Functional\\\\UserLoginEnforceTest\\:\\:\\$modules type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/src/Functional/UserLoginEnforceTest.php
-
message: "#^Access to an undefined property Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\:\\:\\$uri\\.$#"
count: 1
......@@ -375,6 +380,11 @@ parameters:
count: 1
path: tests/src/Kernel/ProvisioningUriItemTest.php
-
message: "#^Property Drupal\\\\Tests\\\\one_time_password\\\\Kernel\\\\ProvisioningUriItemTest\\:\\:\\$modules type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/src/Kernel/ProvisioningUriItemTest.php
-
message: "#^Property Drupal\\\\entity_test\\\\Entity\\\\EntityTest\\:\\:\\$test_field \\(Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\) does not accept array\\.$#"
count: 1
......@@ -419,3 +429,8 @@ parameters:
message: "#^Parameter \\#2 \\$account of method Drupal\\\\Core\\\\Entity\\\\ContentEntityBase\\:\\:access\\(\\) expects Drupal\\\\Core\\\\Session\\\\AccountInterface\\|null, Drupal\\\\user\\\\Entity\\\\User\\|false given\\.$#"
count: 1
path: tests/src/Kernel/UserFieldAttachTest.php
-
message: "#^Property Drupal\\\\Tests\\\\one_time_password\\\\Kernel\\\\UserFieldAttachTest\\:\\:\\$modules type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/src/Kernel/UserFieldAttachTest.php
includes:
- phpstan-baseline.neon
parameters:
level: max
paths:
- src
- tests
reportUnmatchedIgnoredErrors: true
checkMissingIterableValueType: false
level: 7
......@@ -6,6 +6,7 @@ use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Entity\User;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;
/**
* A form for setting up one time passwords.
......@@ -22,7 +23,7 @@ class PasswordSetupForm extends FormBase {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, User $user = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, ?User $user = NULL) {
$form_state->set('user', $user);
if ($user->one_time_password->isEmpty()) {
$form['instructions'] = [
......@@ -36,11 +37,25 @@ class PasswordSetupForm extends FormBase {
}
else {
$password = $user->one_time_password->getOneTimePassword();
$qr_code = new QrCode($password->getProvisioningUri());
$qr_code->setSize(200);
// @todo Remove BC support in
// https://www.drupal.org/project/one_time_password/issues/3465857
if (method_exists(QrCode::class, 'writeDataUri')) {
$qr_code = new QrCode($password->getProvisioningUri());
$qr_code->setSize(200);
// @phpstan-ignore-next-line
$data_uri = $qr_code->writeDataUri();
}
else {
$qr_code = QrCode::create($password->getProvisioningUri())
->setSize(200);
$writer = new PngWriter();
$result = $writer->write($qr_code);
$data_uri = $result->getDataUri();
}
$form['qr_code'] = [
'#theme' => 'image',
'#uri' => $qr_code->writeDataUri(),
'#uri' => $data_uri,
];
$form['instructions'] = [
'#theme' => 'one_time_password_setup_instructions',
......
......@@ -26,7 +26,12 @@ class ProvisioningUriItemList extends FieldItemList {
public function regenerateOneTimePassword() {
// Only use the default 30 seconds and SHA1 hash because google
// authenticator will ignore other configurations.
$password = TOTP::create();
if (method_exists(TOTP::class, 'generate')) {
$password = TOTP::generate();
}
else {
$password = TOTP::create();
}
$password->setLabel($this->getEntity()->label());
$this->list[0] = $this->createItem(0, [
'uri' => $password->getProvisioningUri(),
......
......@@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Manage attaching the new field to the user entity.
*/
class UserFieldAttach implements ContainerInjectionInterface {
final class UserFieldAttach implements ContainerInjectionInterface {
use StringTranslationTrait;
......@@ -86,7 +86,7 @@ class UserFieldAttach implements ContainerInjectionInterface {
/**
* Implements hook_entity_field_access().
*/
public function entityFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
public function entityFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, ?FieldItemListInterface $items = NULL) {
if ($field_definition->getName() === 'one_time_password') {
return AccessResult::forbidden();
}
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\one_time_password\Kernel;
use Drupal\entity_test\Entity\EntityTest;
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\one_time_password\Kernel;
use Drupal\KernelTests\KernelTestBase;
......
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