mirror of
https://github.com/flarum/core.git
synced 2025-08-05 16:07:34 +02:00
fix(testing): use cookie for testing authentication (#3924)
This commit is contained in:
52
framework/core/tests/integration/admin/IndexTest.php
Normal file
52
framework/core/tests/integration/admin/IndexTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration\admin;
|
||||
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use RetrievesAuthorizedUsers;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->prepareDatabase([
|
||||
'users' => [
|
||||
$this->normalUser()
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function admin_can_access_admin_route(): void
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/admin', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function user_cannot_access_admin_route(): void
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/admin', [
|
||||
'authenticatedAs' => 2,
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
}
|
||||
}
|
@@ -59,19 +59,12 @@ class GlobalLogoutTest extends TestCase
|
||||
* @dataProvider canGloballyLogoutDataProvider
|
||||
* @test
|
||||
*/
|
||||
public function can_globally_log_out(int $authenticatedAs, string $identification, string $password)
|
||||
public function can_globally_log_out(int $authenticatedAs)
|
||||
{
|
||||
$loginResponse = $this->send(
|
||||
$this->request('POST', '/login', [
|
||||
'json' => compact('identification', 'password')
|
||||
])
|
||||
);
|
||||
|
||||
$response = $this->send(
|
||||
$this->requestWithCookiesFrom(
|
||||
$this->request('POST', '/global-logout'),
|
||||
$loginResponse,
|
||||
)
|
||||
$this->request('POST', '/global-logout', [
|
||||
'authenticatedAs' => $authenticatedAs,
|
||||
]),
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
@@ -85,10 +78,10 @@ class GlobalLogoutTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// Admin
|
||||
[1, 'admin', 'password'],
|
||||
[1],
|
||||
|
||||
// Normal user
|
||||
[2, 'normal', 'too-obscure'],
|
||||
[2],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace Flarum\Tests\integration\forum;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
@@ -22,10 +21,6 @@ class IndexTest extends TestCase
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Csrf)->exemptRoute('login')
|
||||
);
|
||||
|
||||
$this->prepareDatabase([
|
||||
'users' => [
|
||||
$this->normalUser()
|
||||
@@ -51,18 +46,9 @@ class IndexTest extends TestCase
|
||||
*/
|
||||
public function user_serialized_by_current_user_serializer()
|
||||
{
|
||||
$login = $this->send(
|
||||
$this->request('POST', '/login', [
|
||||
'json' => [
|
||||
'identification' => 'normal',
|
||||
'password' => 'too-obscure'
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/', [
|
||||
'cookiesFrom' => $login
|
||||
'authenticatedAs' => 2,
|
||||
])
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user