From bf9ba8dc2dc351136649e90d01149f2e7efe012b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Mon, 22 Jan 2024 08:48:36 +0100 Subject: [PATCH] chore(tests): UT for CustomFieldCrypt service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../api/Controllers/Account/AccountBase.php | 24 +- .../Crypt/UpdateMasterPasswordCommand.php | 2 +- .../Controllers/Account/AccountSaveBase.php | 13 +- .../Account/SaveDeleteController.php | 10 +- .../AccountManager/BulkEditController.php | 8 +- .../AccountManager/DeleteController.php | 10 +- .../AuthToken/AuthTokenSaveBase.php | 8 +- .../AuthToken/AuthTokenViewBase.php | 14 +- .../Controllers/Category/CategorySaveBase.php | 10 +- .../Controllers/Category/CategoryViewBase.php | 8 +- .../web/Controllers/Client/ClientSaveBase.php | 10 +- .../web/Controllers/Client/ClientViewBase.php | 8 +- .../ConfigEncryption/SaveController.php | 2 +- .../Helpers/Account/AccountHelper.php | 36 +-- .../web/Controllers/Tag/TagSaveBase.php | 10 +- .../web/Controllers/User/UserSaveBase.php | 16 +- .../web/Controllers/User/UserViewBase.php | 10 +- .../UserGroup/UserGroupSaveBase.php | 12 +- .../UserGroup/UserGroupViewBase.php | 12 +- .../UserProfile/UserProfileSaveBase.php | 8 +- .../UserProfile/UserProfileViewBase.php | 8 +- .../Account/Adapters/AccountAdapter.php | 10 +- .../Account/Ports/AccountCryptService.php | 4 +- .../Domain/Account/Services/AccountCrypt.php | 6 +- lib/SP/Domain/Category/Adapters/Category.php | 8 +- .../Domain/Client/Adapters/ClientAdapter.php | 4 +- .../Client/Ports/ClientAdapterInterface.php | 4 +- .../UpdateMasterPassRequest.php | 22 +- .../Domain/Crypt/Ports/MasterPassService.php | 2 +- lib/SP/Domain/Crypt/Services/MasterPass.php | 13 +- ...erface.php => CustomFieldCryptService.php} | 8 +- ...ceInterface.php => CustomFieldService.php} | 2 +- ...CustomFieldService.php => CustomField.php} | 10 +- ...dCryptService.php => CustomFieldCrypt.php} | 100 ++++---- .../UpgradeCustomFieldDataService.php | 14 +- lib/SP/Mvc/Controller/ItemTrait.php | 20 +- .../Account/Adapters/AccountAdapterTest.php | 8 +- .../Account/Services/AccountCryptTest.php | 2 +- .../Domain/Crypt/Services/MasterPassTest.php | 12 +- .../Services/CustomFieldCryptTest.php | 219 ++++++++++++++++++ 40 files changed, 458 insertions(+), 249 deletions(-) rename lib/SP/Domain/Crypt/{Services => Dtos}/UpdateMasterPassRequest.php (74%) rename lib/SP/Domain/CustomField/Ports/{CustomFieldCryptServiceInterface.php => CustomFieldCryptService.php} (84%) rename lib/SP/Domain/CustomField/Ports/{CustomFieldServiceInterface.php => CustomFieldService.php} (98%) rename lib/SP/Domain/CustomField/Services/{CustomFieldService.php => CustomField.php} (96%) rename lib/SP/Domain/CustomField/Services/{CustomFieldCryptService.php => CustomFieldCrypt.php} (53%) create mode 100644 tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php diff --git a/app/modules/api/Controllers/Account/AccountBase.php b/app/modules/api/Controllers/Account/AccountBase.php index 47ba2f74..bdc02d4b 100644 --- a/app/modules/api/Controllers/Account/AccountBase.php +++ b/app/modules/api/Controllers/Account/AccountBase.php @@ -33,7 +33,7 @@ use SP\Domain\Account\Ports\AccountService; use SP\Domain\Api\Ports\ApiService; use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Exceptions\InvalidClassException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Modules\Api\Controllers\ControllerBase; use SP\Modules\Api\Controllers\Help\AccountHelp; @@ -43,22 +43,22 @@ use SP\Modules\Api\Controllers\Help\AccountHelp; abstract class AccountBase extends ControllerBase { protected AccountPresetService $accountPresetService; - protected AccountService $accountService; - protected CustomFieldServiceInterface $customFieldService; - protected AccountAdapterInterface $accountAdapter; + protected AccountService $accountService; + protected CustomFieldService $customFieldService; + protected AccountAdapterInterface $accountAdapter; /** * @throws InvalidClassException */ public function __construct( - Application $application, - Klein $router, - ApiService $apiService, - AclInterface $acl, - AccountPresetService $accountPresetService, - AccountService $accountService, - CustomFieldServiceInterface $customFieldService, - AccountAdapterInterface $accountAdapter + Application $application, + Klein $router, + ApiService $apiService, + AclInterface $acl, + AccountPresetService $accountPresetService, + AccountService $accountService, + CustomFieldService $customFieldService, + AccountAdapterInterface $accountAdapter ) { parent::__construct($application, $router, $apiService, $acl); diff --git a/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php b/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php index df96af72..3bc73445 100644 --- a/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php +++ b/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php @@ -33,9 +33,9 @@ use SP\Domain\Common\Services\ServiceException; use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Config\Services\Config; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\Crypt\Ports\MasterPassService; use SP\Domain\Crypt\Services\MasterPass; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Cli\Commands\CommandBase; use SP\Modules\Cli\Commands\Validators; diff --git a/app/modules/web/Controllers/Account/AccountSaveBase.php b/app/modules/web/Controllers/Account/AccountSaveBase.php index 74b99207..4e3ae892 100644 --- a/app/modules/web/Controllers/Account/AccountSaveBase.php +++ b/app/modules/web/Controllers/Account/AccountSaveBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -28,7 +28,7 @@ namespace SP\Modules\Web\Controllers\Account; use SP\Core\Application; use SP\Domain\Account\Ports\AccountPresetService; use SP\Domain\Account\Ports\AccountService; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Modules\Web\Forms\AccountForm; use SP\Mvc\Controller\ItemTrait; @@ -39,18 +39,19 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class AccountSaveBase extends AccountControllerBase { - use JsonTrait, ItemTrait; + use ItemTrait; + use JsonTrait; protected AccountService $accountService; - protected AccountForm $accountForm; - protected CustomFieldServiceInterface $customFieldService; + protected AccountForm $accountForm; + protected CustomFieldService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, AccountPresetService $accountPresetService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct( $application, diff --git a/app/modules/web/Controllers/Account/SaveDeleteController.php b/app/modules/web/Controllers/Account/SaveDeleteController.php index 4515ce18..b1089152 100644 --- a/app/modules/web/Controllers/Account/SaveDeleteController.php +++ b/app/modules/web/Controllers/Account/SaveDeleteController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -32,7 +32,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Http\JsonMessage; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; @@ -46,14 +46,14 @@ final class SaveDeleteController extends AccountControllerBase use ItemTrait; use JsonTrait; - private AccountService $accountService; - private CustomFieldServiceInterface $customFieldService; + private AccountService $accountService; + private CustomFieldService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct( $application, diff --git a/app/modules/web/Controllers/AccountManager/BulkEditController.php b/app/modules/web/Controllers/AccountManager/BulkEditController.php index 120dbd75..cbff5341 100644 --- a/app/modules/web/Controllers/AccountManager/BulkEditController.php +++ b/app/modules/web/Controllers/AccountManager/BulkEditController.php @@ -35,7 +35,7 @@ use SP\Domain\Account\Ports\AccountService; use SP\Domain\Category\Ports\CategoryService; use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\Tag\Ports\TagServiceInterface; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -60,9 +60,9 @@ final class BulkEditController extends ControllerBase private AccountService $accountService; private AccountSearchService $accountSearchService; private AccountHistoryService $accountHistoryService; - private AccountGrid $accountGrid; - private CustomFieldServiceInterface $customFieldService; - private CategoryService $categoryService; + private AccountGrid $accountGrid; + private CustomFieldService $customFieldService; + private CategoryService $categoryService; private ClientService $clientService; private TagServiceInterface $tagService; private UserServiceInterface $userService; diff --git a/app/modules/web/Controllers/AccountManager/DeleteController.php b/app/modules/web/Controllers/AccountManager/DeleteController.php index 73c46fff..66c4bca7 100644 --- a/app/modules/web/Controllers/AccountManager/DeleteController.php +++ b/app/modules/web/Controllers/AccountManager/DeleteController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -31,7 +31,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Http\JsonMessage; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; @@ -48,14 +48,14 @@ final class DeleteController extends ControllerBase use ItemTrait; use JsonTrait; - private AccountService $accountService; - private CustomFieldServiceInterface $customFieldService; + private AccountService $accountService; + private CustomFieldService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php b/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php index ace32d31..7acacb2b 100644 --- a/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php +++ b/app/modules/web/Controllers/AuthToken/AuthTokenSaveBase.php @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\AuthToken; use SP\Core\Application; use SP\Domain\Auth\Ports\AuthTokenService; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Modules\Web\Forms\AuthTokenForm; @@ -42,15 +42,15 @@ abstract class AuthTokenSaveBase extends ControllerBase use ItemTrait; use JsonTrait; - protected CustomFieldServiceInterface $customFieldService; - protected AuthTokenService $authTokenService; + protected CustomFieldService $customFieldService; + protected AuthTokenService $authTokenService; protected AuthTokenForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AuthTokenService $authTokenService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php b/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php index 815f97b5..ffe89d36 100644 --- a/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php +++ b/app/modules/web/Controllers/AuthToken/AuthTokenViewBase.php @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\User\Ports\UserServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; @@ -57,12 +57,12 @@ abstract class AuthTokenViewBase extends ControllerBase * @throws SessionTimeout */ public function __construct( - Application $application, - WebControllerHelper $webControllerHelper, - private readonly CustomFieldServiceInterface $customFieldService, - private readonly UserServiceInterface $userService, - private readonly AuthTokenService $authTokenService, - private readonly AuthTokenActionInterface $authTokenAction, + Application $application, + WebControllerHelper $webControllerHelper, + private readonly CustomFieldService $customFieldService, + private readonly UserServiceInterface $userService, + private readonly AuthTokenService $authTokenService, + private readonly AuthTokenActionInterface $authTokenAction, ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Category/CategorySaveBase.php b/app/modules/web/Controllers/Category/CategorySaveBase.php index b3798bc7..9c74d57c 100644 --- a/app/modules/web/Controllers/Category/CategorySaveBase.php +++ b/app/modules/web/Controllers/Category/CategorySaveBase.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\Category; use SP\Core\Application; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Modules\Web\Forms\CategoryForm; @@ -41,15 +41,15 @@ abstract class CategorySaveBase extends ControllerBase use ItemTrait; use JsonTrait; - protected CategoryService $categoryService; - protected CustomFieldServiceInterface $customFieldService; - protected CategoryForm $form; + protected CategoryService $categoryService; + protected CustomFieldService $customFieldService; + protected CategoryForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, CategoryService $categoryService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Category/CategoryViewBase.php b/app/modules/web/Controllers/Category/CategoryViewBase.php index 948343d9..34ae36e5 100644 --- a/app/modules/web/Controllers/Category/CategoryViewBase.php +++ b/app/modules/web/Controllers/Category/CategoryViewBase.php @@ -33,7 +33,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; use SP\Mvc\Controller\ItemTrait; @@ -46,14 +46,14 @@ abstract class CategoryViewBase extends ControllerBase { use ItemTrait; - private CategoryService $categoryService; - private CustomFieldServiceInterface $customFieldService; + private CategoryService $categoryService; + private CustomFieldService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, CategoryService $categoryService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Client/ClientSaveBase.php b/app/modules/web/Controllers/Client/ClientSaveBase.php index 083a9718..c0608e3e 100644 --- a/app/modules/web/Controllers/Client/ClientSaveBase.php +++ b/app/modules/web/Controllers/Client/ClientSaveBase.php @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Client; use SP\Core\Application; use SP\Domain\Client\Ports\ClientService; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\ClientForm; use SP\Mvc\Controller\WebControllerHelper; @@ -37,15 +37,15 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class ClientSaveBase extends ControllerBase { - protected ClientService $clientService; - protected CustomFieldServiceInterface $customFieldService; - protected ClientForm $form; + protected ClientService $clientService; + protected CustomFieldService $customFieldService; + protected ClientForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, ClientService $clientService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Client/ClientViewBase.php b/app/modules/web/Controllers/Client/ClientViewBase.php index b5733c4b..ea03ba03 100644 --- a/app/modules/web/Controllers/Client/ClientViewBase.php +++ b/app/modules/web/Controllers/Client/ClientViewBase.php @@ -34,7 +34,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; use SP\Mvc\Controller\ItemTrait; @@ -47,14 +47,14 @@ abstract class ClientViewBase extends ControllerBase { use ItemTrait; - private ClientService $clientService; - private CustomFieldServiceInterface $customFieldService; + private ClientService $clientService; + private CustomFieldService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, ClientService $clientService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/ConfigEncryption/SaveController.php b/app/modules/web/Controllers/ConfigEncryption/SaveController.php index 43dee343..555e5daa 100644 --- a/app/modules/web/Controllers/ConfigEncryption/SaveController.php +++ b/app/modules/web/Controllers/ConfigEncryption/SaveController.php @@ -35,9 +35,9 @@ use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Exceptions\SessionTimeout; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\Crypt\Ports\MasterPassService; use SP\Domain\Crypt\Services\MasterPass; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; use SP\Domain\Task\Ports\TaskInterface; use SP\Domain\Task\Services\Task; use SP\Domain\Task\Services\TaskFactory; diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index f16022b2..8d3b8fe9 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -50,7 +50,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Crypt\Ports\MasterPassService; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\Http\RequestInterface; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; @@ -80,9 +80,9 @@ final class AccountHelper extends AccountHelperBase private MasterPassService $masterPassService; private AccountAclService $accountAclService; private CategoryService $categoryService; - private ClientService $clientService; - private CustomFieldServiceInterface $customFieldService; - private ?AccountPermission $accountAcl = null; + private ClientService $clientService; + private CustomFieldService $customFieldService; + private ?AccountPermission $accountAcl = null; private ?int $accountId = null; private UserServiceInterface $userService; private UserGroupServiceInterface $userGroupService; @@ -92,20 +92,20 @@ final class AccountHelper extends AccountHelperBase Application $application, TemplateInterface $template, RequestInterface $request, - AclInterface $acl, - AccountService $accountService, - AccountHistoryService $accountHistoryService, - PublicLinkService $publicLinkService, - ItemPresetServiceInterface $itemPresetService, - MasterPassService $masterPassService, - AccountActionsHelper $accountActionsHelper, - AccountAclService $accountAclService, - CategoryService $categoryService, - ClientService $clientService, - CustomFieldServiceInterface $customFieldService, - UserServiceInterface $userService, - UserGroupServiceInterface $userGroupService, - TagServiceInterface $tagService + AclInterface $acl, + AccountService $accountService, + AccountHistoryService $accountHistoryService, + PublicLinkService $publicLinkService, + ItemPresetServiceInterface $itemPresetService, + MasterPassService $masterPassService, + AccountActionsHelper $accountActionsHelper, + AccountAclService $accountAclService, + CategoryService $categoryService, + ClientService $clientService, + CustomFieldService $customFieldService, + UserServiceInterface $userService, + UserGroupServiceInterface $userGroupService, + TagServiceInterface $tagService ) { parent::__construct($application, $template, $request, $acl, $accountActionsHelper, $masterPassService); diff --git a/app/modules/web/Controllers/Tag/TagSaveBase.php b/app/modules/web/Controllers/Tag/TagSaveBase.php index 37d5a7d1..bd6bb817 100644 --- a/app/modules/web/Controllers/Tag/TagSaveBase.php +++ b/app/modules/web/Controllers/Tag/TagSaveBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\Tag; use SP\Core\Application; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\Tag\Ports\TagServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\TagForm; @@ -38,14 +38,14 @@ use SP\Mvc\Controller\WebControllerHelper; abstract class TagSaveBase extends ControllerBase { protected TagServiceInterface $tagService; - protected TagForm $form; - protected CustomFieldServiceInterface $customFieldService; + protected TagForm $form; + protected CustomFieldService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, TagServiceInterface $tagService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/User/UserSaveBase.php b/app/modules/web/Controllers/User/UserSaveBase.php index 03f44645..b3e4ee95 100644 --- a/app/modules/web/Controllers/User/UserSaveBase.php +++ b/app/modules/web/Controllers/User/UserSaveBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -32,7 +32,7 @@ use SP\DataModel\UserData; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\Notification\Ports\MailServiceInterface; use SP\Domain\User\Ports\UserPassRecoverServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -46,17 +46,17 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class UserSaveBase extends ControllerBase { - protected UserServiceInterface $userService; - protected CustomFieldServiceInterface $customFieldService; - protected UserForm $form; + protected UserServiceInterface $userService; + protected CustomFieldService $customFieldService; + protected UserForm $form; private MailServiceInterface $mailService; private UserPassRecoverServiceInterface $userPassRecoverService; public function __construct( - Application $application, - WebControllerHelper $webControllerHelper, + Application $application, + WebControllerHelper $webControllerHelper, UserServiceInterface $userService, - CustomFieldServiceInterface $customFieldService, + CustomFieldService $customFieldService, MailServiceInterface $mailService, UserPassRecoverServiceInterface $userPassRecoverService ) { diff --git a/app/modules/web/Controllers/User/UserViewBase.php b/app/modules/web/Controllers/User/UserViewBase.php index d9cfbcdf..aaaeac0a 100644 --- a/app/modules/web/Controllers/User/UserViewBase.php +++ b/app/modules/web/Controllers/User/UserViewBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -33,7 +33,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -51,8 +51,8 @@ abstract class UserViewBase extends ControllerBase protected UserServiceInterface $userService; private UserGroupServiceInterface $userGroupService; - private UserProfileServiceInterface $userProfileService; - private CustomFieldServiceInterface $customFieldService; + private UserProfileServiceInterface $userProfileService; + private CustomFieldService $customFieldService; public function __construct( Application $application, @@ -60,7 +60,7 @@ abstract class UserViewBase extends ControllerBase UserServiceInterface $userService, UserGroupServiceInterface $userGroupService, UserProfileServiceInterface $userProfileService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php b/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php index 29756563..ab5bcfe7 100644 --- a/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php +++ b/app/modules/web/Controllers/UserGroup/UserGroupSaveBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\UserGroup; use SP\Core\Application; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\UserGroupForm; @@ -37,15 +37,15 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class UserGroupSaveBase extends ControllerBase { - protected UserGroupServiceInterface $userGroupService; - protected CustomFieldServiceInterface $customFieldService; - protected UserGroupForm $form; + protected UserGroupServiceInterface $userGroupService; + protected CustomFieldService $customFieldService; + protected UserGroupForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserGroupServiceInterface $userGroupService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php b/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php index aaeee530..82e547b4 100644 --- a/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php +++ b/app/modules/web/Controllers/UserGroup/UserGroupViewBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -33,7 +33,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; use SP\Infrastructure\Common\Repositories\NoSuchItemException; @@ -49,16 +49,16 @@ abstract class UserGroupViewBase extends ControllerBase { use ItemTrait; - private UserGroupServiceInterface $userGroupService; - private CustomFieldServiceInterface $customFieldService; - private UserServiceInterface $userService; + private UserGroupServiceInterface $userGroupService; + private CustomFieldService $customFieldService; + private UserServiceInterface $userService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserGroupServiceInterface $userGroupService, UserServiceInterface $userService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php b/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php index 51f48940..f439337a 100644 --- a/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php +++ b/app/modules/web/Controllers/UserProfile/UserProfileSaveBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\UserProfile; use SP\Core\Application; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\UserProfileForm; @@ -38,14 +38,14 @@ use SP\Mvc\Controller\WebControllerHelper; abstract class UserProfileSaveBase extends ControllerBase { protected UserProfileServiceInterface $userProfileService; - protected CustomFieldServiceInterface $customFieldService; + protected CustomFieldService $customFieldService; protected UserProfileForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserProfileServiceInterface $userProfileService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php b/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php index 6de175d7..8844f037 100644 --- a/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php +++ b/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -34,7 +34,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; @@ -49,13 +49,13 @@ abstract class UserProfileViewBase extends ControllerBase use ItemTrait; private UserProfileServiceInterface $userProfileService; - private CustomFieldServiceInterface $customFieldService; + private CustomFieldService $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserProfileServiceInterface $userProfileService, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/lib/SP/Domain/Account/Adapters/AccountAdapter.php b/lib/SP/Domain/Account/Adapters/AccountAdapter.php index 7a87ff24..1e469ca3 100644 --- a/lib/SP/Domain/Account/Adapters/AccountAdapter.php +++ b/lib/SP/Domain/Account/Adapters/AccountAdapter.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Adapters\CustomFieldAdapter; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Util\Link; @@ -51,9 +51,9 @@ final class AccountAdapter extends Adapter implements AccountAdapterInterface protected array $availableIncludes = ['customFields']; public function __construct( - ConfigDataInterface $configData, - private readonly CustomFieldServiceInterface $customFieldService, - private readonly ActionsInterface $actions + ConfigDataInterface $configData, + private readonly CustomFieldService $customFieldService, + private readonly ActionsInterface $actions ) { parent::__construct($configData); } diff --git a/lib/SP/Domain/Account/Ports/AccountCryptService.php b/lib/SP/Domain/Account/Ports/AccountCryptService.php index 89c24046..7efafc4e 100644 --- a/lib/SP/Domain/Account/Ports/AccountCryptService.php +++ b/lib/SP/Domain/Account/Ports/AccountCryptService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -26,7 +26,7 @@ namespace SP\Domain\Account\Ports; use SP\Domain\Account\Dtos\EncryptedPassword; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; /** * Class AccountCryptService diff --git a/lib/SP/Domain/Account/Services/AccountCrypt.php b/lib/SP/Domain/Account/Services/AccountCrypt.php index 69957e19..71bae59d 100644 --- a/lib/SP/Domain/Account/Services/AccountCrypt.php +++ b/lib/SP/Domain/Account/Services/AccountCrypt.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -38,7 +38,7 @@ use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Crypt\CryptInterface; use SP\Domain\Core\Exceptions\CryptException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\Task\Services\TaskFactory; use SP\Util\Util; @@ -119,7 +119,7 @@ final class AccountCrypt extends Service implements AccountCryptService /** * @param Account[] $accounts * @param callable $passUpdater - * @param UpdateMasterPassRequest $updateMasterPassRequest + * @param \SP\Domain\Crypt\Dtos\UpdateMasterPassRequest $updateMasterPassRequest * * @return EventMessage */ diff --git a/lib/SP/Domain/Category/Adapters/Category.php b/lib/SP/Domain/Category/Adapters/Category.php index 9839b8b5..43369ff6 100644 --- a/lib/SP/Domain/Category/Adapters/Category.php +++ b/lib/SP/Domain/Category/Adapters/Category.php @@ -37,7 +37,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Adapters\CustomFieldAdapter; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Mvc\Controller\ItemTrait; use SP\Util\Link; @@ -53,9 +53,9 @@ final class Category extends Adapter implements CategoryAdapter protected array $availableIncludes = ['customFields']; public function __construct( - ConfigDataInterface $configData, - private readonly CustomFieldServiceInterface $customFieldService, - private readonly ActionsInterface $actions + ConfigDataInterface $configData, + private readonly CustomFieldService $customFieldService, + private readonly ActionsInterface $actions ) { parent::__construct($configData); } diff --git a/lib/SP/Domain/Client/Adapters/ClientAdapter.php b/lib/SP/Domain/Client/Adapters/ClientAdapter.php index 05aba1f0..47b2243f 100644 --- a/lib/SP/Domain/Client/Adapters/ClientAdapter.php +++ b/lib/SP/Domain/Client/Adapters/ClientAdapter.php @@ -34,7 +34,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Adapters\CustomFieldAdapter; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Mvc\Controller\ItemTrait; use SP\Util\Link; @@ -55,7 +55,7 @@ final class ClientAdapter extends Adapter implements ClientAdapterInterface * @throws SPException * @throws ServiceException */ - public function includeCustomFields(Client $data, CustomFieldServiceInterface $customFieldService): Collection + public function includeCustomFields(Client $data, CustomFieldService $customFieldService): Collection { return $this->collection( $this->getCustomFieldsForItem(AclActionsInterface::CLIENT, $data->id, $customFieldService), diff --git a/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php b/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php index a34132f8..f85ed9c8 100644 --- a/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php +++ b/lib/SP/Domain/Client/Ports/ClientAdapterInterface.php @@ -30,7 +30,7 @@ use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; /** * Class ClientAdapter @@ -45,7 +45,7 @@ interface ClientAdapterInterface * @throws SPException * @throws ServiceException */ - public function includeCustomFields(Client $data, CustomFieldServiceInterface $customFieldService): Collection; + public function includeCustomFields(Client $data, CustomFieldService $customFieldService): Collection; public function transform(Client $data): array; } diff --git a/lib/SP/Domain/Crypt/Services/UpdateMasterPassRequest.php b/lib/SP/Domain/Crypt/Dtos/UpdateMasterPassRequest.php similarity index 74% rename from lib/SP/Domain/Crypt/Services/UpdateMasterPassRequest.php rename to lib/SP/Domain/Crypt/Dtos/UpdateMasterPassRequest.php index 6684d5bd..269cf876 100644 --- a/lib/SP/Domain/Crypt/Services/UpdateMasterPassRequest.php +++ b/lib/SP/Domain/Crypt/Dtos/UpdateMasterPassRequest.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -22,33 +22,23 @@ * along with sysPass. If not, see . */ -namespace SP\Domain\Crypt\Services; +namespace SP\Domain\Crypt\Dtos; use SP\Core\Crypt\Hash; use SP\Domain\Task\Ports\TaskInterface; /** * Class UpdateMasterPassRequest - * - * @package SP\Domain\Crypt\Services */ final class UpdateMasterPassRequest { private string $hash; - /** - * UpdateMasterPassRequest constructor. - * - * @param string $currentMasterPass - * @param string $newMasterPass - * @param string $currentHash - * @param TaskInterface|null $task - */ public function __construct( - private string $currentMasterPass, - private string $newMasterPass, - private string $currentHash, - private ?TaskInterface $task = null + private readonly string $currentMasterPass, + private readonly string $newMasterPass, + private readonly string $currentHash, + private readonly ?TaskInterface $task = null ) { $this->hash = Hash::hashKey($newMasterPass); } diff --git a/lib/SP/Domain/Crypt/Ports/MasterPassService.php b/lib/SP/Domain/Crypt/Ports/MasterPassService.php index 9c50faa2..c640ff59 100644 --- a/lib/SP/Domain/Crypt/Ports/MasterPassService.php +++ b/lib/SP/Domain/Crypt/Ports/MasterPassService.php @@ -27,7 +27,7 @@ namespace SP\Domain\Crypt\Ports; use Exception; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; /** * Class MasterPassService diff --git a/lib/SP/Domain/Crypt/Services/MasterPass.php b/lib/SP/Domain/Crypt/Services/MasterPass.php index 0008bfb2..f779d8ef 100644 --- a/lib/SP/Domain/Crypt/Services/MasterPass.php +++ b/lib/SP/Domain/Crypt/Services/MasterPass.php @@ -34,8 +34,9 @@ use SP\Domain\Common\Services\ServiceException; use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\Crypt\Ports\MasterPassService; -use SP\Domain\CustomField\Ports\CustomFieldCryptServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldCryptService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use function SP\processException; @@ -49,11 +50,11 @@ final class MasterPass extends Service implements MasterPassService public const PARAM_MASTER_PASS_HASH = 'masterPwd'; public function __construct( - Application $application, - private readonly ConfigService $configService, - private readonly AccountCryptService $accountCryptService, - private readonly CustomFieldCryptServiceInterface $customFieldCryptService, - private readonly Repository $repository + Application $application, + private readonly ConfigService $configService, + private readonly AccountCryptService $accountCryptService, + private readonly CustomFieldCryptService $customFieldCryptService, + private readonly Repository $repository ) { parent::__construct($application); } diff --git a/lib/SP/Domain/CustomField/Ports/CustomFieldCryptServiceInterface.php b/lib/SP/Domain/CustomField/Ports/CustomFieldCryptService.php similarity index 84% rename from lib/SP/Domain/CustomField/Ports/CustomFieldCryptServiceInterface.php rename to lib/SP/Domain/CustomField/Ports/CustomFieldCryptService.php index b03a3a4a..0f830498 100644 --- a/lib/SP/Domain/CustomField/Ports/CustomFieldCryptServiceInterface.php +++ b/lib/SP/Domain/CustomField/Ports/CustomFieldCryptService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,19 +25,19 @@ namespace SP\Domain\CustomField\Ports; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; /** * Class CustomFieldCryptService * * @package SP\Mgmt\CustomFields */ -interface CustomFieldCryptServiceInterface +interface CustomFieldCryptService { /** * Actualizar los datos encriptados con una nueva clave * - * @param UpdateMasterPassRequest $request + * @param UpdateMasterPassRequest $request * * @throws ServiceException */ diff --git a/lib/SP/Domain/CustomField/Ports/CustomFieldServiceInterface.php b/lib/SP/Domain/CustomField/Ports/CustomFieldService.php similarity index 98% rename from lib/SP/Domain/CustomField/Ports/CustomFieldServiceInterface.php rename to lib/SP/Domain/CustomField/Ports/CustomFieldService.php index 544586d6..6d973a64 100644 --- a/lib/SP/Domain/CustomField/Ports/CustomFieldServiceInterface.php +++ b/lib/SP/Domain/CustomField/Ports/CustomFieldService.php @@ -37,7 +37,7 @@ use SP\Infrastructure\Common\Repositories\NoSuchItemException; * * @package SP\Domain\CustomField\Services */ -interface CustomFieldServiceInterface +interface CustomFieldService { /** * Desencriptar y formatear los datos del campo diff --git a/lib/SP/Domain/CustomField/Services/CustomFieldService.php b/lib/SP/Domain/CustomField/Services/CustomField.php similarity index 96% rename from lib/SP/Domain/CustomField/Services/CustomFieldService.php rename to lib/SP/Domain/CustomField/Services/CustomField.php index 1ba27902..7db80b57 100644 --- a/lib/SP/Domain/CustomField/Services/CustomFieldService.php +++ b/lib/SP/Domain/CustomField/Services/CustomField.php @@ -30,12 +30,13 @@ use SP\Core\Crypt\Crypt; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\CryptException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Models\CustomFieldData; use SP\Domain\CustomField\Ports\CustomFieldDataRepository; use SP\Domain\CustomField\Ports\CustomFieldDefinitionRepository; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; /** @@ -43,7 +44,7 @@ use SP\Infrastructure\Common\Repositories\NoSuchItemException; * * @package SP\Domain\CustomField\Services */ -final class CustomFieldService extends Service implements CustomFieldServiceInterface +final class CustomField extends Service implements CustomFieldService { public function __construct( @@ -65,8 +66,11 @@ final class CustomFieldService extends Service implements CustomFieldServiceInte /** * Desencriptar y formatear los datos del campo * - * @throws CryptoException + * @param string $data + * @param string $key + * @return string * @throws ServiceException + * @throws CryptException */ public function decryptData(string $data, string $key): string { diff --git a/lib/SP/Domain/CustomField/Services/CustomFieldCryptService.php b/lib/SP/Domain/CustomField/Services/CustomFieldCrypt.php similarity index 53% rename from lib/SP/Domain/CustomField/Services/CustomFieldCryptService.php rename to lib/SP/Domain/CustomField/Services/CustomFieldCrypt.php index 72f9cbf7..9a5b77e2 100644 --- a/lib/SP/Domain/CustomField/Services/CustomFieldCryptService.php +++ b/lib/SP/Domain/CustomField/Services/CustomFieldCrypt.php @@ -24,68 +24,61 @@ namespace SP\Domain\CustomField\Services; -defined('APP_ROOT') || die(); - use Exception; use SP\Core\Application; -use SP\Core\Crypt\Crypt; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Core\Crypt\CryptInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; -use SP\Domain\CustomField\Models\CustomFieldData; -use SP\Domain\CustomField\Ports\CustomFieldCryptServiceInterface; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; +use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; +use SP\Domain\CustomField\Ports\CustomFieldCryptService; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\Task\Services\TaskFactory; +use function SP\__; +use function SP\__u; +use function SP\processException; + /** - * Class CustomFieldCryptService - * - * @package SP\Mgmt\CustomFields + * Class CustomFieldCrypt */ -final class CustomFieldCryptService extends Service implements CustomFieldCryptServiceInterface +final class CustomFieldCrypt extends Service implements CustomFieldCryptService { - private CustomFieldService $customFieldService; - private ?UpdateMasterPassRequest $request = null; - - public function __construct(Application $application, CustomFieldServiceInterface $customFieldService) - { + public function __construct( + Application $application, + private readonly CustomFieldService $customFieldService, + private readonly CryptInterface $crypt + ) { parent::__construct($application); - - $this->customFieldService = $customFieldService; } /** * Actualizar los datos encriptados con una nueva clave * - * @param UpdateMasterPassRequest $request - * * @throws ServiceException */ public function updateMasterPassword(UpdateMasterPassRequest $request): void { try { - $this->request = $request; - $this->processUpdateMasterPassword( - function (CustomFieldData $customFieldData) { - return Crypt::decrypt( + $request, + function (CustomFieldDataModel $customFieldData) use ($request) { + return $this->crypt->decrypt( $customFieldData->getData(), $customFieldData->getKey(), - $this->request->getCurrentMasterPass() + $request->getCurrentMasterPass() ); } ); } catch (Exception $e) { $this->eventDispatcher->notify('exception', new Event($e)); - throw new ServiceException( + throw ServiceException::error( __u('Error while updating the custom fields data'), - SPException::ERROR, null, $e->getCode(), $e @@ -97,17 +90,18 @@ final class CustomFieldCryptService extends Service implements CustomFieldCryptS * @throws ConstraintException * @throws QueryException */ - protected function processUpdateMasterPassword(callable $decryptor): void + private function processUpdateMasterPassword(UpdateMasterPassRequest $request, callable $decryptor): void { - $customFields = $this->customFieldService->getAllEncrypted(); + $customFieldsData = $this->customFieldService->getAllEncrypted(); - if (count($customFields) === 0) { + if (count($customFieldsData) === 0) { $this->eventDispatcher->notify( - 'update.masterPassword.customFields', + 'update.masterPassword.customFieldsData', new Event( - $this, EventMessage::factory() - ->addDescription(__u('Update Master Password')) - ->addDescription(__u('There aren\'t any data from custom fields')) + $this, + EventMessage::factory() + ->addDescription(__u('Update Master Password')) + ->addDescription(__u('There aren\'t any data from custom fields')) ) ); @@ -115,16 +109,17 @@ final class CustomFieldCryptService extends Service implements CustomFieldCryptS } $this->eventDispatcher->notify( - 'update.masterPassword.customFields.start', + 'update.masterPassword.customFieldsData.start', new Event( - $this, EventMessage::factory() - ->addDescription(__u('Update Master Password')) - ->addDescription(__u('Updating encrypted data')) + $this, + EventMessage::factory() + ->addDescription(__u('Update Master Password')) + ->addDescription(__u('Updating encrypted data')) ) ); - if ($this->request->useTask()) { - $task = $this->request->getTask(); + if ($request->useTask()) { + $task = $request->getTask(); TaskFactory::update( $task, @@ -138,32 +133,31 @@ final class CustomFieldCryptService extends Service implements CustomFieldCryptS $errors = []; $success = []; - foreach ($customFields as $customField) { + foreach ($customFieldsData as $customFieldData) { try { - $customField->setData($decryptor($customField)); - $this->customFieldService->updateMasterPass( - $customField, - $this->request->getNewMasterPass() + $customFieldData->mutate(['data' => $decryptor($customFieldData)]), + $request->getNewMasterPass() ); - $success[] = $customField->getId(); + $success[] = $customFieldData->getId(); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); - $errors[] = $customField->getId(); + $errors[] = $customFieldData->getId(); } } $this->eventDispatcher->notify( - 'update.masterPassword.customFields.end', + 'update.masterPassword.customFieldsData.end', new Event( - $this, EventMessage::factory() - ->addDescription(__u('Update Master Password')) - ->addDetail(__u('Records updated'), implode(',', $success)) - ->addDetail(__u('Records not updated'), implode(',', $errors)) + $this, + EventMessage::factory() + ->addDescription(__u('Update Master Password')) + ->addDetail(__u('Records updated'), implode(',', $success)) + ->addDetail(__u('Records not updated'), implode(',', $errors)) ) ); } diff --git a/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php b/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php index fc1472b0..5c7d45d6 100644 --- a/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php +++ b/lib/SP/Domain/CustomField/Services/UpgradeCustomFieldDataService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -31,7 +31,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Common\Services\Service; use SP\Domain\Core\Acl\AclActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Domain\CustomField\Ports\UpgradeCustomFieldDataServiceInterface; use SP\Infrastructure\Database\DatabaseInterface; use SP\Infrastructure\Database\QueryData; @@ -44,13 +44,13 @@ use SP\Infrastructure\Database\QueryData; final class UpgradeCustomFieldDataService extends Service implements UpgradeCustomFieldDataServiceInterface { - private CustomFieldServiceInterface $customFieldService; - private DatabaseInterface $database; + private CustomFieldService $customFieldService; + private DatabaseInterface $database; public function __construct( - Application $application, - CustomFieldServiceInterface $customFieldService, - DatabaseInterface $database + Application $application, + CustomFieldService $customFieldService, + DatabaseInterface $database ) { parent::__construct($application); diff --git a/lib/SP/Mvc/Controller/ItemTrait.php b/lib/SP/Mvc/Controller/ItemTrait.php index 8001cb05..a0526610 100644 --- a/lib/SP/Mvc/Controller/ItemTrait.php +++ b/lib/SP/Mvc/Controller/ItemTrait.php @@ -31,9 +31,9 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\CustomField\Models\CustomFieldData; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Services\CustomField; use SP\Domain\CustomField\Services\CustomFieldItem; -use SP\Domain\CustomField\Services\CustomFieldService; use SP\Domain\Http\RequestInterface; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Util\Filter; @@ -56,7 +56,7 @@ trait ItemTrait protected function getCustomFieldsForItem( int $moduleId, ?int $itemId, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ): array { $customFields = []; @@ -72,7 +72,7 @@ trait ItemTrait $customField->typeName = $item['typeName']; $customField->typeText = $item['typeText']; $customField->moduleId = (int)$item['moduleId']; - $customField->formId = CustomFieldService::getFormIdForName($item['definitionName']); + $customField->formId = CustomField::getFormIdForName($item['definitionName']); $customField->isEncrypted = (int)$item['isEncrypted']; if (!empty($item['data']) && !empty($item['key'])) { @@ -98,7 +98,7 @@ trait ItemTrait * @param int $moduleId * @param int|int[] $itemId * @param RequestInterface $request - * @param CustomFieldServiceInterface $customFieldService + * @param CustomFieldService $customFieldService * * @throws ConstraintException * @throws QueryException @@ -110,7 +110,7 @@ trait ItemTrait int $moduleId, int|array $itemId, RequestInterface $request, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ): void { $customFields = self::getCustomFieldsFromRequest($request); @@ -149,7 +149,7 @@ trait ItemTrait * * @param int $moduleId * @param int|int[] $itemId - * @param CustomFieldServiceInterface $customFieldService + * @param CustomFieldService $customFieldService * * @throws ConstraintException * @throws QueryException @@ -158,7 +158,7 @@ trait ItemTrait protected function deleteCustomFieldsForItem( int $moduleId, array|int $itemId, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ): void { if (is_array($itemId)) { $customFieldService->deleteCustomFieldDataBatch($itemId, $moduleId); @@ -173,7 +173,7 @@ trait ItemTrait * @param int $moduleId * @param int|int[] $itemId * @param RequestInterface $request - * @param CustomFieldServiceInterface $customFieldService + * @param CustomFieldService $customFieldService * * @throws ConstraintException * @throws QueryException @@ -183,7 +183,7 @@ trait ItemTrait int $moduleId, int|array $itemId, RequestInterface $request, - CustomFieldServiceInterface $customFieldService + CustomFieldService $customFieldService ): void { $customFields = self::getCustomFieldsFromRequest($request); diff --git a/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php b/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php index 72a8dc61..96f4eed3 100644 --- a/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php +++ b/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -32,7 +32,7 @@ use SP\Domain\Account\Adapters\AccountAdapter; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\ActionNotFoundException; use SP\Domain\Core\Acl\ActionsInterface; -use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldService; use SP\Mvc\View\Components\SelectItemAdapter; use SPT\Generators\AccountDataGenerator; use SPT\Generators\CustomFieldGenerator; @@ -67,7 +67,7 @@ class AccountAdapterTest extends UnitaryTestCase $adapter = new AccountAdapter( $this->config->getConfigData(), - $this->createStub(CustomFieldServiceInterface::class), + $this->createStub(CustomFieldService::class), $actions ); $accountData = $dataGenerator->buildAccountEnrichedDto(); @@ -130,7 +130,7 @@ class AccountAdapterTest extends UnitaryTestCase public function testIncludeCustomFields(): void { $customFieldData = CustomFieldGenerator::factory()->buildSimpleModel(); - $customFieldsService = $this->createStub(CustomFieldServiceInterface::class); + $customFieldsService = $this->createStub(CustomFieldService::class); $customFieldsService->expects(self::once()) ->method('getForModuleAndItemId') ->willReturn([$customFieldData]); diff --git a/tests/SPT/Domain/Account/Services/AccountCryptTest.php b/tests/SPT/Domain/Account/Services/AccountCryptTest.php index bf5d9f33..8b3d091c 100644 --- a/tests/SPT/Domain/Account/Services/AccountCryptTest.php +++ b/tests/SPT/Domain/Account/Services/AccountCryptTest.php @@ -34,7 +34,7 @@ use SP\Domain\Account\Services\AccountCrypt; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Crypt\CryptInterface; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\Task\Ports\TaskInterface; use SP\Domain\Task\Services\TaskFactory; use SP\Infrastructure\File\FileException; diff --git a/tests/SPT/Domain/Crypt/Services/MasterPassTest.php b/tests/SPT/Domain/Crypt/Services/MasterPassTest.php index 9437af7a..8d219c6d 100644 --- a/tests/SPT/Domain/Crypt/Services/MasterPassTest.php +++ b/tests/SPT/Domain/Crypt/Services/MasterPassTest.php @@ -34,9 +34,9 @@ use SP\Domain\Common\Services\ServiceException; use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; use SP\Domain\Crypt\Services\MasterPass; -use SP\Domain\Crypt\Services\UpdateMasterPassRequest; -use SP\Domain\CustomField\Ports\CustomFieldCryptServiceInterface; +use SP\Domain\CustomField\Ports\CustomFieldCryptService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SPT\UnitaryTestCase; @@ -49,9 +49,9 @@ class MasterPassTest extends UnitaryTestCase { private ConfigService|MockObject $configService; - private AccountCryptService|MockObject $accountCryptService; - private CustomFieldCryptServiceInterface|MockObject $customFieldCryptService; - private MockObject|RepositoryInterface $repository; + private AccountCryptService|MockObject $accountCryptService; + private CustomFieldCryptService|MockObject $customFieldCryptService; + private MockObject|RepositoryInterface $repository; private MasterPass $masterPass; public function testCheckUserUpdateMPassWithFutureTime() @@ -224,7 +224,7 @@ class MasterPassTest extends UnitaryTestCase $this->configService = $this->createMock(ConfigService::class); $this->accountCryptService = $this->createMock(AccountCryptService::class); - $this->customFieldCryptService = $this->createMock(CustomFieldCryptServiceInterface::class); + $this->customFieldCryptService = $this->createMock(CustomFieldCryptService::class); $this->repository = $this->createMock(Repository::class); $this->masterPass = new MasterPass( diff --git a/tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php b/tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php new file mode 100644 index 00000000..d987193e --- /dev/null +++ b/tests/SPT/Domain/CustomField/Services/CustomFieldCryptTest.php @@ -0,0 +1,219 @@ +. + */ + +namespace SPT\Domain\CustomField\Services; + +use PHPUnit\Framework\Constraint\Callback; +use PHPUnit\Framework\MockObject\Exception; +use PHPUnit\Framework\MockObject\MockObject; +use RuntimeException; +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Core\Crypt\CryptInterface; +use SP\Domain\Crypt\Dtos\UpdateMasterPassRequest; +use SP\Domain\CustomField\Models\CustomFieldData as CustomFieldDataModel; +use SP\Domain\CustomField\Ports\CustomFieldService; +use SP\Domain\CustomField\Services\CustomFieldCrypt; +use SP\Domain\Task\Ports\TaskInterface; +use SP\Domain\Task\Services\TaskFactory; +use SP\Infrastructure\File\FileException; +use SPT\Generators\CustomFieldDataGenerator; +use SPT\UnitaryTestCase; + +/** + * Class CustomFieldCryptTest + * + * @group unitary + */ +class CustomFieldCryptTest extends UnitaryTestCase +{ + + private CustomFieldService|MockObject $customFieldService; + private CryptInterface|MockObject $crypt; + private CustomFieldCrypt $customFieldCrypt; + + /** + * @throws ServiceException + */ + public function testUpdateMasterPassword() + { + $hash = self::$faker->sha1; + $request = new UpdateMasterPassRequest('secret', 'test_secret', $hash); + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldService + ->expects(self::once()) + ->method('getAllEncrypted') + ->willReturn([$customFieldData]); + + $data = self::$faker->text(); + + $this->crypt + ->expects(self::once()) + ->method('decrypt') + ->with($customFieldData->getData(), $customFieldData->getKey(), $request->getCurrentMasterPass()) + ->willReturn($data); + + $this->customFieldService + ->expects(self::once()) + ->method('updateMasterPass') + ->with( + new Callback(static function (CustomFieldDataModel $customFieldData) use ($data) { + return $customFieldData->getData() === $data; + }), + $request->getNewMasterPass() + ); + + $this->customFieldCrypt->updateMasterPassword($request); + } + + /** + * @throws ServiceException + */ + public function testUpdateMasterPasswordWithNoData() + { + $hash = self::$faker->sha1; + $request = new UpdateMasterPassRequest('secret', 'test_secret', $hash); + + $this->customFieldService + ->expects(self::once()) + ->method('getAllEncrypted') + ->willReturn([]); + + $data = self::$faker->text(); + + $this->crypt + ->expects(self::never()) + ->method('decrypt'); + + $this->customFieldService + ->expects(self::never()) + ->method('updateMasterPass'); + + $this->customFieldCrypt->updateMasterPassword($request); + } + + /** + * @throws ServiceException + * @throws Exception + * @throws FileException + */ + public function testUpdateMasterPasswordWithTask() + { + $task = $this->createStub(TaskInterface::class); + $task->method('getTaskId')->willReturn(self::$faker->colorName()); + $task->method('getUid')->willReturn(self::$faker->uuid()); + + TaskFactory::register($task); + + $hash = self::$faker->sha1; + $request = new UpdateMasterPassRequest('secret', 'test_secret', $hash, $task); + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldService + ->expects(self::once()) + ->method('getAllEncrypted') + ->willReturn([$customFieldData]); + + $data = self::$faker->text(); + + $this->crypt + ->expects(self::once()) + ->method('decrypt') + ->with($customFieldData->getData(), $customFieldData->getKey(), $request->getCurrentMasterPass()) + ->willReturn($data); + + $this->customFieldService + ->expects(self::once()) + ->method('updateMasterPass') + ->with( + new Callback(static function (CustomFieldDataModel $customFieldData) use ($data) { + return $customFieldData->getData() === $data; + }), + $request->getNewMasterPass() + ); + + $this->customFieldCrypt->updateMasterPassword($request); + } + + /** + * @throws ServiceException + */ + public function testUpdateMasterPasswordWithCryptError() + { + $hash = self::$faker->sha1; + $request = new UpdateMasterPassRequest('secret', 'test_secret', $hash); + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldService + ->expects(self::once()) + ->method('getAllEncrypted') + ->willReturn([$customFieldData]); + + $this->crypt + ->expects(self::once()) + ->method('decrypt') + ->willThrowException(new RuntimeException('test')); + + $this->customFieldService + ->expects(self::never()) + ->method('updateMasterPass'); + + $this->customFieldCrypt->updateMasterPassword($request); + } + + public function testUpdateMasterPasswordWithError() + { + $hash = self::$faker->sha1; + $request = new UpdateMasterPassRequest('secret', 'test_secret', $hash); + $customFieldData = CustomFieldDataGenerator::factory()->buildCustomFieldData(); + + $this->customFieldService + ->expects(self::once()) + ->method('getAllEncrypted') + ->willThrowException(new RuntimeException('test')); + + $this->crypt + ->expects(self::never()) + ->method('decrypt'); + + $this->customFieldService + ->expects(self::never()) + ->method('updateMasterPass'); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('Error while updating the custom fields data'); + + $this->customFieldCrypt->updateMasterPassword($request); + } + + protected function setUp(): void + { + parent::setUp(); + + $this->customFieldService = $this->createMock(CustomFieldService::class); + $this->crypt = $this->createMock(CryptInterface::class); + + $this->customFieldCrypt = new CustomFieldCrypt($this->application, $this->customFieldService, $this->crypt); + } +}