Problem/Motivation

In UiHelperTrait::drupalLogin() we call user_pass_reset_url() to build a url for 'user.reset' route, and then append '/login?destination=user/' . $account->id().
This does not work if the url ends with a language suffix like '_en'.
We would end up with a url like '***/user/reset/552/***/_*****_en/login?destination=user/552'.

This is relevant for contrib modules that use core traits for testing.

Steps to reproduce

Create and enable a language negotiation plugin which appends a suffix like '_en' (or perhaps '/en') to the url.
Write a functional test with that module and plugin enabled.
Call ->drupalLogin() in that test.

Proposed resolution

Instead of calling user_pass_reset_url(), we build a url for 'user.reset.login', which already has the '/login' suffix.
Unfortunately there is no built-in function for that.

Given that user_pass_reset_url() is a legacy procedural function, and we will have to redesign that part of Drupal in a modern way, for now we should simply hard-code everything.

We might even refrain from adding a new method in UiHelperTrait, as this could nameclash with existing methods in contrib tests, and we might want to remove it again in the future. Instead, we just inline everything. Ugly but least disruptive.

We can backport this to as many branches as possible.

Testing: I just realized that I would need to write an entire language negotiation plugin just to test this.
This would be a lot of effort for little benefit.
Maybe people can just keep this as a patch for now.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3599305

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

donquixote created an issue. See original summary.

donquixote’s picture

I just notice, this only applies to older Drupal versions prior to #3581056: Introduce a OneTimeAuthentication service and deprecate user_pass_rehash.
Still we could fix it for those versions.

donquixote’s picture

Version: main » 11.3.x-dev

11.3.x is the latest which does not have the new OneTimeAuthentication service.

donquixote’s picture

Issue summary: View changes

donquixote’s picture

Test fail seems a bit random.
Here is a patch for people to use.

donquixote’s picture

Patch for 10.6.x.

EDIT: a/ and b/ prefix missing in patch.
Going to fix later.

donquixote’s picture

Patch format should be fixed now.