diff --git a/phpunit.xml b/phpunit.xml index f062ec810c67a21709f308afaeb05b6273df07de..99f13c440ebda9fb9d82c09ba44c6e075b32e978 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="test/unitTests/define.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> + <php> + <server name='HTTP_HOST' value='http://localhost/MaarchParapheurDevelop' /> + <server name='SERVER_PORT' value='80' /> + </php> <coverage> <include> <directory suffix="Test.php">test</directory> diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index b24c49658fc38943e7e7567ebde6fcc1ac0f416b..8929b5f1eb6a6aa38f7f8660e6d62f3c7ba3b7a0 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -135,6 +135,8 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'Body email is empty or not a valid email']); } elseif (!empty($body['x509Fingerprint']) && !Validator::stringType()->validate($body['x509Fingerprint'])) { return $response->withStatus(400)->withJson(['errors' => 'Body x509Fingerprint is not a string']); + } elseif (!Validator::stringType()->notEmpty()->validate($body['phone'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body phone is empty or not a string']); } $body['login'] = strtolower($body['login']); @@ -143,8 +145,6 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'Login already exists', 'lang' => 'userLoginAlreadyExists']); } - $body['x509_fingerprint'] = $body['x509Fingerprint']; - if (!empty($body['isRest'])) { $body['"isRest"'] = true; } @@ -205,6 +205,8 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'Body email is empty or not a valid email']); } elseif (!empty($body['x509Fingerprint']) && !Validator::stringType()->validate($body['x509Fingerprint'])) { return $response->withStatus(400)->withJson(['errors' => 'Body x509Fingerprint is not a string']); + } elseif (!Validator::stringType()->notEmpty()->validate($body['phone'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body phone is empty or not a string']); } $user = UserModel::getById(['id' => $args['id'], 'select' => [1]]); diff --git a/src/app/user/models/UserModel.php b/src/app/user/models/UserModel.php index 42ca5c83f34afc8a855c464f5c1b026d688be060..69c7d660dccc16f3b20fd7fb98b56a9a11c08cd0 100755 --- a/src/app/user/models/UserModel.php +++ b/src/app/user/models/UserModel.php @@ -101,7 +101,7 @@ class UserModel 'picture' => $args['picture'], 'password_modification_date' => 'CURRENT_TIMESTAMP', 'signature_modes' => $args['signatureModes'], - 'x509_fingerprint' => $args['x509_fingerprint'], + 'x509_fingerprint' => $args['x509_fingerprint'] ] ]); diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php index 32dde88a04da6ff6514252c465a40d18c0c5adbe..fed906f671102396ab98c4c002c01778e69e7980 100755 --- a/src/core/controllers/AuthenticationController.php +++ b/src/core/controllers/AuthenticationController.php @@ -105,7 +105,7 @@ class AuthenticationController $connection = ConfigurationModel::getConnection(); if (in_array($connection, ['default', 'ldap'])) { - if (!Validator::stringType()->notEmpty()->validate($body['login']) || !Validator::stringType()->notEmpty()->validate($body['password'])) { + if (!array_key_exists('login', $body) || !array_key_exists('password', $body) || !Validator::stringType()->notEmpty()->validate($body['login']) || !Validator::stringType()->notEmpty()->validate($body['password'])) { return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } } diff --git a/src/core/models/PasswordModel.php b/src/core/models/PasswordModel.php index 2ddb2fae0a3e11f0a603c5555daccf3515514158..c2e2ee351e48d5d24c250afba3b5f97385256557 100755 --- a/src/core/models/PasswordModel.php +++ b/src/core/models/PasswordModel.php @@ -23,8 +23,8 @@ class PasswordModel $aRules = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['password_rules'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], + 'where' => $aArgs['where'] ?? [], + 'data' => $aArgs['data'] ?? [], ]); return $aRules; diff --git a/test/unitTests/app/user/UserControllerTest.php b/test/unitTests/app/user/UserControllerTest.php index c7e9bb16d6273ce718a44d514f91d343f48d9820..1960aea0278392f375239070dff17b079cae0810 100755 --- a/test/unitTests/app/user/UserControllerTest.php +++ b/test/unitTests/app/user/UserControllerTest.php @@ -22,10 +22,12 @@ class UserControllerTest extends TestCase $request = \Slim\Http\Request::createFromEnvironment($environment); $aArgs = [ - 'login' => 'emailLogin', - 'firstname' => 'Prénom', - 'lastname' => 'Nom', - 'email' => 'email@test.fr' + 'login' => 'emailLogin', + 'firstname' => 'Prénom', + 'lastname' => 'Nom', + 'email' => 'email@test.fr', + 'phone' => '0701020304', + 'x509_fingerprint' => 'fingerprint' ]; $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); @@ -164,9 +166,9 @@ class UserControllerTest extends TestCase $this->assertSame('Nom', $responseBody->user->lastname); $response = $userController->getById($request, new \Slim\Http\Response(), ['id' => -1]); + $this->assertSame(400, $response->getStatusCode()); $responseBody = json_decode((string)$response->getBody()); - - $this->assertEmpty($responseBody->users); + $this->assertSame('User does not exist', $responseBody->errors); } public function testUpdate() @@ -204,7 +206,8 @@ class UserControllerTest extends TestCase $aArgs = [ 'firstname' => 'Jolly', 'lastname' => 'Jumper', - 'email' => 'email@test.fr' + 'email' => 'email@test.fr', + 'phone' => '0701020304' ]; $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);