3 namespace Wallabag\CoreBundle\Tests\Controller
;
5 use Wallabag\CoreBundle\Tests\WallabagCoreTestCase
;
7 class SecurityControllerTest
extends WallabagCoreTestCase
9 public function testLoginWithout2Factor()
11 $this->logInAs('admin');
12 $client = $this->getClient();
13 $client->followRedirects();
15 $client->request('GET', '/config');
16 $this->assertContains('RSS', $client->getResponse()->getContent());
19 public function testLoginWith2Factor()
21 $client = $this->getClient();
23 if ($client->getContainer()->getParameter('twofactor_auth')) {
24 $client->followRedirects();
26 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
28 ->getRepository('WallabagUserBundle:User')
29 ->findOneByUsername('admin');
30 $user->setTwoFactorAuthentication(true);
34 $this->logInAs('admin');
35 $client->request('GET', '/config');
36 $this->assertContains('trusted computer', $client->getResponse()->getContent());
40 ->getRepository('WallabagUserBundle:User')
41 ->findOneByUsername('admin');
42 $user->setTwoFactorAuthentication(false);
48 public function testTrustedComputer()
50 $client = $this->getClient();
52 if ($client->getContainer()->getParameter('twofactor_auth')) {
53 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
55 ->getRepository('WallabagUserBundle:User')
56 ->findOneByUsername('admin');
58 $date = new \
DateTime();
59 $user->addTrustedComputer('ABCDEF', $date->add(new \
DateInterval('P1M')));
60 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
61 $this->assertFalse($user->isTrustedComputer('FEDCBA'));