]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
Allow login by email
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / SecurityControllerTest.php
CommitLineData
0d6a7929
NL
1<?php
2
23634d5d 3namespace Tests\Wallabag\CoreBundle\Controller;
0d6a7929 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
0d6a7929
NL
6
7class 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');
16 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]);
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');
4094ea47 26 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]);
0d6a7929
NL
27 }
28
29 public function testLoginWith2Factor()
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');
45 $user->setTwoFactorAuthentication(true);
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');
57 $user->setTwoFactorAuthentication(false);
58 $em->persist($user);
59 $em->flush();
0d6a7929
NL
60 }
61
62 public function testTrustedComputer()
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
JB
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'));
0d6a7929 81 }
8541b3c4
NL
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();
08d6bedc 94 $client->request('GET', '/register');
72e634b0 95 $this->assertContains('registration.submit', $client->getResponse()->getContent());
8541b3c4 96 }
0d6a7929 97}