2121use Cake \Http \CallbackStream ;
2222use Cake \Http \Response ;
2323use Cake \Http \ServerRequest ;
24+ use Cake \Routing \Router ;
2425use Cake \TestSuite \TestCase ;
2526use DebugKit \Middleware \DebugKitMiddleware ;
2627use Psr \Http \Server \RequestHandlerInterface ;
@@ -50,7 +51,7 @@ public function setUp(): void
5051 parent ::setUp ();
5152
5253 $ connection = ConnectionManager::get ('test ' );
53- $ this ->skipIf ($ connection ->getDriver () instanceof Sqlite, 'Schema insertion/removal breaks SQLite ' );
54+ $ this ->skipIf ($ connection ->getDriver () instanceof Sqlite, 'This test fails in CI with sqlite ' );
5455 $ this ->oldConfig = Configure::read ('DebugKit ' );
5556 $ this ->restore = $ GLOBALS ['__PHPUNIT_BOOTSTRAP ' ];
5657 unset($ GLOBALS ['__PHPUNIT_BOOTSTRAP ' ]);
@@ -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 . '" ' .
@@ -132,6 +133,39 @@ public function testInvokeSaveData()
132133 $ this ->assertTextEquals ($ expected , $ body );
133134 }
134135
136+ /**
137+ * Ensure data is saved for HTML requests
138+ *
139+ * @return void
140+ */
141+ public function testInvokeInjectCspNonce ()
142+ {
143+ $ request = new ServerRequest ([
144+ 'url ' => '/articles ' ,
145+ 'environment ' => ['REQUEST_METHOD ' => 'GET ' ],
146+ ]);
147+ $ request = $ request ->withAttribute ('cspScriptNonce ' , 'csp-nonce ' );
148+ Router::setRequest ($ request );
149+
150+ $ response = new Response ([
151+ 'statusCode ' => 200 ,
152+ 'type ' => 'text/html ' ,
153+ 'body ' => '<html><title>test</title><body><p>some text</p></body> ' ,
154+ ]);
155+
156+ $ handler = $ this ->handler ();
157+ $ handler ->expects ($ this ->once ())
158+ ->method ('handle ' )
159+ ->willReturn ($ response );
160+
161+ $ middleware = new DebugKitMiddleware ();
162+ $ response = $ middleware ->process ($ request , $ handler );
163+ $ this ->assertInstanceOf (Response::class, $ response , 'Should return the response ' );
164+
165+ $ body = (string )$ response ->getBody ();
166+ $ this ->assertStringContainsString ('nonce="csp-nonce" ' , $ body );
167+ }
168+
135169 /**
136170 * Ensure that streaming results are tracked, but not modified.
137171 *
0 commit comments