Skip to content

Commit

Permalink
🐛 Should properly initialize auth timeout session
Browse files Browse the repository at this point in the history
Signed-off-by: Julio Motol <[email protected]>
  • Loading branch information
juliomotol committed May 10, 2023
1 parent 6224614 commit 13b8062
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## v4.0.1 (2022-05-11)

### Fixed

- Should properly initialize auth timeout session.

## v4.0.0 (2022-02-16)

Laravel Auth Timeout has received a complete refresh. Please make sure to read through all the changes.
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/InitializeAuthTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class InitializeAuthTimeout
{
public function handle(): void
{
if (! Session::isStarted()) {
if (Session::isStarted()) {
AuthTimeout::init();
}
}
Expand Down
18 changes: 10 additions & 8 deletions tests/CheckAuthTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

use Carbon\Carbon;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Events\Login;
use Illuminate\Foundation\Auth\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Session;
use JulioMotol\AuthTimeout\Facades\AuthTimeout;
use JulioMotol\AuthTimeout\Middlewares\CheckAuthTimeout;
use function Pest\Laravel\actingAs;
use function Pest\Laravel\travel;

afterEach(function () {
Expand All @@ -22,7 +19,11 @@
});

it('should proceed when user is guest', function () {
expect(AuthTimeout::lastActiveAt())->toBeNull();

runMiddleware();

expect(AuthTimeout::lastActiveAt())->toBeNull();
});

it('should timeout when idled', function () {
Expand Down Expand Up @@ -53,10 +54,10 @@
})->throws(AuthenticationException::class);

it('should reset session when not timed out', function () {
$startTime = Carbon::now();

login();

$startTime = AuthTimeout::lastActiveAt();

travel(config('auth-timeout.timeout') - 1)->minutes();

runMiddleware();
Expand All @@ -66,10 +67,11 @@

function login()
{
$user = new User();
Session::start();

Auth::login(new User());

actingAs($user);
Event::dispatch(new Login('test', $user, false));
expect(AuthTimeout::lastActiveAt())->toBeInstanceOf(Carbon::class);
}

function runMiddleware()
Expand Down

0 comments on commit 13b8062

Please sign in to comment.