Browse Source

change error codes to 400

remotes/origin/poc-doctrine-migrations
Clark Tomlinson 11 years ago
parent
commit
8c0856779b
  1. 24
      apps/encryption/controller/recoverycontroller.php
  2. 16
      apps/encryption/tests/controller/RecoveryControllerTest.php

24
apps/encryption/controller/recoverycontroller.php

@ -75,34 +75,34 @@ class RecoveryController extends Controller {
if (empty($recoveryPassword)) { if (empty($recoveryPassword)) {
$errorMessage = (string)$this->l->t('Missing recovery key password'); $errorMessage = (string)$this->l->t('Missing recovery key password');
return new DataResponse(['data' => ['message' => $errorMessage]], return new DataResponse(['data' => ['message' => $errorMessage]],
Http::STATUS_INTERNAL_SERVER_ERROR);
Http::STATUS_BAD_REQUEST);
} }
if (empty($confirmPassword)) { if (empty($confirmPassword)) {
$errorMessage = (string)$this->l->t('Please repeat the recovery key password'); $errorMessage = (string)$this->l->t('Please repeat the recovery key password');
return new DataResponse(['data' => ['message' => $errorMessage]], return new DataResponse(['data' => ['message' => $errorMessage]],
Http::STATUS_INTERNAL_SERVER_ERROR);
Http::STATUS_BAD_REQUEST);
} }
if ($recoveryPassword !== $confirmPassword) { if ($recoveryPassword !== $confirmPassword) {
$errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password');
return new DataResponse(['data' => ['message' => $errorMessage]], return new DataResponse(['data' => ['message' => $errorMessage]],
Http::STATUS_INTERNAL_SERVER_ERROR);
Http::STATUS_BAD_REQUEST);
} }
if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') { if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') {
if ($this->recovery->enableAdminRecovery($recoveryPassword)) { if ($this->recovery->enableAdminRecovery($recoveryPassword)) {
return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully enabled')]]); return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully enabled')]]);
} }
return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
} elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') { } elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') {
if ($this->recovery->disableAdminRecovery($recoveryPassword)) { if ($this->recovery->disableAdminRecovery($recoveryPassword)) {
return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully disabled')]]); return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully disabled')]]);
} }
return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
} }
// this response should never be sent but just in case. // this response should never be sent but just in case.
return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]], Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]], Http::STATUS_BAD_REQUEST);
} }
/** /**
@ -115,22 +115,22 @@ class RecoveryController extends Controller {
//check if both passwords are the same //check if both passwords are the same
if (empty($oldPassword)) { if (empty($oldPassword)) {
$errorMessage = (string)$this->l->t('Please provide the old recovery password'); $errorMessage = (string)$this->l->t('Please provide the old recovery password');
return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
} }
if (empty($newPassword)) { if (empty($newPassword)) {
$errorMessage = (string)$this->l->t('Please provide a new recovery password'); $errorMessage = (string)$this->l->t('Please provide a new recovery password');
return new DataResponse (['data' => ['message' => $errorMessage]], Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse (['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
} }
if (empty($confirmPassword)) { if (empty($confirmPassword)) {
$errorMessage = (string)$this->l->t('Please repeat the new recovery password'); $errorMessage = (string)$this->l->t('Please repeat the new recovery password');
return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
} }
if ($newPassword !== $confirmPassword) { if ($newPassword !== $confirmPassword) {
$errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password');
return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_INTERNAL_SERVER_ERROR);
return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
} }
$result = $this->recovery->changeRecoveryKeyPassword($newPassword, $result = $this->recovery->changeRecoveryKeyPassword($newPassword,
@ -149,7 +149,7 @@ class RecoveryController extends Controller {
'data' => [ 'data' => [
'message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.') 'message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.')
] ]
], Http::STATUS_INTERNAL_SERVER_ERROR);
], Http::STATUS_BAD_REQUEST);
} }
/** /**
@ -186,7 +186,7 @@ class RecoveryController extends Controller {
'data' => [ 'data' => [
'message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator') 'message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator')
] ]
], Http::STATUS_INTERNAL_SERVER_ERROR);
], Http::STATUS_BAD_REQUEST);
} }
} }

16
apps/encryption/tests/controller/RecoveryControllerTest.php

@ -40,9 +40,9 @@ class RecoveryControllerTest extends TestCase {
public function adminRecoveryProvider() { public function adminRecoveryProvider() {
return [ return [
['test', 'test', '1', 'Recovery key successfully enabled', HTTP::STATUS_OK], ['test', 'test', '1', 'Recovery key successfully enabled', HTTP::STATUS_OK],
['', 'test', '1', 'Missing recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
['test', '', '1', 'Please repeat the recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
['test', 'soimething that doesn\'t match', '1', 'Repeated recovery key password does not match the provided recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
['', 'test', '1', 'Missing recovery key password', HTTP::STATUS_BAD_REQUEST],
['test', '', '1', 'Please repeat the recovery key password', HTTP::STATUS_BAD_REQUEST],
['test', 'soimething that doesn\'t match', '1', 'Repeated recovery key password does not match the provided recovery key password', HTTP::STATUS_BAD_REQUEST],
['test', 'test', '0', 'Recovery key successfully disabled', HTTP::STATUS_OK], ['test', 'test', '0', 'Recovery key successfully disabled', HTTP::STATUS_OK],
]; ];
} }
@ -79,11 +79,11 @@ class RecoveryControllerTest extends TestCase {
public function changeRecoveryPasswordProvider() { public function changeRecoveryPasswordProvider() {
return [ return [
['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', HTTP::STATUS_INTERNAL_SERVER_ERROR],
['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', HTTP::STATUS_BAD_REQUEST],
['test', 'test', 'oldtest', 'Password successfully changed.', HTTP::STATUS_OK], ['test', 'test', 'oldtest', 'Password successfully changed.', HTTP::STATUS_OK],
['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
['', 'test', 'oldtest', 'Please provide a new recovery password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
['test', 'test', '', 'Please provide the old recovery password', HTTP::STATUS_INTERNAL_SERVER_ERROR]
['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', HTTP::STATUS_BAD_REQUEST],
['', 'test', 'oldtest', 'Please provide a new recovery password', HTTP::STATUS_BAD_REQUEST],
['test', 'test', '', 'Please provide the old recovery password', HTTP::STATUS_BAD_REQUEST]
]; ];
} }
@ -117,7 +117,7 @@ class RecoveryControllerTest extends TestCase {
public function userSetRecoveryProvider() { public function userSetRecoveryProvider() {
return [ return [
['1', 'Recovery Key enabled', Http::STATUS_OK], ['1', 'Recovery Key enabled', Http::STATUS_OK],
['0', 'Could not enable the recovery key, please try again or contact your administrator', Http::STATUS_INTERNAL_SERVER_ERROR]
['0', 'Could not enable the recovery key, please try again or contact your administrator', Http::STATUS_BAD_REQUEST]
]; ];
} }

Loading…
Cancel
Save