aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Security
diff options
context:
space:
mode:
authorSam Bull <aa6bs0@sambull.org>2019-07-08 20:54:45 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2019-07-18 12:16:29 +0200
commitea935f65fdc94b94b4509a139477b52f046dc03f (patch)
treec50f8360389cec594044ee35798da2534bd6a9a6 /tests/lib/Security
parent3d0e0f23530160419f182ac9e896dea6f7bc9f59 (diff)
downloadnextcloud-server-ea935f65fdc94b94b4509a139477b52f046dc03f.tar.gz
nextcloud-server-ea935f65fdc94b94b4509a139477b52f046dc03f.zip
Add support for CSP_NONCE server variable
Allow passing a nonce from the web server, allowing the possibility to enforce a strict CSP from the web server. Signed-off-by: Sam Bull <git@sambull.org> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/Security')
-rw-r--r--tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php23
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php
index 3211a5284f8..705a0b22db8 100644
--- a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php
+++ b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php
@@ -21,23 +21,26 @@
namespace Test\Security\CSP;
+use OC\AppFramework\Http\Request;
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
use OC\Security\CSRF\CsrfToken;
use OC\Security\CSRF\CsrfTokenManager;
-use OCP\IRequest;
use Test\TestCase;
class ContentSecurityPolicyNonceManagerTest extends TestCase {
/** @var CsrfTokenManager */
private $csrfTokenManager;
+ /** @var Request */
+ private $request;
/** @var ContentSecurityPolicyNonceManager */
private $nonceManager;
public function setUp() {
$this->csrfTokenManager = $this->createMock(CsrfTokenManager::class);
+ $this->request = $this->createMock(Request::class);
$this->nonceManager = new ContentSecurityPolicyNonceManager(
$this->csrfTokenManager,
- $this->createMock(IRequest::class)
+ $this->request
);
}
@@ -56,4 +59,20 @@ class ContentSecurityPolicyNonceManagerTest extends TestCase {
$this->assertSame('TXlUb2tlbg==', $this->nonceManager->getNonce());
$this->assertSame('TXlUb2tlbg==', $this->nonceManager->getNonce());
}
+
+ public function testGetNonceServerVar() {
+ $token = 'SERVERNONCE';
+ $this->request
+ ->method('__isset')
+ ->with('server')
+ ->willReturn(true);
+
+ $this->request
+ ->method('__get')
+ ->with('server')
+ ->willReturn(['CSP_NONCE' => $token]);
+
+ $this->assertSame($token, $this->nonceManager->getNonce());
+ $this->assertSame($token, $this->nonceManager->getNonce());
+ }
}