37 lines
1.4 KiB
PHP
37 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace NoccyLabs\SimpleJwt\Key;
|
||
|
|
||
|
|
||
|
class JwtDerivedKeyTest extends \PhpUnit\Framework\TestCase
|
||
|
{
|
||
|
public function testTheDerivedKeysShouldBeConsistent()
|
||
|
{
|
||
|
$key1a = new JwtDerivedKey("foo", "foosalt");
|
||
|
$key1b = new JwtDerivedKey("foo", "foosalt");
|
||
|
$this->assertNotNull($key1a);
|
||
|
$this->assertEquals($key1a->getBinaryKey(), $key1b->getBinaryKey());
|
||
|
|
||
|
$key2a = new JwtDerivedKey("bar", "foosalt");
|
||
|
$key2b = new JwtDerivedKey("bar", "barsalt");
|
||
|
$key2c = new JwtDerivedKey("bar", "barsalt");
|
||
|
$this->assertNotNull($key2a);
|
||
|
$this->assertNotEquals($key2a->getBinaryKey(), $key2b->getBinaryKey());
|
||
|
$this->assertEquals($key2b->getBinaryKey(), $key2c->getBinaryKey());
|
||
|
}
|
||
|
|
||
|
public function testTheDerivedKeysShouldBeUnique()
|
||
|
{
|
||
|
$keys = [];
|
||
|
$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();
|
||
|
|
||
|
$unique = array_unique($keys);
|
||
|
$this->assertEquals(count($keys), count($unique));
|
||
|
}
|
||
|
|
||
|
}
|