diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-03-22 14:08:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 14:08:45 +0300 |
commit | 0acd4b5f8202be8b3f3b4e6d7481e3d23e496b86 (patch) | |
tree | 06897c455b69be134fcd61b0f0130609ce7a75a1 /tests/lib | |
parent | b6209d61251f7abacefb8cf3c164d39bcba29100 (diff) | |
parent | 67452b94ca0b59a063c4364f5930bb5186db2d55 (diff) |
Merge pull request #31235 from nextcloud/techdebt/noid/extract-request-id
Extract request id handling to dedicated class so it can be injected without DB dependency
Diffstat (limited to 'tests/lib')
12 files changed, 270 insertions, 280 deletions
diff --git a/tests/lib/AppFramework/Controller/ApiControllerTest.php b/tests/lib/AppFramework/Controller/ApiControllerTest.php index 71eb97b94da..975b92c5b96 100644 --- a/tests/lib/AppFramework/Controller/ApiControllerTest.php +++ b/tests/lib/AppFramework/Controller/ApiControllerTest.php @@ -26,6 +26,7 @@ namespace Test\AppFramework\Controller; use OC\AppFramework\Http\Request; use OCP\AppFramework\ApiController; use OCP\IConfig; +use OCP\IRequestId; class ChildApiController extends ApiController { }; @@ -38,12 +39,8 @@ class ApiControllerTest extends \Test\TestCase { public function testCors() { $request = new Request( ['server' => ['HTTP_ORIGIN' => 'test']], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $this->controller = new ChildApiController('app', $request, 'verbs', 'headers', 100); diff --git a/tests/lib/AppFramework/Controller/ControllerTest.php b/tests/lib/AppFramework/Controller/ControllerTest.php index 1d72482e75d..4d36fcadce1 100644 --- a/tests/lib/AppFramework/Controller/ControllerTest.php +++ b/tests/lib/AppFramework/Controller/ControllerTest.php @@ -29,6 +29,8 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\IConfig; use OCP\IRequest; +use OCP\IRequestId; +use OC\AppFramework\DependencyInjection\DIContainer; class ChildController extends Controller { public function __construct($appName, $request) { @@ -75,15 +77,11 @@ class ControllerTest extends \Test\TestCase { 'session' => ['sezession' => 'kein'], 'method' => 'hi', ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); - $this->app = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer') + $this->app = $this->getMockBuilder(DIContainer::class) ->setMethods(['getAppName']) ->setConstructorArgs(['test']) ->getMock(); diff --git a/tests/lib/AppFramework/Controller/OCSControllerTest.php b/tests/lib/AppFramework/Controller/OCSControllerTest.php index 91a61047871..ce110f435ef 100644 --- a/tests/lib/AppFramework/Controller/OCSControllerTest.php +++ b/tests/lib/AppFramework/Controller/OCSControllerTest.php @@ -28,7 +28,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\EmptyContentSecurityPolicy; use OCP\AppFramework\OCSController; use OCP\IConfig; -use OCP\Security\ISecureRandom; +use OCP\IRequestId; class ChildOCSController extends OCSController { } @@ -42,12 +42,8 @@ class OCSControllerTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test', ], ], - $this->getMockBuilder(ISecureRandom::class) - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $controller = new ChildOCSController('app', $request, 'verbs', 'headers', 100); @@ -67,12 +63,8 @@ class OCSControllerTest extends \Test\TestCase { public function testXML() { $controller = new ChildOCSController('app', new Request( [], - $this->getMockBuilder(ISecureRandom::class) - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) )); $controller->setOCSVersion(1); @@ -100,12 +92,8 @@ class OCSControllerTest extends \Test\TestCase { public function testJSON() { $controller = new ChildOCSController('app', new Request( [], - $this->getMockBuilder(ISecureRandom::class) - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) )); $controller->setOCSVersion(1); $expected = '{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK",' . @@ -121,12 +109,8 @@ class OCSControllerTest extends \Test\TestCase { public function testXMLV2() { $controller = new ChildOCSController('app', new Request( [], - $this->getMockBuilder(ISecureRandom::class) - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) )); $controller->setOCSVersion(2); @@ -152,12 +136,8 @@ class OCSControllerTest extends \Test\TestCase { public function testJSONV2() { $controller = new ChildOCSController('app', new Request( [], - $this->getMockBuilder(ISecureRandom::class) - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) )); $controller->setOCSVersion(2); $expected = '{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":{"test":"hi"}}}'; diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php index 3004123b81b..9a3d40d1c6b 100644 --- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php +++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php @@ -30,7 +30,7 @@ use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\Security\SecurityMiddleware; use OCP\AppFramework\QueryException; use OCP\IConfig; -use OCP\Security\ISecureRandom; +use OCP\IRequestId; /** * @group DB @@ -69,7 +69,7 @@ class DIContainerTest extends \Test\TestCase { public function testMiddlewareDispatcherIncludesSecurityMiddleware() { $this->container['Request'] = new Request( ['method' => 'GET'], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $dispatcher = $this->container['MiddlewareDispatcher']; diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php index a76b78385e7..e1d78082a2d 100644 --- a/tests/lib/AppFramework/Http/DispatcherTest.php +++ b/tests/lib/AppFramework/Http/DispatcherTest.php @@ -37,6 +37,7 @@ use OCP\IConfig; use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; +use OCP\IRequestId; class TestController extends Controller { /** @@ -316,12 +317,8 @@ class DispatcherTest extends \Test\TestCase { ], 'method' => 'POST' ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $this->dispatcher = new Dispatcher( $this->http, $this->middlewareDispatcher, $this->reflector, @@ -351,12 +348,8 @@ class DispatcherTest extends \Test\TestCase { ], 'method' => 'POST', ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $this->dispatcher = new Dispatcher( $this->http, $this->middlewareDispatcher, $this->reflector, @@ -389,12 +382,8 @@ class DispatcherTest extends \Test\TestCase { ], 'method' => 'GET' ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $this->dispatcher = new Dispatcher( $this->http, $this->middlewareDispatcher, $this->reflector, @@ -426,12 +415,8 @@ class DispatcherTest extends \Test\TestCase { ], 'method' => 'GET' ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $this->dispatcher = new Dispatcher( $this->http, $this->middlewareDispatcher, $this->reflector, @@ -464,12 +449,8 @@ class DispatcherTest extends \Test\TestCase { ], 'method' => 'PUT' ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $this->dispatcher = new Dispatcher( $this->http, $this->middlewareDispatcher, $this->reflector, @@ -504,12 +485,8 @@ class DispatcherTest extends \Test\TestCase { ], 'method' => 'POST' ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') - ->disableOriginalConstructor() - ->getMock(), - $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ); $this->dispatcher = new Dispatcher( $this->http, $this->middlewareDispatcher, $this->reflector, diff --git a/tests/lib/AppFramework/Http/RequestIdTest.php b/tests/lib/AppFramework/Http/RequestIdTest.php new file mode 100644 index 00000000000..9f9afed4b7f --- /dev/null +++ b/tests/lib/AppFramework/Http/RequestIdTest.php @@ -0,0 +1,76 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\AppFramework\Http; + +use OC\AppFramework\Http\RequestId; +use OCP\Security\ISecureRandom; +use PHPUnit\Framework\MockObject\MockObject; + +/** + * Class RequestIdTest + * + * @package OC\AppFramework\Http + */ +class RequestIdTest extends \Test\TestCase { + /** @var ISecureRandom|MockObject */ + protected $secureRandom; + + protected function setUp(): void { + parent::setUp(); + + $this->secureRandom = $this->createMock(ISecureRandom::class); + } + + public function testGetIdWithModUnique(): void { + $requestId = new RequestId( + 'GeneratedUniqueIdByModUnique', + $this->secureRandom + ); + + $this->secureRandom->expects($this->never()) + ->method('generate'); + + $this->assertSame('GeneratedUniqueIdByModUnique', $requestId->getId()); + $this->assertSame('GeneratedUniqueIdByModUnique', $requestId->getId()); + } + + public function testGetIdWithoutModUnique(): void { + $requestId = new RequestId( + '', + $this->secureRandom + ); + + $this->secureRandom->expects($this->once()) + ->method('generate') + ->with('20') + ->willReturnOnConsecutiveCalls( + 'GeneratedByNextcloudItself1', + 'GeneratedByNextcloudItself2', + 'GeneratedByNextcloudItself3' + ); + + $this->assertSame('GeneratedByNextcloudItself1', $requestId->getId()); + $this->assertSame('GeneratedByNextcloudItself1', $requestId->getId()); + } +} diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index a4a03b6479c..e15f3fe656c 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -14,7 +14,7 @@ use OC\AppFramework\Http\Request; use OC\Security\CSRF\CsrfToken; use OC\Security\CSRF\CsrfTokenManager; use OCP\IConfig; -use OCP\Security\ISecureRandom; +use OCP\IRequestId; /** * Class RequestTest @@ -24,8 +24,8 @@ use OCP\Security\ISecureRandom; class RequestTest extends \Test\TestCase { /** @var string */ protected $stream = 'fakeinput://data'; - /** @var ISecureRandom */ - protected $secureRandom; + /** @var IRequestId */ + protected $requestId; /** @var IConfig */ protected $config; /** @var CsrfTokenManager */ @@ -39,10 +39,11 @@ class RequestTest extends \Test\TestCase { } stream_wrapper_register('fakeinput', 'Test\AppFramework\Http\RequestStream'); - $this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(); - $this->config = $this->getMockBuilder(IConfig::class)->getMock(); - $this->csrfTokenManager = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager') - ->disableOriginalConstructor()->getMock(); + $this->requestId = $this->createMock(IRequestId::class); + $this->config = $this->createMock(IConfig::class); + $this->csrfTokenManager = $this->getMockBuilder(CsrfTokenManager::class) + ->disableOriginalConstructor() + ->getMock(); } protected function tearDown(): void { @@ -58,7 +59,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -90,7 +91,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -113,7 +114,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -133,7 +134,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -153,7 +154,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -170,7 +171,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -192,7 +193,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -216,7 +217,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -238,7 +239,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -263,7 +264,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -284,7 +285,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -312,7 +313,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -341,7 +342,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( $vars, - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -354,54 +355,6 @@ class RequestTest extends \Test\TestCase { $this->assertEquals('3', $request->getParams()['id']); } - public function testGetIdWithModUnique() { - $vars = [ - 'server' => [ - 'UNIQUE_ID' => 'GeneratedUniqueIdByModUnique' - ], - ]; - - $request = new Request( - $vars, - $this->secureRandom, - $this->config, - $this->csrfTokenManager, - $this->stream - ); - - $this->assertSame('GeneratedUniqueIdByModUnique', $request->getId()); - } - - public function testGetIdWithoutModUnique() { - $this->secureRandom->expects($this->once()) - ->method('generate') - ->with('20') - ->willReturn('GeneratedByOwnCloudItself'); - - $request = new Request( - [], - $this->secureRandom, - $this->config, - $this->csrfTokenManager, - $this->stream - ); - - $this->assertSame('GeneratedByOwnCloudItself', $request->getId()); - } - - public function testGetIdWithoutModUniqueStable() { - $request = new Request( - [], - \OC::$server->getSecureRandom(), - $this->config, - $this->csrfTokenManager, - $this->stream - ); - $firstId = $request->getId(); - $secondId = $request->getId(); - $this->assertSame($firstId, $secondId); - } - public function testGetRemoteAddressWithoutTrustedRemote() { $this->config ->expects($this->once()) @@ -417,7 +370,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -446,7 +399,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -475,7 +428,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -504,7 +457,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -537,7 +490,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -570,7 +523,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -599,7 +552,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -623,7 +576,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -651,7 +604,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_X_FORWARDED_FOR' => '[2001:db8:85a3:8d3:1319:8a2e:370:7348]', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -702,7 +655,7 @@ class RequestTest extends \Test\TestCase { 'SERVER_PROTOCOL' => $input, ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -730,7 +683,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -757,7 +710,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -769,7 +722,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -793,7 +746,7 @@ class RequestTest extends \Test\TestCase { 'HTTPS' => 'on' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -814,7 +767,7 @@ class RequestTest extends \Test\TestCase { 'HTTPS' => 'off' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -835,7 +788,7 @@ class RequestTest extends \Test\TestCase { 'HTTPS' => '' ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -852,7 +805,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -878,7 +831,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -900,7 +853,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_USER_AGENT' => $testAgent, ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -918,7 +871,7 @@ class RequestTest extends \Test\TestCase { public function testUndefinedUserAgent($testAgent, $userAgent, $matches) { $request = new Request( [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1056,7 +1009,7 @@ class RequestTest extends \Test\TestCase { 'SERVER_NAME' => 'from.server.name:8080', ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1073,7 +1026,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_HOST' => 'from.host.header:8080', ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1102,7 +1055,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1131,7 +1084,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1155,7 +1108,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1184,7 +1137,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1213,7 +1166,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1239,7 +1192,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1285,7 +1238,7 @@ class RequestTest extends \Test\TestCase { 'REMOTE_ADDR' => '1.2.3.4', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1302,7 +1255,7 @@ class RequestTest extends \Test\TestCase { ->willReturn(''); $request = new Request( [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1330,7 +1283,7 @@ class RequestTest extends \Test\TestCase { $request = new Request( [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1351,7 +1304,7 @@ class RequestTest extends \Test\TestCase { 'SCRIPT_NAME' => '/var/www/index.php', ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1372,7 +1325,7 @@ class RequestTest extends \Test\TestCase { 'SCRIPT_NAME' => '/var/www/index.php', ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1395,7 +1348,7 @@ class RequestTest extends \Test\TestCase { 'SCRIPT_NAME' => $scriptName, ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1418,7 +1371,7 @@ class RequestTest extends \Test\TestCase { 'SCRIPT_NAME' => $scriptName, ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1441,7 +1394,7 @@ class RequestTest extends \Test\TestCase { 'SCRIPT_NAME' => $scriptName, ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1464,7 +1417,7 @@ class RequestTest extends \Test\TestCase { 'SCRIPT_NAME' => $scriptName, ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1519,7 +1472,7 @@ class RequestTest extends \Test\TestCase { 'REQUEST_URI' => '/test.php' ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1559,7 +1512,7 @@ class RequestTest extends \Test\TestCase { 'SCRIPT_NAME' => '/test.php', ] ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1587,7 +1540,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1617,7 +1570,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1647,7 +1600,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1673,7 +1626,7 @@ class RequestTest extends \Test\TestCase { 'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1697,7 +1650,7 @@ class RequestTest extends \Test\TestCase { 'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1721,7 +1674,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1749,7 +1702,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookiestrict' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1777,7 +1730,7 @@ class RequestTest extends \Test\TestCase { '__Host-nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1809,7 +1762,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1832,7 +1785,7 @@ class RequestTest extends \Test\TestCase { ->setMethods(['getScriptName']) ->setConstructorArgs([ [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1857,7 +1810,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1880,7 +1833,7 @@ class RequestTest extends \Test\TestCase { 'RandomCookie' => 'asdf', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1903,7 +1856,7 @@ class RequestTest extends \Test\TestCase { session_name() => 'asdf', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1926,7 +1879,7 @@ class RequestTest extends \Test\TestCase { 'nc_token' => 'asdf', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1950,7 +1903,7 @@ class RequestTest extends \Test\TestCase { 'foo' => 'bar', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -1977,7 +1930,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -2001,7 +1954,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookiestrict' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -2025,7 +1978,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookielax' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -2049,7 +2002,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookiestrict' => 'true', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -2074,7 +2027,7 @@ class RequestTest extends \Test\TestCase { 'nc_sameSiteCookiestrict' => 'false', ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -2109,7 +2062,7 @@ class RequestTest extends \Test\TestCase { 'HTTP_REQUESTTOKEN' => $invalidToken, ], ], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream @@ -2132,7 +2085,7 @@ class RequestTest extends \Test\TestCase { ->setMethods(['getScriptName']) ->setConstructorArgs([ [], - $this->secureRandom, + $this->requestId, $this->config, $this->csrfTokenManager, $this->stream diff --git a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php index 9a5254fb4dd..f408320971d 100644 --- a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php +++ b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php @@ -28,6 +28,7 @@ use OC\AppFramework\Middleware\MiddlewareDispatcher; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; use OCP\IConfig; +use OCP\IRequestId; // needed to test ordering class TestMiddleware extends Middleware { @@ -129,8 +130,8 @@ class MiddlewareDispatcherTest extends \Test\TestCase { ->setConstructorArgs(['app', new Request( ['method' => 'GET'], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder(IConfig::class)->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ) ])->getMock(); } @@ -272,7 +273,7 @@ class MiddlewareDispatcherTest extends \Test\TestCase { public function testExceptionShouldRunAfterExceptionOfOnlyPreviouslyExecutedMiddlewares() { $m1 = $this->getMiddleware(); $m2 = $this->getMiddleware(true); - $m3 = $this->getMockBuilder('\OCP\AppFramework\Middleware')->getMock(); + $m3 = $this->createMock(Middleware::class); $m3->expects($this->never()) ->method('afterException'); $m3->expects($this->never()) diff --git a/tests/lib/AppFramework/Middleware/MiddlewareTest.php b/tests/lib/AppFramework/Middleware/MiddlewareTest.php index 42e38bbd999..bd61aab4673 100644 --- a/tests/lib/AppFramework/Middleware/MiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/MiddlewareTest.php @@ -24,9 +24,12 @@ namespace Test\AppFramework\Middleware; use OC\AppFramework\Http\Request; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; use OCP\IConfig; +use OCP\IRequestId; +use OC\AppFramework\DependencyInjection\DIContainer; class ChildMiddleware extends Middleware { }; @@ -49,22 +52,22 @@ class MiddlewareTest extends \Test\TestCase { $this->middleware = new ChildMiddleware(); - $this->api = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer') + $this->api = $this->getMockBuilder(DIContainer::class) ->disableOriginalConstructor() ->getMock(); - $this->controller = $this->getMockBuilder('OCP\AppFramework\Controller') + $this->controller = $this->getMockBuilder(Controller::class) ->setMethods([]) ->setConstructorArgs([ $this->api, new Request( [], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder(IConfig::class)->getMock() + $this->createMock(IRequestId::class), + $this->createMock(IConfig::class) ) ])->getMock(); $this->exception = new \Exception(); - $this->response = $this->getMockBuilder('OCP\AppFramework\Http\Response')->getMock(); + $this->response = $this->getMockBuilder(Response::class)->getMock(); } diff --git a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php index c89f38b44f5..cc6c74c16c4 100644 --- a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php @@ -21,7 +21,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; use OCP\IConfig; -use OCP\Security\ISecureRandom; +use OCP\IRequestId; class CORSMiddlewareTest extends \Test\TestCase { @@ -52,7 +52,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test' ] ], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); @@ -71,7 +71,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test' ] ], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); @@ -88,7 +88,7 @@ class CORSMiddlewareTest extends \Test\TestCase { public function testNoOriginHeaderNoCORSHEADER() { $request = new Request( [], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); @@ -112,7 +112,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test' ] ], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); @@ -130,7 +130,7 @@ class CORSMiddlewareTest extends \Test\TestCase { public function testNoCORSShouldAllowCookieAuth() { $request = new Request( [], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); @@ -155,7 +155,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->session->expects($this->once()) @@ -181,7 +181,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->session->expects($this->once()) @@ -207,7 +207,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->session->expects($this->once()) @@ -228,7 +228,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); @@ -244,7 +244,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); @@ -264,7 +264,7 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index 1af2b2b9f1c..276ebe8f9ac 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -42,9 +42,9 @@ use OCP\IConfig; use OCP\IL10N; use OCP\INavigationManager; use OCP\IRequest; +use OCP\IRequestId; use OCP\IURLGenerator; use OCP\IUserSession; -use OCP\Security\ISecureRandom; use Psr\Log\LoggerInterface; class SecurityMiddlewareTest extends \Test\TestCase { @@ -500,7 +500,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { 'REQUEST_URI' => 'nextcloud/index.php/apps/specialapp' ] ], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->middleware = $this->getMiddleware(false, false, false); @@ -534,7 +534,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { 'REQUEST_URI' => 'nextcloud/index.php/apps/specialapp', ], ], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); @@ -580,7 +580,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { 'REQUEST_URI' => 'nextcloud/index.php/apps/specialapp' ] ], - $this->createMock(ISecureRandom::class), + $this->createMock(IRequestId::class), $this->createMock(IConfig::class) ); $this->middleware = $this->getMiddleware(false, false, false); diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index 8913e2f99c1..fcd45bab5bd 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -9,10 +9,13 @@ namespace Test\User; use OC\AppFramework\Http\Request; +use OC\Authentication\Exceptions\InvalidTokenException; +use OC\Authentication\Exceptions\PasswordLoginForbiddenException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; use OC\Security\Bruteforce\Throttler; use OC\Session\Memory; +use OC\User\LoginException; use OC\User\Manager; use OC\User\Session; use OC\User\User; @@ -23,6 +26,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\ILogger; use OCP\IRequest; +use OCP\IRequestId; use OCP\ISession; use OCP\IUser; use OCP\Lockdown\ILockdownManager; @@ -30,6 +34,7 @@ use OCP\Security\ISecureRandom; use OCP\User\Events\PostLoginEvent; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use OC\Security\CSRF\CsrfTokenManager; /** * @group DB @@ -136,7 +141,7 @@ class SessionTest extends \Test\TestCase { ->method('getUID') ->willReturn('foo'); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); $userSession->setUser($user); } @@ -147,7 +152,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('bar') - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $session->expects($this->exactly(2)) ->method('set') ->with($this->callback(function ($key) { @@ -217,7 +222,7 @@ class SessionTest extends \Test\TestCase { public function testLoginValidPasswordDisabled() { - $this->expectException(\OC\User\LoginException::class); + $this->expectException(LoginException::class); $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); $session->expects($this->never()) @@ -227,9 +232,9 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('bar') - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); - $managerMethods = get_class_methods(\OC\User\Manager::class); + $managerMethods = get_class_methods(Manager::class); //keep following methods intact in order to ensure hooks are working $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) @@ -257,13 +262,13 @@ class SessionTest extends \Test\TestCase { $this->dispatcher->expects($this->never()) ->method('dispatch'); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); $userSession->login('foo', 'bar'); } public function testLoginInvalidPassword() { $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); - $managerMethods = get_class_methods(\OC\User\Manager::class); + $managerMethods = get_class_methods(Manager::class); //keep following methods intact in order to ensure hooks are working $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) @@ -276,7 +281,7 @@ class SessionTest extends \Test\TestCase { ]) ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); $user = $this->createMock(IUser::class); @@ -287,7 +292,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('bar') - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $user->expects($this->never()) ->method('isEnabled'); @@ -308,7 +313,7 @@ class SessionTest extends \Test\TestCase { public function testLoginNonExisting() { $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); $manager = $this->createMock(Manager::class); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); $session->expects($this->never()) ->method('set'); @@ -317,7 +322,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('bar') - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $manager->expects($this->once()) ->method('checkPasswordNoLogging') @@ -328,13 +333,13 @@ class SessionTest extends \Test\TestCase { } public function testLogClientInNoTokenPasswordWith2fa() { - $this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); + $this->expectException(PasswordLoginForbiddenException::class); $manager = $this->createMock(Manager::class); $session = $this->createMock(ISession::class); $request = $this->createMock(IRequest::class); - /** @var \OC\User\Session $userSession */ + /** @var Session $userSession */ $userSession = $this->getMockBuilder(Session::class) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher]) ->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser']) @@ -343,7 +348,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('doe') - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $this->config->expects($this->once()) ->method('getSystemValue') ->with('token_auth_enforced', false) @@ -379,7 +384,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('doe') - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $this->config->expects($this->once()) ->method('getSystemValue') ->with('token_auth_enforced', false) @@ -396,7 +401,7 @@ class SessionTest extends \Test\TestCase { $session = $this->createMock(ISession::class); $request = $this->createMock(IRequest::class); - /** @var \OC\User\Session $userSession */ + /** @var Session $userSession */ $userSession = $this->getMockBuilder(Session::class) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher]) ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser']) @@ -432,13 +437,13 @@ class SessionTest extends \Test\TestCase { public function testLogClientInNoTokenPasswordNo2fa() { - $this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); + $this->expectException(PasswordLoginForbiddenException::class); $manager = $this->createMock(Manager::class); $session = $this->createMock(ISession::class); $request = $this->createMock(IRequest::class); - /** @var \OC\User\Session $userSession */ + /** @var Session $userSession */ $userSession = $this->getMockBuilder(Session::class) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher]) ->setMethods(['login', 'isTwoFactorEnforced']) @@ -447,7 +452,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('doe') - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $this->config->expects($this->once()) ->method('getSystemValue') ->with('token_auth_enforced', false) @@ -477,7 +482,7 @@ class SessionTest extends \Test\TestCase { public function testRememberLoginValidToken() { $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); - $managerMethods = get_class_methods(\OC\User\Manager::class); + $managerMethods = get_class_methods(Manager::class); //keep following methods intact in order to ensure hooks are working $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) @@ -567,7 +572,7 @@ class SessionTest extends \Test\TestCase { public function testRememberLoginInvalidSessionToken() { $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); - $managerMethods = get_class_methods(\OC\User\Manager::class); + $managerMethods = get_class_methods(Manager::class); //keep following methods intact in order to ensure hooks are working $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) @@ -612,7 +617,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('renewSessionToken') ->with($oldSessionId, $sessionId) - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $user->expects($this->never()) ->method('getUID') @@ -632,7 +637,7 @@ class SessionTest extends \Test\TestCase { public function testRememberLoginInvalidToken() { $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); - $managerMethods = get_class_methods(\OC\User\Manager::class); + $managerMethods = get_class_methods(Manager::class); //keep following methods intact in order to ensure hooks are working $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) @@ -685,7 +690,7 @@ class SessionTest extends \Test\TestCase { public function testRememberLoginInvalidUser() { $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); - $managerMethods = get_class_methods(\OC\User\Manager::class); + $managerMethods = get_class_methods(Manager::class); //keep following methods intact in order to ensure hooks are working $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) @@ -735,7 +740,7 @@ class SessionTest extends \Test\TestCase { 'bar' => new User('bar', null, $this->createMock(EventDispatcherInterface::class)) ]; - $manager = $this->getMockBuilder('\OC\User\Manager') + $manager = $this->getMockBuilder(Manager::class) ->disableOriginalConstructor() ->getMock(); @@ -768,18 +773,18 @@ class SessionTest extends \Test\TestCase { $manager = $this->createMock(Manager::class); $session = $this->createMock(ISession::class); $user = $this->createMock(IUser::class); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); - $random = $this->createMock(ISecureRandom::class); + $requestId = $this->createMock(IRequestId::class); $config = $this->createMock(IConfig::class); - $csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager') + $csrf = $this->getMockBuilder(CsrfTokenManager::class) ->disableOriginalConstructor() ->getMock(); - $request = new \OC\AppFramework\Http\Request([ + $request = new Request([ 'server' => [ 'HTTP_USER_AGENT' => 'Firefox', ] - ], $random, $config, $csrf); + ], $requestId, $config, $csrf); $uid = 'user123'; $loginName = 'User123'; @@ -796,7 +801,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with($password) - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $this->tokenProvider->expects($this->once()) ->method('generateToken') @@ -809,18 +814,18 @@ class SessionTest extends \Test\TestCase { $manager = $this->createMock(Manager::class); $session = $this->createMock(ISession::class); $user = $this->createMock(IUser::class); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); - $random = $this->createMock(ISecureRandom::class); + $requestId = $this->createMock(IRequestId::class); $config = $this->createMock(IConfig::class); - $csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager') + $csrf = $this->getMockBuilder(CsrfTokenManager::class) ->disableOriginalConstructor() ->getMock(); - $request = new \OC\AppFramework\Http\Request([ + $request = new Request([ 'server' => [ 'HTTP_USER_AGENT' => 'Firefox', ] - ], $random, $config, $csrf); + ], $requestId, $config, $csrf); $uid = 'user123'; $loginName = 'User123'; @@ -837,7 +842,7 @@ class SessionTest extends \Test\TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with($password) - ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException())); + ->will($this->throwException(new InvalidTokenException())); $this->tokenProvider->expects($this->once()) ->method('generateToken') @@ -847,24 +852,24 @@ class SessionTest extends \Test\TestCase { } public function testCreateSessionTokenWithTokenPassword() { - $manager = $this->getMockBuilder('\OC\User\Manager') + $manager = $this->getMockBuilder(Manager::class) ->disableOriginalConstructor() ->getMock(); $session = $this->createMock(ISession::class); $token = $this->createMock(IToken::class); $user = $this->createMock(IUser::class); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); - $random = $this->createMock(ISecureRandom::class); + $requestId = $this->createMock(IRequestId::class); $config = $this->createMock(IConfig::class); - $csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager') + $csrf = $this->getMockBuilder(CsrfTokenManager::class) ->disableOriginalConstructor() ->getMock(); - $request = new \OC\AppFramework\Http\Request([ + $request = new Request([ 'server' => [ 'HTTP_USER_AGENT' => 'Firefox', ] - ], $random, $config, $csrf); + ], $requestId, $config, $csrf); $uid = 'user123'; $loginName = 'User123'; @@ -896,11 +901,11 @@ class SessionTest extends \Test\TestCase { } public function testCreateSessionTokenWithNonExistentUser() { - $manager = $this->getMockBuilder('\OC\User\Manager') + $manager = $this->getMockBuilder(Manager::class) ->disableOriginalConstructor() ->getMock(); $session = $this->createMock(ISession::class); - $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); + $userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); $request = $this->createMock(IRequest::class); $uid = 'user123'; |