diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | 74 |
1 files changed, 41 insertions, 33 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php index b9f5d835..ed292633 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | |||
@@ -12,53 +12,61 @@ class SecurityControllerTest extends WallabagCoreTestCase | |||
12 | $client = $this->getClient(); | 12 | $client = $this->getClient(); |
13 | $client->followRedirects(); | 13 | $client->followRedirects(); |
14 | 14 | ||
15 | $client->request('GET', '/config'); | 15 | $crawler = $client->request('GET', '/config'); |
16 | $this->assertContains('RSS', $client->getResponse()->getContent()); | 16 | $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(array('_text'))[0]); |
17 | } | 17 | } |
18 | 18 | ||
19 | public function testLoginWith2Factor() | 19 | public function testLoginWith2Factor() |
20 | { | 20 | { |
21 | $client = $this->getClient(); | 21 | $client = $this->getClient(); |
22 | 22 | ||
23 | if ($client->getContainer()->getParameter('twofactor_auth')) { | 23 | if (!$client->getContainer()->getParameter('twofactor_auth')) { |
24 | $client->followRedirects(); | 24 | $this->markTestSkipped('twofactor_auth is not enabled.'); |
25 | 25 | ||
26 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 26 | return; |
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 | } | 27 | } |
28 | |||
29 | $client->followRedirects(); | ||
30 | |||
31 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
32 | $user = $em | ||
33 | ->getRepository('WallabagUserBundle:User') | ||
34 | ->findOneByUsername('admin'); | ||
35 | $user->setTwoFactorAuthentication(true); | ||
36 | $em->persist($user); | ||
37 | $em->flush(); | ||
38 | |||
39 | $this->logInAs('admin'); | ||
40 | $crawler = $client->request('GET', '/config'); | ||
41 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(array('_text'))[0]); | ||
42 | |||
43 | // restore user | ||
44 | $user = $em | ||
45 | ->getRepository('WallabagUserBundle:User') | ||
46 | ->findOneByUsername('admin'); | ||
47 | $user->setTwoFactorAuthentication(false); | ||
48 | $em->persist($user); | ||
49 | $em->flush(); | ||
46 | } | 50 | } |
47 | 51 | ||
48 | public function testTrustedComputer() | 52 | public function testTrustedComputer() |
49 | { | 53 | { |
50 | $client = $this->getClient(); | 54 | $client = $this->getClient(); |
51 | 55 | ||
52 | if ($client->getContainer()->getParameter('twofactor_auth')) { | 56 | if (!$client->getContainer()->getParameter('twofactor_auth')) { |
53 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 57 | $this->markTestSkipped('twofactor_auth is not enabled.'); |
54 | $user = $em | ||
55 | ->getRepository('WallabagUserBundle:User') | ||
56 | ->findOneByUsername('admin'); | ||
57 | 58 | ||
58 | $date = new \DateTime(); | 59 | return; |
59 | $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); | ||
60 | $this->assertTrue($user->isTrustedComputer('ABCDEF')); | ||
61 | $this->assertFalse($user->isTrustedComputer('FEDCBA')); | ||
62 | } | 60 | } |
61 | |||
62 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
63 | $user = $em | ||
64 | ->getRepository('WallabagUserBundle:User') | ||
65 | ->findOneByUsername('admin'); | ||
66 | |||
67 | $date = new \DateTime(); | ||
68 | $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); | ||
69 | $this->assertTrue($user->isTrustedComputer('ABCDEF')); | ||
70 | $this->assertFalse($user->isTrustedComputer('FEDCBA')); | ||
63 | } | 71 | } |
64 | } | 72 | } |