]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |
6 | ||
7 | class SecurityControllerTest extends WallabagCoreTestCase | |
8 | { | |
9 | public function testLoginWithEmail() | |
10 | { | |
11 | $this->logInAsUsingHttp('bigboss@wallabag.org'); | |
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(['_text'])[0]); | |
17 | } | |
18 | ||
19 | public function testLoginWithout2Factor() | |
20 | { | |
21 | $this->logInAs('admin'); | |
22 | $client = $this->getClient(); | |
23 | $client->followRedirects(); | |
24 | ||
25 | $crawler = $client->request('GET', '/config'); | |
26 | $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); | |
27 | } | |
28 | ||
29 | public function testLoginWith2Factor() | |
30 | { | |
31 | $client = $this->getClient(); | |
32 | ||
33 | if (!$client->getContainer()->getParameter('twofactor_auth')) { | |
34 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
35 | ||
36 | return; | |
37 | } | |
38 | ||
39 | $client->followRedirects(); | |
40 | ||
41 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
42 | $user = $em | |
43 | ->getRepository('WallabagUserBundle:User') | |
44 | ->findOneByUsername('admin'); | |
45 | $user->setTwoFactorAuthentication(true); | |
46 | $em->persist($user); | |
47 | $em->flush(); | |
48 | ||
49 | $this->logInAsUsingHttp('admin'); | |
50 | $crawler = $client->request('GET', '/config'); | |
51 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); | |
52 | ||
53 | // restore user | |
54 | $user = $em | |
55 | ->getRepository('WallabagUserBundle:User') | |
56 | ->findOneByUsername('admin'); | |
57 | $user->setTwoFactorAuthentication(false); | |
58 | $em->persist($user); | |
59 | $em->flush(); | |
60 | } | |
61 | ||
62 | public function testTrustedComputer() | |
63 | { | |
64 | $client = $this->getClient(); | |
65 | ||
66 | if (!$client->getContainer()->getParameter('twofactor_auth')) { | |
67 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
68 | ||
69 | return; | |
70 | } | |
71 | ||
72 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
73 | $user = $em | |
74 | ->getRepository('WallabagUserBundle:User') | |
75 | ->findOneByUsername('admin'); | |
76 | ||
77 | $date = new \DateTime(); | |
78 | $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); | |
79 | $this->assertTrue($user->isTrustedComputer('ABCDEF')); | |
80 | $this->assertFalse($user->isTrustedComputer('FEDCBA')); | |
81 | } | |
82 | ||
83 | public function testEnabledRegistration() | |
84 | { | |
85 | $client = $this->getClient(); | |
86 | ||
87 | if (!$client->getContainer()->getParameter('fosuser_registration')) { | |
88 | $this->markTestSkipped('fosuser_registration is not enabled.'); | |
89 | ||
90 | return; | |
91 | } | |
92 | ||
93 | $client->followRedirects(); | |
94 | $client->request('GET', '/register'); | |
95 | $this->assertContains('registration.submit', $client->getResponse()->getContent()); | |
96 | } | |
97 | } |