Skip to content

Commit 830e0c3

Browse files
committed
Add test to assert fresh cert is fetched after signature failure
1 parent 42bb678 commit 830e0c3

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tests/TaskHandlerTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace Tests;
44

55
use Firebase\JWT\JWT;
6+
use Firebase\JWT\SignatureInvalidException;
67
use Google\Cloud\Tasks\V2\CloudTasksClient;
7-
use GuzzleHttp\Client;
8-
use Illuminate\Support\Facades\Cache;
8+
use Illuminate\Cache\Events\CacheHit;
9+
use Illuminate\Cache\Events\KeyWritten;
10+
use Illuminate\Support\Facades\Event;
911
use Illuminate\Support\Facades\Mail;
1012
use Mockery;
11-
use phpseclib\Crypt\RSA;
1213
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksException;
1314
use Stackkit\LaravelGoogleCloudTasksQueue\OpenIdVerificator;
1415
use Stackkit\LaravelGoogleCloudTasksQueue\TaskHandler;
@@ -116,6 +117,21 @@ public function it_will_validate_the_token_expiration()
116117
$this->handler->handle($this->simpleJob());
117118
}
118119

120+
/** @test */
121+
public function in_case_of_signature_verification_failure_it_will_retry()
122+
{
123+
Event::fake();
124+
125+
$this->jwt->shouldReceive('decode')->andThrow(SignatureInvalidException::class);
126+
127+
$this->expectException(SignatureInvalidException::class);
128+
129+
$this->handler->handle($this->simpleJob());
130+
131+
Event::assertDispatched(CacheHit::class);
132+
Event::assertDispatched(KeyWritten::class);
133+
}
134+
119135
/** @test */
120136
public function it_runs_the_incoming_job()
121137
{

0 commit comments

Comments
 (0)