aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/UserBundle
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-06-09 11:05:34 +0200
committerGitHub <noreply@github.com>2017-06-09 11:05:34 +0200
commit5c762616c378d20b96eda0f0727eb4c760d4119d (patch)
tree086049b73cf8d547f18c28963a60f36c5679cfcc /tests/Wallabag/UserBundle
parent3f474025d889c3eff20b481f005f4d292f1ef29d (diff)
parentf81a34e37929a822755d120215d2f18f042ff713 (diff)
downloadwallabag-5c762616c378d20b96eda0f0727eb4c760d4119d.tar.gz
wallabag-5c762616c378d20b96eda0f0727eb4c760d4119d.tar.zst
wallabag-5c762616c378d20b96eda0f0727eb4c760d4119d.zip
Merge pull request #3195 from wallabag/authentication-error
Log an error level message when user auth fail
Diffstat (limited to 'tests/Wallabag/UserBundle')
-rw-r--r--tests/Wallabag/UserBundle/EventListener/AuthenticationFailureListenerTest.php66
1 files changed, 66 insertions, 0 deletions
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 @@
1<?php
2
3namespace Tests\Wallabag\UserBundle\EventListener;
4
5use Symfony\Component\EventDispatcher\EventDispatcher;
6use Symfony\Component\HttpFoundation\Request;
7use Wallabag\UserBundle\EventListener\AuthenticationFailureListener;
8use Monolog\Logger;
9use Monolog\Handler\TestHandler;
10use Symfony\Component\HttpFoundation\RequestStack;
11use Symfony\Component\Security\Core\AuthenticationEvents;
12use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
13
14class AuthenticationFailureListenerTest extends \PHPUnit_Framework_TestCase
15{
16 private $requestStack;
17 private $logHandler;
18 private $listener;
19 private $dispatcher;
20
21 protected function setUp()
22 {
23 $request = Request::create('/');
24 $request->request->set('_username', 'admin');
25
26 $this->requestStack = new RequestStack();
27 $this->requestStack->push($request);
28
29 $this->logHandler = new TestHandler();
30 $logger = new Logger('test', [$this->logHandler]);
31
32 $this->listener = new AuthenticationFailureListener(
33 $this->requestStack,
34 $logger
35 );
36
37 $this->dispatcher = new EventDispatcher();
38 $this->dispatcher->addSubscriber($this->listener);
39 }
40
41 public function testOnAuthenticationFailure()
42 {
43 $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
44 ->disableOriginalConstructor()
45 ->getMock();
46
47 $exception = $this->getMockBuilder('Symfony\Component\Security\Core\Exception\AuthenticationException')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $event = new AuthenticationFailureEvent(
52 $token,
53 $exception
54 );
55
56 $this->dispatcher->dispatch(
57 AuthenticationEvents::AUTHENTICATION_FAILURE,
58 $event
59 );
60
61 $records = $this->logHandler->getRecords();
62
63 $this->assertCount(1, $records);
64 $this->assertSame('Authentication failure for user "admin", from IP "127.0.0.1", with UA: "Symfony/3.X".', $records[0]['message']);
65 }
66}