Add extensive controller and model tests
This commit is contained in:
34
tests/Unit/FortifyServiceProviderTest.php
Normal file
34
tests/Unit/FortifyServiceProviderTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use App\Providers\FortifyServiceProvider;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Session\Store;
|
||||
use Illuminate\Session\ArraySessionHandler;
|
||||
use Laravel\Fortify\Fortify;
|
||||
|
||||
it('registers rate limiters for login and two-factor', function (): void {
|
||||
(new FortifyServiceProvider(app()))->boot();
|
||||
|
||||
$loginLimiter = RateLimiter::limiter('login');
|
||||
$twoFactorLimiter = RateLimiter::limiter('two-factor');
|
||||
|
||||
$request = Request::create('/login', 'POST', [
|
||||
Fortify::username() => 'Test@Example.com',
|
||||
]);
|
||||
$request->server->set('REMOTE_ADDR', '127.0.0.1');
|
||||
$request->setLaravelSession(new Store('test', new ArraySessionHandler(60)));
|
||||
$request->session()->put('login.id', 'login-id');
|
||||
|
||||
$loginLimit = $loginLimiter($request);
|
||||
|
||||
expect($loginLimit)->toBeInstanceOf(Limit::class);
|
||||
expect($loginLimit->maxAttempts)->toBe(5);
|
||||
expect($loginLimit->key)->toBe(Str::transliterate('test@example.com|127.0.0.1'));
|
||||
|
||||
$twoFactorLimit = $twoFactorLimiter($request);
|
||||
expect($twoFactorLimit)->toBeInstanceOf(Limit::class);
|
||||
expect($twoFactorLimit->maxAttempts)->toBe(5);
|
||||
});
|
||||
Reference in New Issue
Block a user