diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index d75e1841f8e29b863da1cd11c8f171c2fdb87d5c..b62b4305f1a0af351df5ef46644acfd65756b970 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -143,12 +143,14 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'Login already exists', 'lang' => 'userLoginAlreadyExists']); } - if (!empty($body['x509Fingerprint'])) { - $body['x509_fingerprint'] = $body['x509Fingerprint']; - } + // if (!empty($body['x509Fingerprint'])) { + // $body['x509_fingerprint'] = $body['x509Fingerprint']; + // } + + $body['x509_fingerprint'] = !empty($body['x509Fingerprint']) ? $body['x509Fingerprint'] : null; if (empty($body['phone'])) { - $body['phone'] = ''; + $body['phone'] = null; } if (!empty($body['isRest'])) { diff --git a/src/app/user/models/UserModel.php b/src/app/user/models/UserModel.php index cf2827378e3700fa1b009160eabbbfe800f3801b..69c7d660dccc16f3b20fd7fb98b56a9a11c08cd0 100755 --- a/src/app/user/models/UserModel.php +++ b/src/app/user/models/UserModel.php @@ -100,7 +100,8 @@ class UserModel '"isRest"' => empty($args['isRest']) ? 'false' : 'true', 'picture' => $args['picture'], 'password_modification_date' => 'CURRENT_TIMESTAMP', - 'signature_modes' => $args['signatureModes'] + 'signature_modes' => $args['signatureModes'], + 'x509_fingerprint' => $args['x509_fingerprint'] ] ]); diff --git a/test/unitTests/app/user/UserControllerTest.php b/test/unitTests/app/user/UserControllerTest.php index e3a5961a55316d1e1a6adac9bf1fccf808241b4a..3767bd83b338b4a2d52fca84feb00663e87b447b 100755 --- a/test/unitTests/app/user/UserControllerTest.php +++ b/test/unitTests/app/user/UserControllerTest.php @@ -13,6 +13,7 @@ class UserControllerTest extends TestCase { private static $signatureId = null; private static $userId = null; + private static $userIdToDelete = null; public function testCreateUser() { @@ -22,10 +23,11 @@ class UserControllerTest extends TestCase $request = \Slim\Http\Request::createFromEnvironment($environment); $aArgs = [ - 'login' => 'emailLogin', + 'login' => 'emailLoginFingerprint', 'firstname' => 'Prénom', 'lastname' => 'Nom', - 'email' => 'email@test.fr' + 'email' => 'email@test.fr', + 'phone' => '0701020304' ]; $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); @@ -35,6 +37,23 @@ class UserControllerTest extends TestCase $this->assertIsInt($responseBody->id); self::$userId = $responseBody->id; + //with x509Fingerprint + $aArgs = [ + 'login' => 'emailLogin', + 'firstname' => 'Prénom', + 'lastname' => 'Nom', + 'email' => 'email@test.fr', + 'x509Fingerprint' => 'fingerprint', + 'isRest' => true + ]; + + $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + $response = $userController->create($fullRequest, new \Slim\Http\Response()); + $responseBody = json_decode((string)$response->getBody()); + + $this->assertIsInt($responseBody->id); + self::$userIdToDelete = $responseBody->id; + //Mail missing $aArgs = [ 'login' => 'failLogin', @@ -169,6 +188,20 @@ class UserControllerTest extends TestCase $this->assertSame('User does not exist', $responseBody->errors); } + public function testGetFingerprintById() + { + $previousUserId = $GLOBALS['id']; + $GLOBALS['id'] = self::$userIdToDelete; + $userController = new \User\controllers\UserController(); + + //find "userIdToDelete" fingerprint before user gets deleted + $response = $userController->getUserInformationsById(['id' => self::$userIdToDelete]); + + $this->assertNotEmpty($response); + $this->assertNotEmpty($response['x509Fingerprint']); + $GLOBALS['id'] = $previousUserId; + } + public function testUpdate() { $userController = new \User\controllers\UserController(); @@ -204,7 +237,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); @@ -291,4 +325,15 @@ class UserControllerTest extends TestCase ]); $GLOBALS['id'] = $previousUserId; } + + public function testDelete() + { + $userController = new \User\controllers\UserController(); + + $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']); + $request = \Slim\Http\Request::createFromEnvironment($environment); + $response = $userController->delete($request, new \Slim\Http\Response(), ['id' => self::$userIdToDelete]); + + $this->assertSame(204, $response->getStatusCode()); + } }