aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-10-14 17:10:12 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-10-14 17:10:12 +0200
commit0d6a7929e17c84052cbb3e494d5e5c195c24ca04 (patch)
treee14295a1adbedf7381cd7d66310fa96bfbeffcf3
parent2db616b586f473238706e554e809086935e0f33a (diff)
downloadwallabag-0d6a7929e17c84052cbb3e494d5e5c195c24ca04.tar.gz
wallabag-0d6a7929e17c84052cbb3e494d5e5c195c24ca04.tar.zst
wallabag-0d6a7929e17c84052cbb3e494d5e5c195c24ca04.zip
add tests for 2factor authentication
-rw-r--r--app/config/config.yml3
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php58
-rw-r--r--src/Wallabag/UserBundle/Resources/config/services.yml19
3 files changed, 59 insertions, 21 deletions
diff --git a/app/config/config.yml b/app/config/config.yml
index b2699c83..4a2c02bf 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -173,11 +173,10 @@ fos_oauth_server:
173 user_provider: fos_user.user_manager 173 user_provider: fos_user.user_manager
174 174
175scheb_two_factor: 175scheb_two_factor:
176
177 trusted_computer: 176 trusted_computer:
178 enabled: true 177 enabled: true
179 cookie_name: wllbg_trusted_computer 178 cookie_name: wllbg_trusted_computer
180 cookie_lifetime: 5184000 179 cookie_lifetime: 2592000
181 180
182 email: 181 email:
183 enabled: true 182 enabled: true
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php
new file mode 100644
index 00000000..3402b340
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php
@@ -0,0 +1,58 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6
7class SecurityControllerTest extends WallabagCoreTestCase
8{
9 public function testLoginWithout2Factor()
10 {
11 $this->logInAs('admin');
12 $client = $this->getClient();
13 $client->followRedirects();
14
15 $client->request('GET', '/config');
16 $this->assertContains('RSS', $client->getResponse()->getContent());
17 }
18
19 public function testLoginWith2Factor()
20 {
21 $client = $this->getClient();
22 $client->followRedirects();
23
24 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
25 $user = $em
26 ->getRepository('WallabagUserBundle:User')
27 ->findOneByUsername('admin');
28 $user->setTwoFactorAuthentication(true);
29 $em->persist($user);
30 $em->flush();
31
32 $this->logInAs('admin');
33 $client->request('GET', '/config');
34 $this->assertContains('trusted computer', $client->getResponse()->getContent());
35
36 // restore user
37 $user = $em
38 ->getRepository('WallabagUserBundle:User')
39 ->findOneByUsername('admin');
40 $user->setTwoFactorAuthentication(false);
41 $em->persist($user);
42 $em->flush();
43 }
44
45 public function testTrustedComputer()
46 {
47 $client = $this->getClient();
48 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
49 $user = $em
50 ->getRepository('WallabagUserBundle:User')
51 ->findOneByUsername('admin');
52
53 $date = new \DateTime();
54 $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M')));
55 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
56 $this->assertFalse($user->isTrustedComputer('FEDCBA'));
57 }
58}
diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml
index 9cdd247d..e69de29b 100644
--- a/src/Wallabag/UserBundle/Resources/config/services.yml
+++ b/src/Wallabag/UserBundle/Resources/config/services.yml
@@ -1,19 +0,0 @@
1parameters:
2 wallabag_user.twofactor.email.provider.class: Wallabag\UserBundle\Security\TwoFactor\Email\Helper
3 wallabag_user.twofactor.email.interactive_login_listener.class: Wallabag\UserBundle\Security\TwoFactor\Email\InteractiveLoginListener
4 wallabag_user.twofactor.email.request_listener.class: Wallabag\UserBundle\Security\TwoFactor\Email\RequestListener
5
6services:
7 wallabag_user.twofactor.email.provider:
8 class: %wallabag_user.twofactor.email.provider.class%
9 arguments: ['@doctrine.orm.entity_manager', '@mailer']
10 wallabag_user.twofactor.email.interactive_login_listener:
11 class: %wallabag_user.twofactor.email.interactive_login_listener.class%
12 tags:
13 - { name: kernel.event_listener, event: security.interactive_login, method: onSecurityInteractiveLogin }
14 arguments: ['@wallabag_user.twofactor.email.provider']
15 wallabag_user.twofactor.email.request_listener:
16 class: %wallabag_user.twofactor.email.request_listener.class%
17 tags:
18 - { name: kernel.event_listener, event: kernel.request, method: onCoreRequest, priority: -1 }
19 arguments: ['@wallabag_user.twofactor.email.provider', '@security.context', '@templating', '@router']