PHP 8.2 Deprecated cleaning

This commit is contained in:
2023-04-03 21:15:54 +02:00
parent 528b959859
commit d34d5a820a
6 changed files with 65 additions and 64 deletions

View File

@@ -13,6 +13,15 @@ use Domframework\Authjwt;
/** Test the Authjwt.php file */
class AuthjwtTest extends \PHPUnit_Framework_TestCase
{
/** @var string */
private $cacheDir;
/** @var string */
private $serverKey;
/** @var string */
private $cipherKey;
/** @var string */
private $token;
public function __construct()
{
$this->cacheDir = "/tmp/testDFWJWT-" . time();
@@ -26,11 +35,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
exec("rm -rf $this->cacheDir");
}
/** Create a valid token as email is provided
/**
* Create a valid token as email is provided
* payload = ["email" => "toto@example.com", "password" => "ToTo"];
*/
public function testJWT1()
// {{{
{
$authjwt = new Authjwt();
$authjwt->cacheDir = $this->cacheDir;
@@ -40,12 +49,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$this->token = $authjwt->createJwtToken($auth);
$this->assertSame(strlen($this->token), 145);
}
// }}}
/** Check if the authentication work
*/
/**
* Check if the authentication work
*/
public function testAuthValid1()
// {{{
{
$authjwt = new Authjwt();
$_SERVER["HTTP_AUTHENTICATION"] = "Bearer " . $this->token;
@@ -59,12 +67,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
["email" => "toto@example.com", "password" => "ToTo"]
);
}
// }}}
/** Invalid Token : reject with invalid signature
*/
/**
* Invalid Token : reject with invalid signature
*/
public function testInvalidToken1()
// {{{
{
$this->expectException("Exception", "JWT Signature not readable", 403);
$authjwt = new Authjwt();
@@ -75,12 +82,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt->authentication("unused", "unused");
$res = $authjwt->getdetails();
}
// }}}
/** Invalid Token : reject with bad algorithm
*/
/**
* Invalid Token : reject with bad algorithm
*/
public function testInvalidToken2()
// {{{
{
$this->expectException("Exception", "JWT with Empty algorithm", 403);
$authjwt = new Authjwt();
@@ -91,12 +97,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt->authentication("unused", "unused");
$res = $authjwt->getdetails();
}
// }}}
/** Invalid Token : No token provided
*/
/**
* Invalid Token : No token provided
*/
public function testInvalidToken3()
// {{{
{
$this->expectException("Exception", "No Authentication available", 401);
$authjwt = new Authjwt();
@@ -107,12 +112,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt->authentication("unused", "unused");
$res = $authjwt->getdetails();
}
// }}}
/** Invalid Token : No Bearer authentication
*/
/**
* Invalid Token : No Bearer authentication
*/
public function testInvalidToken4()
// {{{
{
$this->expectException(
"Exception",
@@ -127,12 +131,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt->authentication("unused", "unused");
$res = $authjwt->getdetails();
}
// }}}
/** Invalid Token : no email in it
*/
/**
* Invalid Token : no email in it
*/
public function testInvalidToken5()
// {{{
{
$this->expectException(
"Exception",
@@ -149,12 +152,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt->authentication("unused", "unused");
$res = $authjwt->getdetails();
}
// }}}
/** Anonymous payload
*/
/**
* Anonymous payload
*/
public function testAnonymous1()
// {{{
{
$this->expectException(
"Exception",
@@ -171,12 +173,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt->authentication("unused", "unused");
$res = $authjwt->getdetails();
}
// }}}
/** Logout
*/
/**
* Logout
*/
public function testLogout1()
// {{{
{
$authjwt = new Authjwt();
$authjwt->cacheDir = $this->cacheDir;
@@ -186,12 +187,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$res = $authjwt->logout();
$this->assertSame($res, true);
}
// }}}
/** Logout : No Auth provided
*/
/**
* Logout : No Auth provided
*/
public function testLogout2()
// {{{
{
$this->expectException("Exception", "No Authentication available", 401);
$authjwt = new Authjwt();
@@ -201,12 +201,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
unset($_SERVER["HTTP_AUTHENTICATION"]);
$res = $authjwt->logout();
}
// }}}
/** Logout : No Bearer available
*/
/**
* Logout : No Bearer available
*/
public function testLogout3()
// {{{
{
$this->expectException(
"Exception",
@@ -220,24 +219,22 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$_SERVER["HTTP_AUTHENTICATION"] = "Another auth";
$res = $authjwt->logout();
}
// }}}
/** Not needed function connect
*/
/**
* Not needed function connect
*/
public function testUnusedFunctions1()
// {{{
{
$authjwt = new Authjwt();
$res = $authjwt->connect();
$this->assertSame($res, true);
}
// }}}
/** Not needed function changepassword
*/
/**
* Not needed function changepassword
*/
public function testUnusedFunctions2()
// {{{
{
$this->expectException(
"Exception",
@@ -247,12 +244,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt = new Authjwt();
$res = $authjwt->changepassword("unused", "unused");
}
// }}}
/** Not needed function overwritepassword
*/
/**
* Not needed function overwritepassword
*/
public function testUnusedFunctions3()
// {{{
{
$this->expectException(
"Exception",
@@ -262,5 +258,4 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase
$authjwt = new Authjwt();
$res = $authjwt->overwritepassword("unused", "unused");
}
// }}}
}