Skip to content

Commit

Permalink
test: Test file authorization check
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed May 6, 2024
1 parent 669accf commit 27735d1
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tests/lib/TaskProcessing/TaskProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -362,6 +363,7 @@ protected function setUp(): void {
\OC::$server->get(IAppDataFactory::class),
);

$this->shareManager = $this->createMock(\OCP\Share\IManager::class);

$this->manager = new Manager(
$this->coordinator,
Expand All @@ -375,6 +377,7 @@ protected function setUp(): void {
$textProcessingManager,
$text2imageManager,
\OC::$server->get(ISpeechToTextManager::class),
$this->shareManager,
);
}

Expand All @@ -399,7 +402,7 @@ public function testShouldNotHaveAnyProviders() {
$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));
}

Expand All @@ -415,6 +418,26 @@ public function testProviderShouldBeRegisteredAndTaskFailValidation() {
$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)
Expand Down Expand Up @@ -524,11 +547,12 @@ public function testAsyncProviderWithFilesShouldBeRegisteredAndRun() {
$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);
Expand Down Expand Up @@ -606,6 +630,7 @@ public function testOldTasksShouldBeCleanedUp() {
$timeFactory,
$this->taskMapper,
\OC::$server->get(LoggerInterface::class),
\OCP\Server::get(IAppDataFactory::class),
);
$bgJob->setArgument([]);
$bgJob->start($this->jobList);
Expand Down

0 comments on commit 27735d1

Please sign in to comment.