aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-07-11 11:36:54 +0200
committerGitHub <noreply@github.com>2023-07-11 11:36:54 +0200
commite285d72c10924999e1243ef0482498f32d6443c2 (patch)
treec951e01355497af5a3f93fef844431d694f3e601 /apps
parent12ee2581aa943da93054f7839fecc8f83eb3cee1 (diff)
parent33913ebc344f84de88b3e58accc137801e90edb4 (diff)
downloadnextcloud-server-e285d72c10924999e1243ef0482498f32d6443c2.tar.gz
nextcloud-server-e285d72c10924999e1243ef0482498f32d6443c2.zip
Merge pull request #38561 from nextcloud/feat/noid/allow-to-match-client-versions-with-regex
feat(request): Allow to match the client version with the IRequest::U…
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php6
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/AuthTest.php20
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php47
-rw-r--r--apps/workflowengine/tests/Check/RequestUserAgentTest.php32
4 files changed, 36 insertions, 69 deletions
diff --git a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php
index 257068b9576..5d3f7104d6a 100644
--- a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php
@@ -26,6 +26,7 @@
namespace OCA\DAV\Connector\Sabre;
use OCP\IConfig;
+use OCP\IRequest;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\DAV\Server;
@@ -65,10 +66,7 @@ class BlockLegacyClientPlugin extends ServerPlugin {
}
$minimumSupportedDesktopVersion = $this->config->getSystemValue('minimum.supported.desktop.version', '2.3.0');
-
- // Match on the mirall version which is in scheme "Mozilla/5.0 (%1) mirall/%2" or
- // "mirall/%1" for older releases
- preg_match("/(?:mirall\\/)([\d.]+)/i", $userAgent, $versionMatches);
+ preg_match(IRequest::USER_AGENT_CLIENT_DESKTOP, $userAgent, $versionMatches);
if (isset($versionMatches[1]) &&
version_compare($versionMatches[1], $minimumSupportedDesktopVersion) === -1) {
throw new \Sabre\DAV\Exception\Forbidden('Unsupported client version.');
diff --git a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
index be841295f0b..b3b3341240a 100644
--- a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
@@ -301,11 +301,6 @@ class AuthTest extends TestCase {
$this->request
->expects($this->any())
->method('isUserAgent')
- ->with([
- '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/',
- '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/',
- '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/',
- ])
->willReturn(false);
$this->session
->expects($this->any())
@@ -351,11 +346,6 @@ class AuthTest extends TestCase {
$this->request
->expects($this->any())
->method('isUserAgent')
- ->with([
- '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/',
- '/^Mozilla\/5\.0 \(Android\) ownCloud\-android.*$/',
- '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/',
- ])
->willReturn(false);
$this->session
->expects($this->any())
@@ -405,11 +395,6 @@ class AuthTest extends TestCase {
$this->request
->expects($this->any())
->method('isUserAgent')
- ->with([
- '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/',
- '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/',
- '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/',
- ])
->willReturn(false);
$this->session
->expects($this->any())
@@ -451,11 +436,6 @@ class AuthTest extends TestCase {
$this->request
->expects($this->any())
->method('isUserAgent')
- ->with([
- '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/',
- '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/',
- '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/',
- ])
->willReturn(true);
$this->session
->expects($this->any())
diff --git a/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php
index e0a274321f0..616e9796ab4 100644
--- a/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -28,7 +30,9 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
+use Sabre\HTTP\RequestInterface;
/**
* Class BlockLegacyClientPluginTest
@@ -36,7 +40,7 @@ use Test\TestCase;
* @package OCA\DAV\Tests\unit\Connector\Sabre
*/
class BlockLegacyClientPluginTest extends TestCase {
- /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
private $config;
/** @var BlockLegacyClientPlugin */
private $blockLegacyClientVersionPlugin;
@@ -44,34 +48,25 @@ class BlockLegacyClientPluginTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->config = $this->createMock(IConfig::class);
$this->blockLegacyClientVersionPlugin = new BlockLegacyClientPlugin($this->config);
}
- /**
- * @return array
- */
- public function oldDesktopClientProvider() {
+ public function oldDesktopClientProvider(): array {
return [
- ['Mozilla/5.0 (1.5.0) mirall/1.5.0'],
- ['mirall/1.5.0'],
- ['mirall/1.5.4'],
- ['mirall/1.6.0'],
+ ['Mozilla/5.0 (Windows) mirall/1.5.0'],
['Mozilla/5.0 (Bogus Text) mirall/1.6.9'],
];
}
/**
* @dataProvider oldDesktopClientProvider
- * @param string $userAgent
*/
- public function testBeforeHandlerException($userAgent): void {
+ public function testBeforeHandlerException(string $userAgent): void {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
$this->expectExceptionMessage('Unsupported client version.');
- /** @var \Sabre\HTTP\RequestInterface | \PHPUnit\Framework\MockObject\MockObject $request */
+ /** @var RequestInterface|MockObject $request */
$request = $this->createMock('\Sabre\HTTP\RequestInterface');
$request
->expects($this->once())
@@ -88,26 +83,20 @@ class BlockLegacyClientPluginTest extends TestCase {
$this->blockLegacyClientVersionPlugin->beforeHandler($request);
}
- /**
- * @return array
- */
- public function newAndAlternateDesktopClientProvider() {
+ public function newAndAlternateDesktopClientProvider(): array {
return [
- ['Mozilla/5.0 (1.7.0) mirall/1.7.0'],
- ['mirall/1.8.3'],
- ['mirall/1.7.2'],
- ['mirall/1.7.0'],
+ ['Mozilla/5.0 (Windows) mirall/1.7.0'],
['Mozilla/5.0 (Bogus Text) mirall/1.9.3'],
+ ['Mozilla/5.0 (Not Our Client But Old Version) LegacySync/1.1.0'],
];
}
/**
* @dataProvider newAndAlternateDesktopClientProvider
- * @param string $userAgent
*/
- public function testBeforeHandlerSuccess($userAgent): void {
- /** @var \Sabre\HTTP\RequestInterface | \PHPUnit\Framework\MockObject\MockObject $request */
- $request = $this->createMock('\Sabre\HTTP\RequestInterface');
+ public function testBeforeHandlerSuccess(string $userAgent): void {
+ /** @var RequestInterface|MockObject $request */
+ $request = $this->createMock(RequestInterface::class);
$request
->expects($this->once())
->method('getHeader')
@@ -124,8 +113,8 @@ class BlockLegacyClientPluginTest extends TestCase {
}
public function testBeforeHandlerNoUserAgent(): void {
- /** @var \Sabre\HTTP\RequestInterface | \PHPUnit\Framework\MockObject\MockObject $request */
- $request = $this->createMock('\Sabre\HTTP\RequestInterface');
+ /** @var RequestInterface|MockObject $request */
+ $request = $this->createMock(RequestInterface::class);
$request
->expects($this->once())
->method('getHeader')
diff --git a/apps/workflowengine/tests/Check/RequestUserAgentTest.php b/apps/workflowengine/tests/Check/RequestUserAgentTest.php
index 3111b4ffc8e..dbf52a112cb 100644
--- a/apps/workflowengine/tests/Check/RequestUserAgentTest.php
+++ b/apps/workflowengine/tests/Check/RequestUserAgentTest.php
@@ -57,46 +57,46 @@ class RequestUserAgentTest extends TestCase {
public function dataExecuteCheck() {
return [
- ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', true],
- ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', false],
+ ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
+ ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
['is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
['is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
['is', 'android', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
- ['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', false],
- ['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', true],
+ ['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
+ ['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
['!is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
['!is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
['!is', 'android', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
- ['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', false],
- ['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', true],
+ ['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
+ ['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
['is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
['is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
['is', 'ios', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
- ['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', true],
- ['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', false],
+ ['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
+ ['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
['!is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
['!is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
['!is', 'ios', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
- ['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', false],
- ['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', false],
+ ['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
+ ['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
['is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
['is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
['is', 'desktop', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],
- ['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', true],
- ['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', true],
+ ['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
+ ['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
['!is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
['!is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
['!is', 'desktop', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
- ['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', false],
- ['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', false],
+ ['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
+ ['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
['is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
['is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
['is', 'mail', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', true],
- ['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android v2.2.0', true],
- ['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS v2.2.0', true],
+ ['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
+ ['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
['!is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
['!is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
['!is', 'mail', 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v2.2.0', false],