Skip to content

Commit fe236f1

Browse files
committed
Ignore authorization plugin only if set in config
1 parent d6fa82c commit fe236f1

4 files changed

Lines changed: 52 additions & 10 deletions

File tree

docs/en/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ Configuration
4444
// Allow e.g. http://foo.bar.dev or http://my-shop.local domains locally
4545
Configure::write('DebugKit.safeTld', ['dev', 'local', 'example']);
4646

47-
* ``DebugKit.forceEnable`` - Force DebugKit to display. Careful with this, it is usually
47+
* ``DebugKit.forceEnable`` - Force DebugKit to display. Careful with this, it is usually
4848
safer to simply whitelist your local TLDs. Example usage::
4949

5050
// Before loading DebugKit
5151
Configure::write('DebugKit.forceEnable', true);
5252

53+
* ``DebugKit.ignoreAuthorization`` - Set to true to ignore Cake Authorization plugin for DebugKit requests. Disabled by default.
54+
5355
Database Configuration
5456
----------------------
5557

@@ -77,7 +79,7 @@ connection in your **config/app.php** file. For example::
7779
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
7880
],
7981

80-
You can safely remove the **tmp/debug_kit.sqlite** file at any point.
82+
You can safely remove the **tmp/debug_kit.sqlite** file at any point.
8183
DebugKit will regenerate it when necessary.
8284

8385
Toolbar Usage

docs/fr/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Ensuite, vous devez activer le plugin en exécutant la ligne suivante::
3030

3131
bin/cake plugin load DebugKit
3232

33+
Configuration
34+
=============
35+
36+
* ``DebugKit.ignoreAuthorization`` - Définie à true pour ignorer le plugin Cake Authorization uniquement pour les requêtes DebugKit. Par défaut à false.
37+
3338
Stockage de DebugKit
3439
====================
3540

src/Controller/DebugKitController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Cake\Controller\Controller;
1616
use Cake\Core\Configure;
1717
use Cake\Event\Event;
18+
use Cake\Log\Log;
1819
use Cake\Http\Exception\NotFoundException;
1920

2021
/**
@@ -31,15 +32,23 @@ class DebugKitController extends Controller
3132
*/
3233
public function beforeFilter(Event $event)
3334
{
34-
// TODO add config override.
3535
if (!Configure::read('debug')) {
3636
throw new NotFoundException('Not available without debug mode on.');
3737
}
3838

39-
// Skip authorization for DebuKit requests
39+
// If CakePHP Authorization\Authorization plugin is enabled,
40+
// ignore it, only if `DebugKit.ignoreAuthorization` is set to true
4041
$authorizationService = $this->getRequest()->getAttribute('authorization');
4142
if ($authorizationService instanceof \Authorization\AuthorizationService) {
42-
$authorizationService->skipAuthorization();
43+
if (Configure::read('DebugKit.ignoreAuthorization')) {
44+
$authorizationService->skipAuthorization();
45+
} else {
46+
Log::info(
47+
"Cake Authorization plugin is enabled. If you would like " .
48+
"to force DebugKit to ignore it, set `DebugKit.ignoreAuthorization` " .
49+
" Configure option to true."
50+
);
51+
}
4352
}
4453
}
4554
}

tests/TestCase/Controller/DebugKitControllerTest.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public function testDebugDisabled()
4747
}
4848

4949
/**
50-
* tests authorization is checked to avoid
51-
* AuthorizationRequiredException throwned
50+
* Build controller with AuthorizationService
51+
* in request attribute
5252
*
53-
* @return void
53+
* @return DebugKit\Controller\DebugKitController
5454
*/
55-
public function testSkipAuthorization()
55+
private function _buildController()
5656
{
5757
$request = new ServerRequest(['url' => '/debug-kit/']);
5858

@@ -61,9 +61,35 @@ public function testSkipAuthorization()
6161

6262
$request = $request->withAttribute('authorization', $authorization);
6363

64-
$controller = new DebugKitController($request, new Response());
64+
return new DebugKitController($request, new Response());
65+
}
66+
67+
/**
68+
* tests authorization is enabled but not ignored
69+
*
70+
* @return void
71+
*/
72+
public function testDontIgnoreAuthorization()
73+
{
74+
$controller = $this->_buildController();
6575
$event = new Event('testing');
76+
$controller->beforeFilter($event);
6677

78+
$this->assertFalse($controller->getRequest()->getAttribute('authorization')->authorizationChecked());
79+
}
80+
81+
/**
82+
* tests authorization is checked to avoid
83+
* AuthorizationRequiredException throwned
84+
*
85+
* @return void
86+
*/
87+
public function testIgnoreAuthorization()
88+
{
89+
Configure::write('DebugKit.ignoreAuthorization', true);
90+
91+
$controller = $this->_buildController();
92+
$event = new Event('testing');
6793
$controller->beforeFilter($event);
6894

6995
$this->assertTrue($controller->getRequest()->getAttribute('authorization')->authorizationChecked());

0 commit comments

Comments
 (0)