From f81a34e37929a822755d120215d2f18f042ff713 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Jun 2017 09:45:43 +0200 Subject: Use a listener to catch auth failure --- .../AuthenticationFailureListenerTest.php | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php (limited to 'tests/Wallabag/UserBundle/EventListener') diff --git a/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php b/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php new file mode 100644 index 00000000..6191ea13 --- /dev/null +++ b/tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php @@ -0,0 +1,66 @@ +request->set('_username', 'admin'); + + $this->requestStack = new RequestStack(); + $this->requestStack->push($request); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + + $this->listener = new AuthenticationFailureListener( + $this->requestStack, + $logger + ); + + $this->dispatcher = new EventDispatcher(); + $this->dispatcher->addSubscriber($this->listener); + } + + public function testOnAuthenticationFailure() + { + $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') + ->disableOriginalConstructor() + ->getMock(); + + $exception = $this->getMockBuilder('Symfony\Component\Security\Core\Exception\AuthenticationException') + ->disableOriginalConstructor() + ->getMock(); + + $event = new AuthenticationFailureEvent( + $token, + $exception + ); + + $this->dispatcher->dispatch( + AuthenticationEvents::AUTHENTICATION_FAILURE, + $event + ); + + $records = $this->logHandler->getRecords(); + + $this->assertCount(1, $records); + $this->assertSame('Authentication failure for user "admin", from IP "127.0.0.1", with UA: "Symfony/3.X".', $records[0]['message']); + } +} -- cgit v1.2.3