]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Crypt site credential password
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / EntryControllerTest.php
index b77e5ec1c591c96369896d29f234b7b8ac0a7156..803806853883ad6cc00eb979c97b4450cb5a9cf6 100644 (file)
@@ -5,6 +5,7 @@ namespace Tests\Wallabag\CoreBundle\Controller;
 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 use Wallabag\CoreBundle\Entity\Config;
 use Wallabag\CoreBundle\Entity\Entry;
+use Wallabag\CoreBundle\Entity\SiteCredential;
 
 class EntryControllerTest extends WallabagCoreTestCase
 {
@@ -989,8 +990,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertEquals($url, $entry->getUrl());
         $this->assertContains('Perpignan', $entry->getTitle());
         // instead of checking for the filename (which might change) check that the image is now local
-        $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent());
-        $this->assertEquals('fr', $entry->getLanguage());
+        $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent());
 
         $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
     }
@@ -1252,9 +1252,9 @@ class EntryControllerTest extends WallabagCoreTestCase
                 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
                 'ru',
             ],
-            'wrong fr-FR' => [
-                'http://www.zataz.com/fff-darknet/axzz4jUg2QJjH',
-                '',
+            'fr-FR' => [
+                'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
+                'fr_FR',
             ],
             'de' => [
                 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
@@ -1280,10 +1280,14 @@ class EntryControllerTest extends WallabagCoreTestCase
                 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
                 'pt_BR',
             ],
-            'fucked list of languages' => [
+            'fucked_list_of_languages' => [
                 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
                 '',
             ],
+            'es-ES' => [
+                'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google',
+                'es_ES',
+            ],
         ];
     }
 
@@ -1318,4 +1322,56 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertEquals($url, $content->getUrl());
         $this->assertEquals($expectedLanguage, $content->getLanguage());
     }
+
+    /**
+     * This test will require an internet connection.
+     */
+    public function testRestrictedArticle()
+    {
+        $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475';
+        $this->logInAs('admin');
+        $client = $this->getClient();
+        $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+
+        // enable restricted access
+        $client->getContainer()->get('craue_config')->set('restricted_access', 1);
+
+        // create a new site_credential
+        $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
+        $credential = new SiteCredential($user);
+        $credential->setHost('monde-diplomatique.fr');
+        $credential->setUsername('foo');
+        $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
+
+        $em->persist($credential);
+        $em->flush();
+
+        $crawler = $client->request('GET', '/new');
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('form[name=entry]')->form();
+
+        $data = [
+            'entry[url]' => $url,
+        ];
+
+        $client->submit($form, $data);
+
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+        $crawler = $client->followRedirect();
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+        $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
+
+        $content = $em
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId($url, $this->getLoggedInUserId());
+
+        $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
+        $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
+
+        $client->getContainer()->get('craue_config')->set('restricted_access', 0);
+    }
 }