From f31fbc5bcfa978f0fdddd0d832865af81cb5ed2f Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 20 Mar 2020 18:28:28 +0100 Subject: [PATCH] Tests: Use new authenticatedAs option where useful There are two more API integration tests that explicitly add the "Authorization" header right now: - `Flarum\Tests\integration\api\authentication\WithApiKeyTest` - `Flarum\Tests\integration\api\csrf_protection\RequireCsrfTokenTest` These two specifically test authentication, so in those cases the explicitness seems desirable. --- tests/integration/api/notifications/ListTest.php | 8 +++----- tests/integration/api/users/CreationTest.php | 6 ++---- tests/integration/api/users/ListTest.php | 8 +++----- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/integration/api/notifications/ListTest.php b/tests/integration/api/notifications/ListTest.php index 1e0b3d2c6..946885483 100644 --- a/tests/integration/api/notifications/ListTest.php +++ b/tests/integration/api/notifications/ListTest.php @@ -24,9 +24,6 @@ class ListTest extends TestCase 'users' => [ $this->normalUser(), ], - 'access_tokens' => [ - ['token' => 'normaltoken', 'user_id' => 2], - ], ]); } @@ -48,8 +45,9 @@ class ListTest extends TestCase public function shows_index_for_user() { $response = $this->send( - $this->request('GET', '/api/notifications') - ->withHeader('Authorization', 'Token normaltoken') + $this->request('GET', '/api/notifications', [ + 'authenticatedAs' => 2, + ]) ); $this->assertEquals(200, $response->getStatusCode()); diff --git a/tests/integration/api/users/CreationTest.php b/tests/integration/api/users/CreationTest.php index 25c763577..65351c0e6 100644 --- a/tests/integration/api/users/CreationTest.php +++ b/tests/integration/api/users/CreationTest.php @@ -35,9 +35,6 @@ class CreationTest extends TestCase 'settings' => [ ['key' => 'mail_driver', 'value' => 'log'], ], - 'access_tokens' => [ - ['token' => 'admintoken', 'user_id' => 1], - ], ]); } @@ -128,6 +125,7 @@ class CreationTest extends TestCase 'POST', '/api/users', [ + 'authenticatedAs' => 1, 'json' => [ 'data' => [ 'attributes' => [ @@ -139,7 +137,7 @@ class CreationTest extends TestCase ] ], ] - )->withHeader('Authorization', 'Token admintoken') + ) ); $this->assertEquals(201, $response->getStatusCode()); diff --git a/tests/integration/api/users/ListTest.php b/tests/integration/api/users/ListTest.php index 4aff4e5da..627998f12 100644 --- a/tests/integration/api/users/ListTest.php +++ b/tests/integration/api/users/ListTest.php @@ -33,9 +33,6 @@ class ListTest extends TestCase 'group_user' => [ ['user_id' => 1, 'group_id' => 1], ], - 'access_tokens' => [ - ['token' => 'admintoken', 'user_id' => 1], - ], ]); } @@ -76,8 +73,9 @@ class ListTest extends TestCase public function shows_index_for_admin() { $response = $this->send( - $this->request('GET', '/api/users') - ->withHeader('Authorization', 'Token admintoken') + $this->request('GET', '/api/users', [ + 'authenticatedAs' => 1, + ]) ); $this->assertEquals(200, $response->getStatusCode());