2015-02-09 15:30:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Lukas Reschke lukas@owncloud.com
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-05-18 16:40:34 +00:00
|
|
|
namespace Test\AppFramework\Http;
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ContentSecurityPolicyTest
|
|
|
|
*
|
|
|
|
* @package OC\AppFramework\Http
|
|
|
|
*/
|
|
|
|
class ContentSecurityPolicyTest extends \Test\TestCase {
|
|
|
|
|
|
|
|
/** @var ContentSecurityPolicy */
|
|
|
|
private $contentSecurityPolicy;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->contentSecurityPolicy = new ContentSecurityPolicy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDefault() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$defaultPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
$this->assertSame($defaultPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyScriptDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.owncloud.com 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyScriptDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.owncloud.com www.owncloud.org 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowScriptDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowScriptDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowScriptDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.owncloud.com 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowScriptDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowScriptDomainMultipleStacked() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowScriptDomain('www.owncloud.org')->disallowScriptDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
public function testGetPolicyScriptAllowInline() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-inline' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->allowInlineScript(true);
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyScriptAllowInlineWithDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.owncloud.com 'unsafe-inline' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->allowInlineScript(true);
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyScriptDisallowInlineAndEval() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->allowInlineScript(false);
|
2015-02-16 11:30:21 +00:00
|
|
|
$this->contentSecurityPolicy->allowEvalScript(false);
|
2015-02-09 15:30:01 +00:00
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyStyleDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' www.owncloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyStyleDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' www.owncloud.com www.owncloud.org 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowStyleDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowStyleDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowStyleDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' www.owncloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowStyleDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowStyleDomainMultipleStacked() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowStyleDomain('www.owncloud.org')->disallowStyleDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
public function testGetPolicyStyleAllowInline() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->allowInlineStyle(true);
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyStyleAllowInlineWithDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' www.owncloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyStyleDisallowInline() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->allowInlineStyle(false);
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyImageDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.owncloud.com;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyImageDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.owncloud.com www.owncloud.org;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowImageDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowImageDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowImageDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.owncloud.com;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowImageDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowImageDomainMultipleStakes() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowImageDomain('www.owncloud.org')->disallowImageDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
public function testGetPolicyFontDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' www.owncloud.com;connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyFontDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' www.owncloud.com www.owncloud.org;connect-src 'self';media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowFontDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFontDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFontDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' www.owncloud.com;connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFontDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFontDomainMultipleStakes() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFontDomain('www.owncloud.org')->disallowFontDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
public function testGetPolicyConnectDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self' www.owncloud.com;media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyConnectDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self' www.owncloud.com www.owncloud.org;media-src 'self'";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowConnectDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowConnectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowConnectDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self' www.owncloud.com;media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowConnectDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowConnectDomainMultipleStakes() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowConnectDomain('www.owncloud.org')->disallowConnectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
public function testGetPolicyMediaDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self' www.owncloud.com";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyMediaDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self' www.owncloud.com www.owncloud.org";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowMediaDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowMediaDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowMediaDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self' www.owncloud.com";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowMediaDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowMediaDomainMultipleStakes() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowMediaDomain('www.owncloud.org')->disallowMediaDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
public function testGetPolicyObjectDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';object-src www.owncloud.com";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyObjectDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';object-src www.owncloud.com www.owncloud.org";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowObjectDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowObjectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowObjectDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';object-src www.owncloud.com";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowObjectDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowObjectDomainMultipleStakes() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowObjectDomain('www.owncloud.org')->disallowObjectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-09 15:30:01 +00:00
|
|
|
public function testGetAllowedFrameDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';frame-src www.owncloud.com";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyFrameDomainValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';frame-src www.owncloud.com www.owncloud.org";
|
2015-02-09 15:30:01 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:44:37 +00:00
|
|
|
public function testGetPolicyDisallowFrameDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFrameDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFrameDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';frame-src www.owncloud.com";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFrameDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFrameDomainMultipleStakes() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFrameDomain('www.owncloud.org')->disallowFrameDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
2015-02-26 11:54:15 +00:00
|
|
|
public function testGetAllowedChildSrcDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';child-src child.owncloud.com";
|
2015-02-26 11:54:15 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyChildSrcValidMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';child-src child.owncloud.com child.owncloud.org";
|
2015-02-26 11:54:15 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
2015-05-20 09:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowChildSrcDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowChildSrcDomainMultiple() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';child-src www.owncloud.com";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowChildSrcDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowChildSrcDomainMultipleStakes() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
2015-05-20 09:44:37 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowChildSrcDomain('www.owncloud.org')->disallowChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
2015-02-26 11:54:15 +00:00
|
|
|
}
|
2017-06-19 11:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetAllowedFrameAncestorDomain() {
|
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';frame-ancestors sub.nextcloud.com";
|
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameAncestorDomain('sub.nextcloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyFrameAncestorValidMultiple() {
|
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';frame-ancestors sub.nextcloud.com foo.nextcloud.com";
|
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameAncestorDomain('sub.nextcloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameAncestorDomain('foo.nextcloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFrameAncestorDomain() {
|
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameAncestorDomain('www.nextcloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFrameAncestorDomain('www.nextcloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFrameAncestorDomainMultiple() {
|
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self';frame-ancestors www.nextcloud.com";
|
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameAncestorDomain('www.nextcloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFrameAncestorDomain('www.nextcloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFrameAncestorDomainMultipleStakes() {
|
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'";
|
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowChildSrcDomain('www.owncloud.org')->disallowChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
2015-02-09 15:30:01 +00:00
|
|
|
}
|