mirror of
https://github.com/flarum/framework.git
synced 2024-12-05 09:03:36 +08:00
d64750b3eb
This naming is clearer as to the intended effect. Changes include: - A migration to rename all permissions - Updating the seed migration to use the original naming from the start - Replacing usage of the old names with new names in code - Throwing warnings when the old names are used.
98 lines
2.4 KiB
PHP
98 lines
2.4 KiB
PHP
<?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\api\access_tokens;
|
|
|
|
use Carbon\Carbon;
|
|
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
|
use Flarum\Testing\integration\TestCase;
|
|
|
|
class RemembererTest extends TestCase
|
|
{
|
|
use RetrievesAuthorizedUsers;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->prepareDatabase([
|
|
'access_tokens' => [
|
|
['token' => 'a', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
|
|
['token' => 'b', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session_remember'],
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function non_remember_tokens_cannot_be_used()
|
|
{
|
|
$this->populateDatabase();
|
|
|
|
Carbon::setTestNow('2021-01-01 02:30:00');
|
|
|
|
$response = $this->send(
|
|
$this->request('GET', '/api')->withCookieParams([
|
|
'flarum_remember' => 'a',
|
|
])
|
|
);
|
|
|
|
Carbon::setTestNow();
|
|
|
|
$data = json_decode($response->getBody(), true);
|
|
$this->assertFalse($data['data']['attributes']['canSearchUsers']);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function expired_tokens_cannot_be_used()
|
|
{
|
|
$this->populateDatabase();
|
|
|
|
Carbon::setTestNow('2027-01-01 02:30:00');
|
|
|
|
$response = $this->send(
|
|
$this->request('GET', '/api')->withCookieParams([
|
|
'flarum_remember' => 'b',
|
|
])
|
|
);
|
|
|
|
Carbon::setTestNow();
|
|
|
|
$data = json_decode($response->getBody(), true);
|
|
$this->assertFalse($data['data']['attributes']['canSearchUsers']);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function valid_tokens_can_be_used()
|
|
{
|
|
$this->populateDatabase();
|
|
|
|
Carbon::setTestNow('2021-01-01 02:30:00');
|
|
|
|
$response = $this->send(
|
|
$this->request('GET', '/api')->withCookieParams([
|
|
'flarum_remember' => 'b',
|
|
])
|
|
);
|
|
|
|
Carbon::setTestNow();
|
|
|
|
$data = json_decode($response->getBody(), true);
|
|
$this->assertTrue($data['data']['attributes']['canSearchUsers']);
|
|
}
|
|
}
|