51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace NoccyLabs\SimpleJWT;
|
|
|
|
use NoccyLabs\SimpleJWT\Key\JWTPlaintextKey;
|
|
|
|
class JWTTokenTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
|
|
/**
|
|
* @covers NoccyLabs\SimpleJWT\JWTToken
|
|
* @covers NoccyLabs\SimpleJWT\Key\JWTPlaintextKey
|
|
* @covers NoccyLabs\SimpleJWT\Collection\PropertyBag
|
|
* @covers NoccyLabs\SimpleJWT\JWTUtil
|
|
*/
|
|
public function testGeneratingTokens()
|
|
{
|
|
$key = new JWTPlaintextKey("test");
|
|
|
|
$tok = new JWTToken($key);
|
|
$tok->addClaim("foo", true);
|
|
|
|
$token = $tok->getSignedToken();
|
|
|
|
$this->assertNotNull($token);
|
|
$this->assertTrue($tok->isGenerated());
|
|
}
|
|
|
|
/**
|
|
* @covers NoccyLabs\SimpleJWT\JWTToken
|
|
* @covers NoccyLabs\SimpleJWT\Key\JWTPlaintextKey
|
|
* @covers NoccyLabs\SimpleJWT\Collection\PropertyBag
|
|
* @covers NoccyLabs\SimpleJWT\JWTUtil
|
|
*/
|
|
public function testParsingTokens()
|
|
{
|
|
$key = new JWTPlaintextKey("test");
|
|
|
|
$tok = new JWTToken($key);
|
|
$tok->addClaim("foo", true);
|
|
|
|
$token = $tok->getSignedToken();
|
|
|
|
$parsed = new JWTToken($key, $token);
|
|
|
|
$this->assertTrue($parsed->isValid());
|
|
$this->assertFalse($parsed->isGenerated());
|
|
|
|
}
|
|
}
|