php-simple-jwt/tests/Key/JWTDerivedKeyTest.php

44 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2021-02-11 12:22:51 +00:00
<?php
2023-04-09 00:40:21 +00:00
namespace NoccyLabs\SimpleJWT\Key;
2021-02-11 12:22:51 +00:00
2023-04-09 00:40:21 +00:00
class JWTDerivedKeyTest extends \PHPUnit\Framework\TestCase
2021-02-11 12:22:51 +00:00
{
2023-04-09 00:40:21 +00:00
/**
2023-04-09 22:04:43 +00:00
* @covers \NoccyLabs\SimpleJWT\Key\JWTDerivedKey
2023-04-09 00:40:21 +00:00
*/
2021-02-11 12:22:51 +00:00
public function testTheDerivedKeysShouldBeConsistent()
{
2023-04-09 00:40:21 +00:00
$key1a = new JWTDerivedKey("foo", "foosalt");
$key1b = new JWTDerivedKey("foo", "foosalt");
2021-02-11 12:22:51 +00:00
$this->assertNotNull($key1a);
$this->assertEquals($key1a->getBinaryKey(), $key1b->getBinaryKey());
2023-04-09 00:40:21 +00:00
$key2a = new JWTDerivedKey("bar", "foosalt");
$key2b = new JWTDerivedKey("bar", "barsalt");
$key2c = new JWTDerivedKey("bar", "barsalt");
2021-02-11 12:22:51 +00:00
$this->assertNotNull($key2a);
$this->assertNotEquals($key2a->getBinaryKey(), $key2b->getBinaryKey());
$this->assertEquals($key2b->getBinaryKey(), $key2c->getBinaryKey());
}
2023-04-09 00:40:21 +00:00
/**
2023-04-09 22:04:43 +00:00
* @covers \NoccyLabs\SimpleJWT\Key\JWTDerivedKey
2023-04-09 00:40:21 +00:00
*/
2021-02-11 12:22:51 +00:00
public function testTheDerivedKeysShouldBeUnique()
{
$keys = [];
2023-04-09 00:40:21 +00:00
$keys[] = (new JWTDerivedKey("foo", "foosalt"))->getBinaryKey();
$keys[] = (new JWTDerivedKey("foo", "barsalt"))->getBinaryKey();
$keys[] = (new JWTDerivedKey("foo", "bazsalt"))->getBinaryKey();
$keys[] = (new JWTDerivedKey("bar", "foosalt"))->getBinaryKey();
$keys[] = (new JWTDerivedKey("bar", "barsalt"))->getBinaryKey();
$keys[] = (new JWTDerivedKey("bar", "bazsalt"))->getBinaryKey();
2021-02-11 12:22:51 +00:00
$unique = array_unique($keys);
$this->assertEquals(count($keys), count($unique));
}
2023-04-09 00:40:21 +00:00
}