]>
Commit | Line | Data |
---|---|---|
0d6a7929 NL |
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 | $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 | } |