1
0
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:
Alexander Skvortsov
2021-02-22 17:08:36 -05:00
committed by GitHub
parent c4ffa73d31
commit 0d81f248f8
5 changed files with 206 additions and 5 deletions

View 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;
}
}