You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm guessing it uses Carbon under the hood, a good solution it would be using Carbon::setTestNow() with your date before generating the token, so it can create it with the simulated now(), and then reset the setTestNow to your current date so you can verify if it expired.
Here's a little example:
publicfunctiontest_token_expire()
{
Config::set('jwt.ttl', 1);
// Traveling to the past by 1 minute
Carbon::setTestNow(Carbon::now()->subMinutes(1));
$user = $this->user();
$response = $this
->withHeaders(['X-DEVICE-ID' => md5(microtime(true))])
->postJson('/v1/login', [
'username' => $user->email,
'password' => 'password'
])
->assertOk();
$token = $response->json('data.token');
$this
->withToken($token)
->get('/v1/me')
->assertOk();
// Traveling back to the present time
Carbon::setTestNow();
$this
->withToken($token)
->get('/v1/me')
->assertUnauthorized();
}
Subject of the issue
I was asked to implement test for jwt token expire for our application.
Because jwt.ttl is in minutes we can't wait 1 minute in test. Instead I'm trying to time travel but that doesn't work.
Your environment
Steps to reproduce
Expected behaviour
Last API should fail, because token is expired after traveling 1 year.
Actual behaviour
Last API isn't failing and user token still works after 1 year.
The text was updated successfully, but these errors were encountered: