3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
7 class SecurityControllerTest
extends WallabagCoreTestCase
9 public function testLoginWithEmail()
11 $this->logInAsUsingHttp('bigboss@wallabag.org');
12 $client = $this->getClient();
13 $client->followRedirects();
15 $crawler = $client->request('GET', '/config');
16 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]);
19 public function testLoginWithout2Factor()
21 $this->logInAs('admin');
22 $client = $this->getClient();
23 $client->followRedirects();
25 $crawler = $client->request('GET', '/config');
26 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]);
29 public function testLoginWith2Factor()
31 $client = $this->getClient();
33 if (!$client->getContainer()->getParameter('twofactor_auth')) {
34 $this->markTestSkipped('twofactor_auth is not enabled.');
39 $client->followRedirects();
41 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
43 ->getRepository('WallabagUserBundle:User')
44 ->findOneByUsername('admin');
45 $user->setTwoFactorAuthentication(true);
49 $this->logInAsUsingHttp('admin');
50 $crawler = $client->request('GET', '/config');
51 $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
55 ->getRepository('WallabagUserBundle:User')
56 ->findOneByUsername('admin');
57 $user->setTwoFactorAuthentication(false);
62 public function testTrustedComputer()
64 $client = $this->getClient();
66 if (!$client->getContainer()->getParameter('twofactor_auth')) {
67 $this->markTestSkipped('twofactor_auth is not enabled.');
72 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
74 ->getRepository('WallabagUserBundle:User')
75 ->findOneByUsername('admin');
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'));
83 public function testEnabledRegistration()
85 $client = $this->getClient();
87 if (!$client->getContainer()->getParameter('fosuser_registration')) {
88 $this->markTestSkipped('fosuser_registration is not enabled.');
93 $client->followRedirects();
94 $client->request('GET', '/register');
95 $this->assertContains('registration.submit', $client->getResponse()->getContent());