]> BookStack Code Mirror - bookstack/blobdiff - tests/SecurityHeaderTest.php
ZIP Imports: Added API examples, finished testing
[bookstack] / tests / SecurityHeaderTest.php
index d369e695c516a8fc2d0093b9bbc0afc39f66a650..fe98e32080b9d0f26835cac8ba4acec0ad5371ac 100644 (file)
@@ -17,7 +17,7 @@ class SecurityHeaderTest extends TestCase
 
     public function test_cookies_samesite_none_when_iframe_hosts_set()
     {
-        $this->runWithEnv('ALLOWED_IFRAME_HOSTS', 'http://example.com', function () {
+        $this->runWithEnv(['ALLOWED_IFRAME_HOSTS' => 'http://example.com'], function () {
             $resp = $this->get('/');
             foreach ($resp->headers->getCookies() as $cookie) {
                 $this->assertEquals('none', $cookie->getSameSite());
@@ -27,14 +27,14 @@ class SecurityHeaderTest extends TestCase
 
     public function test_secure_cookies_controlled_by_app_url()
     {
-        $this->runWithEnv('APP_URL', 'http://example.com', function () {
+        $this->runWithEnv(['APP_URL' => 'http://example.com'], function () {
             $resp = $this->get('/');
             foreach ($resp->headers->getCookies() as $cookie) {
                 $this->assertFalse($cookie->isSecure());
             }
         });
 
-        $this->runWithEnv('APP_URL', 'https://example.com', function () {
+        $this->runWithEnv(['APP_URL' => 'https://example.com'], function () {
             $resp = $this->get('/');
             foreach ($resp->headers->getCookies() as $cookie) {
                 $this->assertTrue($cookie->isSecure());
@@ -52,7 +52,7 @@ class SecurityHeaderTest extends TestCase
 
     public function test_iframe_csp_includes_extra_hosts_if_configured()
     {
-        $this->runWithEnv('ALLOWED_IFRAME_HOSTS', 'https://a.example.com https://b.example.com', function () {
+        $this->runWithEnv(['ALLOWED_IFRAME_HOSTS' => 'https://a.example.com https://b.example.com'], function () {
             $resp = $this->get('/');
             $frameHeader = $this->getCspHeader($resp, 'frame-ancestors');
 
@@ -139,6 +139,18 @@ class SecurityHeaderTest extends TestCase
         $this->assertEquals('frame-src \'self\' https://example.com https://diagrams.example.com', $scriptHeader);
     }
 
+    public function test_frame_src_csp_header_drawio_host_includes_port_if_existing()
+    {
+        config()->set([
+            'app.iframe_sources' => 'https://example.com',
+            'services.drawio'    => 'https://diagrams.example.com:8080/testing?cat=dog',
+        ]);
+
+        $resp = $this->get('/');
+        $scriptHeader = $this->getCspHeader($resp, 'frame-src');
+        $this->assertEquals('frame-src \'self\' https://example.com https://diagrams.example.com:8080', $scriptHeader);
+    }
+
     public function test_cache_control_headers_are_set_on_responses()
     {
         // Public access