]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
Fix tests
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / SecurityControllerTest.php
index f503ff4bd8daff2bd2d64209d643d2d0e231d410..6b51f403521fca078d303591667ef59743d7f0a9 100644 (file)
@@ -6,6 +6,16 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 
 class SecurityControllerTest extends WallabagCoreTestCase
 {
+    public function testLoginWithEmail()
+    {
+        $this->logInAsUsingHttp('bigboss@wallabag.org');
+        $client = $this->getClient();
+        $client->followRedirects();
+
+        $crawler = $client->request('GET', '/config');
+        $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]);
+    }
+
     public function testLoginWithout2Factor()
     {
         $this->logInAs('admin');
@@ -13,10 +23,10 @@ class SecurityControllerTest extends WallabagCoreTestCase
         $client->followRedirects();
 
         $crawler = $client->request('GET', '/config');
-        $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]);
+        $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]);
     }
 
-    public function testLoginWith2Factor()
+    public function testLoginWith2FactorEmail()
     {
         $client = $this->getClient();
 
@@ -32,24 +42,24 @@ class SecurityControllerTest extends WallabagCoreTestCase
         $user = $em
             ->getRepository('WallabagUserBundle:User')
             ->findOneByUsername('admin');
-        $user->setTwoFactorAuthentication(true);
+        $user->setEmailTwoFactor(true);
         $em->persist($user);
         $em->flush();
 
-        $this->logInAs('admin');
+        $this->logInAsUsingHttp('admin');
         $crawler = $client->request('GET', '/config');
-        $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
+        $this->assertContains('trusted', $crawler->filter('body')->extract(['_text'])[0]);
 
         // restore user
         $user = $em
             ->getRepository('WallabagUserBundle:User')
             ->findOneByUsername('admin');
-        $user->setTwoFactorAuthentication(false);
+        $user->setEmailTwoFactor(false);
         $em->persist($user);
         $em->flush();
     }
 
-    public function testTrustedComputer()
+    public function testLoginWith2FactorGoogle()
     {
         $client = $this->getClient();
 
@@ -59,14 +69,41 @@ class SecurityControllerTest extends WallabagCoreTestCase
             return;
         }
 
+        $client->followRedirects();
+
         $em = $client->getContainer()->get('doctrine.orm.entity_manager');
         $user = $em
             ->getRepository('WallabagUserBundle:User')
             ->findOneByUsername('admin');
+        $user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM');
+        $em->persist($user);
+        $em->flush();
+
+        $this->logInAsUsingHttp('admin');
+        $crawler = $client->request('GET', '/config');
+        $this->assertContains('trusted', $crawler->filter('body')->extract(['_text'])[0]);
+
+        // restore user
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('admin');
+        $user->setGoogleAuthenticatorSecret(null);
+        $em->persist($user);
+        $em->flush();
+    }
 
-        $date = new \DateTime();
-        $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M')));
-        $this->assertTrue($user->isTrustedComputer('ABCDEF'));
-        $this->assertFalse($user->isTrustedComputer('FEDCBA'));
+    public function testEnabledRegistration()
+    {
+        $client = $this->getClient();
+
+        if (!$client->getContainer()->getParameter('fosuser_registration')) {
+            $this->markTestSkipped('fosuser_registration is not enabled.');
+
+            return;
+        }
+
+        $client->followRedirects();
+        $client->request('GET', '/register');
+        $this->assertContains('registration.submit', $client->getResponse()->getContent());
     }
 }