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