1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

fix(testing): use cookie for testing authentication (#3924)

This commit is contained in:
Sami Mazouz
2023-11-10 22:35:24 +01:00
committed by GitHub
parent 3107319812
commit 693bce912a
4 changed files with 65 additions and 30 deletions

View File

@@ -11,6 +11,7 @@ namespace Flarum\Testing\integration;
use Carbon\Carbon;
use Dflydev\FigCookies\SetCookie;
use Flarum\Http\CookieFactory;
use Illuminate\Support\Str;
use Laminas\Diactoros\CallbackStream;
use Psr\Http\Message\ResponseInterface as Response;
@@ -46,11 +47,14 @@ trait BuildsHttpRequests
'user_id' => $userId,
'created_at' => Carbon::now()->toDateTimeString(),
'last_activity_at' => Carbon::now()->toDateTimeString(),
'type' => 'session'
'type' => 'session_remember'
]);
$cookies = $this->app()->getContainer()->make(CookieFactory::class);
return $req
->withAddedHeader('Authorization', "Token {$token}")
->withAttribute('bypassCsrfToken', true)
->withCookieParams([$cookies->getName('remember') => $token])
// We save the token as an attribute so that we can retrieve it for test purposes.
->withAttribute('tests_token', $token);
}