| @@ 5-33 (lines=29) @@ | ||
| 2 | ||
| 3 | namespace Emarref\Jwt\Algorithm; |
|
| 4 | ||
| 5 | class Hs256Test extends \PHPUnit_Framework_TestCase |
|
| 6 | { |
|
| 7 | const ALGORITHM = 'sha256'; |
|
| 8 | ||
| 9 | private static $name = 'HS256'; |
|
| 10 | private static $secret = 'secret'; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var Hs256 |
|
| 14 | */ |
|
| 15 | private $algorithm; |
|
| 16 | ||
| 17 | public function setUp() |
|
| 18 | { |
|
| 19 | $this->algorithm = new Hs256(self::$secret); |
|
| 20 | } |
|
| 21 | ||
| 22 | public function testGetName() |
|
| 23 | { |
|
| 24 | $this->assertSame(self::$name, $this->algorithm->getName()); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function testCompute() |
|
| 28 | { |
|
| 29 | $unencryptedValue = 'foobar'; |
|
| 30 | $encryptedValue = hash_hmac(self::ALGORITHM, $unencryptedValue, self::$secret, true); |
|
| 31 | $this->assertSame($encryptedValue, $this->algorithm->compute($unencryptedValue)); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||
| @@ 5-33 (lines=29) @@ | ||
| 2 | ||
| 3 | namespace Emarref\Jwt\Algorithm; |
|
| 4 | ||
| 5 | class Hs384Test extends \PHPUnit_Framework_TestCase |
|
| 6 | { |
|
| 7 | const ALGORITHM = 'sha384'; |
|
| 8 | ||
| 9 | private static $name = 'HS384'; |
|
| 10 | private static $secret = 'secret'; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var Hs384 |
|
| 14 | */ |
|
| 15 | private $algorithm; |
|
| 16 | ||
| 17 | public function setUp() |
|
| 18 | { |
|
| 19 | $this->algorithm = new Hs384(self::$secret); |
|
| 20 | } |
|
| 21 | ||
| 22 | public function testGetName() |
|
| 23 | { |
|
| 24 | $this->assertSame(self::$name, $this->algorithm->getName()); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function testCompute() |
|
| 28 | { |
|
| 29 | $unencryptedValue = 'foobar'; |
|
| 30 | $encryptedValue = hash_hmac(self::ALGORITHM, $unencryptedValue, self::$secret, true); |
|
| 31 | $this->assertSame($encryptedValue, $this->algorithm->compute($unencryptedValue)); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||
| @@ 5-33 (lines=29) @@ | ||
| 2 | ||
| 3 | namespace Emarref\Jwt\Algorithm; |
|
| 4 | ||
| 5 | class Hs512Test extends \PHPUnit_Framework_TestCase |
|
| 6 | { |
|
| 7 | const ALGORITHM = 'sha512'; |
|
| 8 | ||
| 9 | private static $name = 'HS512'; |
|
| 10 | private static $secret = 'secret'; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var Hs512 |
|
| 14 | */ |
|
| 15 | private $algorithm; |
|
| 16 | ||
| 17 | public function setUp() |
|
| 18 | { |
|
| 19 | $this->algorithm = new Hs512(self::$secret); |
|
| 20 | } |
|
| 21 | ||
| 22 | public function testGetName() |
|
| 23 | { |
|
| 24 | $this->assertSame(self::$name, $this->algorithm->getName()); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function testCompute() |
|
| 28 | { |
|
| 29 | $unencryptedValue = 'foobar'; |
|
| 30 | $encryptedValue = hash_hmac(self::ALGORITHM, $unencryptedValue, self::$secret, true); |
|
| 31 | $this->assertSame($encryptedValue, $this->algorithm->compute($unencryptedValue)); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||