aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests
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 /src/Wallabag/CoreBundle/Tests
parent2db616b586f473238706e554e809086935e0f33a (diff)
downloadwallabag-0d6a7929e17c84052cbb3e494d5e5c195c24ca04.tar.gz
wallabag-0d6a7929e17c84052cbb3e494d5e5c195c24ca04.tar.zst
wallabag-0d6a7929e17c84052cbb3e494d5e5c195c24ca04.zip
add tests for 2factor authentication
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php58
1 files changed, 58 insertions, 0 deletions
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}