aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/tests/Check
diff options
context:
space:
mode:
Diffstat (limited to 'apps/workflowengine/tests/Check')
-rw-r--r--apps/workflowengine/tests/Check/AbstractStringCheckTest.php117
-rw-r--r--apps/workflowengine/tests/Check/FileMimeTypeTest.php177
-rw-r--r--apps/workflowengine/tests/Check/RequestRemoteAddressTest.php102
-rw-r--r--apps/workflowengine/tests/Check/RequestTimeTest.php126
-rw-r--r--apps/workflowengine/tests/Check/RequestUserAgentTest.php94
5 files changed, 616 insertions, 0 deletions
diff --git a/apps/workflowengine/tests/Check/AbstractStringCheckTest.php b/apps/workflowengine/tests/Check/AbstractStringCheckTest.php
new file mode 100644
index 00000000000..26d4ccb8553
--- /dev/null
+++ b/apps/workflowengine/tests/Check/AbstractStringCheckTest.php
@@ -0,0 +1,117 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\WorkflowEngine\Tests\Check;
+
+use OCA\WorkflowEngine\Check\AbstractStringCheck;
+use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
+
+class AbstractStringCheckTest extends \Test\TestCase {
+ protected function getCheckMock(): AbstractStringCheck|MockObject {
+ $l = $this->getMockBuilder(IL10N::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $l->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($string, $args) {
+ return sprintf($string, $args);
+ });
+
+ $check = $this->getMockBuilder(AbstractStringCheck::class)
+ ->setConstructorArgs([
+ $l,
+ ])
+ ->onlyMethods([
+ 'executeCheck',
+ 'getActualValue',
+ ])
+ ->getMock();
+
+ return $check;
+ }
+
+ public static function dataExecuteStringCheck(): array {
+ return [
+ ['is', 'same', 'same', true],
+ ['is', 'different', 'not the same', false],
+ ['!is', 'same', 'same', false],
+ ['!is', 'different', 'not the same', true],
+
+ ['matches', '/match/', 'match', true],
+ ['matches', '/different/', 'not the same', false],
+ ['!matches', '/match/', 'match', false],
+ ['!matches', '/different/', 'not the same', true],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteStringCheck')]
+ public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
+ $check = $this->getCheckMock();
+
+ /** @var AbstractStringCheck $check */
+ $this->assertEquals($expected, $this->invokePrivate($check, 'executeStringCheck', [$operation, $checkValue, $actualValue]));
+ }
+
+ public static function dataValidateCheck(): array {
+ return [
+ ['is', '/Invalid(Regex/'],
+ ['!is', '/Invalid(Regex/'],
+ ['matches', '/Valid(Regex)/'],
+ ['!matches', '/Valid(Regex)/'],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')]
+ public function testValidateCheck(string $operator, string $value): void {
+ $check = $this->getCheckMock();
+
+ /** @var AbstractStringCheck $check */
+ $check->validateCheck($operator, $value);
+
+ $this->addToAssertionCount(1);
+ }
+
+ public static function dataValidateCheckInvalid(): array {
+ return [
+ ['!!is', '', 1, 'The given operator is invalid'],
+ ['less', '', 1, 'The given operator is invalid'],
+ ['matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'],
+ ['!matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')]
+ public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
+ $check = $this->getCheckMock();
+
+ try {
+ /** @var AbstractStringCheck $check */
+ $check->validateCheck($operator, $value);
+ } catch (\UnexpectedValueException $e) {
+ $this->assertEquals($exceptionCode, $e->getCode());
+ $this->assertEquals($exceptionMessage, $e->getMessage());
+ }
+ }
+
+ public static function dataMatch(): array {
+ return [
+ ['/valid/', 'valid', [], true],
+ ['/valid/', 'valid', [md5('/valid/') => [md5('valid') => false]], false], // Cache hit
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataMatch')]
+ public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void {
+ $check = $this->getCheckMock();
+
+ $this->invokePrivate($check, 'matches', [$matches]);
+
+ $this->assertEquals($expected, $this->invokePrivate($check, 'match', [$pattern, $subject]));
+ }
+}
diff --git a/apps/workflowengine/tests/Check/FileMimeTypeTest.php b/apps/workflowengine/tests/Check/FileMimeTypeTest.php
new file mode 100644
index 00000000000..55aea3db172
--- /dev/null
+++ b/apps/workflowengine/tests/Check/FileMimeTypeTest.php
@@ -0,0 +1,177 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\WorkflowEngine\Tests\Check;
+
+use OC\Files\Storage\Temporary;
+use OCA\WorkflowEngine\Check\FileMimeType;
+use OCP\Files\IMimeTypeDetector;
+use OCP\IL10N;
+use OCP\IRequest;
+use Test\TestCase;
+
+class TemporaryNoLocal extends Temporary {
+ public function instanceOfStorage(string $class): bool {
+ if ($class === '\OC\Files\Storage\Local') {
+ return false;
+ } else {
+ return parent::instanceOfStorage($class);
+ }
+ }
+}
+
+/**
+ * @group DB
+ */
+class FileMimeTypeTest extends TestCase {
+ /** @var IL10N */
+ private $l10n;
+ /** @var IRequest */
+ private $request;
+ /** @var IMimeTypeDetector */
+ private $mimeDetector;
+
+ private $extensions = [
+ '.txt' => 'text/plain-path-detected',
+ ];
+
+ private $content = [
+ 'text-content' => 'text/plain-content-detected',
+ ];
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->request = $this->createMock(IRequest::class);
+ $this->mimeDetector = $this->createMock(IMimeTypeDetector::class);
+ $this->mimeDetector->method('detectPath')
+ ->willReturnCallback(function ($path) {
+ foreach ($this->extensions as $extension => $mime) {
+ if (str_contains($path, $extension)) {
+ return $mime;
+ }
+ }
+ return 'application/octet-stream';
+ });
+ $this->mimeDetector->method('detectContent')
+ ->willReturnCallback(function ($path) {
+ $body = file_get_contents($path);
+ foreach ($this->content as $match => $mime) {
+ if (str_contains($body, $match)) {
+ return $mime;
+ }
+ }
+ return 'application/octet-stream';
+ });
+ }
+
+ public function testUseCachedMimetype(): void {
+ $storage = new Temporary([]);
+ $storage->mkdir('foo');
+ $storage->file_put_contents('foo/bar.txt', 'asd');
+ $storage->getScanner()->scan('');
+
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'foo/bar.txt');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain'));
+ }
+
+ public function testNonCachedNotExists(): void {
+ $storage = new Temporary([]);
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'foo/bar.txt');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain-path-detected'));
+ }
+
+ public function testNonCachedLocal(): void {
+ $storage = new Temporary([]);
+ $storage->mkdir('foo');
+ $storage->file_put_contents('foo/bar.txt', 'text-content');
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'foo/bar.txt');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain-content-detected'));
+ }
+
+ public function testNonCachedNotLocal(): void {
+ $storage = new TemporaryNoLocal([]);
+ $storage->mkdir('foo');
+ $storage->file_put_contents('foo/bar.txt', 'text-content');
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'foo/bar.txt');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain-content-detected'));
+ }
+
+ public function testFallback(): void {
+ $storage = new Temporary([]);
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'unknown');
+
+ $this->assertTrue($check->executeCheck('is', 'application/octet-stream'));
+ }
+
+ public function testFromCacheCached(): void {
+ $storage = new Temporary([]);
+ $storage->mkdir('foo');
+ $storage->file_put_contents('foo/bar.txt', 'text-content');
+ $storage->getScanner()->scan('');
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'foo/bar.txt');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain'));
+
+ $storage->getCache()->clear();
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain'));
+
+ $newCheck = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $newCheck->setFileInfo($storage, 'foo/bar.txt');
+ $this->assertTrue($newCheck->executeCheck('is', 'text/plain-content-detected'));
+ }
+
+ public function testExistsCached(): void {
+ $storage = new TemporaryNoLocal([]);
+ $storage->mkdir('foo');
+ $storage->file_put_contents('foo/bar.txt', 'text-content');
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'foo/bar.txt');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain-content-detected'));
+ $storage->unlink('foo/bar.txt');
+ $this->assertTrue($check->executeCheck('is', 'text/plain-content-detected'));
+
+ $newCheck = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $newCheck->setFileInfo($storage, 'foo/bar.txt');
+ $this->assertTrue($newCheck->executeCheck('is', 'text/plain-path-detected'));
+ }
+
+ public function testNonExistsNotCached(): void {
+ $storage = new TemporaryNoLocal([]);
+
+ $check = new FileMimeType($this->l10n, $this->request, $this->mimeDetector);
+ $check->setFileInfo($storage, 'foo/bar.txt');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain-path-detected'));
+
+ $storage->mkdir('foo');
+ $storage->file_put_contents('foo/bar.txt', 'text-content');
+
+ $this->assertTrue($check->executeCheck('is', 'text/plain-content-detected'));
+ }
+}
diff --git a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php
new file mode 100644
index 00000000000..c0e56daefa8
--- /dev/null
+++ b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php
@@ -0,0 +1,102 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\WorkflowEngine\Tests\Check;
+
+use OCA\WorkflowEngine\Check\RequestRemoteAddress;
+use OCP\IL10N;
+use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
+
+class RequestRemoteAddressTest extends \Test\TestCase {
+
+ protected IRequest&MockObject $request;
+
+ protected function getL10NMock(): IL10N&MockObject {
+ $l = $this->createMock(IL10N::class);
+ $l->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($string, $args) {
+ return sprintf($string, $args);
+ });
+ return $l;
+ }
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ }
+
+ public static function dataExecuteCheckIPv4(): array {
+ return [
+ ['127.0.0.1/32', '127.0.0.1', true],
+ ['127.0.0.1/32', '127.0.0.0', false],
+ ['127.0.0.1/31', '127.0.0.0', true],
+ ['127.0.0.1/32', '127.0.0.2', false],
+ ['127.0.0.1/31', '127.0.0.2', false],
+ ['127.0.0.1/30', '127.0.0.2', true],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')]
+ public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void {
+ $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
+
+ $this->request->expects($this->once())
+ ->method('getRemoteAddress')
+ ->willReturn($ip);
+
+ $this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value));
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')]
+ public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void {
+ $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
+
+ $this->request->expects($this->once())
+ ->method('getRemoteAddress')
+ ->willReturn($ip);
+
+ $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value));
+ }
+
+ public static function dataExecuteCheckIPv6(): array {
+ return [
+ ['::1/128', '::1', true],
+ ['::2/128', '::3', false],
+ ['::2/127', '::3', true],
+ ['::1/128', '::2', false],
+ ['::1/127', '::2', false],
+ ['::1/126', '::2', true],
+ ['1234::1/127', '1234::', true],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')]
+ public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void {
+ $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
+
+ $this->request->expects($this->once())
+ ->method('getRemoteAddress')
+ ->willReturn($ip);
+
+ $this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value));
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')]
+ public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void {
+ $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
+
+ $this->request->expects($this->once())
+ ->method('getRemoteAddress')
+ ->willReturn($ip);
+
+ $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv6', $value));
+ }
+}
diff --git a/apps/workflowengine/tests/Check/RequestTimeTest.php b/apps/workflowengine/tests/Check/RequestTimeTest.php
new file mode 100644
index 00000000000..a8439b8b9f4
--- /dev/null
+++ b/apps/workflowengine/tests/Check/RequestTimeTest.php
@@ -0,0 +1,126 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\WorkflowEngine\Tests\Check;
+
+use OCA\WorkflowEngine\Check\RequestTime;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
+
+class RequestTimeTest extends \Test\TestCase {
+ protected ITimeFactory&MockObject $timeFactory;
+
+ protected function getL10NMock(): IL10N&MockObject {
+ $l = $this->createMock(IL10N::class);
+ $l->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($string, $args) {
+ return sprintf($string, $args);
+ });
+ return $l;
+ }
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ }
+
+ public static function dataExecuteCheck(): array {
+ return [
+ [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false], // 2016-07-07T07:41:45+02:00
+ [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true], // 2016-07-07T08:41:45+02:00
+ [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467902505, true], // 2016-07-07T16:41:45+02:00
+ [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467906105, false], // 2016-07-07T17:41:45+02:00
+ [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467870105, true], // 2016-07-07T07:41:45+02:00
+ [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467873705, false], // 2016-07-07T08:41:45+02:00
+ [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467902505, false], // 2016-07-07T16:41:45+02:00
+ [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467906105, true], // 2016-07-07T17:41:45+02:00
+
+ [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467843105, false], // 2016-07-07T07:41:45+09:30
+ [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467846705, true], // 2016-07-07T08:41:45+09:30
+ [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467875505, true], // 2016-07-07T16:41:45+09:30
+ [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467879105, false], // 2016-07-07T17:41:45+09:30
+ [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467843105, true], // 2016-07-07T07:41:45+09:30
+ [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467846705, false], // 2016-07-07T08:41:45+09:30
+ [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467875505, false], // 2016-07-07T16:41:45+09:30
+ [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467879105, true], // 2016-07-07T17:41:45+09:30
+
+ [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467916905, false], // 2016-07-07T07:41:45-11:00
+ [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467920505, true], // 2016-07-07T08:41:45-11:00
+ [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467949305, true], // 2016-07-07T16:41:45-11:00
+ [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467952905, false], // 2016-07-07T17:41:45-11:00
+ [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467916905, true], // 2016-07-07T07:41:45-11:00
+ [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467920505, false], // 2016-07-07T08:41:45-11:00
+ [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467949305, false], // 2016-07-07T16:41:45-11:00
+ [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467952905, true], // 2016-07-07T17:41:45-11:00
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')]
+ public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void {
+ $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
+
+ $this->timeFactory->expects($this->once())
+ ->method('getTime')
+ ->willReturn($timestamp);
+
+ $this->assertEquals($expected, $check->executeCheck('in', $value));
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')]
+ public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void {
+ $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
+
+ $this->timeFactory->expects($this->once())
+ ->method('getTime')
+ ->willReturn($timestamp);
+
+ $this->assertEquals(!$expected, $check->executeCheck('!in', $value));
+ }
+
+ public static function dataValidateCheck(): array {
+ return [
+ ['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'],
+ ['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'],
+ ['in', '["08:00 America/Port-au-Prince","17:00 America/Argentina/San_Luis"]'],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')]
+ public function testValidateCheck(string $operator, string $value): void {
+ $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
+ $check->validateCheck($operator, $value);
+ $this->addToAssertionCount(1);
+ }
+
+ public static function dataValidateCheckInvalid(): array {
+ return [
+ ['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'],
+ ['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
+ ['in', '["08:00 Europe/Berlin","27:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
+ ['in', '["08:00 Europa/Berlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
+ ['in', '["08:00 Europe/Berlin","17:00 Europa/Berlin"]', 4, 'The given end time is invalid'],
+ ['in', '["08:00 Europe/Bearlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
+ ['in', '["08:00 Europe/Berlin","17:00 Europe/Bearlin"]', 4, 'The given end time is invalid'],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')]
+ public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
+ $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
+
+ try {
+ $check->validateCheck($operator, $value);
+ } catch (\UnexpectedValueException $e) {
+ $this->assertEquals($exceptionCode, $e->getCode());
+ $this->assertEquals($exceptionMessage, $e->getMessage());
+ }
+ }
+}
diff --git a/apps/workflowengine/tests/Check/RequestUserAgentTest.php b/apps/workflowengine/tests/Check/RequestUserAgentTest.php
new file mode 100644
index 00000000000..09eaea6555b
--- /dev/null
+++ b/apps/workflowengine/tests/Check/RequestUserAgentTest.php
@@ -0,0 +1,94 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\WorkflowEngine\Tests\Check;
+
+use OCA\WorkflowEngine\Check\AbstractStringCheck;
+use OCA\WorkflowEngine\Check\RequestUserAgent;
+use OCP\IL10N;
+use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class RequestUserAgentTest extends TestCase {
+ protected IRequest&MockObject $request;
+ protected RequestUserAgent $check;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ /** @var IL10N&MockObject $l */
+ $l = $this->createMock(IL10N::class);
+ $l->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($string, $args) {
+ return sprintf($string, $args);
+ });
+
+ $this->check = new RequestUserAgent($l, $this->request);
+ }
+
+ public static function dataExecuteCheck(): array {
+ return [
+ ['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', 'Filelink for *cloud/2.2.0', false],
+ ['!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', 'Filelink for *cloud/2.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', 'Filelink for *cloud/2.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', 'Filelink for *cloud/2.2.0', true],
+
+ ['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', 'Filelink for *cloud/2.2.0', false],
+ ['!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', 'Filelink for *cloud/2.2.0', true],
+
+ ['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', 'Filelink for *cloud/2.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', 'Filelink for *cloud/2.2.0', false],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')]
+ public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
+ $this->request->expects($this->once())
+ ->method('getHeader')
+ ->willReturn($actualValue);
+
+ /** @var AbstractStringCheck $check */
+ $this->assertEquals($expected, $this->check->executeCheck($operation, $checkValue));
+ }
+}