]>
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 | { | |
08d6bedc FB |
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'); | |
f277bc04 | 16 | $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]); |
08d6bedc FB |
17 | } |
18 | ||
0d6a7929 NL |
19 | public function testLoginWithout2Factor() |
20 | { | |
21 | $this->logInAs('admin'); | |
22 | $client = $this->getClient(); | |
23 | $client->followRedirects(); | |
24 | ||
0d42217e | 25 | $crawler = $client->request('GET', '/config'); |
531c8d0a | 26 | $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]); |
0d6a7929 NL |
27 | } |
28 | ||
a6b242a1 | 29 | public function testLoginWith2FactorEmail() |
0d6a7929 NL |
30 | { |
31 | $client = $this->getClient(); | |
0d6a7929 | 32 | |
0d42217e JB |
33 | if (!$client->getContainer()->getParameter('twofactor_auth')) { |
34 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
b308b263 | 35 | |
0d42217e JB |
36 | return; |
37 | } | |
0d6a7929 | 38 | |
0d42217e | 39 | $client->followRedirects(); |
18cf594f | 40 | |
0d42217e JB |
41 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
42 | $user = $em | |
43 | ->getRepository('WallabagUserBundle:User') | |
44 | ->findOneByUsername('admin'); | |
a6b242a1 | 45 | $user->setEmailTwoFactor(true); |
0d42217e JB |
46 | $em->persist($user); |
47 | $em->flush(); | |
18cf594f | 48 | |
fdc90ceb | 49 | $this->logInAsUsingHttp('admin'); |
0d42217e | 50 | $crawler = $client->request('GET', '/config'); |
4094ea47 | 51 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); |
0d42217e JB |
52 | |
53 | // restore user | |
54 | $user = $em | |
55 | ->getRepository('WallabagUserBundle:User') | |
56 | ->findOneByUsername('admin'); | |
a6b242a1 | 57 | $user->setEmailTwoFactor(false); |
0d42217e JB |
58 | $em->persist($user); |
59 | $em->flush(); | |
0d6a7929 NL |
60 | } |
61 | ||
a6b242a1 | 62 | public function testLoginWith2FactorGoogle() |
0d6a7929 NL |
63 | { |
64 | $client = $this->getClient(); | |
18cf594f | 65 | |
0d42217e JB |
66 | if (!$client->getContainer()->getParameter('twofactor_auth')) { |
67 | $this->markTestSkipped('twofactor_auth is not enabled.'); | |
b308b263 | 68 | |
0d42217e | 69 | return; |
18cf594f | 70 | } |
0d42217e | 71 | |
a6b242a1 JB |
72 | $client->followRedirects(); |
73 | ||
0d42217e JB |
74 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
75 | $user = $em | |
76 | ->getRepository('WallabagUserBundle:User') | |
77 | ->findOneByUsername('admin'); | |
a6b242a1 JB |
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]); | |
0d42217e | 85 | |
a6b242a1 JB |
86 | // restore user |
87 | $user = $em | |
88 | ->getRepository('WallabagUserBundle:User') | |
89 | ->findOneByUsername('admin'); | |
90 | $user->setGoogleAuthenticatorSecret(null); | |
91 | $em->persist($user); | |
92 | $em->flush(); | |
0d6a7929 | 93 | } |
8541b3c4 NL |
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(); | |
08d6bedc | 106 | $client->request('GET', '/register'); |
72e634b0 | 107 | $this->assertContains('registration.submit', $client->getResponse()->getContent()); |
8541b3c4 | 108 | } |
0d6a7929 | 109 | } |