Skip to content

Commit

Permalink
Add test case for expired token
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupola committed Mar 6, 2018
1 parent b195031 commit a961563
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/JwtAuthenticationTest.php
Expand Up @@ -30,6 +30,7 @@ class JwtAuthenticationTest extends TestCase
{
/* @codingStandardsIgnoreStart */
public static $token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJBY21lIFRvb3RocGljcyBMdGQiLCJpYXQiOjE0Mjg4MTk5NDEsImV4cCI6MTc0NDM1Mjc0MSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoic29tZW9uZUBleGFtcGxlLmNvbSIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSIsImRlbGV0ZSJdfQ.YzPxtyHLqiJMUaPE6DzBonGUyqLlddxIisxSFk2Gk7Y";
public static $expired = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJBY21lIFRvb3RocGljcyBMdGQiLCJpYXQiOjE0Mjg4MTk5NDEsImV4cCI6MTQ4MDcyMzIwMCwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoic29tZW9uZUBleGFtcGxlLmNvbSIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSIsImRlbGV0ZSJdfQ.ZydGEHVmca4ofQRCuMOfZrUXprAoe5GcySg4I-lwIjc";
/* @codingStandardsIgnoreEnd */

public static $token_as_array = [
Expand Down Expand Up @@ -245,6 +246,30 @@ public function testShouldReturn400WithInvalidToken()
$this->assertEquals("", $response->getBody());
}

public function testShouldReturn400WithExpiredToken()
{
$request = (new ServerRequestFactory)
->createServerRequest("GET", "https://example.com/api")
->withHeader("Authorization", "Bearer " . self::$expired);

$default = function (ServerRequestInterface $request) {
$response = (new ResponseFactory)->createResponse();
$response->getBody()->write("Success");
return $response;
};

$collection = new MiddlewareCollection([
new JwtAuthentication([
"secret" => "supersecretkeyyoushouldnotcommittogithub"
])
]);

$response = $collection->dispatch($request, $default);

$this->assertEquals(401, $response->getStatusCode());
$this->assertEquals("", $response->getBody());
}

public function testShouldReturn200WithoutTokenWithPath()
{
$request = (new ServerRequestFactory)
Expand Down

0 comments on commit a961563

Please sign in to comment.