3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
7 class SecurityControllerTest
extends WallabagCoreTestCase
9 public function testLoginWithout2Factor()
11 $this->logInAs('admin');
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 testLoginWith2Factor()
21 $client = $this->getClient();
23 if (!$client->getContainer()->getParameter('twofactor_auth')) {
24 $this->markTestSkipped('twofactor_auth is not enabled.');
29 $client->followRedirects();
31 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
33 ->getRepository('WallabagUserBundle:User')
34 ->findOneByUsername('admin');
35 $user->setTwoFactorAuthentication(true);
39 $this->logInAsUsingHttp('admin');
40 $crawler = $client->request('GET', '/config');
41 $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
45 ->getRepository('WallabagUserBundle:User')
46 ->findOneByUsername('admin');
47 $user->setTwoFactorAuthentication(false);
52 public function testTrustedComputer()
54 $client = $this->getClient();
56 if (!$client->getContainer()->getParameter('twofactor_auth')) {
57 $this->markTestSkipped('twofactor_auth is not enabled.');
62 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
64 ->getRepository('WallabagUserBundle:User')
65 ->findOneByUsername('admin');
67 $date = new \
DateTime();
68 $user->addTrustedComputer('ABCDEF', $date->add(new \
DateInterval('P1M')));
69 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
70 $this->assertFalse($user->isTrustedComputer('FEDCBA'));
73 public function testEnabledRegistration()
75 $client = $this->getClient();
77 if (!$client->getContainer()->getParameter('fosuser_registration')) {
78 $this->markTestSkipped('fosuser_registration is not enabled.');
83 $client->followRedirects();
84 $crawler = $client->request('GET', '/register');
85 $this->assertContains('registration.submit', $client->getResponse()->getContent());