Passage en Namespace et tous les tests fonctionnels OK

This commit is contained in:
2021-05-10 11:48:15 +02:00
parent 536dd0d56b
commit eb30d8ef97
56 changed files with 1091 additions and 964 deletions

View File

@@ -7,19 +7,21 @@
namespace Domframework\Tests;
/** Test the jwt.php file */
class jwtTest extends \PHPUnit_Framework_TestCase
use Domframework\Jwt;
/** Test the Jwt.php file */
class JwtTest extends \PHPUnit_Framework_TestCase
{
public function test_createKey_1 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$res = $jwt->createKey ();
$this->assertSame (40, strlen ($res));
}
public function test_sign_1 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$res = $this->invokeMethod ($jwt, "sign", "TEXT TO SIGN", "KEY TO USE",
"HS384");
$this->assertSame (
@@ -29,7 +31,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_sign_2 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$res = $this->invokeMethod ($jwt, "sign", "text to sign", "KEY TO USE",
"HS384");
$this->assertSame (
@@ -39,7 +41,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_sign_3 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$res = $this->invokeMethod ($jwt, "sign", "text to sign", "key to use",
"HS384");
$this->assertSame (
@@ -49,7 +51,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_encode_1 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$res = $jwt->encode (array ("payload" => "value"), "key to use", "HS384");
$this->assertSame (
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.".
@@ -59,7 +61,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_decode_1 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$res = $jwt->decode (
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.".
"eyJwYXlsb2FkIjoidmFsdWUifQ.".
@@ -71,7 +73,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_decode_2 ()
{
$GLOBALS["hash_equals"] = false;
$jwt = new jwt ();
$jwt = new Jwt ();
$res = $jwt->decode (
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.".
"eyJwYXlsb2FkIjoidmFsdWUifQ.".
@@ -82,7 +84,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_decode_3 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$this->expectException ("Exception", "JWT with Empty algorithm");
$res = $jwt->decode (
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUXXXXXJ9.".
@@ -93,7 +95,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_decode_4 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$this->expectException ("Exception", "JWT Payload not readable");
$res = $jwt->decode (
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.".
@@ -104,7 +106,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_decode_5 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$this->expectException ("Exception",
"JWT Signature verification failed");
$res = $jwt->decode (
@@ -116,7 +118,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_decode_6 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$this->expectException ("Exception",
"JWT Signature not readable");
$res = $jwt->decode (
@@ -128,7 +130,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
public function test_decode_7 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$this->expectException ("Exception",
"Malformed JWT Token");
$res = $jwt->decode (
@@ -144,7 +146,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
*/
public function testEncrypt1 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$key = $jwt->createKey ();
$res = $jwt->encode (
["email" => "toto@example.com", "password" => "ToTo"],
@@ -156,7 +158,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
*/
public function testEncrypyt2 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$key = $jwt->createKey ();
$payload = (object)["email" => "toto@example.com", "password" => "ToTo"];
$token = $jwt->encode ($payload, $key, "HS256", "123456789012345678901234");
@@ -168,7 +170,7 @@ class jwtTest extends \PHPUnit_Framework_TestCase
*/
public function testEncrypt3 ()
{
$jwt = new jwt ();
$jwt = new Jwt ();
$key = $jwt->createKey ();
$payload = (object)["email" => "toto@example.com", "password" => "ToTo"];
$token = $jwt->encode ($payload, $key, "HS256", "123456789012345678901234");