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 $crawler = $client->request('GET', '/config');
16 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(array('_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.');
28 $client->followRedirects();
30 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
32 ->getRepository('WallabagUserBundle:User')
33 ->findOneByUsername('admin');
34 $user->setTwoFactorAuthentication(true);
38 $this->logInAs('admin');
39 $crawler = $client->request('GET', '/config');
40 $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(array('_text'))[0]);
44 ->getRepository('WallabagUserBundle:User')
45 ->findOneByUsername('admin');
46 $user->setTwoFactorAuthentication(false);
51 public function testTrustedComputer()
53 $client = $this->getClient();
55 if (!$client->getContainer()->getParameter('twofactor_auth')) {
56 $this->markTestSkipped('twofactor_auth is not enabled.');
60 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
62 ->getRepository('WallabagUserBundle:User')
63 ->findOneByUsername('admin');
65 $date = new \
DateTime();
66 $user->addTrustedComputer('ABCDEF', $date->add(new \
DateInterval('P1M')));
67 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
68 $this->assertFalse($user->isTrustedComputer('FEDCBA'));