Renamed SecureRequestedRightChecker and implemented integration tests for it

This commit is contained in:
Kevin Frantz 2019-02-16 09:19:49 +01:00
parent 8f0b806719
commit 2aebdd603c
10 changed files with 109 additions and 23 deletions

View File

@ -57,3 +57,5 @@ services:
public: true public: true
App\Domain\FormManagement\RequestedActionFormBuilderService: App\Domain\FormManagement\RequestedActionFormBuilderService:
public: true public: true
App\Domain\SecureManagement\SecureRequestedRightCheckerService:
public: true

View File

@ -4,6 +4,9 @@ namespace App\Domain\ActionManagement;
use App\Entity\EntityInterface; use App\Entity\EntityInterface;
/**
* @author kevinfrantz
*/
interface ActionInterface interface ActionInterface
{ {
/** /**

View File

@ -11,7 +11,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface; use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface; use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface; use App\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -29,9 +29,9 @@ final class ActionService implements ActionServiceInterface
private $requestedAction; private $requestedAction;
/** /**
* @var SecureRequestedRightCheckerInterface * @var SecureRequestedRightCheckerServiceInterface
*/ */
private $secureRequestedRightChecker; private $secureRequestedRightCheckerService;
/** /**
* @var LayerRepositoryFactoryServiceInterface * @var LayerRepositoryFactoryServiceInterface
@ -51,10 +51,10 @@ final class ActionService implements ActionServiceInterface
/** /**
* @param RequestedActionInterface $requestedActionService * @param RequestedActionInterface $requestedActionService
*/ */
public function __construct(RequestedActionServiceInterface $requestedActionService, SecureRequestedRightCheckerInterface $secureRequestedRightChecker, RequestStack $requestStack, LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, EntityManagerInterface $entityManager) public function __construct(RequestedActionServiceInterface $requestedActionService, SecureRequestedRightCheckerServiceInterface $secureRequestedRightChecker, RequestStack $requestStack, LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, EntityManagerInterface $entityManager)
{ {
$this->requestedAction = $requestedActionService; $this->requestedAction = $requestedActionService;
$this->secureRequestedRightChecker = $secureRequestedRightChecker; $this->secureRequestedRightCheckerService = $secureRequestedRightChecker;
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
$this->layerRepositoryFactoryService = $layerRepositoryFactoryService; $this->layerRepositoryFactoryService = $layerRepositoryFactoryService;
$this->requestedActionFormBuilderService = $requestedActionFormBuilderService; $this->requestedActionFormBuilderService = $requestedActionFormBuilderService;
@ -78,7 +78,7 @@ final class ActionService implements ActionServiceInterface
*/ */
public function isRequestedActionSecure(): bool public function isRequestedActionSecure(): bool
{ {
return $this->secureRequestedRightChecker->check($this->requestedAction); return $this->secureRequestedRightCheckerService->check($this->requestedAction);
} }
/** /**

View File

@ -9,7 +9,7 @@ use App\Domain\RightManagement\RightTransformerServiceInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
final class SecureRequestedRightChecker implements SecureRequestedRightCheckerInterface final class SecureRequestedRightCheckerService implements SecureRequestedRightCheckerServiceInterface
{ {
/** /**
* @var RightTransformerServiceInterface * @var RightTransformerServiceInterface
@ -27,7 +27,7 @@ final class SecureRequestedRightChecker implements SecureRequestedRightCheckerIn
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @see \App\Domain\SecureManagement\SecureRequestedRightCheckerInterface::check() * @see \App\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface::check()
*/ */
public function check(RequestedRightInterface $requestedRight): bool public function check(RequestedRightInterface $requestedRight): bool
{ {

View File

@ -9,7 +9,7 @@ use App\Domain\RequestManagement\Right\RequestedRightInterface;
* *
* @author kevinfrantz * @author kevinfrantz
*/ */
interface SecureRequestedRightCheckerInterface interface SecureRequestedRightCheckerServiceInterface
{ {
/** /**
* @param RequestedRightInterface $requestedRight * @param RequestedRightInterface $requestedRight

View File

@ -23,7 +23,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityService;
use App\Entity\Source\PureSource; use App\Entity\Source\PureSource;
use App\Attribut\ClassAttributInterface; use App\Attribut\ClassAttributInterface;
use App\Domain\RepositoryManagement\LayerRepositoryFactoryService; use App\Domain\RepositoryManagement\LayerRepositoryFactoryService;
use App\Domain\SecureManagement\SecureRequestedRightChecker; use App\Domain\SecureManagement\SecureRequestedRightCheckerService;
use App\Domain\RightManagement\RightTransformerService; use App\Domain\RightManagement\RightTransformerService;
/** /**
@ -79,7 +79,7 @@ class CreateSourceActionIntegrationTest extends KernelTestCase
$this->requestStack->push($this->request); $this->requestStack->push($this->request);
$layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager); $layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager);
$rightTransformerService = new RightTransformerService(); $rightTransformerService = new RightTransformerService();
$secureRequestedRightChecker = new SecureRequestedRightChecker($rightTransformerService); $secureRequestedRightChecker = new SecureRequestedRightCheckerService($rightTransformerService);
$this->actionService = new ActionService($this->requestedActionService, $secureRequestedRightChecker, $this->requestStack, $layerRepositoryFactoryService, $entityFormBuilderService, $entityManager); $this->actionService = new ActionService($this->requestedActionService, $secureRequestedRightChecker, $this->requestStack, $layerRepositoryFactoryService, $entityFormBuilderService, $entityManager);
$this->createSourceAction = new CreateSourceAction($this->actionService); $this->createSourceAction = new CreateSourceAction($this->actionService);
} }

View File

@ -0,0 +1,81 @@
<?php
namespace tests\Integration\Domain\SecureManagement;
use App\Entity\Source\AbstractSource;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Meta\Right;
use App\Domain\RequestManagement\Right\RequestedRight;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
/**
* @author kevinfrantz
*/
class SecureRequestedRightCheckerServiceIntegrationTest extends KernelTestCase
{
/**
* @var SecureRequestedRightCheckerServiceInterface
*/
private $secureRequestedRightCheckerService;
public function setUp(): void
{
self::bootKernel();
$this->secureRequestedRightCheckerService = self::$container->get(SecureRequestedRightCheckerServiceInterface::class);
}
public function testGranted(): void
{
$reciever = new class() extends AbstractSource {
};
$layer = LayerType::SOURCE;
$crud = CRUDType::READ;
$source = new class() extends AbstractSource {
};
$right = new Right();
$right->setSource($source);
$right->setLayer($layer);
$right->setCrud($crud);
$right->setReciever($reciever);
$source->getLaw()->getRights()->add($right);
$requestedRight = new RequestedRight();
$requestedRight->setCrud($crud);
$requestedRight->setLayer($layer);
$requestedRight->setReciever($reciever);
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('hasId')->willReturn(true);
$requestedEntity->method('getEntity')->willReturn($source);
$requestedRight->setRequestedEntity($requestedEntity);
$result = $this->secureRequestedRightCheckerService->check($requestedRight);
$this->assertTrue($result);
}
public function testNotGranted(): void
{
$reciever = new class() extends AbstractSource {
};
$layer = LayerType::SOURCE;
$crud = CRUDType::READ;
$source = new class() extends AbstractSource {
};
$right = new Right();
$right->setSource($source);
$right->setLayer($layer);
$right->setCrud(CRUDType::CREATE);
$right->setReciever($reciever);
$source->getLaw()->getRights()->add($right);
$requestedRight = new RequestedRight();
$requestedRight->setCrud($crud);
$requestedRight->setLayer($layer);
$requestedRight->setReciever($reciever);
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('hasId')->willReturn(true);
$requestedEntity->method('getEntity')->willReturn($source);
$requestedRight->setRequestedEntity($requestedEntity);
$result = $this->secureRequestedRightCheckerService->check($requestedRight);
$this->assertFalse($result);
}
}

View File

@ -5,7 +5,6 @@ namespace tests\Unit\Domain\ActionManagement;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Domain\ActionManagement\ActionService; use App\Domain\ActionManagement\ActionService;
use App\Domain\RequestManagement\Action\RequestedActionInterface; use App\Domain\RequestManagement\Action\RequestedActionInterface;
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
@ -18,6 +17,7 @@ use App\Entity\EntityInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface; use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface; use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
use App\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -30,9 +30,9 @@ class ActionServiceTest extends TestCase
private $requestedActionService; private $requestedActionService;
/** /**
* @var SecureRequestedRightCheckerInterface|MockObject * @var SecureRequestedRightCheckerServiceInterface
*/ */
private $secureRequestedRightChecker; private $secureRequestedRightCheckerService;
/** /**
* @var RequestedActionFormBuilderServiceInterface|MockObject * @var RequestedActionFormBuilderServiceInterface|MockObject
@ -79,17 +79,17 @@ class ActionServiceTest extends TestCase
$this->requestedActionService = $this->createMock(RequestedActionServiceInterface::class); $this->requestedActionService = $this->createMock(RequestedActionServiceInterface::class);
$this->requestedActionService->method('getRequestedEntity')->willReturn($this->requestedEntity); $this->requestedActionService->method('getRequestedEntity')->willReturn($this->requestedEntity);
$this->secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class); $this->secureRequestedRightCheckerService = $this->createMock(SecureRequestedRightCheckerServiceInterface::class);
$this->requestedActionFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class); $this->requestedActionFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
$this->requestStack = $this->createMock(RequestStack::class); $this->requestStack = $this->createMock(RequestStack::class);
$this->layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class); $this->layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class); $this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->actionService = new ActionService($this->requestedActionService, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->requestedActionFormBuilderService, $this->entityManager); $this->actionService = new ActionService($this->requestedActionService, $this->secureRequestedRightCheckerService, $this->requestStack, $this->layerRepositoryFactoryService, $this->requestedActionFormBuilderService, $this->entityManager);
} }
public function testIsRequestedActionSecure(): void public function testIsRequestedActionSecure(): void
{ {
$this->secureRequestedRightChecker->method('check')->willReturn(true); $this->secureRequestedRightCheckerService->method('check')->willReturn(true);
$this->assertTrue($this->actionService->isRequestedActionSecure()); $this->assertTrue($this->actionService->isRequestedActionSecure());
} }

View File

@ -12,7 +12,7 @@ use App\Entity\Source\PureSourceInterface;
use App\Domain\ActionManagement\ActionService; use App\Domain\ActionManagement\ActionService;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface; use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface; use App\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface; use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
@ -31,7 +31,7 @@ class CreateSourceActionTest extends TestCase
$request->query->set(ClassAttributInterface::CLASS_ATTRIBUT_NAME, PureSource::class); $request->query->set(ClassAttributInterface::CLASS_ATTRIBUT_NAME, PureSource::class);
$request->request->set(SlugAttributInterface::SLUG_ATTRIBUT_NAME, 'randomname'); $request->request->set(SlugAttributInterface::SLUG_ATTRIBUT_NAME, 'randomname');
$requestedActionService = $this->createMock(RequestedActionServiceInterface::class); $requestedActionService = $this->createMock(RequestedActionServiceInterface::class);
$secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class); $secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerServiceInterface::class);
$entityManager = $this->createMock(EntityManagerInterface::class); $entityManager = $this->createMock(EntityManagerInterface::class);
$pureSourceType = $this->createMock(PureSourceTypeInterface::class); $pureSourceType = $this->createMock(PureSourceTypeInterface::class);
$pureSourceType->method('isValid')->willReturn(true); $pureSourceType->method('isValid')->willReturn(true);

View File

@ -9,13 +9,13 @@ use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Meta\Right; use App\Entity\Meta\Right;
use App\Domain\RequestManagement\Right\RequestedRight; use App\Domain\RequestManagement\Right\RequestedRight;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface; use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Domain\SecureManagement\SecureRequestedRightChecker; use App\Domain\SecureManagement\SecureRequestedRightCheckerService;
use App\Domain\RightManagement\RightTransformerService; use App\Domain\RightManagement\RightTransformerService;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
class SecureRequestedRightCheckerTest extends TestCase class SecureRequestedRightCheckerServiceTest extends TestCase
{ {
public function testGranted(): void public function testGranted(): void
{ {
@ -40,7 +40,7 @@ class SecureRequestedRightCheckerTest extends TestCase
$requestedEntity->method('getEntity')->willReturn($source); $requestedEntity->method('getEntity')->willReturn($source);
$requestedRight->setRequestedEntity($requestedEntity); $requestedRight->setRequestedEntity($requestedEntity);
$rightTransformerService = new RightTransformerService(); $rightTransformerService = new RightTransformerService();
$secureEntityChecker = new SecureRequestedRightChecker($rightTransformerService); $secureEntityChecker = new SecureRequestedRightCheckerService($rightTransformerService);
$result = $secureEntityChecker->check($requestedRight); $result = $secureEntityChecker->check($requestedRight);
$this->assertTrue($result); $this->assertTrue($result);
} }
@ -68,7 +68,7 @@ class SecureRequestedRightCheckerTest extends TestCase
$requestedEntity->method('getEntity')->willReturn($source); $requestedEntity->method('getEntity')->willReturn($source);
$requestedRight->setRequestedEntity($requestedEntity); $requestedRight->setRequestedEntity($requestedEntity);
$rightTransformerService = new RightTransformerService(); $rightTransformerService = new RightTransformerService();
$secureEntityChecker = new SecureRequestedRightChecker($rightTransformerService); $secureEntityChecker = new SecureRequestedRightCheckerService($rightTransformerService);
$result = $secureEntityChecker->check($requestedRight); $result = $secureEntityChecker->check($requestedRight);
$this->assertFalse($result); $this->assertFalse($result);
} }