]>
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 | ||
0d42217e JB |
15 | $crawler = $client->request('GET', '/config'); |
16 | $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(array('_text'))[0]); | |
0d6a7929 NL |
17 | } |
18 | ||
19 | public function testLoginWith2Factor() | |
20 | { | |
21 | $client = $this->getClient(); | |
0d6a7929 | 22 | |
0d42217e JB |
23 | if (!$client->getContainer()->getParameter('twofactor_auth')) { |
24 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
25 | return; | |
26 | } | |
0d6a7929 | 27 | |
0d42217e | 28 | $client->followRedirects(); |
18cf594f | 29 | |
0d42217e JB |
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(); | |
18cf594f | 37 | |
0d42217e JB |
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(); | |
0d6a7929 NL |
49 | } |
50 | ||
51 | public function testTrustedComputer() | |
52 | { | |
53 | $client = $this->getClient(); | |
18cf594f | 54 | |
0d42217e JB |
55 | if (!$client->getContainer()->getParameter('twofactor_auth')) { |
56 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
57 | return; | |
18cf594f | 58 | } |
0d42217e JB |
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')); | |
0d6a7929 NL |
69 | } |
70 | } |