diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-05-06 10:22:59 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2024-05-14 11:38:40 +0200 |
commit | ef44af1f4804c6dffa9c2565431ab6973d6d7270 (patch) | |
tree | 20cfa1feab530737f0d17e1e9685671a7a90a156 /tests | |
parent | 6203c1c7da21041717e0ec2ecb3ba7f957822c74 (diff) | |
download | nextcloud-server-ef44af1f4804c6dffa9c2565431ab6973d6d7270.tar.gz nextcloud-server-ef44af1f4804c6dffa9c2565431ab6973d6d7270.zip |
test: Test file authorization check
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/TaskProcessing/TaskProcessingTest.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php index 5be43314d3e..596f831cde4 100644 --- a/tests/lib/TaskProcessing/TaskProcessingTest.php +++ b/tests/lib/TaskProcessing/TaskProcessingTest.php @@ -31,6 +31,7 @@ use OCP\TaskProcessing\Events\TaskFailedEvent; use OCP\TaskProcessing\Events\TaskSuccessfulEvent; use OCP\TaskProcessing\Exception\NotFoundException; use OCP\TaskProcessing\Exception\ProcessingException; +use OCP\TaskProcessing\Exception\UnauthorizedException; use OCP\TaskProcessing\Exception\ValidationException; use OCP\TaskProcessing\IManager; use OCP\TaskProcessing\IProvider; @@ -362,6 +363,7 @@ class TaskProcessingTest extends \Test\TestCase { \OC::$server->get(IAppDataFactory::class), ); + $this->shareManager = $this->createMock(\OCP\Share\IManager::class); $this->manager = new Manager( $this->coordinator, @@ -375,6 +377,7 @@ class TaskProcessingTest extends \Test\TestCase { $textProcessingManager, $text2imageManager, \OC::$server->get(ISpeechToTextManager::class), + $this->shareManager, ); } @@ -399,7 +402,7 @@ class TaskProcessingTest extends \Test\TestCase { $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([]); self::assertCount(0, $this->manager->getAvailableTaskTypes()); self::assertFalse($this->manager->hasProviders()); - self::expectException(PreConditionNotMetException::class); + self::expectException(\OCP\TaskProcessing\Exception\PreConditionNotMetException::class); $this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null)); } @@ -415,6 +418,26 @@ class TaskProcessingTest extends \Test\TestCase { $this->manager->scheduleTask($task); } + public function testProviderShouldBeRegisteredAndTaskWithFilesFailValidation() { + $this->shareManager->expects($this->any())->method('getAccessList')->willReturn(['users' => []]); + $this->registrationContext->expects($this->any())->method('getTaskProcessingTaskTypes')->willReturn([ + new ServiceRegistration('test', AudioToImage::class) + ]); + $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([ + new ServiceRegistration('test', AsyncProvider::class) + ]); + $this->shareManager->expects($this->any())->method('getAccessList')->willReturn(['users' => [null]]); + self::assertCount(1, $this->manager->getAvailableTaskTypes()); + + self::assertTrue($this->manager->hasProviders()); + $audioId = $this->getFile('audioInput', 'Hello')->getId(); + $task = new Task(AudioToImage::ID, ['audio' => $audioId], 'test', null); + self::assertNull($task->getId()); + self::assertEquals(Task::STATUS_UNKNOWN, $task->getStatus()); + self::expectException(UnauthorizedException::class); + $this->manager->scheduleTask($task); + } + public function testProviderShouldBeRegisteredAndFail() { $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([ new ServiceRegistration('test', FailingSyncProvider::class) @@ -524,11 +547,12 @@ class TaskProcessingTest extends \Test\TestCase { $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([ new ServiceRegistration('test', AsyncProvider::class) ]); + $this->shareManager->expects($this->any())->method('getAccessList')->willReturn(['users' => ['testuser' => 1]]); self::assertCount(1, $this->manager->getAvailableTaskTypes()); self::assertTrue($this->manager->hasProviders()); $audioId = $this->getFile('audioInput', 'Hello')->getId(); - $task = new Task(AudioToImage::ID, ['audio' => $audioId], 'test', null); + $task = new Task(AudioToImage::ID, ['audio' => $audioId], 'test', 'testuser'); self::assertNull($task->getId()); self::assertEquals(Task::STATUS_UNKNOWN, $task->getStatus()); $this->manager->scheduleTask($task); @@ -606,6 +630,7 @@ class TaskProcessingTest extends \Test\TestCase { $timeFactory, $this->taskMapper, \OC::$server->get(LoggerInterface::class), + \OCP\Server::get(IAppDataFactory::class), ); $bgJob->setArgument([]); $bgJob->start($this->jobList); |