2016-01-28 13:33:02 +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;
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ContentSecurityPolicyTest
|
|
|
|
*
|
|
|
|
* @package OC\AppFramework\Http
|
|
|
|
*/
|
|
|
|
class EmptyContentSecurityPolicyTest extends \Test\TestCase {
|
|
|
|
|
|
|
|
/** @var EmptyContentSecurityPolicy */
|
|
|
|
private $contentSecurityPolicy;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->contentSecurityPolicy = new EmptyContentSecurityPolicy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDefault() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$defaultPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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 www.owncloud.com";
|
2016-01-28 13:33:02 +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 www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowScriptDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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 www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowScriptDomain('www.owncloud.org')->disallowScriptDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyScriptAllowInline() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'unsafe-inline'";
|
2016-01-28 13:33:02 +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 www.owncloud.com 'unsafe-inline'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->allowInlineScript(true);
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyScriptAllowInlineAndEval() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'unsafe-inline' 'unsafe-eval'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->allowInlineScript(true);
|
|
|
|
$this->contentSecurityPolicy->allowEvalScript(true);
|
|
|
|
$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';style-src www.owncloud.com";
|
2016-01-28 13:33:02 +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';style-src www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowStyleDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';style-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowStyleDomain('www.owncloud.org')->disallowStyleDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyStyleAllowInline() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';style-src 'unsafe-inline'";
|
2016-01-28 13:33:02 +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';style-src www.owncloud.com 'unsafe-inline'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedStyleDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->allowInlineStyle(true);
|
|
|
|
$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'";
|
2016-01-28 13:33:02 +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';img-src www.owncloud.com";
|
2016-01-28 13:33:02 +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';img-src www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowImageDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';img-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedImageDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowImageDomain('www.owncloud.org')->disallowImageDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyFontDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';font-src www.owncloud.com";
|
2016-01-28 13:33:02 +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';font-src www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFontDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';font-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFontDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFontDomain('www.owncloud.org')->disallowFontDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyConnectDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';connect-src www.owncloud.com";
|
2016-01-28 13:33:02 +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';connect-src www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowConnectDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';connect-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedConnectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowConnectDomain('www.owncloud.org')->disallowConnectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyMediaDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';media-src www.owncloud.com";
|
2016-01-28 13:33:02 +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';media-src www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowMediaDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';media-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedMediaDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowMediaDomain('www.owncloud.org')->disallowMediaDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyObjectDomainValid() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';object-src www.owncloud.com";
|
2016-01-28 13:33:02 +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';object-src www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowObjectDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';object-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedObjectDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowObjectDomain('www.owncloud.org')->disallowObjectDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAllowedFrameDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';frame-src www.owncloud.com";
|
2016-01-28 13:33:02 +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';frame-src www.owncloud.com www.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowFrameDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';frame-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedFrameDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowFrameDomain('www.owncloud.org')->disallowFrameDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAllowedChildSrcDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';child-src child.owncloud.com";
|
2016-01-28 13:33:02 +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';child-src child.owncloud.com child.owncloud.org";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyDisallowChildSrcDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self'";
|
2016-01-28 13:33:02 +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';child-src www.owncloud.com";
|
2016-01-28 13:33:02 +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'";
|
2016-01-28 13:33:02 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->contentSecurityPolicy->disallowChildSrcDomain('www.owncloud.org')->disallowChildSrcDomain('www.owncloud.com');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
2016-10-24 09:00:00 +00:00
|
|
|
|
|
|
|
public function testGetPolicyWithJsNonceAndScriptDomains() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'nonce-TXlKc05vbmNl' www.nextcloud.com www.nextcloud.org";
|
2016-10-24 09:00:00 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com');
|
|
|
|
$this->contentSecurityPolicy->useJsNonce('MyJsNonce');
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.org');
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyWithJsNonceAndSelfScriptDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'nonce-TXlKc05vbmNl'";
|
2016-10-24 09:00:00 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->useJsNonce('MyJsNonce');
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain("'self'");
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyWithoutJsNonceAndSelfScriptDomain() {
|
2017-03-29 00:44:15 +00:00
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self'";
|
2016-10-24 09:00:00 +00:00
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addAllowedScriptDomain("'self'");
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
2018-10-16 12:04:22 +00:00
|
|
|
|
|
|
|
public function testGetPolicyWithReportUri() {
|
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';report-uri https://my-report-uri.com";
|
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addReportTo("https://my-report-uri.com");
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPolicyWithMultipleReportUri() {
|
|
|
|
$expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';report-uri https://my-report-uri.com https://my-other-report-uri.com";
|
|
|
|
|
|
|
|
$this->contentSecurityPolicy->addReportTo("https://my-report-uri.com");
|
|
|
|
$this->contentSecurityPolicy->addReportTo("https://my-other-report-uri.com");
|
|
|
|
$this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy());
|
|
|
|
}
|
2016-01-28 13:33:02 +00:00
|
|
|
}
|