]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
3c3354d7f818e433b10b4e3bb12bd5216bd49e9e
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / SecurityControllerTest.php
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_feed.description', $crawler->filter('body')->extract(['_text'])[0]);
27 }
28
29 public function testLoginWith2FactorEmail()
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->setEmailTwoFactor(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->setEmailTwoFactor(false);
58 $em->persist($user);
59 $em->flush();
60 }
61
62 public function testLoginWith2FactorGoogle()
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 $client->followRedirects();
73
74 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
75 $user = $em
76 ->getRepository('WallabagUserBundle:User')
77 ->findOneByUsername('admin');
78 $user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM');
79 $em->persist($user);
80 $em->flush();
81
82 $this->logInAsUsingHttp('admin');
83 $crawler = $client->request('GET', '/config');
84 $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
85
86 // restore user
87 $user = $em
88 ->getRepository('WallabagUserBundle:User')
89 ->findOneByUsername('admin');
90 $user->setGoogleAuthenticatorSecret(null);
91 $em->persist($user);
92 $em->flush();
93 }
94
95 public function testEnabledRegistration()
96 {
97 $client = $this->getClient();
98
99 if (!$client->getContainer()->getParameter('fosuser_registration')) {
100 $this->markTestSkipped('fosuser_registration is not enabled.');
101
102 return;
103 }
104
105 $client->followRedirects();
106 $client->request('GET', '/register');
107 $this->assertContains('registration.submit', $client->getResponse()->getContent());
108 }
109 }