aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/Http/RequestTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/AppFramework/Http/RequestTest.php')
-rw-r--r--tests/lib/AppFramework/Http/RequestTest.php378
1 files changed, 188 insertions, 190 deletions
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php
index 2af5d3ef18a..7ea2cb31482 100644
--- a/tests/lib/AppFramework/Http/RequestTest.php
+++ b/tests/lib/AppFramework/Http/RequestTest.php
@@ -1,14 +1,10 @@
<?php
+
/**
- * @copyright 2013 Thomas Tanghus (thomas@tanghus.net)
- * @copyright 2016 Lukas Reschke lukas@owncloud.com
- * @copyright 2022 Stanimir Bozhilov (stanimir@audriga.com)
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace Test\AppFramework\Http;
use OC\AppFramework\Http\Request;
@@ -52,7 +48,7 @@ class RequestTest extends \Test\TestCase {
parent::tearDown();
}
- public function testRequestAccessors() {
+ public function testRequestAccessors(): void {
$vars = [
'get' => ['name' => 'John Q. Public', 'nickname' => 'Joey'],
'method' => 'GET',
@@ -82,7 +78,7 @@ class RequestTest extends \Test\TestCase {
}
// urlParams has precedence over POST which has precedence over GET
- public function testPrecedence() {
+ public function testPrecedence(): void {
$vars = [
'get' => ['name' => 'John Q. Public', 'nickname' => 'Joey'],
'post' => ['name' => 'Jane Doe', 'nickname' => 'Janey'],
@@ -105,7 +101,7 @@ class RequestTest extends \Test\TestCase {
- public function testImmutableArrayAccess() {
+ public function testImmutableArrayAccess(): void {
$this->expectException(\RuntimeException::class);
$vars = [
@@ -125,7 +121,7 @@ class RequestTest extends \Test\TestCase {
}
- public function testImmutableMagicAccess() {
+ public function testImmutableMagicAccess(): void {
$this->expectException(\RuntimeException::class);
$vars = [
@@ -145,7 +141,7 @@ class RequestTest extends \Test\TestCase {
}
- public function testGetTheMethodRight() {
+ public function testGetTheMethodRight(): void {
$this->expectException(\LogicException::class);
$vars = [
@@ -164,7 +160,7 @@ class RequestTest extends \Test\TestCase {
$request->post;
}
- public function testTheMethodIsRight() {
+ public function testTheMethodIsRight(): void {
$vars = [
'get' => ['name' => 'John Q. Public', 'nickname' => 'Joey'],
'method' => 'GET',
@@ -184,7 +180,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('Joey', $result['nickname']);
}
- public function testJsonPost() {
+ public function testJsonPost(): void {
global $data;
$data = '{"name": "John Q. Public", "nickname": "Joey"}';
$vars = [
@@ -208,7 +204,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('Joey', $request['nickname']);
}
- public function testScimJsonPost() {
+ public function testScimJsonPost(): void {
global $data;
$data = '{"userName":"testusername", "displayName":"Example User"}';
$vars = [
@@ -232,7 +228,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('Example User', $request['displayName']);
}
- public function testCustomJsonPost() {
+ public function testCustomJsonPost(): void {
global $data;
$data = '{"propertyA":"sometestvalue", "propertyB":"someothertestvalue"}';
@@ -256,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"'],
@@ -264,10 +260,8 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider notJsonDataProvider
- */
- public function testNotJsonPost($testData) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataNotJsonData')]
+ public function testNotJsonPost(string $testData): void {
global $data;
$data = $testData;
$vars = [
@@ -288,7 +282,7 @@ class RequestTest extends \Test\TestCase {
// ensure there's no error attempting to decode the content
}
- public function testNotScimJsonPost() {
+ public function testNotScimJsonPost(): void {
global $data;
$data = 'this is not valid scim json';
$vars = [
@@ -309,7 +303,7 @@ class RequestTest extends \Test\TestCase {
// ensure there's no error attempting to decode the content
}
- public function testNotCustomJsonPost() {
+ public function testNotCustomJsonPost(): void {
global $data;
$data = 'this is not valid json';
$vars = [
@@ -330,7 +324,7 @@ class RequestTest extends \Test\TestCase {
// ensure there's no error attempting to decode the content
}
- public function testPatch() {
+ public function testPatch(): void {
global $data;
$data = http_build_query(['name' => 'John Q. Public', 'nickname' => 'Joey'], '', '&');
@@ -354,7 +348,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('Joey', $result['nickname']);
}
- public function testJsonPatchAndPut() {
+ public function testJsonPatchAndPut(): void {
global $data;
// PUT content
@@ -400,7 +394,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame(null, $result['nickname']);
}
- public function testScimJsonPatchAndPut() {
+ public function testScimJsonPatchAndPut(): void {
global $data;
// PUT content
@@ -446,7 +440,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame(null, $result['displayName']);
}
- public function testCustomJsonPatchAndPut() {
+ public function testCustomJsonPatchAndPut(): void {
global $data;
// PUT content
@@ -492,7 +486,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame(null, $result['propertyB']);
}
- public function testPutStream() {
+ public function testPutStream(): void {
global $data;
$data = file_get_contents(__DIR__ . '/../../../data/testimage.png');
@@ -527,7 +521,7 @@ class RequestTest extends \Test\TestCase {
}
- public function testSetUrlParameters() {
+ public function testSetUrlParameters(): void {
$vars = [
'post' => [],
'method' => 'POST',
@@ -549,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' => [
[
@@ -713,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(
[
@@ -741,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'],
@@ -771,12 +756,12 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider httpProtocolProvider
*
* @param mixed $input
* @param string $expected
*/
- public function testGetHttpProtocol($input, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataHttpProtocol')]
+ public function testGetHttpProtocol($input, $expected): void {
$request = new Request(
[
'server' => [
@@ -792,12 +777,32 @@ class RequestTest extends \Test\TestCase {
$this->assertSame($expected, $request->getHttpProtocol());
}
- public function testGetServerProtocolWithOverride() {
+ 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', '', ''],
]);
@@ -809,10 +814,10 @@ class RequestTest extends \Test\TestCase {
$this->stream
);
- $this->assertSame('customProtocol', $request->getServerProtocol());
+ $this->assertSame('http', $request->getServerProtocol());
}
- public function testGetServerProtocolWithProtoValid() {
+ public function testGetServerProtocolWithProtoValid(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -853,7 +858,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('http', $requestHttp->getServerProtocol());
}
- public function testGetServerProtocolWithHttpsServerValueOn() {
+ public function testGetServerProtocolWithHttpsServerValueOn(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -874,7 +879,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('https', $request->getServerProtocol());
}
- public function testGetServerProtocolWithHttpsServerValueOff() {
+ public function testGetServerProtocolWithHttpsServerValueOff(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -895,7 +900,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('http', $request->getServerProtocol());
}
- public function testGetServerProtocolWithHttpsServerValueEmpty() {
+ public function testGetServerProtocolWithHttpsServerValueEmpty(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -916,7 +921,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('http', $request->getServerProtocol());
}
- public function testGetServerProtocolDefault() {
+ public function testGetServerProtocolDefault(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -933,7 +938,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('http', $request->getServerProtocol());
}
- public function testGetServerProtocolBehindLoadBalancers() {
+ public function testGetServerProtocolBehindLoadBalancers(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -961,12 +966,12 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider userAgentProvider
* @param string $testAgent
* @param array $userAgent
* @param bool $matches
*/
- public function testUserAgent($testAgent, $userAgent, $matches) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUserAgent')]
+ public function testUserAgent($testAgent, $userAgent, $matches): void {
$request = new Request(
[
'server' => [
@@ -983,12 +988,12 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider userAgentProvider
* @param string $testAgent
* @param array $userAgent
* @param bool $matches
*/
- public function testUndefinedUserAgent($testAgent, $userAgent, $matches) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUserAgent')]
+ public function testUndefinedUserAgent($testAgent, $userAgent, $matches): void {
$request = new Request(
[],
$this->requestId,
@@ -1000,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)',
@@ -1122,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',
@@ -1160,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',
],
@@ -1168,18 +1170,18 @@ 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);
$this->assertSame($version, $matches[1]);
}
- public function testInsecureServerHostServerNameHeader() {
+ public function testInsecureServerHostServerNameHeader(): void {
$request = new Request(
[
'server' => [
@@ -1195,7 +1197,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('from.server.name:8080', $request->getInsecureServerHost());
}
- public function testInsecureServerHostHttpHostHeader() {
+ public function testInsecureServerHostHttpHostHeader(): void {
$request = new Request(
[
'server' => [
@@ -1212,7 +1214,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('from.host.header:8080', $request->getInsecureServerHost());
}
- public function testInsecureServerHostHttpFromForwardedHeaderSingle() {
+ public function testInsecureServerHostHttpFromForwardedHeaderSingle(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -1241,7 +1243,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('from.forwarded.host:8080', $request->getInsecureServerHost());
}
- public function testInsecureServerHostHttpFromForwardedHeaderStacked() {
+ public function testInsecureServerHostHttpFromForwardedHeaderStacked(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -1270,7 +1272,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('from.forwarded.host2:8080', $request->getInsecureServerHost());
}
- public function testGetServerHostWithOverwriteHost() {
+ public function testGetServerHostWithOverwriteHost(): void {
$this->config
->method('getSystemValueString')
->willReturnCallback(function ($key, $default) {
@@ -1294,7 +1296,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('my.overwritten.host', $request->getServerHost());
}
- public function testGetServerHostWithTrustedDomain() {
+ public function testGetServerHostWithTrustedDomain(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -1323,7 +1325,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('my.trusted.host', $request->getServerHost());
}
- public function testGetServerHostWithUntrustedDomain() {
+ public function testGetServerHostWithUntrustedDomain(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -1352,7 +1354,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('my.trusted.host', $request->getServerHost());
}
- public function testGetServerHostWithNoTrustedDomain() {
+ public function testGetServerHostWithNoTrustedDomain(): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
@@ -1378,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']],
@@ -1390,12 +1389,8 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataGetServerHostTrustedDomain
- * @param $expected
- * @param $trustedDomain
- */
- public function testGetServerHostTrustedDomain($expected, $trustedDomain) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetServerHostTrustedDomain')]
+ public function testGetServerHostTrustedDomain(string $expected, $trustedDomain): void {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($key, $default) use ($trustedDomain) {
@@ -1424,7 +1419,7 @@ class RequestTest extends \Test\TestCase {
$this->assertSame($expected, $request->getServerHost());
}
- public function testGetOverwriteHostDefaultNull() {
+ public function testGetOverwriteHostDefaultNull(): void {
$this->config
->expects($this->once())
->method('getSystemValueString')
@@ -1441,7 +1436,7 @@ class RequestTest extends \Test\TestCase {
$this->assertNull(self::invokePrivate($request, 'getOverwriteHost'));
}
- public function testGetOverwriteHostWithOverwrite() {
+ public function testGetOverwriteHostWithOverwrite(): void {
$this->config
->expects($this->exactly(3))
->method('getSystemValueString')
@@ -1462,7 +1457,7 @@ class RequestTest extends \Test\TestCase {
}
- public function testGetPathInfoNotProcessible() {
+ public function testGetPathInfoNotProcessible(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The requested uri(/foo.php) cannot be processed by the script \'/var/www/index.php\')');
@@ -1483,7 +1478,7 @@ class RequestTest extends \Test\TestCase {
}
- public function testGetRawPathInfoNotProcessible() {
+ public function testGetRawPathInfoNotProcessible(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The requested uri(/foo.php) cannot be processed by the script \'/var/www/index.php\')');
@@ -1504,12 +1499,12 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider genericPathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
- public function testGetPathInfoWithoutSetEnvGeneric($requestUri, $scriptName, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGenericPathInfo')]
+ public function testGetPathInfoWithoutSetEnvGeneric($requestUri, $scriptName, $expected): void {
$request = new Request(
[
'server' => [
@@ -1527,12 +1522,12 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider genericPathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
- public function testGetRawPathInfoWithoutSetEnvGeneric($requestUri, $scriptName, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGenericPathInfo')]
+ public function testGetRawPathInfoWithoutSetEnvGeneric($requestUri, $scriptName, $expected): void {
$request = new Request(
[
'server' => [
@@ -1550,12 +1545,12 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider rawPathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
- public function testGetRawPathInfoWithoutSetEnv($requestUri, $scriptName, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRawPathInfo')]
+ public function testGetRawPathInfoWithoutSetEnv($requestUri, $scriptName, $expected): void {
$request = new Request(
[
'server' => [
@@ -1573,12 +1568,12 @@ class RequestTest extends \Test\TestCase {
}
/**
- * @dataProvider pathInfoProvider
* @param string $requestUri
* @param string $scriptName
* @param string $expected
*/
- public function testGetPathInfoWithoutSetEnv($requestUri, $scriptName, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataPathInfo')]
+ public function testGetPathInfoWithoutSetEnv($requestUri, $scriptName, $expected): void {
$request = new Request(
[
'server' => [
@@ -1595,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/'],
@@ -1610,25 +1602,19 @@ 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'],
];
}
- public function testGetRequestUriWithoutOverwrite() {
+ public function testGetRequestUriWithoutOverwrite(): void {
$this->config
->expects($this->once())
->method('getSystemValueString')
@@ -1650,17 +1636,15 @@ 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
- */
- public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr, $remoteAddr = '') {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetRequestUriWithOverwrite')]
+ public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr, $remoteAddr = ''): void {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
@@ -1670,7 +1654,7 @@ class RequestTest extends \Test\TestCase {
]);
$request = $this->getMockBuilder(Request::class)
- ->setMethods(['getScriptName'])
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[
'server' => [
@@ -1693,10 +1677,10 @@ class RequestTest extends \Test\TestCase {
$this->assertSame($expectedUri, $request->getRequestUri());
}
- public function testPassesCSRFCheckWithGet() {
+ 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' => [
@@ -1723,10 +1707,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesCSRFCheck());
}
- public function testPassesCSRFCheckWithPost() {
+ 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' => [
@@ -1753,10 +1737,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesCSRFCheck());
}
- public function testPassesCSRFCheckWithHeader() {
+ 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' => [
@@ -1783,10 +1767,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesCSRFCheck());
}
- public function testPassesCSRFCheckWithGetAndWithoutCookies() {
+ 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' => [
@@ -1807,10 +1791,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesCSRFCheck());
}
- public function testPassesCSRFCheckWithPostAndWithoutCookies() {
+ 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' => [
@@ -1831,10 +1815,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesCSRFCheck());
}
- public function testPassesCSRFCheckWithHeaderAndWithoutCookies() {
+ 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' => [
@@ -1855,10 +1839,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesCSRFCheck());
}
- public function testFailsCSRFCheckWithHeaderAndNotAllChecksPassing() {
+ 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' => [
@@ -1882,10 +1866,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesCSRFCheck());
}
- public function testPassesStrictCookieCheckWithAllCookiesAndStrict() {
+ 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' => [
@@ -1914,10 +1898,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesStrictCookieCheck());
}
- public function testFailsStrictCookieCheckWithAllCookiesAndMissingStrict() {
+ 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' => [
@@ -1946,10 +1930,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesStrictCookieCheck());
}
- public function testGetCookieParams() {
+ public function testGetCookieParams(): void {
/** @var Request $request */
$request = $this->getMockBuilder(Request::class)
- ->setMethods(['getScriptName'])
+ ->onlyMethods(['getScriptName'])
->setConstructorArgs([
[],
$this->requestId,
@@ -1962,10 +1946,10 @@ class RequestTest extends \Test\TestCase {
$this->assertSame(session_get_cookie_params(), $actual);
}
- public function testPassesStrictCookieCheckWithAllCookies() {
+ 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' => [
@@ -1987,10 +1971,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesStrictCookieCheck());
}
- public function testPassesStrictCookieCheckWithRandomCookies() {
+ 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' => [
@@ -2010,10 +1994,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesStrictCookieCheck());
}
- public function testFailsStrictCookieCheckWithSessionCookie() {
+ 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' => [
@@ -2033,10 +2017,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesStrictCookieCheck());
}
- public function testFailsStrictCookieCheckWithRememberMeCookie() {
+ 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' => [
@@ -2056,10 +2040,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesStrictCookieCheck());
}
- public function testFailsCSRFCheckWithPostAndWithCookies() {
+ 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' => [
@@ -2083,10 +2067,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesCSRFCheck());
}
- public function testFailStrictCookieCheckWithOnlyLaxCookie() {
+ 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' => [
@@ -2107,10 +2091,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesStrictCookieCheck());
}
- public function testFailStrictCookieCheckWithOnlyStrictCookie() {
+ 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' => [
@@ -2131,10 +2115,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesStrictCookieCheck());
}
- public function testPassesLaxCookieCheck() {
+ 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' => [
@@ -2155,10 +2139,10 @@ class RequestTest extends \Test\TestCase {
$this->assertTrue($request->passesLaxCookieCheck());
}
- public function testFailsLaxCookieCheckWithOnlyStrictCookie() {
+ 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' => [
@@ -2179,10 +2163,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesLaxCookieCheck());
}
- public function testSkipCookieCheckForOCSRequests() {
+ 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' => [
@@ -2204,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'],
@@ -2215,14 +2196,11 @@ class RequestTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider invalidTokenDataProvider
- * @param string $invalidToken
- */
- public function testPassesCSRFCheckWithInvalidToken($invalidToken) {
+ #[\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' => [
@@ -2246,10 +2224,10 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesCSRFCheck());
}
- public function testPassesCSRFCheckWithoutTokenFail() {
+ 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,
@@ -2261,4 +2239,24 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesCSRFCheck());
}
+
+ public function testPassesCSRFCheckWithOCSAPIRequestHeader(): void {
+ /** @var Request $request */
+ $request = $this->getMockBuilder(Request::class)
+ ->onlyMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_OCS_APIREQUEST' => 'true',
+ ],
+ ],
+ $this->requestId,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+
+ $this->assertTrue($request->passesCSRFCheck());
+ }
}