mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02:00
Refactor password checker, add extender (#2176)
This commit is contained in:
committed by
GitHub
parent
fa10d794a4
commit
509adf228a
94
tests/integration/extenders/AuthTest.php
Normal file
94
tests/integration/extenders/AuthTest.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?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\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class AuthTest extends TestCase
|
||||
{
|
||||
use RetrievesAuthorizedUsers;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function standard_password_works_by_default()
|
||||
{
|
||||
$this->app();
|
||||
|
||||
$user = User::find(1);
|
||||
|
||||
$this->assertTrue($user->checkPassword('password'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function standard_password_can_be_disabled()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Auth)
|
||||
->removePasswordChecker('standard')
|
||||
);
|
||||
|
||||
$this->app();
|
||||
|
||||
$user = User::find(1);
|
||||
|
||||
$this->assertFalse($user->checkPassword('password'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_checker_can_be_added()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Auth)
|
||||
->removePasswordChecker('standard')
|
||||
->addPasswordChecker('custom_true', CustomTrueChecker::class)
|
||||
);
|
||||
|
||||
$this->app();
|
||||
|
||||
$user = User::find(1);
|
||||
|
||||
$this->assertTrue($user->checkPassword('DefinitelyNotThePassword'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function false_checker_overrides_true()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Auth)
|
||||
->addPasswordChecker('custom_false', function (User $user, $password) {
|
||||
return false;
|
||||
})
|
||||
);
|
||||
|
||||
$this->app();
|
||||
|
||||
$user = User::find(1);
|
||||
|
||||
$this->assertFalse($user->checkPassword('password'));
|
||||
}
|
||||
}
|
||||
|
||||
class CustomTrueChecker
|
||||
{
|
||||
public function __invoke(User $user, $password)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user