]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
Added a button to disable 2FA when enabled
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / ConfigControllerTest.php
index d8478ce3e13ea17ef27fb8fe9ea955df48893e81..b3b3a19a74a8c43c427d3896c51ec9d7d791717c 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Tests\Wallabag\CoreBundle\Controller;
 
+use Symfony\Component\HttpFoundation\File\UploadedFile;
 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 use Wallabag\AnnotationBundle\Entity\Annotation;
 use Wallabag\CoreBundle\Entity\Config;
@@ -50,7 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $data = [
             'config[theme]' => 'baggy',
             'config[items_per_page]' => '30',
-            'config[reading_speed]' => '0.5',
+            'config[reading_speed]' => '100',
             'config[action_mark_as_read]' => '0',
             'config[language]' => 'en',
         ];
@@ -91,7 +92,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $crawler = $client->request('GET', '/config');
         $form = $crawler->filter('button[id=config_save]')->form();
         $data = [
-            'config[reading_speed]' => '2',
+            'config[reading_speed]' => '400',
         ];
         $client->submit($form, $data);
 
@@ -105,7 +106,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $crawler = $client->request('GET', '/config');
         $form = $crawler->filter('button[id=config_save]')->form();
         $data = [
-            'config[reading_speed]' => '0.5',
+            'config[reading_speed]' => '100',
         ];
         $client->submit($form, $data);
     }
@@ -330,7 +331,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $crawler = $client->followRedirect();
 
         $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
-        $this->assertNotContains('config.form_feed.no_token', $body[0]);
+        $this->assertContains('config.form_feed.token_reset', $body[0]);
     }
 
     public function testGenerateTokenAjax()
@@ -351,6 +352,22 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $this->assertArrayHasKey('token', $content);
     }
 
+    public function testRevokeTokenAjax()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $client->request(
+            'GET',
+            '/revoke-token',
+            [],
+            [],
+            ['HTTP_X-Requested-With' => 'XMLHttpRequest']
+        );
+
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
+    }
+
     public function testFeedUpdate()
     {
         $this->logInAs('admin');
@@ -678,7 +695,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
 
         $config->setTheme('material');
         $config->setItemsPerPage(30);
-        $config->setReadingSpeed(1);
+        $config->setReadingSpeed(200);
         $config->setLanguage('en');
         $config->setPocketConsumerKey('xxxxx');
 
@@ -1028,6 +1045,29 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $em->flush();
     }
 
+    public function testUserDisable2faEmail()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config/otp/email/disable');
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $crawler = $client->followRedirect();
+
+        $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
+        $this->assertContains('flashes.config.notice.otp_disabled', $alert[0]);
+
+        // restore user
+        $em = $this->getEntityManager();
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('admin');
+
+        $this->assertFalse($user->isEmailTwoFactor());
+    }
+
     public function testUserEnable2faGoogle()
     {
         $this->logInAs('admin');
@@ -1081,4 +1121,91 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $this->assertFalse($user->isGoogleTwoFactor());
         $this->assertEmpty($user->getBackupCodes());
     }
+
+    public function testUserDisable2faGoogle()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config/otp/app/disable');
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $crawler = $client->followRedirect();
+
+        $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
+        $this->assertContains('flashes.config.notice.otp_disabled', $alert[0]);
+
+        // restore user
+        $em = $this->getEntityManager();
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('admin');
+
+        $this->assertEmpty($user->getGoogleAuthenticatorSecret());
+        $this->assertEmpty($user->getBackupCodes());
+    }
+
+    public function testExportTaggingRule()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        ob_start();
+        $crawler = $client->request('GET', '/tagging-rule/export');
+        ob_end_clean();
+
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+        $headers = $client->getResponse()->headers;
+        $this->assertSame('application/json', $headers->get('content-type'));
+        $this->assertSame('attachment; filename="tagging_rules_admin.json"', $headers->get('content-disposition'));
+        $this->assertSame('UTF-8', $headers->get('content-transfer-encoding'));
+
+        $content = json_decode($client->getResponse()->getContent(), true);
+
+        $this->assertCount(4, $content);
+        $this->assertSame('content matches "spurs"', $content[0]['rule']);
+        $this->assertSame('sport', $content[0]['tags'][0]);
+    }
+
+    public function testImportTagginfRuleBadFile()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config');
+        $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form();
+
+        $data = [
+            'upload_tagging_rule_file[file]' => '',
+        ];
+
+        $client->submit($form, $data);
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+    }
+
+    public function testImportTagginfRuleFile()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config');
+        $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form();
+
+        $file = new UploadedFile(__DIR__ . '/../fixtures/tagging_rules_admin.json', 'tagging_rules_admin.json');
+
+        $data = [
+            'upload_tagging_rule_file[file]' => $file,
+        ];
+
+        $client->submit($form, $data);
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $user = $client->getContainer()->get('fos_user.user_manager.test')->findUserBy(['username' => 'admin']);
+        $taggingRules = $user->getConfig()->getTaggingRules()->toArray();
+        $this->assertCount(5, $taggingRules);
+        $this->assertSame('title matches "football"', $taggingRules[4]->getRule());
+    }
 }