Skip to content

Commit 6f959c0

Browse files
committed
Fix mistake
1 parent 1a3f08d commit 6f959c0

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/Middleware/DebugKitMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6969
return $response;
7070
}
7171

72-
return $this->service->injectScripts($row, $request, $response);
72+
return $this->service->injectScripts($row, $response);
7373
}
7474
}

src/ToolbarService.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,9 @@ public function injectScripts($row, ResponseInterface $response)
360360
// Use Router to get the request so that we can see the
361361
// state after other middleware have been applied.
362362
$request = Router::getRequest();
363-
if ($request) {
364-
$nonce = $request->getAttribute('cspScriptNonce');
365-
if ($nonce) {
366-
$nonce = sprintf(' nonce="%s"', $nonce);
367-
}
363+
$nonce = '';
364+
if ($request && $request->getAttribute('cspScriptNonce')) {
365+
$nonce = sprintf(' nonce="%s"', $request->getAttribute('cspScriptNonce'));
368366
}
369367

370368
$url = Router::url('/', true);

tests/TestCase/Middleware/DebugKitMiddlewareTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Cake\Http\CallbackStream;
2222
use Cake\Http\Response;
2323
use Cake\Http\ServerRequest;
24+
use Cake\Routing\Router;
2425
use Cake\TestSuite\TestCase;
2526
use DebugKit\Middleware\DebugKitMiddleware;
2627
use Psr\Http\Server\RequestHandlerInterface;
@@ -122,7 +123,7 @@ public function testInvokeSaveData()
122123
$this->assertNotNull($result->panels[11]->summary);
123124
$this->assertSame('Sql Log', $result->panels[11]->title);
124125

125-
$timeStamp = filemtime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'main.js');
126+
$timeStamp = filemtime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'inject-iframe.js');
126127

127128
$expected = '<html><title>test</title><body><p>some text</p>' .
128129
'<script id="__debug_kit_script" data-id="' . $result->id . '" ' .
@@ -144,6 +145,7 @@ public function testInvokeInjectCspNonce()
144145
'environment' => ['REQUEST_METHOD' => 'GET'],
145146
]);
146147
$request = $request->withAttribute('cspScriptNonce', 'csp-nonce');
148+
Router::setRequest($request);
147149

148150
$response = new Response([
149151
'statusCode' => 200,

tests/TestCase/ToolbarServiceTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ public function testInjectScriptsLastBodyTag()
305305
$bar = new ToolbarService($this->events, []);
306306
$bar->loadPanels();
307307
$row = $bar->saveData($request, $response);
308-
$response = $bar->injectScripts($row, response);
308+
$response = $bar->injectScripts($row, $response);
309309

310-
$timeStamp = filemtime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'main.js');
310+
$timeStamp = filemtime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'inject-iframe.js');
311311

312312
$expected = '<html><title>test</title><body><p>some text</p>' .
313313
'<script id="__debug_kit_script" data-id="' . $row->id . '" ' .
@@ -367,6 +367,10 @@ public function testInjectScriptsStreamBodies()
367367
*/
368368
public function testInjectScriptsNoModifyResponse()
369369
{
370+
$request = new Request([
371+
'url' => '/articles/view/123',
372+
'params' => [],
373+
]);
370374
$response = new Response([
371375
'statusCode' => 200,
372376
'type' => 'application/json',

0 commit comments

Comments
 (0)