-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't test token_expire (no time travel?) #2277
Comments
Even if time travelling is bad idea I would appreciate any alternative solution to make such test. |
I'm guessing it uses Here's a little example: public function test_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();
} You can check the documentation for it |
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: