aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/Http
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/AppFramework/Http')
-rw-r--r--tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php1
-rw-r--r--tests/lib/AppFramework/Http/DataResponseTest.php3
-rw-r--r--tests/lib/AppFramework/Http/DispatcherTest.php65
-rw-r--r--tests/lib/AppFramework/Http/DownloadResponseTest.php6
-rw-r--r--tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php1
-rw-r--r--tests/lib/AppFramework/Http/FileDisplayResponseTest.php1
-rw-r--r--tests/lib/AppFramework/Http/JSONResponseTest.php7
-rw-r--r--tests/lib/AppFramework/Http/OutputTest.php1
-rw-r--r--tests/lib/AppFramework/Http/PublicTemplateResponseTest.php10
-rw-r--r--tests/lib/AppFramework/Http/RequestIdTest.php6
-rw-r--r--tests/lib/AppFramework/Http/RequestStream.php1
-rw-r--r--tests/lib/AppFramework/Http/RequestTest.php221
-rw-r--r--tests/lib/AppFramework/Http/ResponseTest.php16
-rw-r--r--tests/lib/AppFramework/Http/TemplateResponseTest.php2
14 files changed, 156 insertions, 185 deletions
diff --git a/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php b/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php
index aa2b29418e4..75527e7eaf8 100644
--- a/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php
+++ b/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/tests/lib/AppFramework/Http/DataResponseTest.php b/tests/lib/AppFramework/Http/DataResponseTest.php
index 7ae19e7d5d8..e9a2c511140 100644
--- a/tests/lib/AppFramework/Http/DataResponseTest.php
+++ b/tests/lib/AppFramework/Http/DataResponseTest.php
@@ -11,6 +11,7 @@ namespace Test\AppFramework\Http;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
+use OCP\Server;
class DataResponseTest extends \Test\TestCase {
/**
@@ -53,7 +54,7 @@ class DataResponseTest extends \Test\TestCase {
'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'",
'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
'X-Robots-Tag' => 'noindex, nofollow',
- 'X-Request-Id' => \OC::$server->get(IRequest::class)->getId(),
+ 'X-Request-Id' => Server::get(IRequest::class)->getId(),
];
$expectedHeaders = array_merge($expectedHeaders, $headers);
diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php
index 7415ecd9486..86c78e840e0 100644
--- a/tests/lib/AppFramework/Http/DispatcherTest.php
+++ b/tests/lib/AppFramework/Http/DispatcherTest.php
@@ -8,6 +8,7 @@
namespace Test\AppFramework\Http;
+use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\Http\Dispatcher;
use OC\AppFramework\Http\Request;
use OC\AppFramework\Middleware\MiddlewareDispatcher;
@@ -20,8 +21,10 @@ use OCP\AppFramework\Http\ParameterOutOfRangeException;
use OCP\AppFramework\Http\Response;
use OCP\Diagnostics\IEventLogger;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IRequestId;
+use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
@@ -29,7 +32,7 @@ use Psr\Log\LoggerInterface;
class TestController extends Controller {
/**
* @param string $appName
- * @param \OCP\IRequest $request
+ * @param IRequest $request
*/
public function __construct($appName, $request) {
parent::__construct($appName, $request);
@@ -63,6 +66,10 @@ class TestController extends Controller {
'text' => [$int, $bool, $test, $test2]
]);
}
+
+ public function test(): Response {
+ return new DataResponse();
+ }
}
/**
@@ -104,33 +111,17 @@ class DispatcherTest extends \Test\TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->eventLogger = $this->createMock(IEventLogger::class);
$this->container = $this->createMock(ContainerInterface::class);
- $app = $this->getMockBuilder(
- 'OC\AppFramework\DependencyInjection\DIContainer')
- ->disableOriginalConstructor()
- ->getMock();
- $request = $this->getMockBuilder(
- '\OC\AppFramework\Http\Request')
- ->disableOriginalConstructor()
- ->getMock();
- $this->http = $this->getMockBuilder(
- \OC\AppFramework\Http::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $app = $this->createMock(DIContainer::class);
+ $request = $this->createMock(Request::class);
+ $this->http = $this->createMock(\OC\AppFramework\Http::class);
- $this->middlewareDispatcher = $this->getMockBuilder(
- '\OC\AppFramework\Middleware\MiddlewareDispatcher')
- ->disableOriginalConstructor()
- ->getMock();
- $this->controller = $this->getMockBuilder(
- '\OCP\AppFramework\Controller')
- ->setMethods([$this->controllerMethod])
+ $this->middlewareDispatcher = $this->createMock(MiddlewareDispatcher::class);
+ $this->controller = $this->getMockBuilder(TestController::class)
+ ->onlyMethods([$this->controllerMethod])
->setConstructorArgs([$app, $request])
->getMock();
- $this->request = $this->getMockBuilder(
- '\OC\AppFramework\Http\Request')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->request = $this->createMock(Request::class);
$this->reflector = new ControllerMethodReflector();
@@ -140,7 +131,7 @@ class DispatcherTest extends \Test\TestCase {
$this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container,
@@ -166,7 +157,7 @@ class DispatcherTest extends \Test\TestCase {
->method('beforeController')
->with($this->equalTo($this->controller),
$this->equalTo($this->controllerMethod))
- ->will($this->throwException($exception));
+ ->willThrowException($exception);
if ($catchEx) {
$this->middlewareDispatcher->expects($this->once())
->method('afterException')
@@ -317,7 +308,7 @@ class DispatcherTest extends \Test\TestCase {
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container
@@ -350,7 +341,7 @@ class DispatcherTest extends \Test\TestCase {
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container
@@ -386,7 +377,7 @@ class DispatcherTest extends \Test\TestCase {
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container
@@ -421,7 +412,7 @@ class DispatcherTest extends \Test\TestCase {
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container
@@ -457,7 +448,7 @@ class DispatcherTest extends \Test\TestCase {
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container
@@ -492,7 +483,7 @@ class DispatcherTest extends \Test\TestCase {
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container
@@ -530,7 +521,7 @@ class DispatcherTest extends \Test\TestCase {
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container
@@ -545,7 +536,7 @@ class DispatcherTest extends \Test\TestCase {
}
- public function rangeDataProvider(): array {
+ public static function rangeDataProvider(): array {
return [
[PHP_INT_MIN, PHP_INT_MAX, 42, false],
[0, 12, -5, true],
@@ -556,9 +547,7 @@ class DispatcherTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider rangeDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('rangeDataProvider')]
public function testEnsureParameterValueSatisfiesRange(int $min, int $max, int $input, bool $throw): void {
$this->reflector = $this->createMock(ControllerMethodReflector::class);
$this->reflector->expects($this->any())
@@ -574,7 +563,7 @@ class DispatcherTest extends \Test\TestCase {
$this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container,
diff --git a/tests/lib/AppFramework/Http/DownloadResponseTest.php b/tests/lib/AppFramework/Http/DownloadResponseTest.php
index ee89e8e55d1..b2f60edd999 100644
--- a/tests/lib/AppFramework/Http/DownloadResponseTest.php
+++ b/tests/lib/AppFramework/Http/DownloadResponseTest.php
@@ -27,9 +27,7 @@ class DownloadResponseTest extends \Test\TestCase {
$this->assertEquals('content', $headers['Content-Type']);
}
- /**
- * @dataProvider filenameEncodingProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('filenameEncodingProvider')]
public function testFilenameEncoding(string $input, string $expected): void {
$response = new ChildDownloadResponse($input, 'content');
$headers = $response->getHeaders();
@@ -37,7 +35,7 @@ class DownloadResponseTest extends \Test\TestCase {
$this->assertEquals('attachment; filename="' . $expected . '"', $headers['Content-Disposition']);
}
- public function filenameEncodingProvider() : array {
+ public static function filenameEncodingProvider() : array {
return [
['TestName.txt', 'TestName.txt'],
['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
diff --git a/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php b/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php
index 3110f632fa7..66abce43cc4 100644
--- a/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php
+++ b/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/tests/lib/AppFramework/Http/FileDisplayResponseTest.php b/tests/lib/AppFramework/Http/FileDisplayResponseTest.php
index 5f602b2e1c6..029ddaad712 100644
--- a/tests/lib/AppFramework/Http/FileDisplayResponseTest.php
+++ b/tests/lib/AppFramework/Http/FileDisplayResponseTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/lib/AppFramework/Http/JSONResponseTest.php b/tests/lib/AppFramework/Http/JSONResponseTest.php
index 175ed852c7b..56f67b23f0d 100644
--- a/tests/lib/AppFramework/Http/JSONResponseTest.php
+++ b/tests/lib/AppFramework/Http/JSONResponseTest.php
@@ -46,10 +46,7 @@ class JSONResponseTest extends \Test\TestCase {
$this->assertEquals($expected, $this->json->render());
}
- /**
- * @return array
- */
- public function renderDataProvider() {
+ public static function renderDataProvider(): array {
return [
[
['test' => 'hi'], '{"test":"hi"}',
@@ -61,10 +58,10 @@ class JSONResponseTest extends \Test\TestCase {
}
/**
- * @dataProvider renderDataProvider
* @param array $input
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('renderDataProvider')]
public function testRender(array $input, $expected): void {
$this->json->setData($input);
$this->assertEquals($expected, $this->json->render());
diff --git a/tests/lib/AppFramework/Http/OutputTest.php b/tests/lib/AppFramework/Http/OutputTest.php
index 58b17c08141..2ba93833dd1 100644
--- a/tests/lib/AppFramework/Http/OutputTest.php
+++ b/tests/lib/AppFramework/Http/OutputTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php b/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php
index d963705bc24..cb7bd97f5da 100644
--- a/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php
+++ b/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php
@@ -7,8 +7,8 @@
namespace Test\AppFramework\Http;
-use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
use Test\TestCase;
class PublicTemplateResponseTest extends TestCase {
@@ -28,7 +28,7 @@ class PublicTemplateResponseTest extends TestCase {
public function testActionSingle(): void {
$actions = [
- new Http\Template\SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0)
+ new SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0)
];
$template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
$template->setHeaderActions($actions);
@@ -41,9 +41,9 @@ class PublicTemplateResponseTest extends TestCase {
public function testActionMultiple(): void {
$actions = [
- new Http\Template\SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100),
- new Http\Template\SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20),
- new Http\Template\SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0)
+ new SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100),
+ new SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20),
+ new SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0)
];
$template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
$template->setHeaderActions($actions);
diff --git a/tests/lib/AppFramework/Http/RequestIdTest.php b/tests/lib/AppFramework/Http/RequestIdTest.php
index b3cfe2a8f4a..9cfd3b1785c 100644
--- a/tests/lib/AppFramework/Http/RequestIdTest.php
+++ b/tests/lib/AppFramework/Http/RequestIdTest.php
@@ -49,11 +49,7 @@ class RequestIdTest extends \Test\TestCase {
$this->secureRandom->expects($this->once())
->method('generate')
->with('20')
- ->willReturnOnConsecutiveCalls(
- 'GeneratedByNextcloudItself1',
- 'GeneratedByNextcloudItself2',
- 'GeneratedByNextcloudItself3'
- );
+ ->willReturn('GeneratedByNextcloudItself1');
$this->assertSame('GeneratedByNextcloudItself1', $requestId->getId());
$this->assertSame('GeneratedByNextcloudItself1', $requestId->getId());
diff --git a/tests/lib/AppFramework/Http/RequestStream.php b/tests/lib/AppFramework/Http/RequestStream.php
index 91259b26c9f..7340391b2d5 100644
--- a/tests/lib/AppFramework/Http/RequestStream.php
+++ b/tests/lib/AppFramework/Http/RequestStream.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php
index 1c7f07580cc..7ea2cb31482 100644
--- a/tests/lib/AppFramework/Http/RequestTest.php
+++ b/tests/lib/AppFramework/Http/RequestTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -251,7 +252,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('someothertestvalue', $result['propertyB']);
}
- public function notJsonDataProvider() {
+ public static function dataNotJsonData(): array {
return [
['this is not valid json'],
['"just a string"'],
@@ -259,10 +260,8 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider notJsonDataProvider
- */
- public function testNotJsonPost($testData): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataNotJsonData')]
+ public function testNotJsonPost(string $testData): void {
global $data;
$data = $testData;
$vars = [
@@ -544,7 +543,7 @@ class RequestTest extends \Test\TestCase {
$this->assertEquals('3', $request->getParams()['id']);
}
- public function dataGetRemoteAddress(): array {
+ public static function dataGetRemoteAddress(): array {
return [
'IPv4 without trusted remote' => [
[
@@ -708,20 +707,14 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataGetRemoteAddress
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetRemoteAddress')]
public function testGetRemoteAddress(array $headers, array $trustedProxies, array $forwardedForHeaders, string $expected): void {
$this->config
->method('getSystemValue')
- ->withConsecutive(
- ['trusted_proxies'],
- ['forwarded_for_headers'],
- )
- ->willReturnOnConsecutiveCalls(
- $trustedProxies,
- $forwardedForHeaders,
- );
+ ->willReturnMap([
+ ['trusted_proxies', [], $trustedProxies],
+ ['forwarded_for_headers', ['HTTP_X_FORWARDED_FOR'], $forwardedForHeaders],
+ ]);
$request = new Request(
[
@@ -736,10 +729,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame($expected, $request->getRemoteAddress());
}
- /**
- * @return array
- */
- public function httpProtocolProvider() {
+ public static function dataHttpProtocol(): array {
return [
// Valid HTTP 1.0
['HTTP/1.0', 'HTTP/1.0'],
@@ -766,11 +756,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider httpProtocolProvider
*
* @param mixed $input
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataHttpProtocol')]
public function testGetHttpProtocol($input, $expected): void {
$request = new Request(
[
@@ -787,12 +777,32 @@ class RequestTest extends \Test\TestCase {
$this->assertSame($expected, $request->getHttpProtocol());
}
- public function testGetServerProtocolWithOverride(): void {
+ public function testGetServerProtocolWithOverrideValid(): void {
+ $this->config
+ ->expects($this->exactly(3))
+ ->method('getSystemValueString')
+ ->willReturnMap([
+ ['overwriteprotocol', '', 'HTTPS'], // should be automatically lowercased
+ ['overwritecondaddr', '', ''],
+ ]);
+
+ $request = new Request(
+ [],
+ $this->requestId,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ );
+
+ $this->assertSame('https', $request->getServerProtocol());
+ }
+
+ public function testGetServerProtocolWithOverrideInValid(): void {
$this->config
->expects($this->exactly(3))
->method('getSystemValueString')
->willReturnMap([
- ['overwriteprotocol', '', 'customProtocol'],
+ ['overwriteprotocol', '', 'bogusProtocol'], // should trigger fallback to http
['overwritecondaddr', '', ''],
]);
@@ -804,7 +814,7 @@ class RequestTest extends \Test\TestCase {
$this->stream
);
- $this->assertSame('customProtocol', $request->getServerProtocol());
+ $this->assertSame('http', $request->getServerProtocol());
}
public function testGetServerProtocolWithProtoValid(): void {
@@ -956,11 +966,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider userAgentProvider
* @param string $testAgent
* @param array $userAgent
* @param bool $matches
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUserAgent')]
public function testUserAgent($testAgent, $userAgent, $matches): void {
$request = new Request(
[
@@ -978,11 +988,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider userAgentProvider
* @param string $testAgent
* @param array $userAgent
* @param bool $matches
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUserAgent')]
public function testUndefinedUserAgent($testAgent, $userAgent, $matches): void {
$request = new Request(
[],
@@ -995,10 +1005,7 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->isUserAgent($userAgent));
}
- /**
- * @return array
- */
- public function userAgentProvider() {
+ public static function dataUserAgent(): array {
return [
[
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
@@ -1117,7 +1124,7 @@ class RequestTest extends \Test\TestCase {
];
}
- public function dataMatchClientVersion(): array {
+ public static function dataMatchClientVersion(): array {
return [
[
'Mozilla/5.0 (Android) Nextcloud-android/3.24.1',
@@ -1155,7 +1162,7 @@ class RequestTest extends \Test\TestCase {
'1.0.0',
],
[
- 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v1.0.0',
+ 'Filelink for *cloud/1.0.0',
Request::USER_AGENT_THUNDERBIRD_ADDON,
'1.0.0',
],
@@ -1163,11 +1170,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider dataMatchClientVersion
* @param string $testAgent
* @param string $userAgent
* @param string $version
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataMatchClientVersion')]
public function testMatchClientVersion(string $testAgent, string $userAgent, string $version): void {
preg_match($userAgent, $testAgent, $matches);
@@ -1373,10 +1380,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('', $request->getServerHost());
}
- /**
- * @return array
- */
- public function dataGetServerHostTrustedDomain() {
+ public static function dataGetServerHostTrustedDomain(): array {
return [
'is array' => ['my.trusted.host', ['my.trusted.host']],
'is array but undefined index 0' => ['my.trusted.host', [2 => 'my.trusted.host']],
@@ -1385,12 +1389,8 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataGetServerHostTrustedDomain
- * @param $expected
- * @param $trustedDomain
- */
- public function testGetServerHostTrustedDomain($expected, $trustedDomain): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetServerHostTrustedDomain')]
+ public function testGetServerHostTrustedDomain(string $expected, $trustedDomain): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) use ($trustedDomain) {
@@ -1499,11 +1499,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider genericPathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGenericPathInfo')]
public function testGetPathInfoWithoutSetEnvGeneric($requestUri, $scriptName, $expected): void {
$request = new Request(
[
@@ -1522,11 +1522,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider genericPathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGenericPathInfo')]
public function testGetRawPathInfoWithoutSetEnvGeneric($requestUri, $scriptName, $expected): void {
$request = new Request(
[
@@ -1545,11 +1545,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider rawPathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRawPathInfo')]
public function testGetRawPathInfoWithoutSetEnv($requestUri, $scriptName, $expected): void {
$request = new Request(
[
@@ -1568,11 +1568,11 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider pathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataPathInfo')]
public function testGetPathInfoWithoutSetEnv($requestUri, $scriptName, $expected): void {
$request = new Request(
[
@@ -1590,10 +1590,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame($expected, $request->getPathInfo());
}
- /**
- * @return array
- */
- public function genericPathInfoProvider() {
+ public static function dataGenericPathInfo(): array {
return [
['/core/index.php?XDEBUG_SESSION_START=14600', '/core/index.php', ''],
['/index.php/apps/files/', 'index.php', '/apps/files/'],
@@ -1605,19 +1602,13 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @return array
- */
- public function rawPathInfoProvider() {
+ public static function dataRawPathInfo(): array {
return [
['/foo%2Fbar/subfolder', '', 'foo%2Fbar/subfolder'],
];
}
- /**
- * @return array
- */
- public function pathInfoProvider() {
+ public static function dataPathInfo(): array {
return [
['/foo%2Fbar/subfolder', '', 'foo/bar/subfolder'],
];
@@ -1645,16 +1636,14 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('/test.php', $request->getRequestUri());
}
- public function providesGetRequestUriWithOverwriteData() {
+ public static function dataGetRequestUriWithOverwrite(): array {
return [
['/scriptname.php/some/PathInfo', '/owncloud/', ''],
['/scriptname.php/some/PathInfo', '/owncloud/', '123', '123.123.123.123'],
];
}
- /**
- * @dataProvider providesGetRequestUriWithOverwriteData
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetRequestUriWithOverwrite')]
public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr, $remoteAddr = ''): void {
$this->config
->expects($this->exactly(2))
@@ -1665,7 +1654,7 @@ class RequestTest extends \Test\TestCase {
]);
$request = $this->getMockBuilder(Request::class)
- ->setMethods(['getScriptName'])
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -1690,8 +1679,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithGet(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'get' => [
@@ -1720,8 +1709,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithPost(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'post' => [
@@ -1750,8 +1739,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithHeader(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -1780,8 +1769,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithGetAndWithoutCookies(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'get' => [
@@ -1804,8 +1793,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithPostAndWithoutCookies(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'post' => [
@@ -1828,8 +1817,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithHeaderAndWithoutCookies(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -1852,8 +1841,8 @@ class RequestTest extends \Test\TestCase {
public function testFailsCSRFCheckWithHeaderAndNotAllChecksPassing(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -1879,8 +1868,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesStrictCookieCheckWithAllCookiesAndStrict(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName', 'getCookieParams'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName', 'getCookieParams'])
->setConstructorArgs([
[
'server' => [
@@ -1911,8 +1900,8 @@ class RequestTest extends \Test\TestCase {
public function testFailsStrictCookieCheckWithAllCookiesAndMissingStrict(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName', 'getCookieParams'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName', 'getCookieParams'])
->setConstructorArgs([
[
'server' => [
@@ -1944,7 +1933,7 @@ class RequestTest extends \Test\TestCase {
public function testGetCookieParams(): void {
/** @var Request $request */
$request = $this->getMockBuilder(Request::class)
- ->setMethods(['getScriptName'])
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[],
$this->requestId,
@@ -1959,8 +1948,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesStrictCookieCheckWithAllCookies(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -1984,8 +1973,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesStrictCookieCheckWithRandomCookies(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2007,8 +1996,8 @@ class RequestTest extends \Test\TestCase {
public function testFailsStrictCookieCheckWithSessionCookie(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2030,8 +2019,8 @@ class RequestTest extends \Test\TestCase {
public function testFailsStrictCookieCheckWithRememberMeCookie(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2053,8 +2042,8 @@ class RequestTest extends \Test\TestCase {
public function testFailsCSRFCheckWithPostAndWithCookies(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'post' => [
@@ -2080,8 +2069,8 @@ class RequestTest extends \Test\TestCase {
public function testFailStrictCookieCheckWithOnlyLaxCookie(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2104,8 +2093,8 @@ class RequestTest extends \Test\TestCase {
public function testFailStrictCookieCheckWithOnlyStrictCookie(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2128,8 +2117,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesLaxCookieCheck(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2152,8 +2141,8 @@ class RequestTest extends \Test\TestCase {
public function testFailsLaxCookieCheckWithOnlyStrictCookie(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2176,8 +2165,8 @@ class RequestTest extends \Test\TestCase {
public function testSkipCookieCheckForOCSRequests(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2199,10 +2188,7 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesStrictCookieCheck());
}
- /**
- * @return array
- */
- public function invalidTokenDataProvider() {
+ public static function dataInvalidToken(): array {
return [
['InvalidSentToken'],
['InvalidSentToken:InvalidSecret'],
@@ -2210,14 +2196,11 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider invalidTokenDataProvider
- * @param string $invalidToken
- */
- public function testPassesCSRFCheckWithInvalidToken($invalidToken): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataInvalidToken')]
+ public function testPassesCSRFCheckWithInvalidToken(string $invalidToken): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -2243,8 +2226,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithoutTokenFail(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[],
$this->requestId,
@@ -2259,8 +2242,8 @@ class RequestTest extends \Test\TestCase {
public function testPassesCSRFCheckWithOCSAPIRequestHeader(): void {
/** @var Request $request */
- $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
- ->setMethods(['getScriptName'])
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
diff --git a/tests/lib/AppFramework/Http/ResponseTest.php b/tests/lib/AppFramework/Http/ResponseTest.php
index 28614b14b40..4c76695f6e4 100644
--- a/tests/lib/AppFramework/Http/ResponseTest.php
+++ b/tests/lib/AppFramework/Http/ResponseTest.php
@@ -9,12 +9,14 @@
namespace Test\AppFramework\Http;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\ContentSecurityPolicy;
+use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Utility\ITimeFactory;
class ResponseTest extends \Test\TestCase {
/**
- * @var \OCP\AppFramework\Http\Response
+ * @var Response
*/
private $childResponse;
@@ -54,7 +56,7 @@ class ResponseTest extends \Test\TestCase {
$expected = [
'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-inline';style-src 'self' 'unsafe-inline';img-src 'self';font-src 'self' data:;connect-src 'self';media-src 'self'",
];
- $policy = new Http\ContentSecurityPolicy();
+ $policy = new ContentSecurityPolicy();
$this->childResponse->setContentSecurityPolicy($policy);
$headers = $this->childResponse->getHeaders();
@@ -63,14 +65,14 @@ class ResponseTest extends \Test\TestCase {
}
public function testGetCsp(): void {
- $policy = new Http\ContentSecurityPolicy();
+ $policy = new ContentSecurityPolicy();
$this->childResponse->setContentSecurityPolicy($policy);
$this->assertEquals($policy, $this->childResponse->getContentSecurityPolicy());
}
public function testGetCspEmpty(): void {
- $this->assertEquals(new Http\EmptyContentSecurityPolicy(), $this->childResponse->getContentSecurityPolicy());
+ $this->assertEquals(new EmptyContentSecurityPolicy(), $this->childResponse->getContentSecurityPolicy());
}
public function testAddHeaderValueNullDeletesIt(): void {
@@ -229,7 +231,7 @@ class ResponseTest extends \Test\TestCase {
$headers = $this->childResponse->getHeaders();
$this->assertEquals('private, max-age=33, must-revalidate', $headers['Cache-Control']);
- $this->assertEquals('Thu, 15 Jan 1970 06:56:40 +0000', $headers['Expires']);
+ $this->assertEquals('Thu, 15 Jan 1970 06:56:40 GMT', $headers['Expires']);
}
@@ -239,7 +241,7 @@ class ResponseTest extends \Test\TestCase {
$lastModified->setTimestamp(1);
$this->childResponse->setLastModified($lastModified);
$headers = $this->childResponse->getHeaders();
- $this->assertEquals('Thu, 01 Jan 1970 00:00:01 +0000', $headers['Last-Modified']);
+ $this->assertEquals('Thu, 01 Jan 1970 00:00:01 GMT', $headers['Last-Modified']);
}
public function testChainability(): void {
@@ -257,7 +259,7 @@ class ResponseTest extends \Test\TestCase {
$this->assertEquals('world', $headers['hello']);
$this->assertEquals(Http::STATUS_NOT_FOUND, $this->childResponse->getStatus());
$this->assertEquals('hi', $this->childResponse->getEtag());
- $this->assertEquals('Thu, 01 Jan 1970 00:00:01 +0000', $headers['Last-Modified']);
+ $this->assertEquals('Thu, 01 Jan 1970 00:00:01 GMT', $headers['Last-Modified']);
$this->assertEquals('private, max-age=33, must-revalidate',
$headers['Cache-Control']);
}
diff --git a/tests/lib/AppFramework/Http/TemplateResponseTest.php b/tests/lib/AppFramework/Http/TemplateResponseTest.php
index ad0fe808b76..28f952e35e3 100644
--- a/tests/lib/AppFramework/Http/TemplateResponseTest.php
+++ b/tests/lib/AppFramework/Http/TemplateResponseTest.php
@@ -13,7 +13,7 @@ use OCP\AppFramework\Http\TemplateResponse;
class TemplateResponseTest extends \Test\TestCase {
/**
- * @var \OCP\AppFramework\Http\TemplateResponse
+ * @var TemplateResponse
*/
private $tpl;