chore(tests): UT for CustomFieldCrypt service

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2024-01-22 08:48:36 +01:00
parent 3fd00722c3
commit bf9ba8dc2d
40 changed files with 458 additions and 249 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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,

View File

@@ -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,

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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
) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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
*/

View File

@@ -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);
}

View File

@@ -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),

View File

@@ -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;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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
*/

View File

@@ -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

View File

@@ -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
{

View File

@@ -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))
)
);
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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]);

View File

@@ -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;

View File

@@ -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(

View File

@@ -0,0 +1,219 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
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);
}
}