34 lines
918 B
PHP
34 lines
918 B
PHP
<?php
|
|
|
|
namespace NoccyLabs\SimpleJwt\Validator;
|
|
|
|
use NoccyLabs\SimpleJwt\JwtToken;
|
|
use NoccyLabs\SimpleJwt\Key\JwtPlaintextKey;
|
|
|
|
class JwtValidatorTest extends \PhpUnit\Framework\TestCase
|
|
{
|
|
|
|
public function testValidKeysShouldPassWithDefaultConfiguration()
|
|
{
|
|
$key = new JwtPlaintextKey("key");
|
|
$token = new JwtToken($key);
|
|
|
|
$validator = new JwtValidator();
|
|
$valid = $validator->validateToken($token);
|
|
$this->assertEquals(true, $valid);
|
|
}
|
|
|
|
public function testExpiredKeysShouldFailWithException()
|
|
{
|
|
$key = new JwtPlaintextKey("key");
|
|
$token = new JwtToken($key);
|
|
$token->header->set("exp", 0);
|
|
|
|
$token = new JwtToken($key, $token->getSignedToken());
|
|
|
|
$validator = new JwtValidator();
|
|
$this->expectException(JwtTokenException::class);
|
|
$valid = $validator->validateToken($token);
|
|
}
|
|
|
|
} |