summaryrefslogtreecommitdiffstats
path: root/tests/lib/security/csrf
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2016-05-20 15:38:20 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-05-20 15:38:20 +0200
commit94ad54ec9b96d41a614fbbad4a97b34c41a6901f (patch)
treef3eb7cdda2704aaf0cd59d58efe66bcbd34cb67d /tests/lib/security/csrf
parent2ef751b1ec28f7b5c7113af60ec8c9fa0ae1cf87 (diff)
downloadnextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.tar.gz
nextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.zip
Move tests/ to PSR-4 (#24731)
* Move a-b to PSR-4 * Move c-d to PSR-4 * Move e+g to PSR-4 * Move h-l to PSR-4 * Move m-r to PSR-4 * Move s-u to PSR-4 * Move files/ to PSR-4 * Move remaining tests to PSR-4 * Remove Test\ from old autoloader
Diffstat (limited to 'tests/lib/security/csrf')
-rw-r--r--tests/lib/security/csrf/CsrfTokenGeneratorTest.php56
-rw-r--r--tests/lib/security/csrf/CsrfTokenManagerTest.php136
-rw-r--r--tests/lib/security/csrf/CsrfTokenTest.php35
-rw-r--r--tests/lib/security/csrf/tokenstorage/SessionStorageTest.php109
4 files changed, 0 insertions, 336 deletions
diff --git a/tests/lib/security/csrf/CsrfTokenGeneratorTest.php b/tests/lib/security/csrf/CsrfTokenGeneratorTest.php
deleted file mode 100644
index 28b85c3951f..00000000000
--- a/tests/lib/security/csrf/CsrfTokenGeneratorTest.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace Test\Security\CSRF;
-
-class CsrfTokenGeneratorTest extends \Test\TestCase {
- /** @var \OCP\Security\ISecureRandom */
- private $random;
- /** @var \OC\Security\CSRF\CsrfTokenGenerator */
- private $csrfTokenGenerator;
-
- public function setUp() {
- parent::setUp();
- $this->random = $this->getMockBuilder('\OCP\Security\ISecureRandom')
- ->disableOriginalConstructor()->getMock();
- $this->csrfTokenGenerator = new \OC\Security\CSRF\CsrfTokenGenerator($this->random);
-
- }
-
- public function testGenerateTokenWithCustomNumber() {
- $this->random
- ->expects($this->once())
- ->method('generate')
- ->with(3)
- ->willReturn('abc');
- $this->assertSame('abc', $this->csrfTokenGenerator->generateToken(3));
- }
-
- public function testGenerateTokenWithDefault() {
- $this->random
- ->expects($this->once())
- ->method('generate')
- ->with(32)
- ->willReturn('12345678901234567890123456789012');
- $this->assertSame('12345678901234567890123456789012', $this->csrfTokenGenerator->generateToken(32));
- }
-}
-
diff --git a/tests/lib/security/csrf/CsrfTokenManagerTest.php b/tests/lib/security/csrf/CsrfTokenManagerTest.php
deleted file mode 100644
index ab19a43e91e..00000000000
--- a/tests/lib/security/csrf/CsrfTokenManagerTest.php
+++ /dev/null
@@ -1,136 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace Test\Security\CSRF;
-
-class CsrfTokenManagerTest extends \Test\TestCase {
- /** @var \OC\Security\CSRF\CsrfTokenManager */
- private $csrfTokenManager;
- /** @var \OC\Security\CSRF\CsrfTokenGenerator */
- private $tokenGenerator;
- /** @var \OC\Security\CSRF\TokenStorage\SessionStorage */
- private $storageInterface;
-
- public function setUp() {
- parent::setUp();
- $this->tokenGenerator = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenGenerator')
- ->disableOriginalConstructor()->getMock();
- $this->storageInterface = $this->getMockBuilder('\OC\Security\CSRF\TokenStorage\SessionStorage')
- ->disableOriginalConstructor()->getMock();
-
- $this->csrfTokenManager = new \OC\Security\CSRF\CsrfTokenManager(
- $this->tokenGenerator,
- $this->storageInterface
- );
- }
-
- public function testGetTokenWithExistingToken() {
- $this->storageInterface
- ->expects($this->once())
- ->method('hasToken')
- ->willReturn(true);
- $this->storageInterface
- ->expects($this->once())
- ->method('getToken')
- ->willReturn('MyExistingToken');
-
- $expected = new \OC\Security\CSRF\CsrfToken('MyExistingToken');
- $this->assertEquals($expected, $this->csrfTokenManager->getToken());
- }
-
- public function testGetTokenWithoutExistingToken() {
- $this->storageInterface
- ->expects($this->once())
- ->method('hasToken')
- ->willReturn(false);
- $this->tokenGenerator
- ->expects($this->once())
- ->method('generateToken')
- ->willReturn('MyNewToken');
- $this->storageInterface
- ->expects($this->once())
- ->method('setToken')
- ->with('MyNewToken');
-
- $expected = new \OC\Security\CSRF\CsrfToken('MyNewToken');
- $this->assertEquals($expected, $this->csrfTokenManager->getToken());
- }
-
- public function testRefreshToken() {
- $this->tokenGenerator
- ->expects($this->once())
- ->method('generateToken')
- ->willReturn('MyNewToken');
- $this->storageInterface
- ->expects($this->once())
- ->method('setToken')
- ->with('MyNewToken');
-
- $expected = new \OC\Security\CSRF\CsrfToken('MyNewToken');
- $this->assertEquals($expected, $this->csrfTokenManager->refreshToken());
- }
-
- public function testRemoveToken() {
- $this->storageInterface
- ->expects($this->once())
- ->method('removeToken');
-
- $this->csrfTokenManager->removeToken();
- }
-
- public function testIsTokenValidWithoutToken() {
- $this->storageInterface
- ->expects($this->once())
- ->method('hasToken')
- ->willReturn(false);
- $token = new \OC\Security\CSRF\CsrfToken('Token');
-
- $this->assertSame(false, $this->csrfTokenManager->isTokenValid($token));
- }
-
- public function testIsTokenValidWithWrongToken() {
- $this->storageInterface
- ->expects($this->once())
- ->method('hasToken')
- ->willReturn(true);
- $token = new \OC\Security\CSRF\CsrfToken('Token');
- $this->storageInterface
- ->expects($this->once())
- ->method('getToken')
- ->willReturn('MyToken');
-
- $this->assertSame(false, $this->csrfTokenManager->isTokenValid($token));
- }
-
- public function testIsTokenValidWithValidToken() {
- $this->storageInterface
- ->expects($this->once())
- ->method('hasToken')
- ->willReturn(true);
- $token = new \OC\Security\CSRF\CsrfToken('XlQhHjgWCgBXAEI0Khl+IQEiCXN2LUcDHAQTQAc1HQs=:qgkUlg8l3m8WnkOG4XM9Az33pAt1vSVMx4hcJFsxdqc=');
- $this->storageInterface
- ->expects($this->once())
- ->method('getToken')
- ->willReturn('/3JKTq2ldmzcDr1f5zDJ7Wt0lEgqqfKF');
-
- $this->assertSame(true, $this->csrfTokenManager->isTokenValid($token));
- }
-}
diff --git a/tests/lib/security/csrf/CsrfTokenTest.php b/tests/lib/security/csrf/CsrfTokenTest.php
deleted file mode 100644
index da640ce5052..00000000000
--- a/tests/lib/security/csrf/CsrfTokenTest.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace Test\Security\CSRF;
-
-class CsrfTokenTest extends \Test\TestCase {
- public function testGetEncryptedValue() {
- $csrfToken = new \OC\Security\CSRF\CsrfToken('MyCsrfToken');
- $this->assertSame(33, strlen($csrfToken->getEncryptedValue()));
- $this->assertSame(':', $csrfToken->getEncryptedValue()[16]);
- }
-
- public function testGetDecryptedValue() {
- $csrfToken = new \OC\Security\CSRF\CsrfToken('XlQhHjgWCgBXAEI0Khl+IQEiCXN2LUcDHAQTQAc1HQs=:qgkUlg8l3m8WnkOG4XM9Az33pAt1vSVMx4hcJFsxdqc=');
- $this->assertSame('/3JKTq2ldmzcDr1f5zDJ7Wt0lEgqqfKF', $csrfToken->getDecryptedValue());
- }
-}
diff --git a/tests/lib/security/csrf/tokenstorage/SessionStorageTest.php b/tests/lib/security/csrf/tokenstorage/SessionStorageTest.php
deleted file mode 100644
index 550fa49e1b2..00000000000
--- a/tests/lib/security/csrf/tokenstorage/SessionStorageTest.php
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace Test\Security\CSRF\TokenStorage;
-
-class SessionStorageTest extends \Test\TestCase {
- /** @var \OCP\ISession */
- private $session;
- /** @var \OC\Security\CSRF\TokenStorage\SessionStorage */
- private $sessionStorage;
-
- public function setUp() {
- parent::setUp();
- $this->session = $this->getMockBuilder('\OCP\ISession')
- ->disableOriginalConstructor()->getMock();
- $this->sessionStorage = new \OC\Security\CSRF\TokenStorage\SessionStorage($this->session);
- }
-
- /**
- * @return array
- */
- public function getTokenDataProvider() {
- return [
- [
- '',
- ],
- [
- null,
- ],
- ];
- }
-
- /**
- * @param string $token
- * @dataProvider getTokenDataProvider
- *
- * @expectedException \Exception
- * @expectedExceptionMessage Session does not contain a requesttoken
- */
- public function testGetTokenWithEmptyToken($token) {
- $this->session
- ->expects($this->once())
- ->method('get')
- ->with('requesttoken')
- ->willReturn($token);
- $this->sessionStorage->getToken();
- }
-
- public function testGetTokenWithValidToken() {
- $this->session
- ->expects($this->once())
- ->method('get')
- ->with('requesttoken')
- ->willReturn('MyFancyCsrfToken');
- $this->assertSame('MyFancyCsrfToken', $this->sessionStorage->getToken());
- }
-
- public function testSetToken() {
- $this->session
- ->expects($this->once())
- ->method('set')
- ->with('requesttoken', 'TokenToSet');
- $this->sessionStorage->setToken('TokenToSet');
- }
-
- public function testRemoveToken() {
- $this->session
- ->expects($this->once())
- ->method('remove')
- ->with('requesttoken');
- $this->sessionStorage->removeToken();
- }
-
- public function testHasTokenWithExistingToken() {
- $this->session
- ->expects($this->once())
- ->method('exists')
- ->with('requesttoken')
- ->willReturn(true);
- $this->assertSame(true, $this->sessionStorage->hasToken());
- }
-
- public function testHasTokenWithoutExistingToken() {
- $this->session
- ->expects($this->once())
- ->method('exists')
- ->with('requesttoken')
- ->willReturn(false);
- $this->assertSame(false, $this->sessionStorage->hasToken());
- }
-}