]>
Commit | Line | Data |
---|---|---|
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 | $crawler = $client->request('GET', '/config'); | |
16 | $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(array('_text'))[0]); | |
17 | } | |
18 | ||
19 | public function testLoginWith2Factor() | |
20 | { | |
21 | $client = $this->getClient(); | |
22 | ||
23 | if (!$client->getContainer()->getParameter('twofactor_auth')) { | |
24 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
25 | return; | |
26 | } | |
27 | ||
28 | $client->followRedirects(); | |
29 | ||
30 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
31 | $user = $em | |
32 | ->getRepository('WallabagUserBundle:User') | |
33 | ->findOneByUsername('admin'); | |
34 | $user->setTwoFactorAuthentication(true); | |
35 | $em->persist($user); | |
36 | $em->flush(); | |
37 | ||
38 | $this->logInAs('admin'); | |
39 | $crawler = $client->request('GET', '/config'); | |
40 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(array('_text'))[0]); | |
41 | ||
42 | // restore user | |
43 | $user = $em | |
44 | ->getRepository('WallabagUserBundle:User') | |
45 | ->findOneByUsername('admin'); | |
46 | $user->setTwoFactorAuthentication(false); | |
47 | $em->persist($user); | |
48 | $em->flush(); | |
49 | } | |
50 | ||
51 | public function testTrustedComputer() | |
52 | { | |
53 | $client = $this->getClient(); | |
54 | ||
55 | if (!$client->getContainer()->getParameter('twofactor_auth')) { | |
56 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
57 | return; | |
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')); | |
69 | } | |
70 | } |