]>
Commit | Line | Data |
---|---|---|
0d6a7929 NL |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
0d6a7929 | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
0d6a7929 NL |
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 | 15 | $crawler = $client->request('GET', '/config'); |
4094ea47 | 16 | $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_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.'); | |
b308b263 | 25 | |
0d42217e JB |
26 | return; |
27 | } | |
0d6a7929 | 28 | |
0d42217e | 29 | $client->followRedirects(); |
18cf594f | 30 | |
0d42217e JB |
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(); | |
18cf594f | 38 | |
fdc90ceb | 39 | $this->logInAsUsingHttp('admin'); |
0d42217e | 40 | $crawler = $client->request('GET', '/config'); |
4094ea47 | 41 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); |
0d42217e JB |
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(); | |
0d6a7929 NL |
50 | } |
51 | ||
52 | public function testTrustedComputer() | |
53 | { | |
54 | $client = $this->getClient(); | |
18cf594f | 55 | |
0d42217e JB |
56 | if (!$client->getContainer()->getParameter('twofactor_auth')) { |
57 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
b308b263 | 58 | |
0d42217e | 59 | return; |
18cf594f | 60 | } |
0d42217e JB |
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')); | |
0d6a7929 | 71 | } |
8541b3c4 NL |
72 | |
73 | public function testEnabledRegistration() | |
74 | { | |
75 | $client = $this->getClient(); | |
76 | ||
77 | if (!$client->getContainer()->getParameter('fosuser_registration')) { | |
78 | $this->markTestSkipped('fosuser_registration is not enabled.'); | |
79 | ||
80 | return; | |
81 | } | |
82 | ||
83 | $client->followRedirects(); | |
84 | $crawler = $client->request('GET', '/register'); | |
72e634b0 | 85 | $this->assertContains('registration.submit', $client->getResponse()->getContent()); |
8541b3c4 | 86 | } |
0d6a7929 | 87 | } |