Skip to content

Commit 4bd8406

Browse files
committed
minor #16071 [Security] Added a note regarding the loginUser() method (artyuum)
This PR was submitted for the 5.3 branch but it was squashed and merged into the 5.4 branch instead. Discussion ---------- [Security] Added a note regarding the loginUser() method As `@javiereguiluz` [stated](symfony/symfony#32850), this method won't work for 100% of Symfony users. This is my case. I'm testing some protected API routes and the firewall is using a custom authenticator that relies on a custom header called "x-api-key". After spending hours trying to understand what I did wrong in my tests, I decided to dig into the code that defines the `loginUser()` method and noticed that [it can only work with session-based authentication](https://github.com/symfony/symfony/blob/18ab810a8d6d4c17497303df17e931261d542fce/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php#L139). This little note could have saved me some time, so I believe it could help future users as well who are in the same case as me. <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `5.x` for features of unreleased versions). --> Commits ------- 4d29c99 [Security] Added a note regarding the loginUser() method
2 parents 945bb67 + 4d29c99 commit 4bd8406

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

testing.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@ You can pass any
625625
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\TestBrowserToken` object and
626626
stores in the session of the test client.
627627

628+
.. note::
629+
630+
Stateless firewalls cannot use ``loginUser()`` prior to requests by design.
631+
Instead you should add the correct token (i.e. header) in each ``request()`` call.
632+
628633
Making AJAX Requests
629634
....................
630635

0 commit comments

Comments
 (0)