summaryrefslogtreecommitdiffstats
path: root/tests/lib/appframework/http/ResponseTest.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-02-09 16:30:01 +0100
committerLukas Reschke <lukas@owncloud.com>2015-02-16 11:00:41 +0100
commitb20174bdad33f619054db08e320e5e546e2834b1 (patch)
treed23a1cd064027d81ffe81c0c81a1ac943c756be9 /tests/lib/appframework/http/ResponseTest.php
parent786ff6a5a323e2efe54aa6b736c3fbdf12813d79 (diff)
downloadnextcloud-server-b20174bdad33f619054db08e320e5e546e2834b1.tar.gz
nextcloud-server-b20174bdad33f619054db08e320e5e546e2834b1.zip
Allow AppFramework applications to specify a custom CSP header
This change allows AppFramework applications to specify a custom CSP header for example when the default policy is too strict. Furthermore this allows us to partially migrate away from CSS and allowed eval() in our JavaScript components. Legacy ownCloud components will still use the previous policy. Application developers can use this as following in their controllers: ```php $response = new TemplateResponse('activity', 'list', []); $cspHelper = new ContentSecurityPolicyHelper(); $cspHelper->addAllowedScriptDomain('www.owncloud.org'); $response->addHeader('Content-Security-Policy', $cspHelper->getPolicy()); return $response; ``` Fixes https://github.com/owncloud/core/issues/11857 which is a pre-requisite for https://github.com/owncloud/core/issues/13458 and https://github.com/owncloud/core/issues/11925
Diffstat (limited to 'tests/lib/appframework/http/ResponseTest.php')
-rw-r--r--tests/lib/appframework/http/ResponseTest.php29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/lib/appframework/http/ResponseTest.php b/tests/lib/appframework/http/ResponseTest.php
index b4352348bae..77e9441b52c 100644
--- a/tests/lib/appframework/http/ResponseTest.php
+++ b/tests/lib/appframework/http/ResponseTest.php
@@ -49,7 +49,7 @@ class ResponseTest extends \Test\TestCase {
}
- function testSetHeaders(){
+ public function testSetHeaders() {
$expected = array(
'Last-Modified' => 1,
'ETag' => 3,
@@ -58,15 +58,40 @@ class ResponseTest extends \Test\TestCase {
$this->childResponse->setHeaders($expected);
$headers = $this->childResponse->getHeaders();
+ $expected['Content-Security-Policy'] = "default-src 'none';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self';font-src 'self';connect-src 'self';media-src 'self'";
$this->assertEquals($expected, $headers);
}
+ public function testOverwriteCsp() {
+ $expected = [
+ 'Content-Security-Policy' => "default-src 'none';script-src 'self' 'unsafe-inline' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self';font-src 'self';connect-src 'self';media-src 'self'",
+ ];
+ $policy = new Http\ContentSecurityPolicy();
+ $policy->allowInlineScript(true);
+
+ $this->childResponse->setContentSecurityPolicy($policy);
+ $headers = $this->childResponse->getHeaders();
+
+ $this->assertEquals(array_merge($expected, $headers), $headers);
+ }
+
+ public function testGetCsp() {
+ $policy = new Http\ContentSecurityPolicy();
+ $policy->allowInlineScript(true);
+
+ $this->childResponse->setContentSecurityPolicy($policy);
+ $this->assertEquals($policy, $this->childResponse->getContentSecurityPolicy());
+ }
+
+ public function testGetCspEmpty() {
+ $this->assertNull($this->childResponse->getContentSecurityPolicy());
+ }
public function testAddHeaderValueNullDeletesIt(){
$this->childResponse->addHeader('hello', 'world');
$this->childResponse->addHeader('hello', null);
- $this->assertEquals(1, count($this->childResponse->getHeaders()));
+ $this->assertEquals(2, count($this->childResponse->getHeaders()));
}