php-simple-jwt/tests/JwtTokenTest.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2021-02-11 13:22:51 +01:00
<?php
2023-04-09 02:40:21 +02:00
namespace NoccyLabs\SimpleJWT;
2021-02-11 13:22:51 +01:00
2023-04-09 02:40:21 +02:00
use NoccyLabs\SimpleJWT\Key\JWTPlaintextKey;
2021-02-11 13:22:51 +01:00
2023-04-09 02:40:21 +02:00
class JWTTokenTest extends \PHPUnit\Framework\TestCase
2021-02-11 13:22:51 +01:00
{
2023-04-09 02:40:21 +02:00
/**
2023-04-10 00:04:43 +02:00
* @covers NoccyLabs\SimpleJWT\JWTToken
* @covers NoccyLabs\SimpleJWT\Key\JWTPlaintextKey
* @covers NoccyLabs\SimpleJWT\Collection\PropertyBag
* @covers NoccyLabs\SimpleJWT\JWTUtil
2023-04-09 02:40:21 +02:00
*/
2021-02-11 13:22:51 +01:00
public function testGeneratingTokens()
{
2023-04-09 02:40:21 +02:00
$key = new JWTPlaintextKey("test");
2021-02-11 13:22:51 +01:00
2023-04-09 02:40:21 +02:00
$tok = new JWTToken($key);
2021-02-11 13:22:51 +01:00
$tok->addClaim("foo", true);
$token = $tok->getSignedToken();
$this->assertNotNull($token);
$this->assertTrue($tok->isGenerated());
}
2023-04-09 02:40:21 +02:00
/**
2023-04-10 00:04:43 +02:00
* @covers NoccyLabs\SimpleJWT\JWTToken
* @covers NoccyLabs\SimpleJWT\Key\JWTPlaintextKey
* @covers NoccyLabs\SimpleJWT\Collection\PropertyBag
* @covers NoccyLabs\SimpleJWT\JWTUtil
2023-04-09 02:40:21 +02:00
*/
2021-02-11 13:22:51 +01:00
public function testParsingTokens()
{
2023-04-09 02:40:21 +02:00
$key = new JWTPlaintextKey("test");
2021-02-11 13:22:51 +01:00
2023-04-09 02:40:21 +02:00
$tok = new JWTToken($key);
2021-02-11 13:22:51 +01:00
$tok->addClaim("foo", true);
$token = $tok->getSignedToken();
2023-04-09 02:40:21 +02:00
$parsed = new JWTToken($key, $token);
2021-02-11 13:22:51 +01:00
$this->assertTrue($parsed->isValid());
$this->assertFalse($parsed->isGenerated());
}
2023-04-09 02:40:21 +02:00
}