Skip to content

Commit

Permalink
Update RequestListenerTest.php
Browse files Browse the repository at this point in the history
changed tests to reflect removed AuthorizationChecker
  • Loading branch information
cklm committed Oct 22, 2019
1 parent 7afae69 commit 04f96f3
Showing 1 changed file with 8 additions and 75 deletions.
83 changes: 8 additions & 75 deletions test/EventListener/RequestListenerTest.php
Expand Up @@ -16,8 +16,6 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
use Symfony\Component\Security\Core\User\UserInterface;

class RequestListenerTest extends TestCase
Expand Down Expand Up @@ -59,7 +57,6 @@ protected function setUp()
public function testOnKernelRequestUserDataIsSetToScope($user): void
{
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$event = $this->prophesize(GetResponseEvent::class);
$request = $this->prophesize(Request::class);
$token = $this->prophesize(TokenInterface::class);
Expand All @@ -72,8 +69,6 @@ public function testOnKernelRequestUserDataIsSetToScope($user): void

$token->isAuthenticated()
->willReturn(true);
$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
->willReturn(true);

$token->getUser()
->willReturn($user);
Expand Down Expand Up @@ -113,7 +108,6 @@ public function userDataProvider(): \Generator
public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
{
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$event = $this->prophesize(GetResponseEvent::class);

$event->isMasterRequest()
Expand All @@ -126,8 +120,7 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void

$listener = new RequestListener(
$this->currentHub->reveal(),
$tokenStorage->reveal(),
$authorizationChecker->reveal()
$tokenStorage->reveal()
);

$listener->onKernelRequest($event->reveal());
Expand All @@ -138,7 +131,6 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
{
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$event = $this->prophesize(GetResponseEvent::class);

$event->isMasterRequest()
Expand All @@ -151,8 +143,7 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void

$listener = new RequestListener(
$this->currentHub->reveal(),
$tokenStorage->reveal(),
$authorizationChecker->reveal()
$tokenStorage->reveal()
);

$listener->onKernelRequest($event->reveal());
Expand All @@ -162,55 +153,19 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void

public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent(): void
{
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$event = $this->prophesize(GetResponseEvent::class);
$request = $this->prophesize(Request::class);

$event->isMasterRequest()
->willReturn(true);

$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
->shouldNotBeCalled();

$event->getRequest()
->willReturn($request->reveal());
$request->getClientIp()
->willReturn('1.2.3.4');

$listener = new RequestListener(
$this->currentHub->reveal(),
null,
$authorizationChecker->reveal()
);

$listener->onKernelRequest($event->reveal());

$expectedUserData = [
'ip_address' => '1.2.3.4',
];
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
}

public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsent(): void
{
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$event = $this->prophesize(GetResponseEvent::class);
$request = $this->prophesize(Request::class);

$event->isMasterRequest()
->willReturn(true);

$tokenStorage->getToken()
->willReturn($this->prophesize(TokenInterface::class)->reveal());

$event->getRequest()
->willReturn($request->reveal());
$request->getClientIp()
->willReturn('1.2.3.4');

$listener = new RequestListener(
$this->currentHub->reveal(),
$tokenStorage->reveal(),
null
);

Expand All @@ -225,7 +180,6 @@ public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsen
public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
{
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$event = $this->prophesize(GetResponseEvent::class);
$request = $this->prophesize(Request::class);

Expand All @@ -235,18 +189,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
$tokenStorage->getToken()
->willReturn(null);

$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
->shouldNotBeCalled();

$event->getRequest()
->willReturn($request->reveal());
$request->getClientIp()
->willReturn('1.2.3.4');

$listener = new RequestListener(
$this->currentHub->reveal(),
$tokenStorage->reveal(),
$authorizationChecker->reveal()
$tokenStorage->reveal()
);

$listener->onKernelRequest($event->reveal());
Expand All @@ -263,7 +213,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated(): void
{
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$token = $this->prophesize(TokenInterface::class);
$event = $this->prophesize(GetResponseEvent::class);
$request = $this->prophesize(Request::class);
Expand All @@ -277,18 +226,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
$token->isAuthenticated()
->willReturn(false);

$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
->shouldNotBeCalled();

$event->getRequest()
->willReturn($request->reveal());
$request->getClientIp()
->willReturn('1.2.3.4');

$listener = new RequestListener(
$this->currentHub->reveal(),
$tokenStorage->reveal(),
$authorizationChecker->reveal()
$tokenStorage->reveal()
);

$listener->onKernelRequest($event->reveal());
Expand All @@ -302,7 +247,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
{
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$event = $this->prophesize(GetResponseEvent::class);
$request = $this->prophesize(Request::class);

Expand All @@ -312,18 +256,14 @@ public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
$tokenStorage->getToken()
->willReturn(null);

$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
->willReturn(false);

$event->getRequest()
->willReturn($request->reveal());
$request->getClientIp()
->willReturn('1.2.3.4');

$listener = new RequestListener(
$this->currentHub->reveal(),
$tokenStorage->reveal(),
$authorizationChecker->reveal()
$tokenStorage->reveal()
);

$listener->onKernelRequest($event->reveal());
Expand All @@ -347,8 +287,7 @@ public function testOnKernelControllerAddsRouteTag(): void

$listener = new RequestListener(
$this->currentHub->reveal(),
$this->prophesize(TokenStorageInterface::class)->reveal(),
$this->prophesize(AuthorizationCheckerInterface::class)->reveal()
$this->prophesize(TokenStorageInterface::class)->reveal()
);

$listener->onKernelController($event->reveal());
Expand All @@ -371,8 +310,7 @@ public function testOnKernelControllerRouteTagIsNotSetIfRequestDoesNotHaveARoute

$listener = new RequestListener(
$this->currentHub->reveal(),
$this->prophesize(TokenStorageInterface::class)->reveal(),
$this->prophesize(AuthorizationCheckerInterface::class)->reveal()
$this->prophesize(TokenStorageInterface::class)->reveal()
);

$listener->onKernelController($event->reveal());
Expand All @@ -384,7 +322,6 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
->shouldNotBeCalled();

$tokenStorage = $this->prophesize(TokenStorageInterface::class);
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
$event = $this->prophesize(GetResponseEvent::class);

$event->isMasterRequest()
Expand All @@ -393,13 +330,9 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
$tokenStorage->getToken()
->shouldNotBeCalled();

$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
->shouldNotBeCalled();

$listener = new RequestListener(
$this->currentHub->reveal(),
$tokenStorage->reveal(),
$authorizationChecker->reveal()
$tokenStorage->reveal()
);

$listener->onKernelRequest($event->reveal());
Expand Down

0 comments on commit 04f96f3

Please sign in to comment.