| @@ 5-44 (lines=40) @@ | ||
| 2 | ||
| 3 | namespace Emarref\Jwt\Algorithm; |
|
| 4 | ||
| 5 | class Rs256Test extends \PHPUnit_Framework_TestCase |
|
| 6 | { |
|
| 7 | private static $name = 'RS256'; |
|
| 8 | private static $algorithmName = 'sha256'; |
|
| 9 | ||
| 10 | /** |
|
| 11 | * @var string |
|
| 12 | */ |
|
| 13 | private $key; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var Rs256 |
|
| 17 | */ |
|
| 18 | private $algorithm; |
|
| 19 | ||
| 20 | public function setUp() |
|
| 21 | { |
|
| 22 | $this->key = openssl_pkey_new(); |
|
| 23 | $this->algorithm = new Rs256(); |
|
| 24 | } |
|
| 25 | ||
| 26 | public function testGetName() |
|
| 27 | { |
|
| 28 | $this->assertSame(self::$name, $this->algorithm->getName()); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testGetAlgorithm() |
|
| 32 | { |
|
| 33 | $this->assertSame(self::$algorithmName, $this->algorithm->getAlgorithm()); |
|
| 34 | } |
|
| 35 | ||
| 36 | public function testSign() |
|
| 37 | { |
|
| 38 | $unencryptedValue = 'foobar'; |
|
| 39 | openssl_sign($unencryptedValue, $encryptedValue, $this->key, OPENSSL_ALGO_SHA256); |
|
| 40 | $signature = $this->algorithm->sign($unencryptedValue, $this->key); |
|
| 41 | ||
| 42 | $this->assertSame($encryptedValue, $signature); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| @@ 5-44 (lines=40) @@ | ||
| 2 | ||
| 3 | namespace Emarref\Jwt\Algorithm; |
|
| 4 | ||
| 5 | class Rs384Test extends \PHPUnit_Framework_TestCase |
|
| 6 | { |
|
| 7 | private static $name = 'RS384'; |
|
| 8 | private static $algorithmName = 'sha384'; |
|
| 9 | ||
| 10 | /** |
|
| 11 | * @var string |
|
| 12 | */ |
|
| 13 | private $key; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var Rs384 |
|
| 17 | */ |
|
| 18 | private $algorithm; |
|
| 19 | ||
| 20 | public function setUp() |
|
| 21 | { |
|
| 22 | $this->key = openssl_pkey_new(); |
|
| 23 | $this->algorithm = new Rs384(); |
|
| 24 | } |
|
| 25 | ||
| 26 | public function testGetName() |
|
| 27 | { |
|
| 28 | $this->assertSame(self::$name, $this->algorithm->getName()); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testGetAlgorithm() |
|
| 32 | { |
|
| 33 | $this->assertSame(self::$algorithmName, $this->algorithm->getAlgorithm()); |
|
| 34 | } |
|
| 35 | ||
| 36 | public function testSign() |
|
| 37 | { |
|
| 38 | $unencryptedValue = 'foobar'; |
|
| 39 | openssl_sign($unencryptedValue, $encryptedValue, $this->key, OPENSSL_ALGO_SHA384); |
|
| 40 | $signature = $this->algorithm->sign($unencryptedValue, $this->key); |
|
| 41 | ||
| 42 | $this->assertSame($encryptedValue, $signature); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| @@ 5-44 (lines=40) @@ | ||
| 2 | ||
| 3 | namespace Emarref\Jwt\Algorithm; |
|
| 4 | ||
| 5 | class Rs512Test extends \PHPUnit_Framework_TestCase |
|
| 6 | { |
|
| 7 | private static $name = 'RS512'; |
|
| 8 | private static $algorithmName = 'sha512'; |
|
| 9 | ||
| 10 | /** |
|
| 11 | * @var string |
|
| 12 | */ |
|
| 13 | private $key; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var Rs512 |
|
| 17 | */ |
|
| 18 | private $algorithm; |
|
| 19 | ||
| 20 | public function setUp() |
|
| 21 | { |
|
| 22 | $this->key = openssl_pkey_new(); |
|
| 23 | $this->algorithm = new Rs512(); |
|
| 24 | } |
|
| 25 | ||
| 26 | public function testGetName() |
|
| 27 | { |
|
| 28 | $this->assertSame(self::$name, $this->algorithm->getName()); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testGetAlgorithm() |
|
| 32 | { |
|
| 33 | $this->assertSame(self::$algorithmName, $this->algorithm->getAlgorithm()); |
|
| 34 | } |
|
| 35 | ||
| 36 | public function testCompute() |
|
| 37 | { |
|
| 38 | $unencryptedValue = 'foobar'; |
|
| 39 | openssl_sign($unencryptedValue, $encryptedValue, $this->key, OPENSSL_ALGO_SHA512); |
|
| 40 | $signature = $this->algorithm->sign($unencryptedValue, $this->key); |
|
| 41 | ||
| 42 | $this->assertSame($encryptedValue, $signature); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||