]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Disable controller access if feature disabled 3431/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 22 Nov 2017 08:59:11 +0000 (09:59 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 22 Nov 2017 09:00:45 +0000 (10:00 +0100)
If `restricted_access` is disabled, accessing `/site-credentials/` must be disabled.

src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php

index fa2066dccafe8e6de988b64ec5f066962547bf7d..548de74486287c3076311338065cabcd660ede50 100644 (file)
@@ -24,6 +24,8 @@ class SiteCredentialController extends Controller
      */
     public function indexAction()
     {
+        $this->isSiteCredentialsEnabled();
+
         $credentials = $this->get('wallabag_core.site_credential_repository')->findByUser($this->getUser());
 
         return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', [
@@ -43,6 +45,8 @@ class SiteCredentialController extends Controller
      */
     public function newAction(Request $request)
     {
+        $this->isSiteCredentialsEnabled();
+
         $credential = new SiteCredential($this->getUser());
 
         $form = $this->createForm('Wallabag\CoreBundle\Form\Type\SiteCredentialType', $credential);
@@ -83,6 +87,8 @@ class SiteCredentialController extends Controller
      */
     public function editAction(Request $request, SiteCredential $siteCredential)
     {
+        $this->isSiteCredentialsEnabled();
+
         $this->checkUserAction($siteCredential);
 
         $deleteForm = $this->createDeleteForm($siteCredential);
@@ -125,6 +131,8 @@ class SiteCredentialController extends Controller
      */
     public function deleteAction(Request $request, SiteCredential $siteCredential)
     {
+        $this->isSiteCredentialsEnabled();
+
         $this->checkUserAction($siteCredential);
 
         $form = $this->createDeleteForm($siteCredential);
@@ -144,6 +152,16 @@ class SiteCredentialController extends Controller
         return $this->redirectToRoute('site_credentials_index');
     }
 
+    /**
+     * Throw a 404 if the feature is disabled.
+     */
+    private function isSiteCredentialsEnabled()
+    {
+        if (!$this->get('craue_config')->get('restricted_access')) {
+            throw $this->createNotFoundException('Feature "restricted_access" is disabled, controllers too.');
+        }
+    }
+
     /**
      * Creates a form to delete a site credential entity.
      *
index 87ea286712ece3a3631a560e90c81d29ffb256c3..f50744039fa85bb1b476c62abf21ec2dafa9051e 100644 (file)
@@ -8,6 +8,20 @@ use Wallabag\CoreBundle\Entity\SiteCredential;
 
 class SiteCredentialControllerTest extends WallabagCoreTestCase
 {
+    public function testAccessDeniedBecauseFeatureDisabled()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $client->getContainer()->get('craue_config')->set('restricted_access', 0);
+
+        $client->request('GET', '/site-credentials/');
+
+        $this->assertSame(404, $client->getResponse()->getStatusCode());
+
+        $client->getContainer()->get('craue_config')->set('restricted_access', 1);
+    }
+
     public function testListSiteCredential()
     {
         $this->logInAs('admin');