aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-05-31 17:02:36 +0200
committerJoas Schilling <coding@schilljs.com>2023-07-11 07:35:50 +0200
commit2c6f32cb28416a59084ac3069d06b3fb241fa02c (patch)
tree39def21e834829568952911f888ab1706c289c90
parentde3b6a2219c933388c39f07faedc39cd76abd472 (diff)
downloadnextcloud-server-2c6f32cb28416a59084ac3069d06b3fb241fa02c.tar.gz
nextcloud-server-2c6f32cb28416a59084ac3069d06b3fb241fa02c.zip
feat(request): Allow to match the client version with the IRequest::USER_AGENT_* regex
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/public/IRequest.php24
-rw-r--r--tests/lib/AppFramework/Http/RequestTest.php57
2 files changed, 73 insertions, 8 deletions
diff --git a/lib/public/IRequest.php b/lib/public/IRequest.php
index 93f065500cb..bc1f88504a8 100644
--- a/lib/public/IRequest.php
+++ b/lib/public/IRequest.php
@@ -64,43 +64,51 @@ namespace OCP;
interface IRequest {
/**
* @since 9.1.0
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_CLIENT_ANDROID = '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/';
+ public const USER_AGENT_CLIENT_ANDROID = '/^Mozilla\/5\.0 \(Android\) (?:ownCloud|Nextcloud)\-android\/([^ ]*).*$/';
/**
* @since 13.0.0
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_TALK_ANDROID = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v.*$/';
+ public const USER_AGENT_TALK_ANDROID = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v([^ ]*).*$/';
/**
* @since 9.1.0
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/';
+ public const USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (?:mirall|csyncoC)\/([^ ]*).*$/';
/**
* @since 26.0.0
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_TALK_DESKTOP = '/^Mozilla\/5\.0 \((?!Android|iOS)[A-Za-z ]+\) Nextcloud\-Talk v.*$/';
+ public const USER_AGENT_TALK_DESKTOP = '/^Mozilla\/5\.0 \((?!Android|iOS)[A-Za-z ]+\) Nextcloud\-Talk v([^ ]*).*$/';
/**
* @since 9.1.0
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/';
+ public const USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (?:ownCloud|Nextcloud)\-iOS\/([^ ]*).*$/';
/**
* @since 13.0.0
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_TALK_IOS = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v.*$/';
+ public const USER_AGENT_TALK_IOS = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v([^ ]*).*$/';
/**
* @since 13.0.1
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_OUTLOOK_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v.*$/';
+ public const USER_AGENT_OUTLOOK_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v([^ ]*).*$/';
/**
* @since 13.0.1
+ * @since 28.0.0 The regex has a group matching the version number
*/
- public const USER_AGENT_THUNDERBIRD_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v.*$/';
+ public const USER_AGENT_THUNDERBIRD_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v([^ ]*).*$/';
/**
* @since 26.0.0
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php
index 839c7ad4338..0ce2e283bb5 100644
--- a/tests/lib/AppFramework/Http/RequestTest.php
+++ b/tests/lib/AppFramework/Http/RequestTest.php
@@ -1265,6 +1265,63 @@ class RequestTest extends \Test\TestCase {
];
}
+ public function dataMatchClientVersion(): array {
+ return [
+ [
+ 'Mozilla/5.0 (Android) Nextcloud-android/3.24.1',
+ Request::USER_AGENT_CLIENT_ANDROID,
+ '3.24.1',
+ ],
+ [
+ 'Mozilla/5.0 (iOS) Nextcloud-iOS/4.8.2',
+ Request::USER_AGENT_CLIENT_IOS,
+ '4.8.2',
+ ],
+ [
+ 'Mozilla/5.0 (Windows) mirall/3.8.1',
+ Request::USER_AGENT_CLIENT_DESKTOP,
+ '3.8.1',
+ ],
+ [
+ 'Mozilla/5.0 (Android) Nextcloud-Talk v17.10.0',
+ Request::USER_AGENT_TALK_ANDROID,
+ '17.10.0',
+ ],
+ [
+ 'Mozilla/5.0 (iOS) Nextcloud-Talk v17.0.1',
+ Request::USER_AGENT_TALK_IOS,
+ '17.0.1',
+ ],
+ [
+ 'Mozilla/5.0 (Windows) Nextcloud-Talk v0.6.0',
+ Request::USER_AGENT_TALK_DESKTOP,
+ '0.6.0',
+ ],
+ [
+ 'Mozilla/5.0 (Windows) Nextcloud-Outlook v1.0.0',
+ Request::USER_AGENT_OUTLOOK_ADDON,
+ '1.0.0',
+ ],
+ [
+ 'Mozilla/5.0 (Linux) Nextcloud-Thunderbird v1.0.0',
+ Request::USER_AGENT_THUNDERBIRD_ADDON,
+ '1.0.0',
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataMatchClientVersion
+ * @param string $testAgent
+ * @param string $userAgent
+ * @param string $version
+ */
+ public function testMatchClientVersion(string $testAgent, string $userAgent, string $version): void {
+ preg_match($userAgent, $testAgent, $matches);
+
+ $this->assertSame($version, $matches[1]);
+ }
+
public function testInsecureServerHostServerNameHeader() {
$request = new Request(
[