aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php')
-rw-r--r--tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php27
1 files changed, 16 insertions, 11 deletions
diff --git a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php
index f4281bd2b22..3765311155a 100644
--- a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php
+++ b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php
@@ -13,42 +13,46 @@ use OC\AppFramework\Http\Request;
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
use OC\Security\CSRF\CsrfToken;
use OC\Security\CSRF\CsrfTokenManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ContentSecurityPolicyNonceManagerTest extends TestCase {
- /** @var CsrfTokenManager */
- private $csrfTokenManager;
- /** @var Request */
+ /** @var CsrfTokenManager&MockObject */
+ private $CSRFTokenManager;
+ /** @var Request&MockObject */
private $request;
/** @var ContentSecurityPolicyNonceManager */
private $nonceManager;
protected function setUp(): void {
- $this->csrfTokenManager = $this->createMock(CsrfTokenManager::class);
+ $this->CSRFTokenManager = $this->createMock(CsrfTokenManager::class);
$this->request = $this->createMock(Request::class);
$this->nonceManager = new ContentSecurityPolicyNonceManager(
- $this->csrfTokenManager,
+ $this->CSRFTokenManager,
$this->request
);
}
- public function testGetNonce() {
+ public function testGetNonce(): void {
+ $secret = base64_encode('secret');
+ $tokenValue = base64_encode('secret' ^ 'value_') . ':' . $secret;
$token = $this->createMock(CsrfToken::class);
$token
->expects($this->once())
->method('getEncryptedValue')
- ->willReturn('MyToken');
+ ->willReturn($tokenValue);
- $this->csrfTokenManager
+ $this->CSRFTokenManager
->expects($this->once())
->method('getToken')
->willReturn($token);
- $this->assertSame('TXlUb2tlbg==', $this->nonceManager->getNonce());
- $this->assertSame('TXlUb2tlbg==', $this->nonceManager->getNonce());
+ $this->assertSame($secret, $this->nonceManager->getNonce());
+ // call it twice but `getEncryptedValue` is expected to be called only once
+ $this->assertSame($secret, $this->nonceManager->getNonce());
}
- public function testGetNonceServerVar() {
+ public function testGetNonceServerVar(): void {
$token = 'SERVERNONCE';
$this->request
->method('__isset')
@@ -61,6 +65,7 @@ class ContentSecurityPolicyNonceManagerTest extends TestCase {
->willReturn(['CSP_NONCE' => $token]);
$this->assertSame($token, $this->nonceManager->getNonce());
+ // call it twice but `CSP_NONCE` variable is expected to be loaded only once
$this->assertSame($token, $this->nonceManager->getNonce());
}
}