1
0
mirror of https://github.com/flarum/core.git synced 2025-07-31 21:50:50 +02:00

Refactor Route Resolving and Dispatch (#2425)

- Split DispatchRoute. This allows us to run middleware after we figure out which route we're on, but before we actually execute the controller for that route.
- By making the route name explicitly available to middlewares, applications like CSRF and floodgate can set patterns based on route names instead of the path, which is an implementation detail.
- Support using route name match for CSRF extender, deprecate path match
This commit is contained in:
Alexander Skvortsov
2020-11-10 12:52:12 -05:00
committed by GitHub
parent 67741c7a6f
commit 0c95774333
12 changed files with 116 additions and 31 deletions

View File

@@ -50,6 +50,7 @@ class CsrfTest extends TestCase
/**
* @test
* @deprecated
*/
public function create_user_post_doesnt_need_csrf_token_if_whitelisted()
{
@@ -82,19 +83,37 @@ class CsrfTest extends TestCase
/**
* @test
*/
public function post_to_unknown_route_will_cause_400_error_without_csrf_override()
public function create_user_post_doesnt_need_csrf_token_if_whitelisted_via_routename()
{
$this->extend(
(new Extend\Csrf)
->exemptRoute('users.create')
);
$this->prepDb();
$response = $this->send(
$this->request('POST', '/api/fake/route/i/made/up')
$this->request('POST', '/api/users', [
'json' => [
'data' => [
'attributes' => $this->testUser
]
],
])
);
$this->assertEquals(400, $response->getStatusCode());
$this->assertEquals(201, $response->getStatusCode());
$user = User::where('username', $this->testUser['username'])->firstOrFail();
$this->assertEquals(0, $user->is_email_confirmed);
$this->assertEquals($this->testUser['username'], $user->username);
$this->assertEquals($this->testUser['email'], $user->email);
}
/**
* @test
* @deprecated
*/
public function csrf_matches_wildcards_properly()
{