diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | 64 |
1 files changed, 64 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..b9f5d835 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | |||
@@ -0,0 +1,64 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | ||
6 | |||
7 | class 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 | |||
23 | if ($client->getContainer()->getParameter('twofactor_auth')) { | ||
24 | $client->followRedirects(); | ||
25 | |||
26 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
27 | $user = $em | ||
28 | ->getRepository('WallabagUserBundle:User') | ||
29 | ->findOneByUsername('admin'); | ||
30 | $user->setTwoFactorAuthentication(true); | ||
31 | $em->persist($user); | ||
32 | $em->flush(); | ||
33 | |||
34 | $this->logInAs('admin'); | ||
35 | $client->request('GET', '/config'); | ||
36 | $this->assertContains('trusted computer', $client->getResponse()->getContent()); | ||
37 | |||
38 | // restore user | ||
39 | $user = $em | ||
40 | ->getRepository('WallabagUserBundle:User') | ||
41 | ->findOneByUsername('admin'); | ||
42 | $user->setTwoFactorAuthentication(false); | ||
43 | $em->persist($user); | ||
44 | $em->flush(); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | public function testTrustedComputer() | ||
49 | { | ||
50 | $client = $this->getClient(); | ||
51 | |||
52 | if ($client->getContainer()->getParameter('twofactor_auth')) { | ||
53 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
54 | $user = $em | ||
55 | ->getRepository('WallabagUserBundle:User') | ||
56 | ->findOneByUsername('admin'); | ||
57 | |||
58 | $date = new \DateTime(); | ||
59 | $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); | ||
60 | $this->assertTrue($user->isTrustedComputer('ABCDEF')); | ||
61 | $this->assertFalse($user->isTrustedComputer('FEDCBA')); | ||
62 | } | ||
63 | } | ||
64 | } | ||