Compare commits

...

2 Commits

Author SHA1 Message Date
Dominique FOURNIER
d34d5a820a PHP 8.2 Deprecated cleaning 2023-04-03 21:15:54 +02:00
Dominique FOURNIER
528b959859 Dblayeroo : support of objects in foreign parameters 2023-04-03 20:54:35 +02:00
6 changed files with 70 additions and 66 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");
}
// }}}
}

View File

@@ -189,8 +189,8 @@ to this document.
$date = date("Y-m-d H:i:s.u00");
// DST must answer +0200 in winter and +0100 in summer
$dst = date("O");
$this->assertSame($res, "--- Original ${date}0 $dst
+++ New ${date}1 $dst
$this->assertSame($res, "--- Original {$date}0 $dst
+++ New {$date}1 $dst
@@ -0,0 +1,6 @@
+This is an important
+notice! It should

View File

@@ -12,7 +12,10 @@ namespace Domframework;
user by its groups membership */
class Authzgroups
{
/** The table prefix to use */
/**
* The table prefix to use
* @var string
*/
public $tableprefix = "";
/** The dblayer object use to manage the Object table */
private $dbObject = null;
@@ -334,7 +337,7 @@ class Authzgroups
$this->dbObject = new Dblayer($dsn, $username, $password, $driver_options);
$this->dbObject->debug = $this->debug;
$this->dbObject->table = "authzobject";
$this->dbObject->prefix = $this->tableprefix;
$this->dbObject->tableprefix = $this->tableprefix;
$this->dbObject->fields = array(
"idobject" => array("integer", "not null", "autoincrement"),
"module" => array("varchar", "255", "not null"),
@@ -351,7 +354,7 @@ class Authzgroups
$this->dbGroup = new Dblayer($dsn, $username, $password, $driver_options);
$this->dbGroup->debug = $this->debug;
$this->dbGroup->table = "authzgroup";
$this->dbGroup->prefix = $this->tableprefix;
$this->dbGroup->tableprefix = $this->tableprefix;
$this->dbGroup->fields = array(
"idgroup" => array("integer", "not null", "autoincrement"),
"module" => array("varchar", "255", "not null"),
@@ -373,7 +376,7 @@ class Authzgroups
);
$this->dbGroupMember->debug = $this->debug;
$this->dbGroupMember->table = "authzgroupmember";
$this->dbGroupMember->prefix = $this->tableprefix;
$this->dbGroupMember->tableprefix = $this->tableprefix;
$this->dbGroupMember->fields = array(
"idgroupmember" => array("integer", "not null", "autoincrement"),
"user" => array("varchar", "255", "not null"),
@@ -394,7 +397,7 @@ class Authzgroups
$this->dbRight = new Dblayer($dsn, $username, $password, $driver_options);
$this->dbRight->debug = $this->debug;
$this->dbRight->table = "authzright";
$this->dbRight->prefix = $this->tableprefix;
$this->dbRight->tableprefix = $this->tableprefix;
$this->dbRight->fields = array(
"idright" => array("integer", "not null", "autoincrement"),
"idgroup" => array("integer", "not null"),

View File

@@ -234,6 +234,9 @@ extendedKeyUsage = serverAuth, clientAuth
$days = 365,
$altNames = array()
) {
if ($days === null) {
$days = 365;
}
$conf = $this->opensslConf;
if (! empty($altNames)) {
// Copy the commonName from CSR request into subjectAltName

View File

@@ -1044,7 +1044,7 @@ class Dblayeroo
if ($col["is_nullable"] === "NO") {
$tmp[] = "not null";
}
if (substr($col["column_default"], 0, 7) === "nextval") {
if (is_string($col["column_default"]) && substr($col["column_default"], 0, 7) === "nextval") {
$tmp[] = "autoincrement";
$primary = $col["column_name"];
}
@@ -1466,7 +1466,7 @@ class Dblayeroo
$this->DBException("Parameter foreign invalid: " .
"ParentField is not provided");
}
if (! is_string($params[0])) {
if (! is_string($params[0]) && ! is_object($params[0])) {
$this->DBException("Parameter foreign invalid: " .
"parameter 0 is not a string");
}
@@ -1474,7 +1474,7 @@ class Dblayeroo
$this->DBException("Parameter foreign invalid: " .
"parameter 1 is not a string");
}
if (mb_strlen($params[0]) > 64) {
if (is_string($params[0]) && mb_strlen($params[0]) > 64) {
$this->DBException("Parameter foreign invalid: " .
"parameter 0 is too long");
}
@@ -3351,6 +3351,9 @@ class Dblayeroo
);
continue;
}
if (is_object($params[0])) {
$params[0] = $params[0]->tableprefix . $params[0]->table;
}
if (! array_key_exists($params[0], $this->setForeignObj)) {
$this->DBException(sprintf(dgettext(
"domframework",

View File

@@ -362,7 +362,7 @@ class Mail
$headersSplit = preg_split(
"#([\r\n]+)#",
$headersEML,
null,
-1,
PREG_SPLIT_DELIM_CAPTURE
);
for ($i = 0; $i < count($headersSplit); $i = $i + 2) {