@@ -18,60 +18,60 @@ |
||
| 18 | 18 | |
| 19 | 19 | class Personal implements ISettings { |
| 20 | 20 | |
| 21 | - public function __construct( |
|
| 22 | - private Session $session, |
|
| 23 | - private Util $util, |
|
| 24 | - private IUserSession $userSession, |
|
| 25 | - private IInitialState $initialState, |
|
| 26 | - private IAppConfig $appConfig, |
|
| 27 | - private IManager $manager, |
|
| 28 | - ) { |
|
| 29 | - } |
|
| 21 | + public function __construct( |
|
| 22 | + private Session $session, |
|
| 23 | + private Util $util, |
|
| 24 | + private IUserSession $userSession, |
|
| 25 | + private IInitialState $initialState, |
|
| 26 | + private IAppConfig $appConfig, |
|
| 27 | + private IManager $manager, |
|
| 28 | + ) { |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 33 | - * @since 9.1 |
|
| 34 | - */ |
|
| 35 | - public function getForm() { |
|
| 36 | - $recoveryAdminEnabled = $this->appConfig->getValueBool('encryption', 'recoveryAdminEnabled'); |
|
| 37 | - $privateKeySet = $this->session->isPrivateKeySet(); |
|
| 31 | + /** |
|
| 32 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 33 | + * @since 9.1 |
|
| 34 | + */ |
|
| 35 | + public function getForm() { |
|
| 36 | + $recoveryAdminEnabled = $this->appConfig->getValueBool('encryption', 'recoveryAdminEnabled'); |
|
| 37 | + $privateKeySet = $this->session->isPrivateKeySet(); |
|
| 38 | 38 | |
| 39 | - if (!$recoveryAdminEnabled && $privateKeySet) { |
|
| 40 | - return new TemplateResponse('settings', 'settings/empty', [], ''); |
|
| 41 | - } |
|
| 39 | + if (!$recoveryAdminEnabled && $privateKeySet) { |
|
| 40 | + return new TemplateResponse('settings', 'settings/empty', [], ''); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $userId = $this->userSession->getUser()->getUID(); |
|
| 44 | - $recoveryEnabledForUser = $this->util->isRecoveryEnabledForUser($userId); |
|
| 43 | + $userId = $this->userSession->getUser()->getUID(); |
|
| 44 | + $recoveryEnabledForUser = $this->util->isRecoveryEnabledForUser($userId); |
|
| 45 | 45 | |
| 46 | - $this->initialState->provideInitialState('personalSettings', [ |
|
| 47 | - 'recoveryEnabled' => $recoveryAdminEnabled, |
|
| 48 | - 'recoveryEnabledForUser' => $recoveryEnabledForUser, |
|
| 49 | - 'privateKeySet' => $privateKeySet, |
|
| 50 | - 'initialized' => $this->session->getStatus(), |
|
| 51 | - ]); |
|
| 46 | + $this->initialState->provideInitialState('personalSettings', [ |
|
| 47 | + 'recoveryEnabled' => $recoveryAdminEnabled, |
|
| 48 | + 'recoveryEnabledForUser' => $recoveryEnabledForUser, |
|
| 49 | + 'privateKeySet' => $privateKeySet, |
|
| 50 | + 'initialized' => $this->session->getStatus(), |
|
| 51 | + ]); |
|
| 52 | 52 | |
| 53 | - \OCP\Util::addStyle(Application::APP_ID, 'settings_personal'); |
|
| 54 | - \OCP\Util::addScript(Application::APP_ID, 'settings_personal'); |
|
| 55 | - return new TemplateResponse(Application::APP_ID, 'settings', renderAs: ''); |
|
| 56 | - } |
|
| 53 | + \OCP\Util::addStyle(Application::APP_ID, 'settings_personal'); |
|
| 54 | + \OCP\Util::addScript(Application::APP_ID, 'settings_personal'); |
|
| 55 | + return new TemplateResponse(Application::APP_ID, 'settings', renderAs: ''); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function getSection() { |
|
| 59 | - if (!$this->manager->isEnabled()) { |
|
| 60 | - return null; |
|
| 61 | - } |
|
| 58 | + public function getSection() { |
|
| 59 | + if (!$this->manager->isEnabled()) { |
|
| 60 | + return null; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return 'security'; |
|
| 64 | - } |
|
| 63 | + return 'security'; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return int whether the form should be rather on the top or bottom of |
|
| 68 | - * the admin section. The forms are arranged in ascending order of the |
|
| 69 | - * priority values. It is required to return a value between 0 and 100. |
|
| 70 | - * |
|
| 71 | - * E.g.: 70 |
|
| 72 | - * @since 9.1 |
|
| 73 | - */ |
|
| 74 | - public function getPriority() { |
|
| 75 | - return 80; |
|
| 76 | - } |
|
| 66 | + /** |
|
| 67 | + * @return int whether the form should be rather on the top or bottom of |
|
| 68 | + * the admin section. The forms are arranged in ascending order of the |
|
| 69 | + * priority values. It is required to return a value between 0 and 100. |
|
| 70 | + * |
|
| 71 | + * E.g.: 70 |
|
| 72 | + * @since 9.1 |
|
| 73 | + */ |
|
| 74 | + public function getPriority() { |
|
| 75 | + return 80; |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -23,68 +23,68 @@ |
||
| 23 | 23 | use Psr\Log\LoggerInterface; |
| 24 | 24 | |
| 25 | 25 | class Admin implements ISettings { |
| 26 | - public function __construct( |
|
| 27 | - private IL10N $l, |
|
| 28 | - private LoggerInterface $logger, |
|
| 29 | - private IUserSession $userSession, |
|
| 30 | - private IConfig $config, |
|
| 31 | - private IUserManager $userManager, |
|
| 32 | - private ISession $session, |
|
| 33 | - private IInitialState $initialState, |
|
| 34 | - private IAppConfig $appConfig, |
|
| 35 | - ) { |
|
| 36 | - } |
|
| 26 | + public function __construct( |
|
| 27 | + private IL10N $l, |
|
| 28 | + private LoggerInterface $logger, |
|
| 29 | + private IUserSession $userSession, |
|
| 30 | + private IConfig $config, |
|
| 31 | + private IUserManager $userManager, |
|
| 32 | + private ISession $session, |
|
| 33 | + private IInitialState $initialState, |
|
| 34 | + private IAppConfig $appConfig, |
|
| 35 | + ) { |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @return TemplateResponse |
|
| 40 | - */ |
|
| 41 | - public function getForm() { |
|
| 42 | - $crypt = new Crypt( |
|
| 43 | - $this->logger, |
|
| 44 | - $this->userSession, |
|
| 45 | - $this->config, |
|
| 46 | - $this->l); |
|
| 38 | + /** |
|
| 39 | + * @return TemplateResponse |
|
| 40 | + */ |
|
| 41 | + public function getForm() { |
|
| 42 | + $crypt = new Crypt( |
|
| 43 | + $this->logger, |
|
| 44 | + $this->userSession, |
|
| 45 | + $this->config, |
|
| 46 | + $this->l); |
|
| 47 | 47 | |
| 48 | - $util = new Util( |
|
| 49 | - new View(), |
|
| 50 | - $crypt, |
|
| 51 | - $this->userSession, |
|
| 52 | - $this->config, |
|
| 53 | - $this->userManager); |
|
| 48 | + $util = new Util( |
|
| 49 | + new View(), |
|
| 50 | + $crypt, |
|
| 51 | + $this->userSession, |
|
| 52 | + $this->config, |
|
| 53 | + $this->userManager); |
|
| 54 | 54 | |
| 55 | - // Check if an adminRecovery account is enabled for recovering files after lost pwd |
|
| 56 | - $recoveryAdminEnabled = $this->appConfig->getValueBool('encryption', 'recoveryAdminEnabled'); |
|
| 57 | - $session = new Session($this->session); |
|
| 55 | + // Check if an adminRecovery account is enabled for recovering files after lost pwd |
|
| 56 | + $recoveryAdminEnabled = $this->appConfig->getValueBool('encryption', 'recoveryAdminEnabled'); |
|
| 57 | + $session = new Session($this->session); |
|
| 58 | 58 | |
| 59 | - $encryptHomeStorage = $util->shouldEncryptHomeStorage(); |
|
| 59 | + $encryptHomeStorage = $util->shouldEncryptHomeStorage(); |
|
| 60 | 60 | |
| 61 | - $this->initialState->provideInitialState('adminSettings', [ |
|
| 62 | - 'recoveryEnabled' => $recoveryAdminEnabled, |
|
| 63 | - 'initStatus' => $session->getStatus(), |
|
| 64 | - 'encryptHomeStorage' => $encryptHomeStorage, |
|
| 65 | - 'masterKeyEnabled' => $util->isMasterKeyEnabled(), |
|
| 66 | - ]); |
|
| 61 | + $this->initialState->provideInitialState('adminSettings', [ |
|
| 62 | + 'recoveryEnabled' => $recoveryAdminEnabled, |
|
| 63 | + 'initStatus' => $session->getStatus(), |
|
| 64 | + 'encryptHomeStorage' => $encryptHomeStorage, |
|
| 65 | + 'masterKeyEnabled' => $util->isMasterKeyEnabled(), |
|
| 66 | + ]); |
|
| 67 | 67 | |
| 68 | - \OCP\Util::addStyle(Application::APP_ID, 'settings_admin'); |
|
| 69 | - \OCP\Util::addScript(Application::APP_ID, 'settings_admin'); |
|
| 70 | - return new TemplateResponse(Application::APP_ID, 'settings', renderAs: ''); |
|
| 71 | - } |
|
| 68 | + \OCP\Util::addStyle(Application::APP_ID, 'settings_admin'); |
|
| 69 | + \OCP\Util::addScript(Application::APP_ID, 'settings_admin'); |
|
| 70 | + return new TemplateResponse(Application::APP_ID, 'settings', renderAs: ''); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return string the section ID, e.g. 'sharing' |
|
| 75 | - */ |
|
| 76 | - public function getSection() { |
|
| 77 | - return 'security'; |
|
| 78 | - } |
|
| 73 | + /** |
|
| 74 | + * @return string the section ID, e.g. 'sharing' |
|
| 75 | + */ |
|
| 76 | + public function getSection() { |
|
| 77 | + return 'security'; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return int whether the form should be rather on the top or bottom of |
|
| 82 | - * the admin section. The forms are arranged in ascending order of the |
|
| 83 | - * priority values. It is required to return a value between 0 and 100. |
|
| 84 | - * |
|
| 85 | - * E.g.: 70 |
|
| 86 | - */ |
|
| 87 | - public function getPriority() { |
|
| 88 | - return 11; |
|
| 89 | - } |
|
| 80 | + /** |
|
| 81 | + * @return int whether the form should be rather on the top or bottom of |
|
| 82 | + * the admin section. The forms are arranged in ascending order of the |
|
| 83 | + * priority values. It is required to return a value between 0 and 100. |
|
| 84 | + * |
|
| 85 | + * E.g.: 70 |
|
| 86 | + */ |
|
| 87 | + public function getPriority() { |
|
| 88 | + return 11; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -17,62 +17,62 @@ |
||
| 17 | 17 | |
| 18 | 18 | class StatusController extends Controller { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param string $AppName |
|
| 22 | - * @param IRequest $request |
|
| 23 | - * @param IL10N $l |
|
| 24 | - * @param Session $session |
|
| 25 | - * @param IManager $encryptionManager |
|
| 26 | - */ |
|
| 27 | - public function __construct( |
|
| 28 | - $appName, |
|
| 29 | - IRequest $request, |
|
| 30 | - private IL10N $l, |
|
| 31 | - private Session $session, |
|
| 32 | - private IManager $encryptionManager, |
|
| 33 | - ) { |
|
| 34 | - parent::__construct($appName, $request); |
|
| 35 | - } |
|
| 20 | + /** |
|
| 21 | + * @param string $AppName |
|
| 22 | + * @param IRequest $request |
|
| 23 | + * @param IL10N $l |
|
| 24 | + * @param Session $session |
|
| 25 | + * @param IManager $encryptionManager |
|
| 26 | + */ |
|
| 27 | + public function __construct( |
|
| 28 | + $appName, |
|
| 29 | + IRequest $request, |
|
| 30 | + private IL10N $l, |
|
| 31 | + private Session $session, |
|
| 32 | + private IManager $encryptionManager, |
|
| 33 | + ) { |
|
| 34 | + parent::__construct($appName, $request); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return DataResponse |
|
| 39 | - */ |
|
| 40 | - #[NoAdminRequired] |
|
| 41 | - public function getStatus() { |
|
| 42 | - $status = 'error'; |
|
| 43 | - $message = 'no valid init status'; |
|
| 44 | - switch ($this->session->getStatus()) { |
|
| 45 | - case Session::INIT_EXECUTED: |
|
| 46 | - $status = 'interactionNeeded'; |
|
| 47 | - $message = $this->l->t( |
|
| 48 | - 'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.' |
|
| 49 | - ); |
|
| 50 | - break; |
|
| 51 | - case Session::NOT_INITIALIZED: |
|
| 52 | - $status = 'interactionNeeded'; |
|
| 53 | - if ($this->encryptionManager->isEnabled()) { |
|
| 54 | - $message = $this->l->t( |
|
| 55 | - 'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.' |
|
| 56 | - ); |
|
| 57 | - } else { |
|
| 58 | - $message = $this->l->t( |
|
| 59 | - 'Please enable server side encryption in the admin settings in order to use the encryption module.' |
|
| 60 | - ); |
|
| 61 | - } |
|
| 62 | - break; |
|
| 63 | - case Session::INIT_SUCCESSFUL: |
|
| 64 | - $status = 'success'; |
|
| 65 | - $message = $this->l->t('Encryption app is enabled and ready'); |
|
| 66 | - } |
|
| 37 | + /** |
|
| 38 | + * @return DataResponse |
|
| 39 | + */ |
|
| 40 | + #[NoAdminRequired] |
|
| 41 | + public function getStatus() { |
|
| 42 | + $status = 'error'; |
|
| 43 | + $message = 'no valid init status'; |
|
| 44 | + switch ($this->session->getStatus()) { |
|
| 45 | + case Session::INIT_EXECUTED: |
|
| 46 | + $status = 'interactionNeeded'; |
|
| 47 | + $message = $this->l->t( |
|
| 48 | + 'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.' |
|
| 49 | + ); |
|
| 50 | + break; |
|
| 51 | + case Session::NOT_INITIALIZED: |
|
| 52 | + $status = 'interactionNeeded'; |
|
| 53 | + if ($this->encryptionManager->isEnabled()) { |
|
| 54 | + $message = $this->l->t( |
|
| 55 | + 'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.' |
|
| 56 | + ); |
|
| 57 | + } else { |
|
| 58 | + $message = $this->l->t( |
|
| 59 | + 'Please enable server side encryption in the admin settings in order to use the encryption module.' |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | + break; |
|
| 63 | + case Session::INIT_SUCCESSFUL: |
|
| 64 | + $status = 'success'; |
|
| 65 | + $message = $this->l->t('Encryption app is enabled and ready'); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return new DataResponse( |
|
| 69 | - [ |
|
| 70 | - 'status' => $status, |
|
| 71 | - 'initStatus' => $this->session->getStatus(), |
|
| 72 | - 'data' => [ |
|
| 73 | - 'message' => $message, |
|
| 74 | - ], |
|
| 75 | - ] |
|
| 76 | - ); |
|
| 77 | - } |
|
| 68 | + return new DataResponse( |
|
| 69 | + [ |
|
| 70 | + 'status' => $status, |
|
| 71 | + 'initStatus' => $this->session->getStatus(), |
|
| 72 | + 'data' => [ |
|
| 73 | + 'message' => $message, |
|
| 74 | + ], |
|
| 75 | + ] |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -18,136 +18,136 @@ |
||
| 18 | 18 | use Psr\Log\LoggerInterface; |
| 19 | 19 | |
| 20 | 20 | class RecoveryController extends Controller { |
| 21 | - public function __construct( |
|
| 22 | - string $appName, |
|
| 23 | - IRequest $request, |
|
| 24 | - private IL10N $l, |
|
| 25 | - private Recovery $recovery, |
|
| 26 | - private LoggerInterface $logger, |
|
| 27 | - ) { |
|
| 28 | - parent::__construct($appName, $request); |
|
| 29 | - } |
|
| 21 | + public function __construct( |
|
| 22 | + string $appName, |
|
| 23 | + IRequest $request, |
|
| 24 | + private IL10N $l, |
|
| 25 | + private Recovery $recovery, |
|
| 26 | + private LoggerInterface $logger, |
|
| 27 | + ) { |
|
| 28 | + parent::__construct($appName, $request); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function adminRecovery(string $recoveryPassword, string $confirmPassword, bool $adminEnableRecovery): DataResponse { |
|
| 32 | - // Check if both passwords are the same |
|
| 33 | - if (empty($recoveryPassword)) { |
|
| 34 | - $errorMessage = $this->l->t('Missing recovery key password'); |
|
| 35 | - return new DataResponse(['data' => ['message' => $errorMessage]], |
|
| 36 | - Http::STATUS_BAD_REQUEST); |
|
| 37 | - } |
|
| 31 | + public function adminRecovery(string $recoveryPassword, string $confirmPassword, bool $adminEnableRecovery): DataResponse { |
|
| 32 | + // Check if both passwords are the same |
|
| 33 | + if (empty($recoveryPassword)) { |
|
| 34 | + $errorMessage = $this->l->t('Missing recovery key password'); |
|
| 35 | + return new DataResponse(['data' => ['message' => $errorMessage]], |
|
| 36 | + Http::STATUS_BAD_REQUEST); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - if (empty($confirmPassword)) { |
|
| 40 | - $errorMessage = $this->l->t('Please repeat the recovery key password'); |
|
| 41 | - return new DataResponse(['data' => ['message' => $errorMessage]], |
|
| 42 | - Http::STATUS_BAD_REQUEST); |
|
| 43 | - } |
|
| 39 | + if (empty($confirmPassword)) { |
|
| 40 | + $errorMessage = $this->l->t('Please repeat the recovery key password'); |
|
| 41 | + return new DataResponse(['data' => ['message' => $errorMessage]], |
|
| 42 | + Http::STATUS_BAD_REQUEST); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if ($recoveryPassword !== $confirmPassword) { |
|
| 46 | - $errorMessage = $this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
| 47 | - return new DataResponse(['data' => ['message' => $errorMessage]], |
|
| 48 | - Http::STATUS_BAD_REQUEST); |
|
| 49 | - } |
|
| 45 | + if ($recoveryPassword !== $confirmPassword) { |
|
| 46 | + $errorMessage = $this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
| 47 | + return new DataResponse(['data' => ['message' => $errorMessage]], |
|
| 48 | + Http::STATUS_BAD_REQUEST); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - try { |
|
| 52 | - if ($adminEnableRecovery) { |
|
| 53 | - if ($this->recovery->enableAdminRecovery($recoveryPassword)) { |
|
| 54 | - return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully enabled')]]); |
|
| 55 | - } |
|
| 56 | - return new DataResponse(['data' => ['message' => $this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
| 57 | - } else { |
|
| 58 | - if ($this->recovery->disableAdminRecovery($recoveryPassword)) { |
|
| 59 | - return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully disabled')]]); |
|
| 60 | - } |
|
| 61 | - return new DataResponse(['data' => ['message' => $this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
| 62 | - } |
|
| 63 | - } catch (\Exception $e) { |
|
| 64 | - $this->logger->error('Error enabling or disabling recovery key', ['exception' => $e]); |
|
| 65 | - if ($e instanceof GenericEncryptionException) { |
|
| 66 | - return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 67 | - } |
|
| 68 | - return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 69 | - } |
|
| 70 | - } |
|
| 51 | + try { |
|
| 52 | + if ($adminEnableRecovery) { |
|
| 53 | + if ($this->recovery->enableAdminRecovery($recoveryPassword)) { |
|
| 54 | + return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully enabled')]]); |
|
| 55 | + } |
|
| 56 | + return new DataResponse(['data' => ['message' => $this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
| 57 | + } else { |
|
| 58 | + if ($this->recovery->disableAdminRecovery($recoveryPassword)) { |
|
| 59 | + return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully disabled')]]); |
|
| 60 | + } |
|
| 61 | + return new DataResponse(['data' => ['message' => $this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST); |
|
| 62 | + } |
|
| 63 | + } catch (\Exception $e) { |
|
| 64 | + $this->logger->error('Error enabling or disabling recovery key', ['exception' => $e]); |
|
| 65 | + if ($e instanceof GenericEncryptionException) { |
|
| 66 | + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 67 | + } |
|
| 68 | + return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function changeRecoveryPassword(string $newPassword, string $oldPassword, string $confirmPassword): DataResponse { |
|
| 73 | - //check if both passwords are the same |
|
| 74 | - if (empty($oldPassword)) { |
|
| 75 | - $errorMessage = $this->l->t('Please provide the old recovery password'); |
|
| 76 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 77 | - } |
|
| 72 | + public function changeRecoveryPassword(string $newPassword, string $oldPassword, string $confirmPassword): DataResponse { |
|
| 73 | + //check if both passwords are the same |
|
| 74 | + if (empty($oldPassword)) { |
|
| 75 | + $errorMessage = $this->l->t('Please provide the old recovery password'); |
|
| 76 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - if (empty($newPassword)) { |
|
| 80 | - $errorMessage = $this->l->t('Please provide a new recovery password'); |
|
| 81 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 82 | - } |
|
| 79 | + if (empty($newPassword)) { |
|
| 80 | + $errorMessage = $this->l->t('Please provide a new recovery password'); |
|
| 81 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if (empty($confirmPassword)) { |
|
| 85 | - $errorMessage = $this->l->t('Please repeat the new recovery password'); |
|
| 86 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 87 | - } |
|
| 84 | + if (empty($confirmPassword)) { |
|
| 85 | + $errorMessage = $this->l->t('Please repeat the new recovery password'); |
|
| 86 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - if ($newPassword !== $confirmPassword) { |
|
| 90 | - $errorMessage = $this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
| 91 | - return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 92 | - } |
|
| 89 | + if ($newPassword !== $confirmPassword) { |
|
| 90 | + $errorMessage = $this->l->t('Repeated recovery key password does not match the provided recovery key password'); |
|
| 91 | + return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - try { |
|
| 95 | - $result = $this->recovery->changeRecoveryKeyPassword($newPassword, |
|
| 96 | - $oldPassword); |
|
| 94 | + try { |
|
| 95 | + $result = $this->recovery->changeRecoveryKeyPassword($newPassword, |
|
| 96 | + $oldPassword); |
|
| 97 | 97 | |
| 98 | - if ($result) { |
|
| 99 | - return new DataResponse( |
|
| 100 | - [ |
|
| 101 | - 'data' => [ |
|
| 102 | - 'message' => $this->l->t('Password successfully changed.')] |
|
| 103 | - ] |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - return new DataResponse([ |
|
| 107 | - 'data' => [ |
|
| 108 | - 'message' => $this->l->t('Could not change the password. Maybe the old password was not correct.') |
|
| 109 | - ] |
|
| 110 | - ], Http::STATUS_BAD_REQUEST); |
|
| 111 | - } catch (\Exception $e) { |
|
| 112 | - $this->logger->error('Error changing recovery password', ['exception' => $e]); |
|
| 113 | - if ($e instanceof GenericEncryptionException) { |
|
| 114 | - return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 115 | - } |
|
| 116 | - return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 117 | - } |
|
| 118 | - } |
|
| 98 | + if ($result) { |
|
| 99 | + return new DataResponse( |
|
| 100 | + [ |
|
| 101 | + 'data' => [ |
|
| 102 | + 'message' => $this->l->t('Password successfully changed.')] |
|
| 103 | + ] |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + return new DataResponse([ |
|
| 107 | + 'data' => [ |
|
| 108 | + 'message' => $this->l->t('Could not change the password. Maybe the old password was not correct.') |
|
| 109 | + ] |
|
| 110 | + ], Http::STATUS_BAD_REQUEST); |
|
| 111 | + } catch (\Exception $e) { |
|
| 112 | + $this->logger->error('Error changing recovery password', ['exception' => $e]); |
|
| 113 | + if ($e instanceof GenericEncryptionException) { |
|
| 114 | + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 115 | + } |
|
| 116 | + return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @param string $userEnableRecovery |
|
| 122 | - * @return DataResponse |
|
| 123 | - */ |
|
| 124 | - #[NoAdminRequired] |
|
| 125 | - public function userSetRecovery($userEnableRecovery) { |
|
| 126 | - if ($userEnableRecovery === '0' || $userEnableRecovery === '1') { |
|
| 127 | - $result = $this->recovery->setRecoveryForUser($userEnableRecovery); |
|
| 120 | + /** |
|
| 121 | + * @param string $userEnableRecovery |
|
| 122 | + * @return DataResponse |
|
| 123 | + */ |
|
| 124 | + #[NoAdminRequired] |
|
| 125 | + public function userSetRecovery($userEnableRecovery) { |
|
| 126 | + if ($userEnableRecovery === '0' || $userEnableRecovery === '1') { |
|
| 127 | + $result = $this->recovery->setRecoveryForUser($userEnableRecovery); |
|
| 128 | 128 | |
| 129 | - if ($result) { |
|
| 130 | - if ($userEnableRecovery === '0') { |
|
| 131 | - return new DataResponse( |
|
| 132 | - [ |
|
| 133 | - 'data' => [ |
|
| 134 | - 'message' => $this->l->t('Recovery Key disabled')] |
|
| 135 | - ] |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - return new DataResponse( |
|
| 139 | - [ |
|
| 140 | - 'data' => [ |
|
| 141 | - 'message' => $this->l->t('Recovery Key enabled')] |
|
| 142 | - ] |
|
| 143 | - ); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - return new DataResponse( |
|
| 147 | - [ |
|
| 148 | - 'data' => [ |
|
| 149 | - 'message' => $this->l->t('Could not enable the recovery key, please try again or contact your administrator') |
|
| 150 | - ] |
|
| 151 | - ], Http::STATUS_BAD_REQUEST); |
|
| 152 | - } |
|
| 129 | + if ($result) { |
|
| 130 | + if ($userEnableRecovery === '0') { |
|
| 131 | + return new DataResponse( |
|
| 132 | + [ |
|
| 133 | + 'data' => [ |
|
| 134 | + 'message' => $this->l->t('Recovery Key disabled')] |
|
| 135 | + ] |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + return new DataResponse( |
|
| 139 | + [ |
|
| 140 | + 'data' => [ |
|
| 141 | + 'message' => $this->l->t('Recovery Key enabled')] |
|
| 142 | + ] |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + return new DataResponse( |
|
| 147 | + [ |
|
| 148 | + 'data' => [ |
|
| 149 | + 'message' => $this->l->t('Could not enable the recovery key, please try again or contact your administrator') |
|
| 150 | + ] |
|
| 151 | + ], Http::STATUS_BAD_REQUEST); |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -23,77 +23,77 @@ |
||
| 23 | 23 | |
| 24 | 24 | class AdminTest extends TestCase { |
| 25 | 25 | |
| 26 | - protected Admin $admin; |
|
| 26 | + protected Admin $admin; |
|
| 27 | 27 | |
| 28 | - protected IL10N&MockObject $l; |
|
| 29 | - protected LoggerInterface&MockObject $logger; |
|
| 30 | - protected IUserSession&MockObject $userSession; |
|
| 31 | - protected IConfig&MockObject $config; |
|
| 32 | - protected IUserManager&MockObject $userManager; |
|
| 33 | - protected ISession&MockObject $session; |
|
| 34 | - protected IInitialState&MockObject $initialState; |
|
| 35 | - protected IAppConfig&MockObject $appConfig; |
|
| 28 | + protected IL10N&MockObject $l; |
|
| 29 | + protected LoggerInterface&MockObject $logger; |
|
| 30 | + protected IUserSession&MockObject $userSession; |
|
| 31 | + protected IConfig&MockObject $config; |
|
| 32 | + protected IUserManager&MockObject $userManager; |
|
| 33 | + protected ISession&MockObject $session; |
|
| 34 | + protected IInitialState&MockObject $initialState; |
|
| 35 | + protected IAppConfig&MockObject $appConfig; |
|
| 36 | 36 | |
| 37 | - protected function setUp(): void { |
|
| 38 | - parent::setUp(); |
|
| 37 | + protected function setUp(): void { |
|
| 38 | + parent::setUp(); |
|
| 39 | 39 | |
| 40 | - $this->l = $this->createMock(IL10N::class); |
|
| 41 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 42 | - $this->userSession = $this->createMock(IUserSession::class); |
|
| 43 | - $this->config = $this->createMock(IConfig::class); |
|
| 44 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 45 | - $this->session = $this->createMock(ISession::class); |
|
| 46 | - $this->initialState = $this->createMock(IInitialState::class); |
|
| 47 | - $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 40 | + $this->l = $this->createMock(IL10N::class); |
|
| 41 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 42 | + $this->userSession = $this->createMock(IUserSession::class); |
|
| 43 | + $this->config = $this->createMock(IConfig::class); |
|
| 44 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 45 | + $this->session = $this->createMock(ISession::class); |
|
| 46 | + $this->initialState = $this->createMock(IInitialState::class); |
|
| 47 | + $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 48 | 48 | |
| 49 | - $this->admin = new Admin( |
|
| 50 | - $this->l, |
|
| 51 | - $this->logger, |
|
| 52 | - $this->userSession, |
|
| 53 | - $this->config, |
|
| 54 | - $this->userManager, |
|
| 55 | - $this->session, |
|
| 56 | - $this->initialState, |
|
| 57 | - $this->appConfig, |
|
| 58 | - ); |
|
| 59 | - } |
|
| 49 | + $this->admin = new Admin( |
|
| 50 | + $this->l, |
|
| 51 | + $this->logger, |
|
| 52 | + $this->userSession, |
|
| 53 | + $this->config, |
|
| 54 | + $this->userManager, |
|
| 55 | + $this->session, |
|
| 56 | + $this->initialState, |
|
| 57 | + $this->appConfig, |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function testGetForm(): void { |
|
| 62 | - $this->appConfig |
|
| 63 | - ->method('getValueBool') |
|
| 64 | - ->willReturnMap([ |
|
| 65 | - ['encryption', 'recoveryAdminEnabled', true] |
|
| 66 | - ]); |
|
| 67 | - $this->config |
|
| 68 | - ->method('getAppValue') |
|
| 69 | - ->willReturnCallback(function ($app, $key, $default) { |
|
| 70 | - if ($app === 'encryption' && $key === 'recoveryAdminEnabled' && $default === '0') { |
|
| 71 | - return '1'; |
|
| 72 | - } |
|
| 73 | - if ($app === 'encryption' && $key === 'encryptHomeStorage' && $default === '1') { |
|
| 74 | - return '1'; |
|
| 75 | - } |
|
| 76 | - return $default; |
|
| 77 | - }); |
|
| 61 | + public function testGetForm(): void { |
|
| 62 | + $this->appConfig |
|
| 63 | + ->method('getValueBool') |
|
| 64 | + ->willReturnMap([ |
|
| 65 | + ['encryption', 'recoveryAdminEnabled', true] |
|
| 66 | + ]); |
|
| 67 | + $this->config |
|
| 68 | + ->method('getAppValue') |
|
| 69 | + ->willReturnCallback(function ($app, $key, $default) { |
|
| 70 | + if ($app === 'encryption' && $key === 'recoveryAdminEnabled' && $default === '0') { |
|
| 71 | + return '1'; |
|
| 72 | + } |
|
| 73 | + if ($app === 'encryption' && $key === 'encryptHomeStorage' && $default === '1') { |
|
| 74 | + return '1'; |
|
| 75 | + } |
|
| 76 | + return $default; |
|
| 77 | + }); |
|
| 78 | 78 | |
| 79 | - $this->initialState |
|
| 80 | - ->expects(self::once()) |
|
| 81 | - ->method('provideInitialState') |
|
| 82 | - ->with('adminSettings', [ |
|
| 83 | - 'recoveryEnabled' => true, |
|
| 84 | - 'initStatus' => '0', |
|
| 85 | - 'encryptHomeStorage' => true, |
|
| 86 | - 'masterKeyEnabled' => true |
|
| 87 | - ]); |
|
| 88 | - $expected = new TemplateResponse('encryption', 'settings', renderAs: ''); |
|
| 89 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
| 90 | - } |
|
| 79 | + $this->initialState |
|
| 80 | + ->expects(self::once()) |
|
| 81 | + ->method('provideInitialState') |
|
| 82 | + ->with('adminSettings', [ |
|
| 83 | + 'recoveryEnabled' => true, |
|
| 84 | + 'initStatus' => '0', |
|
| 85 | + 'encryptHomeStorage' => true, |
|
| 86 | + 'masterKeyEnabled' => true |
|
| 87 | + ]); |
|
| 88 | + $expected = new TemplateResponse('encryption', 'settings', renderAs: ''); |
|
| 89 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - public function testGetSection(): void { |
|
| 93 | - $this->assertSame('security', $this->admin->getSection()); |
|
| 94 | - } |
|
| 92 | + public function testGetSection(): void { |
|
| 93 | + $this->assertSame('security', $this->admin->getSection()); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function testGetPriority(): void { |
|
| 97 | - $this->assertSame(11, $this->admin->getPriority()); |
|
| 98 | - } |
|
| 96 | + public function testGetPriority(): void { |
|
| 97 | + $this->assertSame(11, $this->admin->getPriority()); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | ]); |
| 67 | 67 | $this->config |
| 68 | 68 | ->method('getAppValue') |
| 69 | - ->willReturnCallback(function ($app, $key, $default) { |
|
| 69 | + ->willReturnCallback(function($app, $key, $default) { |
|
| 70 | 70 | if ($app === 'encryption' && $key === 'recoveryAdminEnabled' && $default === '0') { |
| 71 | 71 | return '1'; |
| 72 | 72 | } |
@@ -20,143 +20,143 @@ |
||
| 20 | 20 | use Test\TestCase; |
| 21 | 21 | |
| 22 | 22 | class RecoveryControllerTest extends TestCase { |
| 23 | - protected RecoveryController $controller; |
|
| 24 | - |
|
| 25 | - protected IRequest&MockObject $requestMock; |
|
| 26 | - protected IConfig&MockObject $configMock; |
|
| 27 | - protected IL10N&MockObject $l10nMock; |
|
| 28 | - protected Recovery&MockObject $recoveryMock; |
|
| 29 | - |
|
| 30 | - public static function adminRecoveryProvider(): array { |
|
| 31 | - return [ |
|
| 32 | - ['test', 'test', true, 'Recovery key successfully enabled', Http::STATUS_OK], |
|
| 33 | - ['', 'test', true, 'Missing recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 34 | - ['test', '', true, 'Please repeat the recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 35 | - ['test', 'something that doesn\'t match', true, 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 36 | - ['test', 'test', false, 'Recovery key successfully disabled', Http::STATUS_OK], |
|
| 37 | - ]; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param $recoveryPassword |
|
| 42 | - * @param $passConfirm |
|
| 43 | - * @param $enableRecovery |
|
| 44 | - * @param $expectedMessage |
|
| 45 | - * @param $expectedStatus |
|
| 46 | - */ |
|
| 47 | - #[\PHPUnit\Framework\Attributes\DataProvider('adminRecoveryProvider')] |
|
| 48 | - public function testAdminRecovery($recoveryPassword, $passConfirm, $enableRecovery, $expectedMessage, $expectedStatus): void { |
|
| 49 | - $this->recoveryMock->expects($this->any()) |
|
| 50 | - ->method('enableAdminRecovery') |
|
| 51 | - ->willReturn(true); |
|
| 52 | - |
|
| 53 | - $this->recoveryMock->expects($this->any()) |
|
| 54 | - ->method('disableAdminRecovery') |
|
| 55 | - ->willReturn(true); |
|
| 56 | - |
|
| 57 | - $response = $this->controller->adminRecovery($recoveryPassword, |
|
| 58 | - $passConfirm, |
|
| 59 | - $enableRecovery); |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - $this->assertEquals($expectedMessage, $response->getData()['data']['message']); |
|
| 63 | - $this->assertEquals($expectedStatus, $response->getStatus()); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public static function changeRecoveryPasswordProvider(): array { |
|
| 67 | - return [ |
|
| 68 | - ['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', Http::STATUS_BAD_REQUEST], |
|
| 69 | - ['test', 'test', 'oldtest', 'Password successfully changed.', Http::STATUS_OK], |
|
| 70 | - ['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 71 | - ['', 'test', 'oldtest', 'Please provide a new recovery password', Http::STATUS_BAD_REQUEST], |
|
| 72 | - ['test', 'test', '', 'Please provide the old recovery password', Http::STATUS_BAD_REQUEST] |
|
| 73 | - ]; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param $password |
|
| 78 | - * @param $confirmPassword |
|
| 79 | - * @param $oldPassword |
|
| 80 | - * @param $expectedMessage |
|
| 81 | - * @param $expectedStatus |
|
| 82 | - */ |
|
| 83 | - #[\PHPUnit\Framework\Attributes\DataProvider('changeRecoveryPasswordProvider')] |
|
| 84 | - public function testChangeRecoveryPassword($password, $confirmPassword, $oldPassword, $expectedMessage, $expectedStatus): void { |
|
| 85 | - $this->recoveryMock->expects($this->any()) |
|
| 86 | - ->method('changeRecoveryKeyPassword') |
|
| 87 | - ->with($password, $oldPassword) |
|
| 88 | - ->willReturnMap([ |
|
| 89 | - ['test', 'oldtestFail', false], |
|
| 90 | - ['test', 'oldtest', true] |
|
| 91 | - ]); |
|
| 92 | - |
|
| 93 | - $response = $this->controller->changeRecoveryPassword($password, |
|
| 94 | - $oldPassword, |
|
| 95 | - $confirmPassword); |
|
| 96 | - |
|
| 97 | - $this->assertEquals($expectedMessage, $response->getData()['data']['message']); |
|
| 98 | - $this->assertEquals($expectedStatus, $response->getStatus()); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public static function userSetRecoveryProvider(): array { |
|
| 102 | - return [ |
|
| 103 | - ['1', 'Recovery Key enabled', Http::STATUS_OK], |
|
| 104 | - ['0', 'Could not enable the recovery key, please try again or contact your administrator', Http::STATUS_BAD_REQUEST] |
|
| 105 | - ]; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param $enableRecovery |
|
| 110 | - * @param $expectedMessage |
|
| 111 | - * @param $expectedStatus |
|
| 112 | - */ |
|
| 113 | - #[\PHPUnit\Framework\Attributes\DataProvider('userSetRecoveryProvider')] |
|
| 114 | - public function testUserSetRecovery($enableRecovery, $expectedMessage, $expectedStatus): void { |
|
| 115 | - $this->recoveryMock->expects($this->any()) |
|
| 116 | - ->method('setRecoveryForUser') |
|
| 117 | - ->with($enableRecovery) |
|
| 118 | - ->willReturnMap([ |
|
| 119 | - ['1', true], |
|
| 120 | - ['0', false] |
|
| 121 | - ]); |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - $response = $this->controller->userSetRecovery($enableRecovery); |
|
| 125 | - |
|
| 126 | - $this->assertEquals($expectedMessage, $response->getData()['data']['message']); |
|
| 127 | - $this->assertEquals($expectedStatus, $response->getStatus()); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - protected function setUp(): void { |
|
| 131 | - parent::setUp(); |
|
| 132 | - |
|
| 133 | - $this->requestMock = $this->getMockBuilder(IRequest::class) |
|
| 134 | - ->disableOriginalConstructor() |
|
| 135 | - ->getMock(); |
|
| 136 | - |
|
| 137 | - $this->configMock = $this->getMockBuilder(IConfig::class) |
|
| 138 | - ->disableOriginalConstructor() |
|
| 139 | - ->getMock(); |
|
| 140 | - |
|
| 141 | - $this->l10nMock = $this->getMockBuilder(IL10N::class) |
|
| 142 | - ->disableOriginalConstructor() |
|
| 143 | - ->getMock(); |
|
| 144 | - |
|
| 145 | - // Make l10n work in our tests |
|
| 146 | - $this->l10nMock->expects($this->any()) |
|
| 147 | - ->method('t') |
|
| 148 | - ->willReturnArgument(0); |
|
| 149 | - |
|
| 150 | - $this->recoveryMock = $this->getMockBuilder(Recovery::class) |
|
| 151 | - ->disableOriginalConstructor() |
|
| 152 | - ->getMock(); |
|
| 153 | - |
|
| 154 | - $this->controller = new RecoveryController( |
|
| 155 | - 'encryption', |
|
| 156 | - $this->requestMock, |
|
| 157 | - $this->l10nMock, |
|
| 158 | - $this->recoveryMock, |
|
| 159 | - $this->createMock(LoggerInterface::class), |
|
| 160 | - ); |
|
| 161 | - } |
|
| 23 | + protected RecoveryController $controller; |
|
| 24 | + |
|
| 25 | + protected IRequest&MockObject $requestMock; |
|
| 26 | + protected IConfig&MockObject $configMock; |
|
| 27 | + protected IL10N&MockObject $l10nMock; |
|
| 28 | + protected Recovery&MockObject $recoveryMock; |
|
| 29 | + |
|
| 30 | + public static function adminRecoveryProvider(): array { |
|
| 31 | + return [ |
|
| 32 | + ['test', 'test', true, 'Recovery key successfully enabled', Http::STATUS_OK], |
|
| 33 | + ['', 'test', true, 'Missing recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 34 | + ['test', '', true, 'Please repeat the recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 35 | + ['test', 'something that doesn\'t match', true, 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 36 | + ['test', 'test', false, 'Recovery key successfully disabled', Http::STATUS_OK], |
|
| 37 | + ]; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param $recoveryPassword |
|
| 42 | + * @param $passConfirm |
|
| 43 | + * @param $enableRecovery |
|
| 44 | + * @param $expectedMessage |
|
| 45 | + * @param $expectedStatus |
|
| 46 | + */ |
|
| 47 | + #[\PHPUnit\Framework\Attributes\DataProvider('adminRecoveryProvider')] |
|
| 48 | + public function testAdminRecovery($recoveryPassword, $passConfirm, $enableRecovery, $expectedMessage, $expectedStatus): void { |
|
| 49 | + $this->recoveryMock->expects($this->any()) |
|
| 50 | + ->method('enableAdminRecovery') |
|
| 51 | + ->willReturn(true); |
|
| 52 | + |
|
| 53 | + $this->recoveryMock->expects($this->any()) |
|
| 54 | + ->method('disableAdminRecovery') |
|
| 55 | + ->willReturn(true); |
|
| 56 | + |
|
| 57 | + $response = $this->controller->adminRecovery($recoveryPassword, |
|
| 58 | + $passConfirm, |
|
| 59 | + $enableRecovery); |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + $this->assertEquals($expectedMessage, $response->getData()['data']['message']); |
|
| 63 | + $this->assertEquals($expectedStatus, $response->getStatus()); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public static function changeRecoveryPasswordProvider(): array { |
|
| 67 | + return [ |
|
| 68 | + ['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', Http::STATUS_BAD_REQUEST], |
|
| 69 | + ['test', 'test', 'oldtest', 'Password successfully changed.', Http::STATUS_OK], |
|
| 70 | + ['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST], |
|
| 71 | + ['', 'test', 'oldtest', 'Please provide a new recovery password', Http::STATUS_BAD_REQUEST], |
|
| 72 | + ['test', 'test', '', 'Please provide the old recovery password', Http::STATUS_BAD_REQUEST] |
|
| 73 | + ]; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param $password |
|
| 78 | + * @param $confirmPassword |
|
| 79 | + * @param $oldPassword |
|
| 80 | + * @param $expectedMessage |
|
| 81 | + * @param $expectedStatus |
|
| 82 | + */ |
|
| 83 | + #[\PHPUnit\Framework\Attributes\DataProvider('changeRecoveryPasswordProvider')] |
|
| 84 | + public function testChangeRecoveryPassword($password, $confirmPassword, $oldPassword, $expectedMessage, $expectedStatus): void { |
|
| 85 | + $this->recoveryMock->expects($this->any()) |
|
| 86 | + ->method('changeRecoveryKeyPassword') |
|
| 87 | + ->with($password, $oldPassword) |
|
| 88 | + ->willReturnMap([ |
|
| 89 | + ['test', 'oldtestFail', false], |
|
| 90 | + ['test', 'oldtest', true] |
|
| 91 | + ]); |
|
| 92 | + |
|
| 93 | + $response = $this->controller->changeRecoveryPassword($password, |
|
| 94 | + $oldPassword, |
|
| 95 | + $confirmPassword); |
|
| 96 | + |
|
| 97 | + $this->assertEquals($expectedMessage, $response->getData()['data']['message']); |
|
| 98 | + $this->assertEquals($expectedStatus, $response->getStatus()); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public static function userSetRecoveryProvider(): array { |
|
| 102 | + return [ |
|
| 103 | + ['1', 'Recovery Key enabled', Http::STATUS_OK], |
|
| 104 | + ['0', 'Could not enable the recovery key, please try again or contact your administrator', Http::STATUS_BAD_REQUEST] |
|
| 105 | + ]; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param $enableRecovery |
|
| 110 | + * @param $expectedMessage |
|
| 111 | + * @param $expectedStatus |
|
| 112 | + */ |
|
| 113 | + #[\PHPUnit\Framework\Attributes\DataProvider('userSetRecoveryProvider')] |
|
| 114 | + public function testUserSetRecovery($enableRecovery, $expectedMessage, $expectedStatus): void { |
|
| 115 | + $this->recoveryMock->expects($this->any()) |
|
| 116 | + ->method('setRecoveryForUser') |
|
| 117 | + ->with($enableRecovery) |
|
| 118 | + ->willReturnMap([ |
|
| 119 | + ['1', true], |
|
| 120 | + ['0', false] |
|
| 121 | + ]); |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + $response = $this->controller->userSetRecovery($enableRecovery); |
|
| 125 | + |
|
| 126 | + $this->assertEquals($expectedMessage, $response->getData()['data']['message']); |
|
| 127 | + $this->assertEquals($expectedStatus, $response->getStatus()); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + protected function setUp(): void { |
|
| 131 | + parent::setUp(); |
|
| 132 | + |
|
| 133 | + $this->requestMock = $this->getMockBuilder(IRequest::class) |
|
| 134 | + ->disableOriginalConstructor() |
|
| 135 | + ->getMock(); |
|
| 136 | + |
|
| 137 | + $this->configMock = $this->getMockBuilder(IConfig::class) |
|
| 138 | + ->disableOriginalConstructor() |
|
| 139 | + ->getMock(); |
|
| 140 | + |
|
| 141 | + $this->l10nMock = $this->getMockBuilder(IL10N::class) |
|
| 142 | + ->disableOriginalConstructor() |
|
| 143 | + ->getMock(); |
|
| 144 | + |
|
| 145 | + // Make l10n work in our tests |
|
| 146 | + $this->l10nMock->expects($this->any()) |
|
| 147 | + ->method('t') |
|
| 148 | + ->willReturnArgument(0); |
|
| 149 | + |
|
| 150 | + $this->recoveryMock = $this->getMockBuilder(Recovery::class) |
|
| 151 | + ->disableOriginalConstructor() |
|
| 152 | + ->getMock(); |
|
| 153 | + |
|
| 154 | + $this->controller = new RecoveryController( |
|
| 155 | + 'encryption', |
|
| 156 | + $this->requestMock, |
|
| 157 | + $this->l10nMock, |
|
| 158 | + $this->recoveryMock, |
|
| 159 | + $this->createMock(LoggerInterface::class), |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -19,56 +19,56 @@ |
||
| 19 | 19 | |
| 20 | 20 | class StatusControllerTest extends TestCase { |
| 21 | 21 | |
| 22 | - protected IRequest&MockObject $requestMock; |
|
| 23 | - protected IL10N&MockObject $l10nMock; |
|
| 24 | - protected Session&MockObject $sessionMock; |
|
| 25 | - protected IManager&MockObject $encryptionManagerMock; |
|
| 22 | + protected IRequest&MockObject $requestMock; |
|
| 23 | + protected IL10N&MockObject $l10nMock; |
|
| 24 | + protected Session&MockObject $sessionMock; |
|
| 25 | + protected IManager&MockObject $encryptionManagerMock; |
|
| 26 | 26 | |
| 27 | - protected StatusController $controller; |
|
| 27 | + protected StatusController $controller; |
|
| 28 | 28 | |
| 29 | - protected function setUp(): void { |
|
| 30 | - parent::setUp(); |
|
| 29 | + protected function setUp(): void { |
|
| 30 | + parent::setUp(); |
|
| 31 | 31 | |
| 32 | - $this->sessionMock = $this->getMockBuilder(Session::class) |
|
| 33 | - ->disableOriginalConstructor()->getMock(); |
|
| 34 | - $this->requestMock = $this->createMock(IRequest::class); |
|
| 32 | + $this->sessionMock = $this->getMockBuilder(Session::class) |
|
| 33 | + ->disableOriginalConstructor()->getMock(); |
|
| 34 | + $this->requestMock = $this->createMock(IRequest::class); |
|
| 35 | 35 | |
| 36 | - $this->l10nMock = $this->getMockBuilder(IL10N::class) |
|
| 37 | - ->disableOriginalConstructor()->getMock(); |
|
| 38 | - $this->l10nMock->expects($this->any()) |
|
| 39 | - ->method('t') |
|
| 40 | - ->willReturnCallback(function ($message) { |
|
| 41 | - return $message; |
|
| 42 | - }); |
|
| 43 | - $this->encryptionManagerMock = $this->createMock(IManager::class); |
|
| 36 | + $this->l10nMock = $this->getMockBuilder(IL10N::class) |
|
| 37 | + ->disableOriginalConstructor()->getMock(); |
|
| 38 | + $this->l10nMock->expects($this->any()) |
|
| 39 | + ->method('t') |
|
| 40 | + ->willReturnCallback(function ($message) { |
|
| 41 | + return $message; |
|
| 42 | + }); |
|
| 43 | + $this->encryptionManagerMock = $this->createMock(IManager::class); |
|
| 44 | 44 | |
| 45 | - $this->controller = new StatusController('encryptionTest', |
|
| 46 | - $this->requestMock, |
|
| 47 | - $this->l10nMock, |
|
| 48 | - $this->sessionMock, |
|
| 49 | - $this->encryptionManagerMock); |
|
| 50 | - } |
|
| 45 | + $this->controller = new StatusController('encryptionTest', |
|
| 46 | + $this->requestMock, |
|
| 47 | + $this->l10nMock, |
|
| 48 | + $this->sessionMock, |
|
| 49 | + $this->encryptionManagerMock); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * |
|
| 54 | - * @param string $status |
|
| 55 | - * @param string $expectedStatus |
|
| 56 | - */ |
|
| 57 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetStatus')] |
|
| 58 | - public function testGetStatus($status, $expectedStatus): void { |
|
| 59 | - $this->sessionMock->expects($this->atLeastOnce()) |
|
| 60 | - ->method('getStatus')->willReturn($status); |
|
| 61 | - $result = $this->controller->getStatus(); |
|
| 62 | - $data = $result->getData(); |
|
| 63 | - $this->assertSame($expectedStatus, $data['status']); |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * |
|
| 54 | + * @param string $status |
|
| 55 | + * @param string $expectedStatus |
|
| 56 | + */ |
|
| 57 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetStatus')] |
|
| 58 | + public function testGetStatus($status, $expectedStatus): void { |
|
| 59 | + $this->sessionMock->expects($this->atLeastOnce()) |
|
| 60 | + ->method('getStatus')->willReturn($status); |
|
| 61 | + $result = $this->controller->getStatus(); |
|
| 62 | + $data = $result->getData(); |
|
| 63 | + $this->assertSame($expectedStatus, $data['status']); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public static function dataTestGetStatus(): array { |
|
| 67 | - return [ |
|
| 68 | - [Session::INIT_EXECUTED, 'interactionNeeded'], |
|
| 69 | - [Session::INIT_SUCCESSFUL, 'success'], |
|
| 70 | - [Session::NOT_INITIALIZED, 'interactionNeeded'], |
|
| 71 | - ['unknown', 'error'], |
|
| 72 | - ]; |
|
| 73 | - } |
|
| 66 | + public static function dataTestGetStatus(): array { |
|
| 67 | + return [ |
|
| 68 | + [Session::INIT_EXECUTED, 'interactionNeeded'], |
|
| 69 | + [Session::INIT_SUCCESSFUL, 'success'], |
|
| 70 | + [Session::NOT_INITIALIZED, 'interactionNeeded'], |
|
| 71 | + ['unknown', 'error'], |
|
| 72 | + ]; |
|
| 73 | + } |
|
| 74 | 74 | } |