@@ -27,92 +27,92 @@ |
||
27 | 27 | */ |
28 | 28 | class CalendarMigratorTest extends TestCase { |
29 | 29 | |
30 | - private IUserManager $userManager; |
|
31 | - |
|
32 | - private CalendarMigrator $migrator; |
|
33 | - |
|
34 | - private OutputInterface $output; |
|
35 | - |
|
36 | - private const ASSETS_DIR = __DIR__ . '/assets/calendars/'; |
|
37 | - |
|
38 | - protected function setUp(): void { |
|
39 | - $app = new App(Application::APP_ID); |
|
40 | - $container = $app->getContainer(); |
|
41 | - |
|
42 | - $this->userManager = $container->get(IUserManager::class); |
|
43 | - $this->migrator = $container->get(CalendarMigrator::class); |
|
44 | - $this->output = $this->createMock(OutputInterface::class); |
|
45 | - } |
|
46 | - |
|
47 | - public static function dataAssets(): array { |
|
48 | - return array_map( |
|
49 | - function (string $filename) { |
|
50 | - /** @var VCalendar $vCalendar */ |
|
51 | - $vCalendar = VObjectReader::read( |
|
52 | - fopen(self::ASSETS_DIR . $filename, 'r'), |
|
53 | - VObjectReader::OPTION_FORGIVING, |
|
54 | - ); |
|
55 | - [$initialCalendarUri, $ext] = explode('.', $filename, 2); |
|
56 | - return [UUIDUtil::getUUID(), $filename, $initialCalendarUri, $vCalendar]; |
|
57 | - }, |
|
58 | - array_diff( |
|
59 | - scandir(self::ASSETS_DIR), |
|
60 | - // Exclude current and parent directories |
|
61 | - ['.', '..'], |
|
62 | - ), |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - private function getProperties(VCalendar $vCalendar): array { |
|
67 | - return array_map( |
|
68 | - fn (VObjectProperty $property) => $property->serialize(), |
|
69 | - array_values(array_filter( |
|
70 | - $vCalendar->children(), |
|
71 | - fn ($child) => $child instanceof VObjectProperty, |
|
72 | - )), |
|
73 | - ); |
|
74 | - } |
|
75 | - |
|
76 | - private function getComponents(VCalendar $vCalendar): array { |
|
77 | - return array_map( |
|
78 | - // Elements of the serialized blob are sorted |
|
79 | - fn (VObjectComponent $component) => $component->serialize(), |
|
80 | - $vCalendar->getComponents(), |
|
81 | - ); |
|
82 | - } |
|
83 | - |
|
84 | - private function getSanitizedComponents(VCalendar $vCalendar): array { |
|
85 | - return array_map( |
|
86 | - // Elements of the serialized blob are sorted |
|
87 | - fn (VObjectComponent $component) => $this->invokePrivate($this->migrator, 'sanitizeComponent', [$component])->serialize(), |
|
88 | - $vCalendar->getComponents(), |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataAssets')] |
|
93 | - public function testImportExportAsset(string $userId, string $filename, string $initialCalendarUri, VCalendar $importCalendar): void { |
|
94 | - $user = $this->userManager->createUser($userId, 'topsecretpassword'); |
|
95 | - |
|
96 | - $problems = $importCalendar->validate(); |
|
97 | - $this->assertEmpty($problems); |
|
98 | - |
|
99 | - $this->invokePrivate($this->migrator, 'importCalendar', [$user, $filename, $initialCalendarUri, $importCalendar, $this->output]); |
|
100 | - |
|
101 | - $calendarExports = $this->invokePrivate($this->migrator, 'getCalendarExports', [$user, $this->output]); |
|
102 | - $this->assertCount(1, $calendarExports); |
|
103 | - |
|
104 | - /** @var VCalendar $exportCalendar */ |
|
105 | - ['vCalendar' => $exportCalendar] = reset($calendarExports); |
|
106 | - |
|
107 | - $this->assertEqualsCanonicalizing( |
|
108 | - $this->getProperties($importCalendar), |
|
109 | - $this->getProperties($exportCalendar), |
|
110 | - ); |
|
111 | - |
|
112 | - $this->assertEqualsCanonicalizing( |
|
113 | - // Components are expected to be sanitized on import |
|
114 | - $this->getSanitizedComponents($importCalendar), |
|
115 | - $this->getComponents($exportCalendar), |
|
116 | - ); |
|
117 | - } |
|
30 | + private IUserManager $userManager; |
|
31 | + |
|
32 | + private CalendarMigrator $migrator; |
|
33 | + |
|
34 | + private OutputInterface $output; |
|
35 | + |
|
36 | + private const ASSETS_DIR = __DIR__ . '/assets/calendars/'; |
|
37 | + |
|
38 | + protected function setUp(): void { |
|
39 | + $app = new App(Application::APP_ID); |
|
40 | + $container = $app->getContainer(); |
|
41 | + |
|
42 | + $this->userManager = $container->get(IUserManager::class); |
|
43 | + $this->migrator = $container->get(CalendarMigrator::class); |
|
44 | + $this->output = $this->createMock(OutputInterface::class); |
|
45 | + } |
|
46 | + |
|
47 | + public static function dataAssets(): array { |
|
48 | + return array_map( |
|
49 | + function (string $filename) { |
|
50 | + /** @var VCalendar $vCalendar */ |
|
51 | + $vCalendar = VObjectReader::read( |
|
52 | + fopen(self::ASSETS_DIR . $filename, 'r'), |
|
53 | + VObjectReader::OPTION_FORGIVING, |
|
54 | + ); |
|
55 | + [$initialCalendarUri, $ext] = explode('.', $filename, 2); |
|
56 | + return [UUIDUtil::getUUID(), $filename, $initialCalendarUri, $vCalendar]; |
|
57 | + }, |
|
58 | + array_diff( |
|
59 | + scandir(self::ASSETS_DIR), |
|
60 | + // Exclude current and parent directories |
|
61 | + ['.', '..'], |
|
62 | + ), |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + private function getProperties(VCalendar $vCalendar): array { |
|
67 | + return array_map( |
|
68 | + fn (VObjectProperty $property) => $property->serialize(), |
|
69 | + array_values(array_filter( |
|
70 | + $vCalendar->children(), |
|
71 | + fn ($child) => $child instanceof VObjectProperty, |
|
72 | + )), |
|
73 | + ); |
|
74 | + } |
|
75 | + |
|
76 | + private function getComponents(VCalendar $vCalendar): array { |
|
77 | + return array_map( |
|
78 | + // Elements of the serialized blob are sorted |
|
79 | + fn (VObjectComponent $component) => $component->serialize(), |
|
80 | + $vCalendar->getComponents(), |
|
81 | + ); |
|
82 | + } |
|
83 | + |
|
84 | + private function getSanitizedComponents(VCalendar $vCalendar): array { |
|
85 | + return array_map( |
|
86 | + // Elements of the serialized blob are sorted |
|
87 | + fn (VObjectComponent $component) => $this->invokePrivate($this->migrator, 'sanitizeComponent', [$component])->serialize(), |
|
88 | + $vCalendar->getComponents(), |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataAssets')] |
|
93 | + public function testImportExportAsset(string $userId, string $filename, string $initialCalendarUri, VCalendar $importCalendar): void { |
|
94 | + $user = $this->userManager->createUser($userId, 'topsecretpassword'); |
|
95 | + |
|
96 | + $problems = $importCalendar->validate(); |
|
97 | + $this->assertEmpty($problems); |
|
98 | + |
|
99 | + $this->invokePrivate($this->migrator, 'importCalendar', [$user, $filename, $initialCalendarUri, $importCalendar, $this->output]); |
|
100 | + |
|
101 | + $calendarExports = $this->invokePrivate($this->migrator, 'getCalendarExports', [$user, $this->output]); |
|
102 | + $this->assertCount(1, $calendarExports); |
|
103 | + |
|
104 | + /** @var VCalendar $exportCalendar */ |
|
105 | + ['vCalendar' => $exportCalendar] = reset($calendarExports); |
|
106 | + |
|
107 | + $this->assertEqualsCanonicalizing( |
|
108 | + $this->getProperties($importCalendar), |
|
109 | + $this->getProperties($exportCalendar), |
|
110 | + ); |
|
111 | + |
|
112 | + $this->assertEqualsCanonicalizing( |
|
113 | + // Components are expected to be sanitized on import |
|
114 | + $this->getSanitizedComponents($importCalendar), |
|
115 | + $this->getComponents($exportCalendar), |
|
116 | + ); |
|
117 | + } |
|
118 | 118 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | private OutputInterface $output; |
35 | 35 | |
36 | - private const ASSETS_DIR = __DIR__ . '/assets/calendars/'; |
|
36 | + private const ASSETS_DIR = __DIR__.'/assets/calendars/'; |
|
37 | 37 | |
38 | 38 | protected function setUp(): void { |
39 | 39 | $app = new App(Application::APP_ID); |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | |
47 | 47 | public static function dataAssets(): array { |
48 | 48 | return array_map( |
49 | - function (string $filename) { |
|
49 | + function(string $filename) { |
|
50 | 50 | /** @var VCalendar $vCalendar */ |
51 | 51 | $vCalendar = VObjectReader::read( |
52 | - fopen(self::ASSETS_DIR . $filename, 'r'), |
|
52 | + fopen(self::ASSETS_DIR.$filename, 'r'), |
|
53 | 53 | VObjectReader::OPTION_FORGIVING, |
54 | 54 | ); |
55 | 55 | [$initialCalendarUri, $ext] = explode('.', $filename, 2); |
@@ -12,96 +12,96 @@ |
||
12 | 12 | use OCA\Files_External\Lib\StorageConfig; |
13 | 13 | |
14 | 14 | class FrontendDefinitionTraitTest extends \Test\TestCase { |
15 | - public function testJsonSerialization(): void { |
|
16 | - $param = $this->getMockBuilder(DefinitionParameter::class) |
|
17 | - ->disableOriginalConstructor() |
|
18 | - ->getMock(); |
|
19 | - $param->method('getName')->willReturn('foo'); |
|
20 | - |
|
21 | - $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); |
|
22 | - $trait->setText('test'); |
|
23 | - $trait->addParameters([$param]); |
|
24 | - $trait->addCustomJs('foo/bar.js'); |
|
25 | - $trait->addCustomJs('bar/foo.js'); |
|
26 | - |
|
27 | - $json = $trait->jsonSerializeDefinition(); |
|
28 | - |
|
29 | - $this->assertEquals('test', $json['name']); |
|
30 | - $this->assertContains('foo/bar.js', $json['custom']); |
|
31 | - $this->assertContains('bar/foo.js', $json['custom']); |
|
32 | - |
|
33 | - $configuration = $json['configuration']; |
|
34 | - $this->assertArrayHasKey('foo', $configuration); |
|
35 | - } |
|
36 | - |
|
37 | - public static function validateStorageProvider(): array { |
|
38 | - return [ |
|
39 | - [true, ['foo' => true, 'bar' => true, 'baz' => true]], |
|
40 | - [false, ['foo' => true, 'bar' => false]] |
|
41 | - ]; |
|
42 | - } |
|
43 | - |
|
44 | - #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')] |
|
45 | - public function testValidateStorage(bool $expectedSuccess, array $params): void { |
|
46 | - $backendParams = []; |
|
47 | - foreach ($params as $name => $valid) { |
|
48 | - $param = $this->getMockBuilder(DefinitionParameter::class) |
|
49 | - ->disableOriginalConstructor() |
|
50 | - ->getMock(); |
|
51 | - $param->method('getName') |
|
52 | - ->willReturn($name); |
|
53 | - $param->method('isOptional') |
|
54 | - ->willReturn(false); |
|
55 | - $param->expects($this->once()) |
|
56 | - ->method('validateValue') |
|
57 | - ->willReturn($valid); |
|
58 | - $backendParams[] = $param; |
|
59 | - } |
|
60 | - |
|
61 | - $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
62 | - ->disableOriginalConstructor() |
|
63 | - ->getMock(); |
|
64 | - $storageConfig->expects($this->any()) |
|
65 | - ->method('getBackendOption') |
|
66 | - ->willReturn(null); |
|
67 | - $storageConfig->expects($this->any()) |
|
68 | - ->method('setBackendOption'); |
|
69 | - |
|
70 | - $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); |
|
71 | - $trait->setText('test'); |
|
72 | - $trait->addParameters($backendParams); |
|
73 | - |
|
74 | - $this->assertEquals($expectedSuccess, $trait->validateStorageDefinition($storageConfig)); |
|
75 | - } |
|
76 | - |
|
77 | - public function testValidateStorageSet(): void { |
|
78 | - $param = $this->getMockBuilder(DefinitionParameter::class) |
|
79 | - ->disableOriginalConstructor() |
|
80 | - ->getMock(); |
|
81 | - $param->method('getName') |
|
82 | - ->willReturn('param'); |
|
83 | - $param->expects($this->once()) |
|
84 | - ->method('validateValue') |
|
85 | - ->willReturnCallback(function (&$value) { |
|
86 | - $value = 'foobar'; |
|
87 | - return true; |
|
88 | - }); |
|
89 | - |
|
90 | - $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
91 | - ->disableOriginalConstructor() |
|
92 | - ->getMock(); |
|
93 | - $storageConfig->expects($this->once()) |
|
94 | - ->method('getBackendOption') |
|
95 | - ->with('param') |
|
96 | - ->willReturn('barfoo'); |
|
97 | - $storageConfig->expects($this->once()) |
|
98 | - ->method('setBackendOption') |
|
99 | - ->with('param', 'foobar'); |
|
100 | - |
|
101 | - $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); |
|
102 | - $trait->setText('test'); |
|
103 | - $trait->addParameter($param); |
|
104 | - |
|
105 | - $this->assertEquals(true, $trait->validateStorageDefinition($storageConfig)); |
|
106 | - } |
|
15 | + public function testJsonSerialization(): void { |
|
16 | + $param = $this->getMockBuilder(DefinitionParameter::class) |
|
17 | + ->disableOriginalConstructor() |
|
18 | + ->getMock(); |
|
19 | + $param->method('getName')->willReturn('foo'); |
|
20 | + |
|
21 | + $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); |
|
22 | + $trait->setText('test'); |
|
23 | + $trait->addParameters([$param]); |
|
24 | + $trait->addCustomJs('foo/bar.js'); |
|
25 | + $trait->addCustomJs('bar/foo.js'); |
|
26 | + |
|
27 | + $json = $trait->jsonSerializeDefinition(); |
|
28 | + |
|
29 | + $this->assertEquals('test', $json['name']); |
|
30 | + $this->assertContains('foo/bar.js', $json['custom']); |
|
31 | + $this->assertContains('bar/foo.js', $json['custom']); |
|
32 | + |
|
33 | + $configuration = $json['configuration']; |
|
34 | + $this->assertArrayHasKey('foo', $configuration); |
|
35 | + } |
|
36 | + |
|
37 | + public static function validateStorageProvider(): array { |
|
38 | + return [ |
|
39 | + [true, ['foo' => true, 'bar' => true, 'baz' => true]], |
|
40 | + [false, ['foo' => true, 'bar' => false]] |
|
41 | + ]; |
|
42 | + } |
|
43 | + |
|
44 | + #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')] |
|
45 | + public function testValidateStorage(bool $expectedSuccess, array $params): void { |
|
46 | + $backendParams = []; |
|
47 | + foreach ($params as $name => $valid) { |
|
48 | + $param = $this->getMockBuilder(DefinitionParameter::class) |
|
49 | + ->disableOriginalConstructor() |
|
50 | + ->getMock(); |
|
51 | + $param->method('getName') |
|
52 | + ->willReturn($name); |
|
53 | + $param->method('isOptional') |
|
54 | + ->willReturn(false); |
|
55 | + $param->expects($this->once()) |
|
56 | + ->method('validateValue') |
|
57 | + ->willReturn($valid); |
|
58 | + $backendParams[] = $param; |
|
59 | + } |
|
60 | + |
|
61 | + $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
62 | + ->disableOriginalConstructor() |
|
63 | + ->getMock(); |
|
64 | + $storageConfig->expects($this->any()) |
|
65 | + ->method('getBackendOption') |
|
66 | + ->willReturn(null); |
|
67 | + $storageConfig->expects($this->any()) |
|
68 | + ->method('setBackendOption'); |
|
69 | + |
|
70 | + $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); |
|
71 | + $trait->setText('test'); |
|
72 | + $trait->addParameters($backendParams); |
|
73 | + |
|
74 | + $this->assertEquals($expectedSuccess, $trait->validateStorageDefinition($storageConfig)); |
|
75 | + } |
|
76 | + |
|
77 | + public function testValidateStorageSet(): void { |
|
78 | + $param = $this->getMockBuilder(DefinitionParameter::class) |
|
79 | + ->disableOriginalConstructor() |
|
80 | + ->getMock(); |
|
81 | + $param->method('getName') |
|
82 | + ->willReturn('param'); |
|
83 | + $param->expects($this->once()) |
|
84 | + ->method('validateValue') |
|
85 | + ->willReturnCallback(function (&$value) { |
|
86 | + $value = 'foobar'; |
|
87 | + return true; |
|
88 | + }); |
|
89 | + |
|
90 | + $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
91 | + ->disableOriginalConstructor() |
|
92 | + ->getMock(); |
|
93 | + $storageConfig->expects($this->once()) |
|
94 | + ->method('getBackendOption') |
|
95 | + ->with('param') |
|
96 | + ->willReturn('barfoo'); |
|
97 | + $storageConfig->expects($this->once()) |
|
98 | + ->method('setBackendOption') |
|
99 | + ->with('param', 'foobar'); |
|
100 | + |
|
101 | + $trait = $this->getMockForTrait(FrontendDefinitionTrait::class); |
|
102 | + $trait->setText('test'); |
|
103 | + $trait->addParameter($param); |
|
104 | + |
|
105 | + $this->assertEquals(true, $trait->validateStorageDefinition($storageConfig)); |
|
106 | + } |
|
107 | 107 | } |
@@ -17,80 +17,80 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class GlobalAuthTest extends TestCase { |
20 | - private IL10N&MockObject $l10n; |
|
21 | - private ICredentialsManager&MockObject $credentialsManager; |
|
22 | - private GlobalAuth $instance; |
|
23 | - |
|
24 | - protected function setUp(): void { |
|
25 | - parent::setUp(); |
|
26 | - $this->l10n = $this->createMock(IL10N::class); |
|
27 | - $this->credentialsManager = $this->createMock(ICredentialsManager::class); |
|
28 | - $this->instance = new GlobalAuth($this->l10n, $this->credentialsManager); |
|
29 | - } |
|
30 | - |
|
31 | - private function getStorageConfig($type, $config = []) { |
|
32 | - /** @var StorageConfig&MockObject $storageConfig */ |
|
33 | - $storageConfig = $this->createMock(StorageConfig::class); |
|
34 | - $storageConfig->expects($this->any()) |
|
35 | - ->method('getType') |
|
36 | - ->willReturn($type); |
|
37 | - $storageConfig->expects($this->any()) |
|
38 | - ->method('getBackendOptions') |
|
39 | - ->willReturnCallback(function () use (&$config) { |
|
40 | - return $config; |
|
41 | - }); |
|
42 | - $storageConfig->expects($this->any()) |
|
43 | - ->method('getBackendOption') |
|
44 | - ->willReturnCallback(function ($key) use (&$config) { |
|
45 | - return $config[$key]; |
|
46 | - }); |
|
47 | - $storageConfig->expects($this->any()) |
|
48 | - ->method('setBackendOption') |
|
49 | - ->willReturnCallback(function ($key, $value) use (&$config): void { |
|
50 | - $config[$key] = $value; |
|
51 | - }); |
|
52 | - |
|
53 | - return $storageConfig; |
|
54 | - } |
|
55 | - |
|
56 | - public function testNoCredentials(): void { |
|
57 | - $this->credentialsManager->expects($this->once()) |
|
58 | - ->method('retrieve') |
|
59 | - ->willReturn(null); |
|
60 | - |
|
61 | - $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN); |
|
62 | - |
|
63 | - $this->instance->manipulateStorageConfig($storage); |
|
64 | - $this->assertEquals([], $storage->getBackendOptions()); |
|
65 | - } |
|
66 | - |
|
67 | - public function testSavedCredentials(): void { |
|
68 | - $this->credentialsManager->expects($this->once()) |
|
69 | - ->method('retrieve') |
|
70 | - ->willReturn([ |
|
71 | - 'user' => 'a', |
|
72 | - 'password' => 'b' |
|
73 | - ]); |
|
74 | - |
|
75 | - $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN); |
|
76 | - |
|
77 | - $this->instance->manipulateStorageConfig($storage); |
|
78 | - $this->assertEquals([ |
|
79 | - 'user' => 'a', |
|
80 | - 'password' => 'b' |
|
81 | - ], $storage->getBackendOptions()); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - public function testNoCredentialsPersonal(): void { |
|
86 | - $this->expectException(InsufficientDataForMeaningfulAnswerException::class); |
|
87 | - |
|
88 | - $this->credentialsManager->expects($this->never()) |
|
89 | - ->method('retrieve'); |
|
90 | - |
|
91 | - $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_PERSONAL); |
|
92 | - |
|
93 | - $this->instance->manipulateStorageConfig($storage); |
|
94 | - $this->assertEquals([], $storage->getBackendOptions()); |
|
95 | - } |
|
20 | + private IL10N&MockObject $l10n; |
|
21 | + private ICredentialsManager&MockObject $credentialsManager; |
|
22 | + private GlobalAuth $instance; |
|
23 | + |
|
24 | + protected function setUp(): void { |
|
25 | + parent::setUp(); |
|
26 | + $this->l10n = $this->createMock(IL10N::class); |
|
27 | + $this->credentialsManager = $this->createMock(ICredentialsManager::class); |
|
28 | + $this->instance = new GlobalAuth($this->l10n, $this->credentialsManager); |
|
29 | + } |
|
30 | + |
|
31 | + private function getStorageConfig($type, $config = []) { |
|
32 | + /** @var StorageConfig&MockObject $storageConfig */ |
|
33 | + $storageConfig = $this->createMock(StorageConfig::class); |
|
34 | + $storageConfig->expects($this->any()) |
|
35 | + ->method('getType') |
|
36 | + ->willReturn($type); |
|
37 | + $storageConfig->expects($this->any()) |
|
38 | + ->method('getBackendOptions') |
|
39 | + ->willReturnCallback(function () use (&$config) { |
|
40 | + return $config; |
|
41 | + }); |
|
42 | + $storageConfig->expects($this->any()) |
|
43 | + ->method('getBackendOption') |
|
44 | + ->willReturnCallback(function ($key) use (&$config) { |
|
45 | + return $config[$key]; |
|
46 | + }); |
|
47 | + $storageConfig->expects($this->any()) |
|
48 | + ->method('setBackendOption') |
|
49 | + ->willReturnCallback(function ($key, $value) use (&$config): void { |
|
50 | + $config[$key] = $value; |
|
51 | + }); |
|
52 | + |
|
53 | + return $storageConfig; |
|
54 | + } |
|
55 | + |
|
56 | + public function testNoCredentials(): void { |
|
57 | + $this->credentialsManager->expects($this->once()) |
|
58 | + ->method('retrieve') |
|
59 | + ->willReturn(null); |
|
60 | + |
|
61 | + $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN); |
|
62 | + |
|
63 | + $this->instance->manipulateStorageConfig($storage); |
|
64 | + $this->assertEquals([], $storage->getBackendOptions()); |
|
65 | + } |
|
66 | + |
|
67 | + public function testSavedCredentials(): void { |
|
68 | + $this->credentialsManager->expects($this->once()) |
|
69 | + ->method('retrieve') |
|
70 | + ->willReturn([ |
|
71 | + 'user' => 'a', |
|
72 | + 'password' => 'b' |
|
73 | + ]); |
|
74 | + |
|
75 | + $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN); |
|
76 | + |
|
77 | + $this->instance->manipulateStorageConfig($storage); |
|
78 | + $this->assertEquals([ |
|
79 | + 'user' => 'a', |
|
80 | + 'password' => 'b' |
|
81 | + ], $storage->getBackendOptions()); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + public function testNoCredentialsPersonal(): void { |
|
86 | + $this->expectException(InsufficientDataForMeaningfulAnswerException::class); |
|
87 | + |
|
88 | + $this->credentialsManager->expects($this->never()) |
|
89 | + ->method('retrieve'); |
|
90 | + |
|
91 | + $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_PERSONAL); |
|
92 | + |
|
93 | + $this->instance->manipulateStorageConfig($storage); |
|
94 | + $this->assertEquals([], $storage->getBackendOptions()); |
|
95 | + } |
|
96 | 96 | } |
@@ -13,51 +13,51 @@ |
||
13 | 13 | use OCA\Files_External\Lib\StorageConfig; |
14 | 14 | |
15 | 15 | class AuthMechanismTest extends \Test\TestCase { |
16 | - public function testJsonSerialization(): void { |
|
17 | - $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
18 | - ->onlyMethods(['jsonSerializeDefinition']) |
|
19 | - ->getMock(); |
|
20 | - $mechanism->expects($this->once()) |
|
21 | - ->method('jsonSerializeDefinition') |
|
22 | - ->willReturn(['foo' => 'bar']); |
|
23 | - |
|
24 | - $mechanism->setScheme('scheme'); |
|
25 | - |
|
26 | - $json = $mechanism->jsonSerialize(); |
|
27 | - $this->assertEquals('bar', $json['foo']); |
|
28 | - $this->assertEquals('scheme', $json['scheme']); |
|
29 | - } |
|
30 | - |
|
31 | - public static function validateStorageProvider(): array { |
|
32 | - return [ |
|
33 | - [true, 'scheme', true], |
|
34 | - [false, 'scheme', false], |
|
35 | - [true, 'foobar', true], |
|
36 | - [false, 'barfoo', true], |
|
37 | - ]; |
|
38 | - } |
|
39 | - |
|
40 | - #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')] |
|
41 | - public function testValidateStorage(bool $expectedSuccess, string $scheme, bool $definitionSuccess): void { |
|
42 | - $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
43 | - ->onlyMethods(['validateStorageDefinition']) |
|
44 | - ->getMock(); |
|
45 | - $mechanism->expects($this->atMost(1)) |
|
46 | - ->method('validateStorageDefinition') |
|
47 | - ->willReturn($definitionSuccess); |
|
48 | - |
|
49 | - $mechanism->setScheme($scheme); |
|
50 | - |
|
51 | - $backend = $this->createMock(Backend::class); |
|
52 | - $backend->expects($this->once()) |
|
53 | - ->method('getAuthSchemes') |
|
54 | - ->willReturn(['scheme' => true, 'foobar' => true]); |
|
55 | - |
|
56 | - $storageConfig = $this->createMock(StorageConfig::class); |
|
57 | - $storageConfig->expects($this->once()) |
|
58 | - ->method('getBackend') |
|
59 | - ->willReturn($backend); |
|
60 | - |
|
61 | - $this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig)); |
|
62 | - } |
|
16 | + public function testJsonSerialization(): void { |
|
17 | + $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
18 | + ->onlyMethods(['jsonSerializeDefinition']) |
|
19 | + ->getMock(); |
|
20 | + $mechanism->expects($this->once()) |
|
21 | + ->method('jsonSerializeDefinition') |
|
22 | + ->willReturn(['foo' => 'bar']); |
|
23 | + |
|
24 | + $mechanism->setScheme('scheme'); |
|
25 | + |
|
26 | + $json = $mechanism->jsonSerialize(); |
|
27 | + $this->assertEquals('bar', $json['foo']); |
|
28 | + $this->assertEquals('scheme', $json['scheme']); |
|
29 | + } |
|
30 | + |
|
31 | + public static function validateStorageProvider(): array { |
|
32 | + return [ |
|
33 | + [true, 'scheme', true], |
|
34 | + [false, 'scheme', false], |
|
35 | + [true, 'foobar', true], |
|
36 | + [false, 'barfoo', true], |
|
37 | + ]; |
|
38 | + } |
|
39 | + |
|
40 | + #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')] |
|
41 | + public function testValidateStorage(bool $expectedSuccess, string $scheme, bool $definitionSuccess): void { |
|
42 | + $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
43 | + ->onlyMethods(['validateStorageDefinition']) |
|
44 | + ->getMock(); |
|
45 | + $mechanism->expects($this->atMost(1)) |
|
46 | + ->method('validateStorageDefinition') |
|
47 | + ->willReturn($definitionSuccess); |
|
48 | + |
|
49 | + $mechanism->setScheme($scheme); |
|
50 | + |
|
51 | + $backend = $this->createMock(Backend::class); |
|
52 | + $backend->expects($this->once()) |
|
53 | + ->method('getAuthSchemes') |
|
54 | + ->willReturn(['scheme' => true, 'foobar' => true]); |
|
55 | + |
|
56 | + $storageConfig = $this->createMock(StorageConfig::class); |
|
57 | + $storageConfig->expects($this->once()) |
|
58 | + ->method('getBackend') |
|
59 | + ->willReturn($backend); |
|
60 | + |
|
61 | + $this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig)); |
|
62 | + } |
|
63 | 63 | } |
@@ -18,119 +18,119 @@ |
||
18 | 18 | * @package OCA\Files_External\Tests\Storage |
19 | 19 | */ |
20 | 20 | class SftpTest extends \Test\Files\Storage\Storage { |
21 | - /** |
|
22 | - * @var SFTP instance |
|
23 | - */ |
|
24 | - protected $instance; |
|
21 | + /** |
|
22 | + * @var SFTP instance |
|
23 | + */ |
|
24 | + protected $instance; |
|
25 | 25 | |
26 | - private $config; |
|
26 | + private $config; |
|
27 | 27 | |
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | 30 | |
31 | - $id = $this->getUniqueID(); |
|
32 | - $this->config = include('files_external/tests/config.sftp.php'); |
|
33 | - if (!is_array($this->config) or !$this->config['run']) { |
|
34 | - $this->markTestSkipped('SFTP backend not configured'); |
|
35 | - } |
|
36 | - $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in |
|
37 | - $this->instance = new SFTP($this->config); |
|
38 | - $this->instance->mkdir('/'); |
|
39 | - } |
|
31 | + $id = $this->getUniqueID(); |
|
32 | + $this->config = include('files_external/tests/config.sftp.php'); |
|
33 | + if (!is_array($this->config) or !$this->config['run']) { |
|
34 | + $this->markTestSkipped('SFTP backend not configured'); |
|
35 | + } |
|
36 | + $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in |
|
37 | + $this->instance = new SFTP($this->config); |
|
38 | + $this->instance->mkdir('/'); |
|
39 | + } |
|
40 | 40 | |
41 | - protected function tearDown(): void { |
|
42 | - if ($this->instance) { |
|
43 | - $this->instance->rmdir('/'); |
|
44 | - } |
|
41 | + protected function tearDown(): void { |
|
42 | + if ($this->instance) { |
|
43 | + $this->instance->rmdir('/'); |
|
44 | + } |
|
45 | 45 | |
46 | - parent::tearDown(); |
|
47 | - } |
|
46 | + parent::tearDown(); |
|
47 | + } |
|
48 | 48 | |
49 | - #[\PHPUnit\Framework\Attributes\DataProvider('configProvider')] |
|
50 | - public function testStorageId($config, $expectedStorageId): void { |
|
51 | - $instance = new SFTP($config); |
|
52 | - $this->assertEquals($expectedStorageId, $instance->getId()); |
|
53 | - } |
|
49 | + #[\PHPUnit\Framework\Attributes\DataProvider('configProvider')] |
|
50 | + public function testStorageId($config, $expectedStorageId): void { |
|
51 | + $instance = new SFTP($config); |
|
52 | + $this->assertEquals($expectedStorageId, $instance->getId()); |
|
53 | + } |
|
54 | 54 | |
55 | - public static function configProvider(): array { |
|
56 | - return [ |
|
57 | - [ |
|
58 | - // no root path |
|
59 | - [ |
|
60 | - 'run' => true, |
|
61 | - 'host' => 'somehost', |
|
62 | - 'user' => 'someuser', |
|
63 | - 'password' => 'somepassword', |
|
64 | - 'root' => '', |
|
65 | - ], |
|
66 | - 'sftp::someuser@somehost//', |
|
67 | - ], |
|
68 | - [ |
|
69 | - // without leading nor trailing slash |
|
70 | - [ |
|
71 | - 'run' => true, |
|
72 | - 'host' => 'somehost', |
|
73 | - 'user' => 'someuser', |
|
74 | - 'password' => 'somepassword', |
|
75 | - 'root' => 'remotedir/subdir', |
|
76 | - ], |
|
77 | - 'sftp::someuser@somehost//remotedir/subdir/', |
|
78 | - ], |
|
79 | - [ |
|
80 | - // regular path |
|
81 | - [ |
|
82 | - 'run' => true, |
|
83 | - 'host' => 'somehost', |
|
84 | - 'user' => 'someuser', |
|
85 | - 'password' => 'somepassword', |
|
86 | - 'root' => '/remotedir/subdir/', |
|
87 | - ], |
|
88 | - 'sftp::someuser@somehost//remotedir/subdir/', |
|
89 | - ], |
|
90 | - [ |
|
91 | - // different port |
|
92 | - [ |
|
93 | - 'run' => true, |
|
94 | - 'host' => 'somehost:8822', |
|
95 | - 'user' => 'someuser', |
|
96 | - 'password' => 'somepassword', |
|
97 | - 'root' => 'remotedir/subdir/', |
|
98 | - ], |
|
99 | - 'sftp::someuser@somehost:8822//remotedir/subdir/', |
|
100 | - ], |
|
101 | - [ |
|
102 | - // ipv6 with port |
|
103 | - [ |
|
104 | - 'run' => true, |
|
105 | - 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329', |
|
106 | - 'user' => 'someuser', |
|
107 | - 'password' => 'somepassword', |
|
108 | - 'root' => 'remotedir/subdir/', |
|
109 | - ], |
|
110 | - 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329//remotedir/subdir/', |
|
111 | - ], |
|
112 | - [ |
|
113 | - // ipv6 without port |
|
114 | - [ |
|
115 | - 'run' => true, |
|
116 | - 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822', |
|
117 | - 'user' => 'someuser', |
|
118 | - 'password' => 'somepassword', |
|
119 | - 'root' => 'remotedir/subdir/', |
|
120 | - ], |
|
121 | - 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
122 | - ], |
|
123 | - [ |
|
124 | - // collapsed ipv6 with port |
|
125 | - [ |
|
126 | - 'run' => true, |
|
127 | - 'host' => 'FE80::0202:B3FF:FE1E:8329:8822', |
|
128 | - 'user' => 'someuser', |
|
129 | - 'password' => 'somepassword', |
|
130 | - 'root' => 'remotedir/subdir/', |
|
131 | - ], |
|
132 | - 'sftp::someuser@FE80::0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
133 | - ], |
|
134 | - ]; |
|
135 | - } |
|
55 | + public static function configProvider(): array { |
|
56 | + return [ |
|
57 | + [ |
|
58 | + // no root path |
|
59 | + [ |
|
60 | + 'run' => true, |
|
61 | + 'host' => 'somehost', |
|
62 | + 'user' => 'someuser', |
|
63 | + 'password' => 'somepassword', |
|
64 | + 'root' => '', |
|
65 | + ], |
|
66 | + 'sftp::someuser@somehost//', |
|
67 | + ], |
|
68 | + [ |
|
69 | + // without leading nor trailing slash |
|
70 | + [ |
|
71 | + 'run' => true, |
|
72 | + 'host' => 'somehost', |
|
73 | + 'user' => 'someuser', |
|
74 | + 'password' => 'somepassword', |
|
75 | + 'root' => 'remotedir/subdir', |
|
76 | + ], |
|
77 | + 'sftp::someuser@somehost//remotedir/subdir/', |
|
78 | + ], |
|
79 | + [ |
|
80 | + // regular path |
|
81 | + [ |
|
82 | + 'run' => true, |
|
83 | + 'host' => 'somehost', |
|
84 | + 'user' => 'someuser', |
|
85 | + 'password' => 'somepassword', |
|
86 | + 'root' => '/remotedir/subdir/', |
|
87 | + ], |
|
88 | + 'sftp::someuser@somehost//remotedir/subdir/', |
|
89 | + ], |
|
90 | + [ |
|
91 | + // different port |
|
92 | + [ |
|
93 | + 'run' => true, |
|
94 | + 'host' => 'somehost:8822', |
|
95 | + 'user' => 'someuser', |
|
96 | + 'password' => 'somepassword', |
|
97 | + 'root' => 'remotedir/subdir/', |
|
98 | + ], |
|
99 | + 'sftp::someuser@somehost:8822//remotedir/subdir/', |
|
100 | + ], |
|
101 | + [ |
|
102 | + // ipv6 with port |
|
103 | + [ |
|
104 | + 'run' => true, |
|
105 | + 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329', |
|
106 | + 'user' => 'someuser', |
|
107 | + 'password' => 'somepassword', |
|
108 | + 'root' => 'remotedir/subdir/', |
|
109 | + ], |
|
110 | + 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329//remotedir/subdir/', |
|
111 | + ], |
|
112 | + [ |
|
113 | + // ipv6 without port |
|
114 | + [ |
|
115 | + 'run' => true, |
|
116 | + 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822', |
|
117 | + 'user' => 'someuser', |
|
118 | + 'password' => 'somepassword', |
|
119 | + 'root' => 'remotedir/subdir/', |
|
120 | + ], |
|
121 | + 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
122 | + ], |
|
123 | + [ |
|
124 | + // collapsed ipv6 with port |
|
125 | + [ |
|
126 | + 'run' => true, |
|
127 | + 'host' => 'FE80::0202:B3FF:FE1E:8329:8822', |
|
128 | + 'user' => 'someuser', |
|
129 | + 'password' => 'somepassword', |
|
130 | + 'root' => 'remotedir/subdir/', |
|
131 | + ], |
|
132 | + 'sftp::someuser@FE80::0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
133 | + ], |
|
134 | + ]; |
|
135 | + } |
|
136 | 136 | } |
@@ -17,53 +17,53 @@ |
||
17 | 17 | use PHPUnit\Framework\MockObject\MockObject; |
18 | 18 | |
19 | 19 | class UserPlaceholderHandlerTest extends \Test\TestCase { |
20 | - protected IUser&MockObject $user; |
|
21 | - protected IUserSession&MockObject $session; |
|
22 | - protected IManager&MockObject $shareManager; |
|
23 | - protected IRequest&MockObject $request; |
|
24 | - protected IUserManager&MockObject $userManager; |
|
25 | - protected UserPlaceholderHandler $handler; |
|
20 | + protected IUser&MockObject $user; |
|
21 | + protected IUserSession&MockObject $session; |
|
22 | + protected IManager&MockObject $shareManager; |
|
23 | + protected IRequest&MockObject $request; |
|
24 | + protected IUserManager&MockObject $userManager; |
|
25 | + protected UserPlaceholderHandler $handler; |
|
26 | 26 | |
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | 29 | |
30 | - $this->user = $this->createMock(IUser::class); |
|
31 | - $this->user->expects($this->any()) |
|
32 | - ->method('getUid') |
|
33 | - ->willReturn('alice'); |
|
34 | - $this->session = $this->createMock(IUserSession::class); |
|
35 | - $this->shareManager = $this->createMock(IManager::class); |
|
36 | - $this->request = $this->createMock(IRequest::class); |
|
37 | - $this->userManager = $this->createMock(IUserManager::class); |
|
30 | + $this->user = $this->createMock(IUser::class); |
|
31 | + $this->user->expects($this->any()) |
|
32 | + ->method('getUid') |
|
33 | + ->willReturn('alice'); |
|
34 | + $this->session = $this->createMock(IUserSession::class); |
|
35 | + $this->shareManager = $this->createMock(IManager::class); |
|
36 | + $this->request = $this->createMock(IRequest::class); |
|
37 | + $this->userManager = $this->createMock(IUserManager::class); |
|
38 | 38 | |
39 | - $this->handler = new UserPlaceholderHandler($this->session, $this->shareManager, $this->request, $this->userManager); |
|
40 | - } |
|
39 | + $this->handler = new UserPlaceholderHandler($this->session, $this->shareManager, $this->request, $this->userManager); |
|
40 | + } |
|
41 | 41 | |
42 | - protected function setUser(): void { |
|
43 | - $this->session->expects($this->any()) |
|
44 | - ->method('getUser') |
|
45 | - ->willReturn($this->user); |
|
46 | - } |
|
42 | + protected function setUser(): void { |
|
43 | + $this->session->expects($this->any()) |
|
44 | + ->method('getUser') |
|
45 | + ->willReturn($this->user); |
|
46 | + } |
|
47 | 47 | |
48 | - public static function optionProvider(): array { |
|
49 | - return [ |
|
50 | - ['/foo/bar/$user/foobar', '/foo/bar/alice/foobar'], |
|
51 | - [['/foo/bar/$user/foobar'], ['/foo/bar/alice/foobar']], |
|
52 | - [['/FOO/BAR/$USER/FOOBAR'], ['/FOO/BAR/alice/FOOBAR']], |
|
53 | - ]; |
|
54 | - } |
|
48 | + public static function optionProvider(): array { |
|
49 | + return [ |
|
50 | + ['/foo/bar/$user/foobar', '/foo/bar/alice/foobar'], |
|
51 | + [['/foo/bar/$user/foobar'], ['/foo/bar/alice/foobar']], |
|
52 | + [['/FOO/BAR/$USER/FOOBAR'], ['/FOO/BAR/alice/FOOBAR']], |
|
53 | + ]; |
|
54 | + } |
|
55 | 55 | |
56 | - #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')] |
|
57 | - public function testHandle(string|array $option, string|array $expected): void { |
|
58 | - $this->setUser(); |
|
59 | - $this->assertSame($expected, $this->handler->handle($option)); |
|
60 | - } |
|
56 | + #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')] |
|
57 | + public function testHandle(string|array $option, string|array $expected): void { |
|
58 | + $this->setUser(); |
|
59 | + $this->assertSame($expected, $this->handler->handle($option)); |
|
60 | + } |
|
61 | 61 | |
62 | - #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')] |
|
63 | - public function testHandleNoUser(string|array $option): void { |
|
64 | - $this->shareManager->expects($this->once()) |
|
65 | - ->method('getShareByToken') |
|
66 | - ->willThrowException(new ShareNotFound()); |
|
67 | - $this->assertSame($option, $this->handler->handle($option)); |
|
68 | - } |
|
62 | + #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')] |
|
63 | + public function testHandleNoUser(string|array $option): void { |
|
64 | + $this->shareManager->expects($this->once()) |
|
65 | + ->method('getShareByToken') |
|
66 | + ->willThrowException(new ShareNotFound()); |
|
67 | + $this->assertSame($option, $this->handler->handle($option)); |
|
68 | + } |
|
69 | 69 | } |
@@ -54,13 +54,13 @@ |
||
54 | 54 | } |
55 | 55 | |
56 | 56 | #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')] |
57 | - public function testHandle(string|array $option, string|array $expected): void { |
|
57 | + public function testHandle(string | array $option, string | array $expected): void { |
|
58 | 58 | $this->setUser(); |
59 | 59 | $this->assertSame($expected, $this->handler->handle($option)); |
60 | 60 | } |
61 | 61 | |
62 | 62 | #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')] |
63 | - public function testHandleNoUser(string|array $option): void { |
|
63 | + public function testHandleNoUser(string | array $option): void { |
|
64 | 64 | $this->shareManager->expects($this->once()) |
65 | 65 | ->method('getShareByToken') |
66 | 66 | ->willThrowException(new ShareNotFound()); |
@@ -23,387 +23,387 @@ |
||
23 | 23 | use PHPUnit\Framework\MockObject\MockObject; |
24 | 24 | |
25 | 25 | abstract class StoragesControllerTestCase extends \Test\TestCase { |
26 | - protected GlobalStoragesController|UserStoragesController $controller; |
|
27 | - protected GlobalStoragesService|UserStoragesService|MockObject $service; |
|
28 | - |
|
29 | - protected function setUp(): void { |
|
30 | - parent::setUp(); |
|
31 | - MountConfig::$skipTest = true; |
|
32 | - } |
|
33 | - |
|
34 | - protected function tearDown(): void { |
|
35 | - MountConfig::$skipTest = false; |
|
36 | - parent::tearDown(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @return \OCA\Files_External\Lib\Backend\Backend&MockObject |
|
41 | - */ |
|
42 | - protected function getBackendMock($class = SMB::class, $storageClass = \OCA\Files_External\Lib\Storage\SMB::class) { |
|
43 | - $backend = $this->createMock(Backend::class); |
|
44 | - $backend->method('getStorageClass') |
|
45 | - ->willReturn($storageClass); |
|
46 | - $backend->method('getIdentifier') |
|
47 | - ->willReturn('identifier:' . $class); |
|
48 | - $backend->method('getParameters') |
|
49 | - ->willReturn([]); |
|
50 | - return $backend; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @return AuthMechanism|MockObject |
|
55 | - */ |
|
56 | - protected function getAuthMechMock($scheme = 'null', $class = NullMechanism::class) { |
|
57 | - $authMech = $this->createMock(AuthMechanism::class); |
|
58 | - $authMech->method('getScheme') |
|
59 | - ->willReturn($scheme); |
|
60 | - $authMech->method('getIdentifier') |
|
61 | - ->willReturn('identifier:' . $class); |
|
62 | - $authMech->method('getParameters') |
|
63 | - ->willReturn([]); |
|
64 | - |
|
65 | - return $authMech; |
|
66 | - } |
|
67 | - |
|
68 | - public function testAddStorage(): void { |
|
69 | - $authMech = $this->getAuthMechMock(); |
|
70 | - $authMech->method('validateStorage') |
|
71 | - ->willReturn(true); |
|
72 | - $authMech->method('isVisibleFor') |
|
73 | - ->willReturn(true); |
|
74 | - $backend = $this->getBackendMock(); |
|
75 | - $backend->method('validateStorage') |
|
76 | - ->willReturn(true); |
|
77 | - $backend->method('isVisibleFor') |
|
78 | - ->willReturn(true); |
|
79 | - |
|
80 | - $storageConfig = new StorageConfig(1); |
|
81 | - $storageConfig->setMountPoint('mount'); |
|
82 | - $storageConfig->setBackend($backend); |
|
83 | - $storageConfig->setAuthMechanism($authMech); |
|
84 | - $storageConfig->setBackendOptions([]); |
|
85 | - |
|
86 | - $this->service->expects($this->once()) |
|
87 | - ->method('createStorage') |
|
88 | - ->willReturn($storageConfig); |
|
89 | - $this->service->expects($this->once()) |
|
90 | - ->method('addStorage') |
|
91 | - ->willReturn($storageConfig); |
|
92 | - |
|
93 | - $response = $this->controller->create( |
|
94 | - 'mount', |
|
95 | - \OCA\Files_External\Lib\Storage\SMB::class, |
|
96 | - NullMechanism::class, |
|
97 | - [], |
|
98 | - [], |
|
99 | - [], |
|
100 | - [], |
|
101 | - null |
|
102 | - ); |
|
103 | - |
|
104 | - $data = $response->getData(); |
|
105 | - $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); |
|
106 | - $this->assertEquals($storageConfig->jsonSerialize(), $data); |
|
107 | - } |
|
108 | - |
|
109 | - public function testAddLocalStorageWhenDisabled(): void { |
|
110 | - $authMech = $this->getAuthMechMock(); |
|
111 | - $backend = $this->getBackendMock(); |
|
112 | - |
|
113 | - $storageConfig = new StorageConfig(1); |
|
114 | - $storageConfig->setMountPoint('mount'); |
|
115 | - $storageConfig->setBackend($backend); |
|
116 | - $storageConfig->setAuthMechanism($authMech); |
|
117 | - $storageConfig->setBackendOptions([]); |
|
118 | - |
|
119 | - $this->service->expects($this->never()) |
|
120 | - ->method('createStorage'); |
|
121 | - $this->service->expects($this->never()) |
|
122 | - ->method('addStorage'); |
|
123 | - |
|
124 | - $response = $this->controller->create( |
|
125 | - 'mount', |
|
126 | - 'local', |
|
127 | - NullMechanism::class, |
|
128 | - [], |
|
129 | - [], |
|
130 | - [], |
|
131 | - [], |
|
132 | - null |
|
133 | - ); |
|
134 | - |
|
135 | - $data = $response->getData(); |
|
136 | - $this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus()); |
|
137 | - } |
|
138 | - |
|
139 | - public function testUpdateStorage(): void { |
|
140 | - $authMech = $this->getAuthMechMock(); |
|
141 | - $authMech->method('validateStorage') |
|
142 | - ->willReturn(true); |
|
143 | - $authMech->method('isVisibleFor') |
|
144 | - ->willReturn(true); |
|
145 | - $backend = $this->getBackendMock(); |
|
146 | - $backend->method('validateStorage') |
|
147 | - ->willReturn(true); |
|
148 | - $backend->method('isVisibleFor') |
|
149 | - ->willReturn(true); |
|
150 | - |
|
151 | - $storageConfig = new StorageConfig(1); |
|
152 | - $storageConfig->setMountPoint('mount'); |
|
153 | - $storageConfig->setBackend($backend); |
|
154 | - $storageConfig->setAuthMechanism($authMech); |
|
155 | - $storageConfig->setBackendOptions([]); |
|
156 | - |
|
157 | - $this->service->expects($this->once()) |
|
158 | - ->method('createStorage') |
|
159 | - ->willReturn($storageConfig); |
|
160 | - $this->service->expects($this->once()) |
|
161 | - ->method('updateStorage') |
|
162 | - ->willReturn($storageConfig); |
|
163 | - |
|
164 | - $response = $this->controller->update( |
|
165 | - 1, |
|
166 | - 'mount', |
|
167 | - \OCA\Files_External\Lib\Storage\SMB::class, |
|
168 | - NullMechanism::class, |
|
169 | - [], |
|
170 | - [], |
|
171 | - [], |
|
172 | - [], |
|
173 | - null |
|
174 | - ); |
|
175 | - |
|
176 | - $data = $response->getData(); |
|
177 | - $this->assertEquals(Http::STATUS_OK, $response->getStatus()); |
|
178 | - $this->assertEquals($storageConfig->jsonSerialize(), $data); |
|
179 | - } |
|
180 | - |
|
181 | - public static function mountPointNamesProvider(): array { |
|
182 | - return [ |
|
183 | - [''], |
|
184 | - ['/'], |
|
185 | - ['//'], |
|
186 | - ]; |
|
187 | - } |
|
188 | - |
|
189 | - #[\PHPUnit\Framework\Attributes\DataProvider('mountPointNamesProvider')] |
|
190 | - public function testAddOrUpdateStorageInvalidMountPoint($mountPoint): void { |
|
191 | - $storageConfig = new StorageConfig(1); |
|
192 | - $storageConfig->setMountPoint($mountPoint); |
|
193 | - $storageConfig->setBackend($this->getBackendMock()); |
|
194 | - $storageConfig->setAuthMechanism($this->getAuthMechMock()); |
|
195 | - $storageConfig->setBackendOptions([]); |
|
196 | - |
|
197 | - $this->service->expects($this->exactly(2)) |
|
198 | - ->method('createStorage') |
|
199 | - ->willReturn($storageConfig); |
|
200 | - $this->service->expects($this->never()) |
|
201 | - ->method('addStorage'); |
|
202 | - $this->service->expects($this->never()) |
|
203 | - ->method('updateStorage'); |
|
204 | - |
|
205 | - $response = $this->controller->create( |
|
206 | - $mountPoint, |
|
207 | - \OCA\Files_External\Lib\Storage\SMB::class, |
|
208 | - NullMechanism::class, |
|
209 | - [], |
|
210 | - [], |
|
211 | - [], |
|
212 | - [], |
|
213 | - null |
|
214 | - ); |
|
215 | - |
|
216 | - $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
217 | - |
|
218 | - $response = $this->controller->update( |
|
219 | - 1, |
|
220 | - $mountPoint, |
|
221 | - \OCA\Files_External\Lib\Storage\SMB::class, |
|
222 | - NullMechanism::class, |
|
223 | - [], |
|
224 | - [], |
|
225 | - [], |
|
226 | - [], |
|
227 | - null |
|
228 | - ); |
|
229 | - |
|
230 | - $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
231 | - } |
|
232 | - |
|
233 | - public function testAddOrUpdateStorageInvalidBackend(): void { |
|
234 | - $this->service->expects($this->exactly(2)) |
|
235 | - ->method('createStorage') |
|
236 | - ->willThrowException(new \InvalidArgumentException()); |
|
237 | - $this->service->expects($this->never()) |
|
238 | - ->method('addStorage'); |
|
239 | - $this->service->expects($this->never()) |
|
240 | - ->method('updateStorage'); |
|
241 | - |
|
242 | - $response = $this->controller->create( |
|
243 | - 'mount', |
|
244 | - '\OC\Files\Storage\InvalidStorage', |
|
245 | - NullMechanism::class, |
|
246 | - [], |
|
247 | - [], |
|
248 | - [], |
|
249 | - [], |
|
250 | - null |
|
251 | - ); |
|
252 | - |
|
253 | - $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
254 | - |
|
255 | - $response = $this->controller->update( |
|
256 | - 1, |
|
257 | - 'mount', |
|
258 | - '\OC\Files\Storage\InvalidStorage', |
|
259 | - NullMechanism::class, |
|
260 | - [], |
|
261 | - [], |
|
262 | - [], |
|
263 | - [], |
|
264 | - null |
|
265 | - ); |
|
266 | - |
|
267 | - $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
268 | - } |
|
269 | - |
|
270 | - public function testUpdateStorageNonExisting(): void { |
|
271 | - $authMech = $this->getAuthMechMock(); |
|
272 | - $authMech->method('validateStorage') |
|
273 | - ->willReturn(true); |
|
274 | - $authMech->method('isVisibleFor') |
|
275 | - ->willReturn(true); |
|
276 | - $backend = $this->getBackendMock(); |
|
277 | - $backend->method('validateStorage') |
|
278 | - ->willReturn(true); |
|
279 | - $backend->method('isVisibleFor') |
|
280 | - ->willReturn(true); |
|
281 | - |
|
282 | - $storageConfig = new StorageConfig(255); |
|
283 | - $storageConfig->setMountPoint('mount'); |
|
284 | - $storageConfig->setBackend($backend); |
|
285 | - $storageConfig->setAuthMechanism($authMech); |
|
286 | - $storageConfig->setBackendOptions([]); |
|
287 | - |
|
288 | - $this->service->expects($this->once()) |
|
289 | - ->method('createStorage') |
|
290 | - ->willReturn($storageConfig); |
|
291 | - $this->service->expects($this->once()) |
|
292 | - ->method('updateStorage') |
|
293 | - ->willThrowException(new NotFoundException()); |
|
294 | - |
|
295 | - $response = $this->controller->update( |
|
296 | - 255, |
|
297 | - 'mount', |
|
298 | - \OCA\Files_External\Lib\Storage\SMB::class, |
|
299 | - NullMechanism::class, |
|
300 | - [], |
|
301 | - [], |
|
302 | - [], |
|
303 | - [], |
|
304 | - null |
|
305 | - ); |
|
306 | - |
|
307 | - $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); |
|
308 | - } |
|
309 | - |
|
310 | - public function testDeleteStorage(): void { |
|
311 | - $this->service->expects($this->once()) |
|
312 | - ->method('removeStorage'); |
|
313 | - |
|
314 | - $response = $this->controller->destroy(1); |
|
315 | - $this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus()); |
|
316 | - } |
|
317 | - |
|
318 | - public function testDeleteStorageNonExisting(): void { |
|
319 | - $this->service->expects($this->once()) |
|
320 | - ->method('removeStorage') |
|
321 | - ->willThrowException(new NotFoundException()); |
|
322 | - |
|
323 | - $response = $this->controller->destroy(255); |
|
324 | - $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); |
|
325 | - } |
|
326 | - |
|
327 | - public function testGetStorage(): void { |
|
328 | - $backend = $this->getBackendMock(); |
|
329 | - $authMech = $this->getAuthMechMock(); |
|
330 | - $storageConfig = new StorageConfig(1); |
|
331 | - $storageConfig->setMountPoint('test'); |
|
332 | - $storageConfig->setBackend($backend); |
|
333 | - $storageConfig->setAuthMechanism($authMech); |
|
334 | - $storageConfig->setBackendOptions(['user' => 'test', 'password', 'password123']); |
|
335 | - $storageConfig->setMountOptions(['priority' => false]); |
|
336 | - |
|
337 | - $this->service->expects($this->once()) |
|
338 | - ->method('getStorage') |
|
339 | - ->with(1) |
|
340 | - ->willReturn($storageConfig); |
|
341 | - $response = $this->controller->show(1); |
|
342 | - |
|
343 | - $this->assertEquals(Http::STATUS_OK, $response->getStatus()); |
|
344 | - $expected = $storageConfig->jsonSerialize(); |
|
345 | - $expected['can_edit'] = false; |
|
346 | - $this->assertEquals($expected, $response->getData()); |
|
347 | - } |
|
348 | - |
|
349 | - public static function validateStorageProvider(): array { |
|
350 | - return [ |
|
351 | - [true, true, true], |
|
352 | - [false, true, false], |
|
353 | - [true, false, false], |
|
354 | - [false, false, false] |
|
355 | - ]; |
|
356 | - } |
|
357 | - |
|
358 | - #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')] |
|
359 | - public function testValidateStorage(bool $backendValidate, bool $authMechValidate, bool $expectSuccess): void { |
|
360 | - $backend = $this->getBackendMock(); |
|
361 | - $backend->method('validateStorage') |
|
362 | - ->willReturn($backendValidate); |
|
363 | - $backend->method('isVisibleFor') |
|
364 | - ->willReturn(true); |
|
365 | - |
|
366 | - $authMech = $this->getAuthMechMock(); |
|
367 | - $authMech->method('validateStorage') |
|
368 | - ->willReturn($authMechValidate); |
|
369 | - $authMech->method('isVisibleFor') |
|
370 | - ->willReturn(true); |
|
371 | - |
|
372 | - $storageConfig = new StorageConfig(); |
|
373 | - $storageConfig->setMountPoint('mount'); |
|
374 | - $storageConfig->setBackend($backend); |
|
375 | - $storageConfig->setAuthMechanism($authMech); |
|
376 | - $storageConfig->setBackendOptions([]); |
|
377 | - |
|
378 | - $this->service->expects($this->once()) |
|
379 | - ->method('createStorage') |
|
380 | - ->willReturn($storageConfig); |
|
381 | - |
|
382 | - if ($expectSuccess) { |
|
383 | - $this->service->expects($this->once()) |
|
384 | - ->method('addStorage') |
|
385 | - ->with($storageConfig) |
|
386 | - ->willReturn($storageConfig); |
|
387 | - } else { |
|
388 | - $this->service->expects($this->never()) |
|
389 | - ->method('addStorage'); |
|
390 | - } |
|
391 | - |
|
392 | - $response = $this->controller->create( |
|
393 | - 'mount', |
|
394 | - \OCA\Files_External\Lib\Storage\SMB::class, |
|
395 | - NullMechanism::class, |
|
396 | - [], |
|
397 | - [], |
|
398 | - [], |
|
399 | - [], |
|
400 | - null |
|
401 | - ); |
|
402 | - |
|
403 | - if ($expectSuccess) { |
|
404 | - $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); |
|
405 | - } else { |
|
406 | - $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
407 | - } |
|
408 | - } |
|
26 | + protected GlobalStoragesController|UserStoragesController $controller; |
|
27 | + protected GlobalStoragesService|UserStoragesService|MockObject $service; |
|
28 | + |
|
29 | + protected function setUp(): void { |
|
30 | + parent::setUp(); |
|
31 | + MountConfig::$skipTest = true; |
|
32 | + } |
|
33 | + |
|
34 | + protected function tearDown(): void { |
|
35 | + MountConfig::$skipTest = false; |
|
36 | + parent::tearDown(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @return \OCA\Files_External\Lib\Backend\Backend&MockObject |
|
41 | + */ |
|
42 | + protected function getBackendMock($class = SMB::class, $storageClass = \OCA\Files_External\Lib\Storage\SMB::class) { |
|
43 | + $backend = $this->createMock(Backend::class); |
|
44 | + $backend->method('getStorageClass') |
|
45 | + ->willReturn($storageClass); |
|
46 | + $backend->method('getIdentifier') |
|
47 | + ->willReturn('identifier:' . $class); |
|
48 | + $backend->method('getParameters') |
|
49 | + ->willReturn([]); |
|
50 | + return $backend; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @return AuthMechanism|MockObject |
|
55 | + */ |
|
56 | + protected function getAuthMechMock($scheme = 'null', $class = NullMechanism::class) { |
|
57 | + $authMech = $this->createMock(AuthMechanism::class); |
|
58 | + $authMech->method('getScheme') |
|
59 | + ->willReturn($scheme); |
|
60 | + $authMech->method('getIdentifier') |
|
61 | + ->willReturn('identifier:' . $class); |
|
62 | + $authMech->method('getParameters') |
|
63 | + ->willReturn([]); |
|
64 | + |
|
65 | + return $authMech; |
|
66 | + } |
|
67 | + |
|
68 | + public function testAddStorage(): void { |
|
69 | + $authMech = $this->getAuthMechMock(); |
|
70 | + $authMech->method('validateStorage') |
|
71 | + ->willReturn(true); |
|
72 | + $authMech->method('isVisibleFor') |
|
73 | + ->willReturn(true); |
|
74 | + $backend = $this->getBackendMock(); |
|
75 | + $backend->method('validateStorage') |
|
76 | + ->willReturn(true); |
|
77 | + $backend->method('isVisibleFor') |
|
78 | + ->willReturn(true); |
|
79 | + |
|
80 | + $storageConfig = new StorageConfig(1); |
|
81 | + $storageConfig->setMountPoint('mount'); |
|
82 | + $storageConfig->setBackend($backend); |
|
83 | + $storageConfig->setAuthMechanism($authMech); |
|
84 | + $storageConfig->setBackendOptions([]); |
|
85 | + |
|
86 | + $this->service->expects($this->once()) |
|
87 | + ->method('createStorage') |
|
88 | + ->willReturn($storageConfig); |
|
89 | + $this->service->expects($this->once()) |
|
90 | + ->method('addStorage') |
|
91 | + ->willReturn($storageConfig); |
|
92 | + |
|
93 | + $response = $this->controller->create( |
|
94 | + 'mount', |
|
95 | + \OCA\Files_External\Lib\Storage\SMB::class, |
|
96 | + NullMechanism::class, |
|
97 | + [], |
|
98 | + [], |
|
99 | + [], |
|
100 | + [], |
|
101 | + null |
|
102 | + ); |
|
103 | + |
|
104 | + $data = $response->getData(); |
|
105 | + $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); |
|
106 | + $this->assertEquals($storageConfig->jsonSerialize(), $data); |
|
107 | + } |
|
108 | + |
|
109 | + public function testAddLocalStorageWhenDisabled(): void { |
|
110 | + $authMech = $this->getAuthMechMock(); |
|
111 | + $backend = $this->getBackendMock(); |
|
112 | + |
|
113 | + $storageConfig = new StorageConfig(1); |
|
114 | + $storageConfig->setMountPoint('mount'); |
|
115 | + $storageConfig->setBackend($backend); |
|
116 | + $storageConfig->setAuthMechanism($authMech); |
|
117 | + $storageConfig->setBackendOptions([]); |
|
118 | + |
|
119 | + $this->service->expects($this->never()) |
|
120 | + ->method('createStorage'); |
|
121 | + $this->service->expects($this->never()) |
|
122 | + ->method('addStorage'); |
|
123 | + |
|
124 | + $response = $this->controller->create( |
|
125 | + 'mount', |
|
126 | + 'local', |
|
127 | + NullMechanism::class, |
|
128 | + [], |
|
129 | + [], |
|
130 | + [], |
|
131 | + [], |
|
132 | + null |
|
133 | + ); |
|
134 | + |
|
135 | + $data = $response->getData(); |
|
136 | + $this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus()); |
|
137 | + } |
|
138 | + |
|
139 | + public function testUpdateStorage(): void { |
|
140 | + $authMech = $this->getAuthMechMock(); |
|
141 | + $authMech->method('validateStorage') |
|
142 | + ->willReturn(true); |
|
143 | + $authMech->method('isVisibleFor') |
|
144 | + ->willReturn(true); |
|
145 | + $backend = $this->getBackendMock(); |
|
146 | + $backend->method('validateStorage') |
|
147 | + ->willReturn(true); |
|
148 | + $backend->method('isVisibleFor') |
|
149 | + ->willReturn(true); |
|
150 | + |
|
151 | + $storageConfig = new StorageConfig(1); |
|
152 | + $storageConfig->setMountPoint('mount'); |
|
153 | + $storageConfig->setBackend($backend); |
|
154 | + $storageConfig->setAuthMechanism($authMech); |
|
155 | + $storageConfig->setBackendOptions([]); |
|
156 | + |
|
157 | + $this->service->expects($this->once()) |
|
158 | + ->method('createStorage') |
|
159 | + ->willReturn($storageConfig); |
|
160 | + $this->service->expects($this->once()) |
|
161 | + ->method('updateStorage') |
|
162 | + ->willReturn($storageConfig); |
|
163 | + |
|
164 | + $response = $this->controller->update( |
|
165 | + 1, |
|
166 | + 'mount', |
|
167 | + \OCA\Files_External\Lib\Storage\SMB::class, |
|
168 | + NullMechanism::class, |
|
169 | + [], |
|
170 | + [], |
|
171 | + [], |
|
172 | + [], |
|
173 | + null |
|
174 | + ); |
|
175 | + |
|
176 | + $data = $response->getData(); |
|
177 | + $this->assertEquals(Http::STATUS_OK, $response->getStatus()); |
|
178 | + $this->assertEquals($storageConfig->jsonSerialize(), $data); |
|
179 | + } |
|
180 | + |
|
181 | + public static function mountPointNamesProvider(): array { |
|
182 | + return [ |
|
183 | + [''], |
|
184 | + ['/'], |
|
185 | + ['//'], |
|
186 | + ]; |
|
187 | + } |
|
188 | + |
|
189 | + #[\PHPUnit\Framework\Attributes\DataProvider('mountPointNamesProvider')] |
|
190 | + public function testAddOrUpdateStorageInvalidMountPoint($mountPoint): void { |
|
191 | + $storageConfig = new StorageConfig(1); |
|
192 | + $storageConfig->setMountPoint($mountPoint); |
|
193 | + $storageConfig->setBackend($this->getBackendMock()); |
|
194 | + $storageConfig->setAuthMechanism($this->getAuthMechMock()); |
|
195 | + $storageConfig->setBackendOptions([]); |
|
196 | + |
|
197 | + $this->service->expects($this->exactly(2)) |
|
198 | + ->method('createStorage') |
|
199 | + ->willReturn($storageConfig); |
|
200 | + $this->service->expects($this->never()) |
|
201 | + ->method('addStorage'); |
|
202 | + $this->service->expects($this->never()) |
|
203 | + ->method('updateStorage'); |
|
204 | + |
|
205 | + $response = $this->controller->create( |
|
206 | + $mountPoint, |
|
207 | + \OCA\Files_External\Lib\Storage\SMB::class, |
|
208 | + NullMechanism::class, |
|
209 | + [], |
|
210 | + [], |
|
211 | + [], |
|
212 | + [], |
|
213 | + null |
|
214 | + ); |
|
215 | + |
|
216 | + $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
217 | + |
|
218 | + $response = $this->controller->update( |
|
219 | + 1, |
|
220 | + $mountPoint, |
|
221 | + \OCA\Files_External\Lib\Storage\SMB::class, |
|
222 | + NullMechanism::class, |
|
223 | + [], |
|
224 | + [], |
|
225 | + [], |
|
226 | + [], |
|
227 | + null |
|
228 | + ); |
|
229 | + |
|
230 | + $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
231 | + } |
|
232 | + |
|
233 | + public function testAddOrUpdateStorageInvalidBackend(): void { |
|
234 | + $this->service->expects($this->exactly(2)) |
|
235 | + ->method('createStorage') |
|
236 | + ->willThrowException(new \InvalidArgumentException()); |
|
237 | + $this->service->expects($this->never()) |
|
238 | + ->method('addStorage'); |
|
239 | + $this->service->expects($this->never()) |
|
240 | + ->method('updateStorage'); |
|
241 | + |
|
242 | + $response = $this->controller->create( |
|
243 | + 'mount', |
|
244 | + '\OC\Files\Storage\InvalidStorage', |
|
245 | + NullMechanism::class, |
|
246 | + [], |
|
247 | + [], |
|
248 | + [], |
|
249 | + [], |
|
250 | + null |
|
251 | + ); |
|
252 | + |
|
253 | + $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
254 | + |
|
255 | + $response = $this->controller->update( |
|
256 | + 1, |
|
257 | + 'mount', |
|
258 | + '\OC\Files\Storage\InvalidStorage', |
|
259 | + NullMechanism::class, |
|
260 | + [], |
|
261 | + [], |
|
262 | + [], |
|
263 | + [], |
|
264 | + null |
|
265 | + ); |
|
266 | + |
|
267 | + $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
268 | + } |
|
269 | + |
|
270 | + public function testUpdateStorageNonExisting(): void { |
|
271 | + $authMech = $this->getAuthMechMock(); |
|
272 | + $authMech->method('validateStorage') |
|
273 | + ->willReturn(true); |
|
274 | + $authMech->method('isVisibleFor') |
|
275 | + ->willReturn(true); |
|
276 | + $backend = $this->getBackendMock(); |
|
277 | + $backend->method('validateStorage') |
|
278 | + ->willReturn(true); |
|
279 | + $backend->method('isVisibleFor') |
|
280 | + ->willReturn(true); |
|
281 | + |
|
282 | + $storageConfig = new StorageConfig(255); |
|
283 | + $storageConfig->setMountPoint('mount'); |
|
284 | + $storageConfig->setBackend($backend); |
|
285 | + $storageConfig->setAuthMechanism($authMech); |
|
286 | + $storageConfig->setBackendOptions([]); |
|
287 | + |
|
288 | + $this->service->expects($this->once()) |
|
289 | + ->method('createStorage') |
|
290 | + ->willReturn($storageConfig); |
|
291 | + $this->service->expects($this->once()) |
|
292 | + ->method('updateStorage') |
|
293 | + ->willThrowException(new NotFoundException()); |
|
294 | + |
|
295 | + $response = $this->controller->update( |
|
296 | + 255, |
|
297 | + 'mount', |
|
298 | + \OCA\Files_External\Lib\Storage\SMB::class, |
|
299 | + NullMechanism::class, |
|
300 | + [], |
|
301 | + [], |
|
302 | + [], |
|
303 | + [], |
|
304 | + null |
|
305 | + ); |
|
306 | + |
|
307 | + $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); |
|
308 | + } |
|
309 | + |
|
310 | + public function testDeleteStorage(): void { |
|
311 | + $this->service->expects($this->once()) |
|
312 | + ->method('removeStorage'); |
|
313 | + |
|
314 | + $response = $this->controller->destroy(1); |
|
315 | + $this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus()); |
|
316 | + } |
|
317 | + |
|
318 | + public function testDeleteStorageNonExisting(): void { |
|
319 | + $this->service->expects($this->once()) |
|
320 | + ->method('removeStorage') |
|
321 | + ->willThrowException(new NotFoundException()); |
|
322 | + |
|
323 | + $response = $this->controller->destroy(255); |
|
324 | + $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); |
|
325 | + } |
|
326 | + |
|
327 | + public function testGetStorage(): void { |
|
328 | + $backend = $this->getBackendMock(); |
|
329 | + $authMech = $this->getAuthMechMock(); |
|
330 | + $storageConfig = new StorageConfig(1); |
|
331 | + $storageConfig->setMountPoint('test'); |
|
332 | + $storageConfig->setBackend($backend); |
|
333 | + $storageConfig->setAuthMechanism($authMech); |
|
334 | + $storageConfig->setBackendOptions(['user' => 'test', 'password', 'password123']); |
|
335 | + $storageConfig->setMountOptions(['priority' => false]); |
|
336 | + |
|
337 | + $this->service->expects($this->once()) |
|
338 | + ->method('getStorage') |
|
339 | + ->with(1) |
|
340 | + ->willReturn($storageConfig); |
|
341 | + $response = $this->controller->show(1); |
|
342 | + |
|
343 | + $this->assertEquals(Http::STATUS_OK, $response->getStatus()); |
|
344 | + $expected = $storageConfig->jsonSerialize(); |
|
345 | + $expected['can_edit'] = false; |
|
346 | + $this->assertEquals($expected, $response->getData()); |
|
347 | + } |
|
348 | + |
|
349 | + public static function validateStorageProvider(): array { |
|
350 | + return [ |
|
351 | + [true, true, true], |
|
352 | + [false, true, false], |
|
353 | + [true, false, false], |
|
354 | + [false, false, false] |
|
355 | + ]; |
|
356 | + } |
|
357 | + |
|
358 | + #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')] |
|
359 | + public function testValidateStorage(bool $backendValidate, bool $authMechValidate, bool $expectSuccess): void { |
|
360 | + $backend = $this->getBackendMock(); |
|
361 | + $backend->method('validateStorage') |
|
362 | + ->willReturn($backendValidate); |
|
363 | + $backend->method('isVisibleFor') |
|
364 | + ->willReturn(true); |
|
365 | + |
|
366 | + $authMech = $this->getAuthMechMock(); |
|
367 | + $authMech->method('validateStorage') |
|
368 | + ->willReturn($authMechValidate); |
|
369 | + $authMech->method('isVisibleFor') |
|
370 | + ->willReturn(true); |
|
371 | + |
|
372 | + $storageConfig = new StorageConfig(); |
|
373 | + $storageConfig->setMountPoint('mount'); |
|
374 | + $storageConfig->setBackend($backend); |
|
375 | + $storageConfig->setAuthMechanism($authMech); |
|
376 | + $storageConfig->setBackendOptions([]); |
|
377 | + |
|
378 | + $this->service->expects($this->once()) |
|
379 | + ->method('createStorage') |
|
380 | + ->willReturn($storageConfig); |
|
381 | + |
|
382 | + if ($expectSuccess) { |
|
383 | + $this->service->expects($this->once()) |
|
384 | + ->method('addStorage') |
|
385 | + ->with($storageConfig) |
|
386 | + ->willReturn($storageConfig); |
|
387 | + } else { |
|
388 | + $this->service->expects($this->never()) |
|
389 | + ->method('addStorage'); |
|
390 | + } |
|
391 | + |
|
392 | + $response = $this->controller->create( |
|
393 | + 'mount', |
|
394 | + \OCA\Files_External\Lib\Storage\SMB::class, |
|
395 | + NullMechanism::class, |
|
396 | + [], |
|
397 | + [], |
|
398 | + [], |
|
399 | + [], |
|
400 | + null |
|
401 | + ); |
|
402 | + |
|
403 | + if ($expectSuccess) { |
|
404 | + $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); |
|
405 | + } else { |
|
406 | + $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); |
|
407 | + } |
|
408 | + } |
|
409 | 409 | } |
@@ -24,315 +24,315 @@ |
||
24 | 24 | * @group DB |
25 | 25 | */ |
26 | 26 | class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { |
27 | - use UserTrait; |
|
28 | - |
|
29 | - protected IGroupManager&MockObject $groupManager; |
|
30 | - protected StoragesService $globalStoragesService; |
|
31 | - protected User $user; |
|
32 | - |
|
33 | - public const USER_ID = 'test_user'; |
|
34 | - public const GROUP_ID = 'test_group'; |
|
35 | - public const GROUP_ID2 = 'test_group2'; |
|
36 | - |
|
37 | - protected function setUp(): void { |
|
38 | - parent::setUp(); |
|
39 | - |
|
40 | - $this->globalStoragesService = $this->service; |
|
41 | - |
|
42 | - $this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class)); |
|
43 | - /** @var IUserSession&MockObject $userSession */ |
|
44 | - $userSession = $this->createMock(IUserSession::class); |
|
45 | - $userSession |
|
46 | - ->expects($this->any()) |
|
47 | - ->method('getUser') |
|
48 | - ->willReturn($this->user); |
|
49 | - |
|
50 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
51 | - $this->groupManager->method('isInGroup') |
|
52 | - ->willReturnCallback(function ($userId, $groupId) { |
|
53 | - if ($userId === self::USER_ID) { |
|
54 | - switch ($groupId) { |
|
55 | - case self::GROUP_ID: |
|
56 | - case self::GROUP_ID2: |
|
57 | - return true; |
|
58 | - } |
|
59 | - } |
|
60 | - return false; |
|
61 | - }); |
|
62 | - $this->groupManager->method('getUserGroupIds') |
|
63 | - ->willReturnCallback(function (IUser $user) { |
|
64 | - if ($user->getUID() === self::USER_ID) { |
|
65 | - return [self::GROUP_ID, self::GROUP_ID2]; |
|
66 | - } else { |
|
67 | - return []; |
|
68 | - } |
|
69 | - }); |
|
70 | - |
|
71 | - $this->service = new UserGlobalStoragesService( |
|
72 | - $this->backendService, |
|
73 | - $this->dbConfig, |
|
74 | - $userSession, |
|
75 | - $this->groupManager, |
|
76 | - $this->mountCache, |
|
77 | - $this->eventDispatcher, |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - public static function applicableStorageProvider(): array { |
|
82 | - return [ |
|
83 | - [[], [], true], |
|
84 | - |
|
85 | - // not applicable cases |
|
86 | - [['user1'], [], false], |
|
87 | - [[], ['group1'], false], |
|
88 | - [['user1'], ['group1'], false], |
|
89 | - |
|
90 | - // applicable cases |
|
91 | - [[self::USER_ID], [], true], |
|
92 | - [[], [self::GROUP_ID], true], |
|
93 | - [[self::USER_ID], ['group1'], true], |
|
94 | - [['user1'], [self::GROUP_ID], true], |
|
95 | - |
|
96 | - // sanity checks |
|
97 | - [['user1', 'user2', self::USER_ID, 'user3'], [], true], |
|
98 | - ]; |
|
99 | - } |
|
100 | - |
|
101 | - #[\PHPUnit\Framework\Attributes\DataProvider('applicableStorageProvider')] |
|
102 | - public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible): void { |
|
103 | - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
104 | - $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
105 | - |
|
106 | - $storage = new StorageConfig(); |
|
107 | - $storage->setMountPoint('mountpoint'); |
|
108 | - $storage->setBackend($backend); |
|
109 | - $storage->setAuthMechanism($authMechanism); |
|
110 | - $storage->setBackendOptions(['password' => 'testPassword']); |
|
111 | - $storage->setApplicableUsers($applicableUsers); |
|
112 | - $storage->setApplicableGroups($applicableGroups); |
|
113 | - |
|
114 | - $newStorage = $this->globalStoragesService->addStorage($storage); |
|
115 | - |
|
116 | - $storages = $this->service->getAllStorages(); |
|
117 | - if ($isVisible) { |
|
118 | - $this->assertEquals(1, count($storages)); |
|
119 | - $retrievedStorage = $this->service->getStorage($newStorage->getId()); |
|
120 | - $this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint()); |
|
121 | - } else { |
|
122 | - $this->assertEquals(0, count($storages)); |
|
123 | - |
|
124 | - try { |
|
125 | - $this->service->getStorage($newStorage->getId()); |
|
126 | - $this->fail('Failed asserting that storage can\'t be accessed by id'); |
|
127 | - } catch (NotFoundException $e) { |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - public function testAddStorage($storageParams = null): void { |
|
134 | - $this->expectException(\DomainException::class); |
|
135 | - |
|
136 | - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
137 | - $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
138 | - |
|
139 | - $storage = new StorageConfig(255); |
|
140 | - $storage->setMountPoint('mountpoint'); |
|
141 | - $storage->setBackend($backend); |
|
142 | - $storage->setAuthMechanism($authMechanism); |
|
143 | - $storage->setBackendOptions(['password' => 'testPassword']); |
|
144 | - |
|
145 | - $this->service->addStorage($storage); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - public function testUpdateStorage($storageParams = null): void { |
|
150 | - $this->expectException(\DomainException::class); |
|
151 | - |
|
152 | - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
153 | - $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
154 | - |
|
155 | - $storage = new StorageConfig(255); |
|
156 | - $storage->setMountPoint('mountpoint'); |
|
157 | - $storage->setBackend($backend); |
|
158 | - $storage->setAuthMechanism($authMechanism); |
|
159 | - $storage->setBackendOptions(['password' => 'testPassword']); |
|
160 | - |
|
161 | - $newStorage = $this->globalStoragesService->addStorage($storage); |
|
162 | - |
|
163 | - $retrievedStorage = $this->service->getStorage($newStorage->getId()); |
|
164 | - $retrievedStorage->setMountPoint('abc'); |
|
165 | - $this->service->updateStorage($retrievedStorage); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - public function testNonExistingStorage(): void { |
|
170 | - $this->expectException(\DomainException::class); |
|
171 | - |
|
172 | - $this->ActualNonExistingStorageTest(); |
|
173 | - } |
|
174 | - |
|
175 | - #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')] |
|
176 | - public function testDeleteStorage($backendOptions, $rustyStorageId): void { |
|
177 | - $this->expectException(\DomainException::class); |
|
178 | - |
|
179 | - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
180 | - $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
181 | - |
|
182 | - $storage = new StorageConfig(255); |
|
183 | - $storage->setMountPoint('mountpoint'); |
|
184 | - $storage->setBackend($backend); |
|
185 | - $storage->setAuthMechanism($authMechanism); |
|
186 | - $storage->setBackendOptions($backendOptions); |
|
187 | - |
|
188 | - $newStorage = $this->globalStoragesService->addStorage($storage); |
|
189 | - $id = $newStorage->getId(); |
|
190 | - |
|
191 | - $this->service->removeStorage($id); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - public function testDeleteUnexistingStorage(): void { |
|
196 | - $this->expectException(\DomainException::class); |
|
197 | - |
|
198 | - $this->actualDeletedUnexistingStorageTest(); |
|
199 | - } |
|
200 | - |
|
201 | - public static function getUniqueStoragesProvider(): array { |
|
202 | - return [ |
|
203 | - // 'all' vs group |
|
204 | - [100, [], [], 100, [], [self::GROUP_ID], 2], |
|
205 | - [100, [], [self::GROUP_ID], 100, [], [], 1], |
|
206 | - |
|
207 | - // 'all' vs user |
|
208 | - [100, [], [], 100, [self::USER_ID], [], 2], |
|
209 | - [100, [self::USER_ID], [], 100, [], [], 1], |
|
210 | - |
|
211 | - // group vs user |
|
212 | - [100, [], [self::GROUP_ID], 100, [self::USER_ID], [], 2], |
|
213 | - [100, [self::USER_ID], [], 100, [], [self::GROUP_ID], 1], |
|
214 | - |
|
215 | - // group+user vs group |
|
216 | - [100, [], [self::GROUP_ID2], 100, [self::USER_ID], [self::GROUP_ID], 2], |
|
217 | - [100, [self::USER_ID], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1], |
|
218 | - |
|
219 | - // user vs 'all' (higher priority) |
|
220 | - [200, [], [], 100, [self::USER_ID], [], 2], |
|
221 | - [100, [self::USER_ID], [], 200, [], [], 1], |
|
222 | - |
|
223 | - // group vs group (higher priority) |
|
224 | - [100, [], [self::GROUP_ID2], 200, [], [self::GROUP_ID], 2], |
|
225 | - [200, [], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1], |
|
226 | - ]; |
|
227 | - } |
|
228 | - |
|
229 | - #[\PHPUnit\Framework\Attributes\DataProvider('getUniqueStoragesProvider')] |
|
230 | - public function testGetUniqueStorages( |
|
231 | - $priority1, $applicableUsers1, $applicableGroups1, |
|
232 | - $priority2, $applicableUsers2, $applicableGroups2, |
|
233 | - $expectedPrecedence, |
|
234 | - ): void { |
|
235 | - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
236 | - $backend->method('isVisibleFor') |
|
237 | - ->willReturn(true); |
|
238 | - $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
239 | - $authMechanism->method('isVisibleFor') |
|
240 | - ->willReturn(true); |
|
241 | - |
|
242 | - $storage1 = new StorageConfig(); |
|
243 | - $storage1->setMountPoint('mountpoint'); |
|
244 | - $storage1->setBackend($backend); |
|
245 | - $storage1->setAuthMechanism($authMechanism); |
|
246 | - $storage1->setBackendOptions(['password' => 'testPassword']); |
|
247 | - $storage1->setPriority($priority1); |
|
248 | - $storage1->setApplicableUsers($applicableUsers1); |
|
249 | - $storage1->setApplicableGroups($applicableGroups1); |
|
250 | - |
|
251 | - $storage1 = $this->globalStoragesService->addStorage($storage1); |
|
252 | - |
|
253 | - $storage2 = new StorageConfig(); |
|
254 | - $storage2->setMountPoint('mountpoint'); |
|
255 | - $storage2->setBackend($backend); |
|
256 | - $storage2->setAuthMechanism($authMechanism); |
|
257 | - $storage2->setBackendOptions(['password' => 'testPassword']); |
|
258 | - $storage2->setPriority($priority2); |
|
259 | - $storage2->setApplicableUsers($applicableUsers2); |
|
260 | - $storage2->setApplicableGroups($applicableGroups2); |
|
261 | - |
|
262 | - $storage2 = $this->globalStoragesService->addStorage($storage2); |
|
263 | - |
|
264 | - $storages = $this->service->getUniqueStorages(); |
|
265 | - $this->assertCount(1, $storages); |
|
266 | - |
|
267 | - if ($expectedPrecedence === 1) { |
|
268 | - $this->assertArrayHasKey($storage1->getID(), $storages); |
|
269 | - } elseif ($expectedPrecedence === 2) { |
|
270 | - $this->assertArrayHasKey($storage2->getID(), $storages); |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - public function testGetStoragesBackendNotVisible(): void { |
|
275 | - // we don't test this here |
|
276 | - $this->addToAssertionCount(1); |
|
277 | - } |
|
278 | - |
|
279 | - public function testGetStoragesAuthMechanismNotVisible(): void { |
|
280 | - // we don't test this here |
|
281 | - $this->addToAssertionCount(1); |
|
282 | - } |
|
283 | - |
|
284 | - public function testHooksAddStorage($a = null, $b = null, $c = null): void { |
|
285 | - // we don't test this here |
|
286 | - $this->addToAssertionCount(1); |
|
287 | - } |
|
288 | - |
|
289 | - public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null): void { |
|
290 | - // we don't test this here |
|
291 | - $this->addToAssertionCount(1); |
|
292 | - } |
|
293 | - |
|
294 | - public function testHooksRenameMountPoint(): void { |
|
295 | - // we don't test this here |
|
296 | - $this->addToAssertionCount(1); |
|
297 | - } |
|
298 | - |
|
299 | - public function testHooksDeleteStorage($a = null, $b = null, $c = null): void { |
|
300 | - // we don't test this here |
|
301 | - $this->addToAssertionCount(1); |
|
302 | - } |
|
303 | - |
|
304 | - public function testLegacyConfigConversionApplicableAll(): void { |
|
305 | - // we don't test this here |
|
306 | - $this->addToAssertionCount(1); |
|
307 | - } |
|
308 | - |
|
309 | - public function testLegacyConfigConversionApplicableUserAndGroup(): void { |
|
310 | - // we don't test this here |
|
311 | - $this->addToAssertionCount(1); |
|
312 | - } |
|
313 | - |
|
314 | - public function testReadLegacyConfigAndGenerateConfigId(): void { |
|
315 | - // we don't test this here |
|
316 | - $this->addToAssertionCount(1); |
|
317 | - } |
|
318 | - |
|
319 | - public function testReadLegacyConfigNoAuthMechanism(): void { |
|
320 | - // we don't test this here |
|
321 | - $this->addToAssertionCount(1); |
|
322 | - } |
|
323 | - |
|
324 | - public function testReadLegacyConfigClass(): void { |
|
325 | - // we don't test this here |
|
326 | - $this->addToAssertionCount(1); |
|
327 | - } |
|
328 | - |
|
329 | - public function testReadEmptyMountPoint(): void { |
|
330 | - // we don't test this here |
|
331 | - $this->addToAssertionCount(1); |
|
332 | - } |
|
333 | - |
|
334 | - public function testUpdateStorageMountPoint(): void { |
|
335 | - // we don't test this here |
|
336 | - $this->addToAssertionCount(1); |
|
337 | - } |
|
27 | + use UserTrait; |
|
28 | + |
|
29 | + protected IGroupManager&MockObject $groupManager; |
|
30 | + protected StoragesService $globalStoragesService; |
|
31 | + protected User $user; |
|
32 | + |
|
33 | + public const USER_ID = 'test_user'; |
|
34 | + public const GROUP_ID = 'test_group'; |
|
35 | + public const GROUP_ID2 = 'test_group2'; |
|
36 | + |
|
37 | + protected function setUp(): void { |
|
38 | + parent::setUp(); |
|
39 | + |
|
40 | + $this->globalStoragesService = $this->service; |
|
41 | + |
|
42 | + $this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class)); |
|
43 | + /** @var IUserSession&MockObject $userSession */ |
|
44 | + $userSession = $this->createMock(IUserSession::class); |
|
45 | + $userSession |
|
46 | + ->expects($this->any()) |
|
47 | + ->method('getUser') |
|
48 | + ->willReturn($this->user); |
|
49 | + |
|
50 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
51 | + $this->groupManager->method('isInGroup') |
|
52 | + ->willReturnCallback(function ($userId, $groupId) { |
|
53 | + if ($userId === self::USER_ID) { |
|
54 | + switch ($groupId) { |
|
55 | + case self::GROUP_ID: |
|
56 | + case self::GROUP_ID2: |
|
57 | + return true; |
|
58 | + } |
|
59 | + } |
|
60 | + return false; |
|
61 | + }); |
|
62 | + $this->groupManager->method('getUserGroupIds') |
|
63 | + ->willReturnCallback(function (IUser $user) { |
|
64 | + if ($user->getUID() === self::USER_ID) { |
|
65 | + return [self::GROUP_ID, self::GROUP_ID2]; |
|
66 | + } else { |
|
67 | + return []; |
|
68 | + } |
|
69 | + }); |
|
70 | + |
|
71 | + $this->service = new UserGlobalStoragesService( |
|
72 | + $this->backendService, |
|
73 | + $this->dbConfig, |
|
74 | + $userSession, |
|
75 | + $this->groupManager, |
|
76 | + $this->mountCache, |
|
77 | + $this->eventDispatcher, |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + public static function applicableStorageProvider(): array { |
|
82 | + return [ |
|
83 | + [[], [], true], |
|
84 | + |
|
85 | + // not applicable cases |
|
86 | + [['user1'], [], false], |
|
87 | + [[], ['group1'], false], |
|
88 | + [['user1'], ['group1'], false], |
|
89 | + |
|
90 | + // applicable cases |
|
91 | + [[self::USER_ID], [], true], |
|
92 | + [[], [self::GROUP_ID], true], |
|
93 | + [[self::USER_ID], ['group1'], true], |
|
94 | + [['user1'], [self::GROUP_ID], true], |
|
95 | + |
|
96 | + // sanity checks |
|
97 | + [['user1', 'user2', self::USER_ID, 'user3'], [], true], |
|
98 | + ]; |
|
99 | + } |
|
100 | + |
|
101 | + #[\PHPUnit\Framework\Attributes\DataProvider('applicableStorageProvider')] |
|
102 | + public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible): void { |
|
103 | + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
104 | + $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
105 | + |
|
106 | + $storage = new StorageConfig(); |
|
107 | + $storage->setMountPoint('mountpoint'); |
|
108 | + $storage->setBackend($backend); |
|
109 | + $storage->setAuthMechanism($authMechanism); |
|
110 | + $storage->setBackendOptions(['password' => 'testPassword']); |
|
111 | + $storage->setApplicableUsers($applicableUsers); |
|
112 | + $storage->setApplicableGroups($applicableGroups); |
|
113 | + |
|
114 | + $newStorage = $this->globalStoragesService->addStorage($storage); |
|
115 | + |
|
116 | + $storages = $this->service->getAllStorages(); |
|
117 | + if ($isVisible) { |
|
118 | + $this->assertEquals(1, count($storages)); |
|
119 | + $retrievedStorage = $this->service->getStorage($newStorage->getId()); |
|
120 | + $this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint()); |
|
121 | + } else { |
|
122 | + $this->assertEquals(0, count($storages)); |
|
123 | + |
|
124 | + try { |
|
125 | + $this->service->getStorage($newStorage->getId()); |
|
126 | + $this->fail('Failed asserting that storage can\'t be accessed by id'); |
|
127 | + } catch (NotFoundException $e) { |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + public function testAddStorage($storageParams = null): void { |
|
134 | + $this->expectException(\DomainException::class); |
|
135 | + |
|
136 | + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
137 | + $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
138 | + |
|
139 | + $storage = new StorageConfig(255); |
|
140 | + $storage->setMountPoint('mountpoint'); |
|
141 | + $storage->setBackend($backend); |
|
142 | + $storage->setAuthMechanism($authMechanism); |
|
143 | + $storage->setBackendOptions(['password' => 'testPassword']); |
|
144 | + |
|
145 | + $this->service->addStorage($storage); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + public function testUpdateStorage($storageParams = null): void { |
|
150 | + $this->expectException(\DomainException::class); |
|
151 | + |
|
152 | + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
153 | + $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
154 | + |
|
155 | + $storage = new StorageConfig(255); |
|
156 | + $storage->setMountPoint('mountpoint'); |
|
157 | + $storage->setBackend($backend); |
|
158 | + $storage->setAuthMechanism($authMechanism); |
|
159 | + $storage->setBackendOptions(['password' => 'testPassword']); |
|
160 | + |
|
161 | + $newStorage = $this->globalStoragesService->addStorage($storage); |
|
162 | + |
|
163 | + $retrievedStorage = $this->service->getStorage($newStorage->getId()); |
|
164 | + $retrievedStorage->setMountPoint('abc'); |
|
165 | + $this->service->updateStorage($retrievedStorage); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + public function testNonExistingStorage(): void { |
|
170 | + $this->expectException(\DomainException::class); |
|
171 | + |
|
172 | + $this->ActualNonExistingStorageTest(); |
|
173 | + } |
|
174 | + |
|
175 | + #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')] |
|
176 | + public function testDeleteStorage($backendOptions, $rustyStorageId): void { |
|
177 | + $this->expectException(\DomainException::class); |
|
178 | + |
|
179 | + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
180 | + $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
181 | + |
|
182 | + $storage = new StorageConfig(255); |
|
183 | + $storage->setMountPoint('mountpoint'); |
|
184 | + $storage->setBackend($backend); |
|
185 | + $storage->setAuthMechanism($authMechanism); |
|
186 | + $storage->setBackendOptions($backendOptions); |
|
187 | + |
|
188 | + $newStorage = $this->globalStoragesService->addStorage($storage); |
|
189 | + $id = $newStorage->getId(); |
|
190 | + |
|
191 | + $this->service->removeStorage($id); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + public function testDeleteUnexistingStorage(): void { |
|
196 | + $this->expectException(\DomainException::class); |
|
197 | + |
|
198 | + $this->actualDeletedUnexistingStorageTest(); |
|
199 | + } |
|
200 | + |
|
201 | + public static function getUniqueStoragesProvider(): array { |
|
202 | + return [ |
|
203 | + // 'all' vs group |
|
204 | + [100, [], [], 100, [], [self::GROUP_ID], 2], |
|
205 | + [100, [], [self::GROUP_ID], 100, [], [], 1], |
|
206 | + |
|
207 | + // 'all' vs user |
|
208 | + [100, [], [], 100, [self::USER_ID], [], 2], |
|
209 | + [100, [self::USER_ID], [], 100, [], [], 1], |
|
210 | + |
|
211 | + // group vs user |
|
212 | + [100, [], [self::GROUP_ID], 100, [self::USER_ID], [], 2], |
|
213 | + [100, [self::USER_ID], [], 100, [], [self::GROUP_ID], 1], |
|
214 | + |
|
215 | + // group+user vs group |
|
216 | + [100, [], [self::GROUP_ID2], 100, [self::USER_ID], [self::GROUP_ID], 2], |
|
217 | + [100, [self::USER_ID], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1], |
|
218 | + |
|
219 | + // user vs 'all' (higher priority) |
|
220 | + [200, [], [], 100, [self::USER_ID], [], 2], |
|
221 | + [100, [self::USER_ID], [], 200, [], [], 1], |
|
222 | + |
|
223 | + // group vs group (higher priority) |
|
224 | + [100, [], [self::GROUP_ID2], 200, [], [self::GROUP_ID], 2], |
|
225 | + [200, [], [self::GROUP_ID], 100, [], [self::GROUP_ID2], 1], |
|
226 | + ]; |
|
227 | + } |
|
228 | + |
|
229 | + #[\PHPUnit\Framework\Attributes\DataProvider('getUniqueStoragesProvider')] |
|
230 | + public function testGetUniqueStorages( |
|
231 | + $priority1, $applicableUsers1, $applicableGroups1, |
|
232 | + $priority2, $applicableUsers2, $applicableGroups2, |
|
233 | + $expectedPrecedence, |
|
234 | + ): void { |
|
235 | + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); |
|
236 | + $backend->method('isVisibleFor') |
|
237 | + ->willReturn(true); |
|
238 | + $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); |
|
239 | + $authMechanism->method('isVisibleFor') |
|
240 | + ->willReturn(true); |
|
241 | + |
|
242 | + $storage1 = new StorageConfig(); |
|
243 | + $storage1->setMountPoint('mountpoint'); |
|
244 | + $storage1->setBackend($backend); |
|
245 | + $storage1->setAuthMechanism($authMechanism); |
|
246 | + $storage1->setBackendOptions(['password' => 'testPassword']); |
|
247 | + $storage1->setPriority($priority1); |
|
248 | + $storage1->setApplicableUsers($applicableUsers1); |
|
249 | + $storage1->setApplicableGroups($applicableGroups1); |
|
250 | + |
|
251 | + $storage1 = $this->globalStoragesService->addStorage($storage1); |
|
252 | + |
|
253 | + $storage2 = new StorageConfig(); |
|
254 | + $storage2->setMountPoint('mountpoint'); |
|
255 | + $storage2->setBackend($backend); |
|
256 | + $storage2->setAuthMechanism($authMechanism); |
|
257 | + $storage2->setBackendOptions(['password' => 'testPassword']); |
|
258 | + $storage2->setPriority($priority2); |
|
259 | + $storage2->setApplicableUsers($applicableUsers2); |
|
260 | + $storage2->setApplicableGroups($applicableGroups2); |
|
261 | + |
|
262 | + $storage2 = $this->globalStoragesService->addStorage($storage2); |
|
263 | + |
|
264 | + $storages = $this->service->getUniqueStorages(); |
|
265 | + $this->assertCount(1, $storages); |
|
266 | + |
|
267 | + if ($expectedPrecedence === 1) { |
|
268 | + $this->assertArrayHasKey($storage1->getID(), $storages); |
|
269 | + } elseif ($expectedPrecedence === 2) { |
|
270 | + $this->assertArrayHasKey($storage2->getID(), $storages); |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + public function testGetStoragesBackendNotVisible(): void { |
|
275 | + // we don't test this here |
|
276 | + $this->addToAssertionCount(1); |
|
277 | + } |
|
278 | + |
|
279 | + public function testGetStoragesAuthMechanismNotVisible(): void { |
|
280 | + // we don't test this here |
|
281 | + $this->addToAssertionCount(1); |
|
282 | + } |
|
283 | + |
|
284 | + public function testHooksAddStorage($a = null, $b = null, $c = null): void { |
|
285 | + // we don't test this here |
|
286 | + $this->addToAssertionCount(1); |
|
287 | + } |
|
288 | + |
|
289 | + public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null): void { |
|
290 | + // we don't test this here |
|
291 | + $this->addToAssertionCount(1); |
|
292 | + } |
|
293 | + |
|
294 | + public function testHooksRenameMountPoint(): void { |
|
295 | + // we don't test this here |
|
296 | + $this->addToAssertionCount(1); |
|
297 | + } |
|
298 | + |
|
299 | + public function testHooksDeleteStorage($a = null, $b = null, $c = null): void { |
|
300 | + // we don't test this here |
|
301 | + $this->addToAssertionCount(1); |
|
302 | + } |
|
303 | + |
|
304 | + public function testLegacyConfigConversionApplicableAll(): void { |
|
305 | + // we don't test this here |
|
306 | + $this->addToAssertionCount(1); |
|
307 | + } |
|
308 | + |
|
309 | + public function testLegacyConfigConversionApplicableUserAndGroup(): void { |
|
310 | + // we don't test this here |
|
311 | + $this->addToAssertionCount(1); |
|
312 | + } |
|
313 | + |
|
314 | + public function testReadLegacyConfigAndGenerateConfigId(): void { |
|
315 | + // we don't test this here |
|
316 | + $this->addToAssertionCount(1); |
|
317 | + } |
|
318 | + |
|
319 | + public function testReadLegacyConfigNoAuthMechanism(): void { |
|
320 | + // we don't test this here |
|
321 | + $this->addToAssertionCount(1); |
|
322 | + } |
|
323 | + |
|
324 | + public function testReadLegacyConfigClass(): void { |
|
325 | + // we don't test this here |
|
326 | + $this->addToAssertionCount(1); |
|
327 | + } |
|
328 | + |
|
329 | + public function testReadEmptyMountPoint(): void { |
|
330 | + // we don't test this here |
|
331 | + $this->addToAssertionCount(1); |
|
332 | + } |
|
333 | + |
|
334 | + public function testUpdateStorageMountPoint(): void { |
|
335 | + // we don't test this here |
|
336 | + $this->addToAssertionCount(1); |
|
337 | + } |
|
338 | 338 | } |
@@ -17,586 +17,586 @@ |
||
17 | 17 | * @group DB |
18 | 18 | */ |
19 | 19 | class GlobalStoragesServiceTest extends StoragesServiceTestCase { |
20 | - protected function setUp(): void { |
|
21 | - parent::setUp(); |
|
22 | - $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher); |
|
23 | - } |
|
24 | - |
|
25 | - protected function tearDown(): void { |
|
26 | - @unlink($this->dataDir . '/mount.json'); |
|
27 | - parent::tearDown(); |
|
28 | - } |
|
29 | - |
|
30 | - protected function makeTestStorageData() { |
|
31 | - return $this->makeStorageConfig([ |
|
32 | - 'mountPoint' => 'mountpoint', |
|
33 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
34 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
35 | - 'backendOptions' => [ |
|
36 | - 'option1' => 'value1', |
|
37 | - 'option2' => 'value2', |
|
38 | - 'password' => 'testPassword', |
|
39 | - ], |
|
40 | - 'applicableUsers' => [], |
|
41 | - 'applicableGroups' => [], |
|
42 | - 'priority' => 15, |
|
43 | - 'mountOptions' => [ |
|
44 | - 'preview' => false, |
|
45 | - ] |
|
46 | - ]); |
|
47 | - } |
|
48 | - |
|
49 | - public static function storageDataProvider(): array { |
|
50 | - return [ |
|
51 | - // all users |
|
52 | - [ |
|
53 | - [ |
|
54 | - 'mountPoint' => 'mountpoint', |
|
55 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
56 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
57 | - 'backendOptions' => [ |
|
58 | - 'option1' => 'value1', |
|
59 | - 'option2' => 'value2', |
|
60 | - 'password' => 'testPassword', |
|
61 | - ], |
|
62 | - 'applicableUsers' => [], |
|
63 | - 'applicableGroups' => [], |
|
64 | - 'priority' => 15, |
|
65 | - ], |
|
66 | - ], |
|
67 | - // some users |
|
68 | - [ |
|
69 | - [ |
|
70 | - 'mountPoint' => 'mountpoint', |
|
71 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
72 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
73 | - 'backendOptions' => [ |
|
74 | - 'option1' => 'value1', |
|
75 | - 'option2' => 'value2', |
|
76 | - 'password' => 'testPassword', |
|
77 | - ], |
|
78 | - 'applicableUsers' => ['user1', 'user2'], |
|
79 | - 'applicableGroups' => [], |
|
80 | - 'priority' => 15, |
|
81 | - ], |
|
82 | - ], |
|
83 | - // some groups |
|
84 | - [ |
|
85 | - [ |
|
86 | - 'mountPoint' => 'mountpoint', |
|
87 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
88 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
89 | - 'backendOptions' => [ |
|
90 | - 'option1' => 'value1', |
|
91 | - 'option2' => 'value2', |
|
92 | - 'password' => 'testPassword', |
|
93 | - ], |
|
94 | - 'applicableUsers' => [], |
|
95 | - 'applicableGroups' => ['group1', 'group2'], |
|
96 | - 'priority' => 15, |
|
97 | - ], |
|
98 | - ], |
|
99 | - // both users and groups |
|
100 | - [ |
|
101 | - [ |
|
102 | - 'mountPoint' => 'mountpoint', |
|
103 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
104 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
105 | - 'backendOptions' => [ |
|
106 | - 'option1' => 'value1', |
|
107 | - 'option2' => 'value2', |
|
108 | - 'password' => 'testPassword', |
|
109 | - ], |
|
110 | - 'applicableUsers' => ['user1', 'user2'], |
|
111 | - 'applicableGroups' => ['group1', 'group2'], |
|
112 | - 'priority' => 15, |
|
113 | - ], |
|
114 | - ], |
|
115 | - ]; |
|
116 | - } |
|
117 | - |
|
118 | - #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')] |
|
119 | - public function testAddStorage($storageParams): void { |
|
120 | - $storage = $this->makeStorageConfig($storageParams); |
|
121 | - $newStorage = $this->service->addStorage($storage); |
|
122 | - |
|
123 | - $baseId = $newStorage->getId(); |
|
124 | - |
|
125 | - $newStorage = $this->service->getStorage($baseId); |
|
126 | - |
|
127 | - $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint()); |
|
128 | - $this->assertEquals($storage->getBackend(), $newStorage->getBackend()); |
|
129 | - $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism()); |
|
130 | - $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions()); |
|
131 | - $this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
132 | - $this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
133 | - $this->assertEquals($storage->getPriority(), $newStorage->getPriority()); |
|
134 | - $this->assertEquals(0, $newStorage->getStatus()); |
|
135 | - |
|
136 | - $nextStorage = $this->service->addStorage($storage); |
|
137 | - $this->assertEquals($baseId + 1, $nextStorage->getId()); |
|
138 | - } |
|
139 | - |
|
140 | - #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')] |
|
141 | - public function testUpdateStorage($updatedStorageParams): void { |
|
142 | - $updatedStorage = $this->makeStorageConfig($updatedStorageParams); |
|
143 | - $storage = $this->makeStorageConfig([ |
|
144 | - 'mountPoint' => 'mountpoint', |
|
145 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
146 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
147 | - 'backendOptions' => [ |
|
148 | - 'option1' => 'value1', |
|
149 | - 'option2' => 'value2', |
|
150 | - 'password' => 'testPassword', |
|
151 | - ], |
|
152 | - 'applicableUsers' => [], |
|
153 | - 'applicableGroups' => [], |
|
154 | - 'priority' => 15, |
|
155 | - ]); |
|
156 | - |
|
157 | - $newStorage = $this->service->addStorage($storage); |
|
158 | - $id = $newStorage->getId(); |
|
159 | - |
|
160 | - $updatedStorage->setId($id); |
|
161 | - |
|
162 | - $this->service->updateStorage($updatedStorage); |
|
163 | - $newStorage = $this->service->getStorage($id); |
|
164 | - |
|
165 | - $this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint()); |
|
166 | - $this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']); |
|
167 | - $this->assertEqualsCanonicalizing($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
168 | - $this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
169 | - $this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority()); |
|
170 | - $this->assertEquals(0, $newStorage->getStatus()); |
|
171 | - } |
|
172 | - |
|
173 | - public static function hooksAddStorageDataProvider(): array { |
|
174 | - return [ |
|
175 | - // applicable all |
|
176 | - [ |
|
177 | - [], |
|
178 | - [], |
|
179 | - // expected hook calls |
|
180 | - [ |
|
181 | - [ |
|
182 | - Filesystem::signal_create_mount, |
|
183 | - MountConfig::MOUNT_TYPE_USER, |
|
184 | - 'all' |
|
185 | - ], |
|
186 | - ], |
|
187 | - ], |
|
188 | - // single user |
|
189 | - [ |
|
190 | - ['user1'], |
|
191 | - [], |
|
192 | - // expected hook calls |
|
193 | - [ |
|
194 | - [ |
|
195 | - Filesystem::signal_create_mount, |
|
196 | - MountConfig::MOUNT_TYPE_USER, |
|
197 | - 'user1', |
|
198 | - ], |
|
199 | - ], |
|
200 | - ], |
|
201 | - // single group |
|
202 | - [ |
|
203 | - [], |
|
204 | - ['group1'], |
|
205 | - // expected hook calls |
|
206 | - [ |
|
207 | - [ |
|
208 | - Filesystem::signal_create_mount, |
|
209 | - MountConfig::MOUNT_TYPE_GROUP, |
|
210 | - 'group1', |
|
211 | - ], |
|
212 | - ], |
|
213 | - ], |
|
214 | - // multiple users |
|
215 | - [ |
|
216 | - ['user1', 'user2'], |
|
217 | - [], |
|
218 | - [ |
|
219 | - [ |
|
220 | - Filesystem::signal_create_mount, |
|
221 | - MountConfig::MOUNT_TYPE_USER, |
|
222 | - 'user1', |
|
223 | - ], |
|
224 | - [ |
|
225 | - Filesystem::signal_create_mount, |
|
226 | - MountConfig::MOUNT_TYPE_USER, |
|
227 | - 'user2', |
|
228 | - ], |
|
229 | - ], |
|
230 | - ], |
|
231 | - // multiple groups |
|
232 | - [ |
|
233 | - [], |
|
234 | - ['group1', 'group2'], |
|
235 | - // expected hook calls |
|
236 | - [ |
|
237 | - [ |
|
238 | - Filesystem::signal_create_mount, |
|
239 | - MountConfig::MOUNT_TYPE_GROUP, |
|
240 | - 'group1' |
|
241 | - ], |
|
242 | - [ |
|
243 | - Filesystem::signal_create_mount, |
|
244 | - MountConfig::MOUNT_TYPE_GROUP, |
|
245 | - 'group2' |
|
246 | - ], |
|
247 | - ], |
|
248 | - ], |
|
249 | - // mixed groups and users |
|
250 | - [ |
|
251 | - ['user1', 'user2'], |
|
252 | - ['group1', 'group2'], |
|
253 | - // expected hook calls |
|
254 | - [ |
|
255 | - [ |
|
256 | - Filesystem::signal_create_mount, |
|
257 | - MountConfig::MOUNT_TYPE_USER, |
|
258 | - 'user1', |
|
259 | - ], |
|
260 | - [ |
|
261 | - Filesystem::signal_create_mount, |
|
262 | - MountConfig::MOUNT_TYPE_USER, |
|
263 | - 'user2', |
|
264 | - ], |
|
265 | - [ |
|
266 | - Filesystem::signal_create_mount, |
|
267 | - MountConfig::MOUNT_TYPE_GROUP, |
|
268 | - 'group1' |
|
269 | - ], |
|
270 | - [ |
|
271 | - Filesystem::signal_create_mount, |
|
272 | - MountConfig::MOUNT_TYPE_GROUP, |
|
273 | - 'group2' |
|
274 | - ], |
|
275 | - ], |
|
276 | - ], |
|
277 | - ]; |
|
278 | - } |
|
279 | - |
|
280 | - #[\PHPUnit\Framework\Attributes\DataProvider('hooksAddStorageDataProvider')] |
|
281 | - public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void { |
|
282 | - $storage = $this->makeTestStorageData(); |
|
283 | - $storage->setApplicableUsers($applicableUsers); |
|
284 | - $storage->setApplicableGroups($applicableGroups); |
|
285 | - $this->service->addStorage($storage); |
|
286 | - |
|
287 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
288 | - |
|
289 | - foreach ($expectedCalls as $index => $call) { |
|
290 | - $this->assertHookCall( |
|
291 | - self::$hookCalls[$index], |
|
292 | - $call[0], |
|
293 | - $storage->getMountPoint(), |
|
294 | - $call[1], |
|
295 | - $call[2] |
|
296 | - ); |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - public static function hooksUpdateStorageDataProvider(): array { |
|
301 | - return [ |
|
302 | - [ |
|
303 | - // nothing to multiple users and groups |
|
304 | - [], |
|
305 | - [], |
|
306 | - ['user1', 'user2'], |
|
307 | - ['group1', 'group2'], |
|
308 | - // expected hook calls |
|
309 | - [ |
|
310 | - // delete the "all entry" |
|
311 | - [ |
|
312 | - Filesystem::signal_delete_mount, |
|
313 | - MountConfig::MOUNT_TYPE_USER, |
|
314 | - 'all', |
|
315 | - ], |
|
316 | - [ |
|
317 | - Filesystem::signal_create_mount, |
|
318 | - MountConfig::MOUNT_TYPE_USER, |
|
319 | - 'user1', |
|
320 | - ], |
|
321 | - [ |
|
322 | - Filesystem::signal_create_mount, |
|
323 | - MountConfig::MOUNT_TYPE_USER, |
|
324 | - 'user2', |
|
325 | - ], |
|
326 | - [ |
|
327 | - Filesystem::signal_create_mount, |
|
328 | - MountConfig::MOUNT_TYPE_GROUP, |
|
329 | - 'group1' |
|
330 | - ], |
|
331 | - [ |
|
332 | - Filesystem::signal_create_mount, |
|
333 | - MountConfig::MOUNT_TYPE_GROUP, |
|
334 | - 'group2' |
|
335 | - ], |
|
336 | - ], |
|
337 | - ], |
|
338 | - [ |
|
339 | - // adding a user and a group |
|
340 | - ['user1'], |
|
341 | - ['group1'], |
|
342 | - ['user1', 'user2'], |
|
343 | - ['group1', 'group2'], |
|
344 | - // expected hook calls |
|
345 | - [ |
|
346 | - [ |
|
347 | - Filesystem::signal_create_mount, |
|
348 | - MountConfig::MOUNT_TYPE_USER, |
|
349 | - 'user2', |
|
350 | - ], |
|
351 | - [ |
|
352 | - Filesystem::signal_create_mount, |
|
353 | - MountConfig::MOUNT_TYPE_GROUP, |
|
354 | - 'group2' |
|
355 | - ], |
|
356 | - ], |
|
357 | - ], |
|
358 | - [ |
|
359 | - // removing a user and a group |
|
360 | - ['user1', 'user2'], |
|
361 | - ['group1', 'group2'], |
|
362 | - ['user1'], |
|
363 | - ['group1'], |
|
364 | - // expected hook calls |
|
365 | - [ |
|
366 | - [ |
|
367 | - Filesystem::signal_delete_mount, |
|
368 | - MountConfig::MOUNT_TYPE_USER, |
|
369 | - 'user2', |
|
370 | - ], |
|
371 | - [ |
|
372 | - Filesystem::signal_delete_mount, |
|
373 | - MountConfig::MOUNT_TYPE_GROUP, |
|
374 | - 'group2' |
|
375 | - ], |
|
376 | - ], |
|
377 | - ], |
|
378 | - [ |
|
379 | - // removing all |
|
380 | - ['user1'], |
|
381 | - ['group1'], |
|
382 | - [], |
|
383 | - [], |
|
384 | - // expected hook calls |
|
385 | - [ |
|
386 | - [ |
|
387 | - Filesystem::signal_delete_mount, |
|
388 | - MountConfig::MOUNT_TYPE_USER, |
|
389 | - 'user1', |
|
390 | - ], |
|
391 | - [ |
|
392 | - Filesystem::signal_delete_mount, |
|
393 | - MountConfig::MOUNT_TYPE_GROUP, |
|
394 | - 'group1' |
|
395 | - ], |
|
396 | - // create the "all" entry |
|
397 | - [ |
|
398 | - Filesystem::signal_create_mount, |
|
399 | - MountConfig::MOUNT_TYPE_USER, |
|
400 | - 'all' |
|
401 | - ], |
|
402 | - ], |
|
403 | - ], |
|
404 | - [ |
|
405 | - // no changes |
|
406 | - ['user1'], |
|
407 | - ['group1'], |
|
408 | - ['user1'], |
|
409 | - ['group1'], |
|
410 | - // no hook calls |
|
411 | - [] |
|
412 | - ] |
|
413 | - ]; |
|
414 | - } |
|
415 | - |
|
416 | - #[\PHPUnit\Framework\Attributes\DataProvider('hooksUpdateStorageDataProvider')] |
|
417 | - public function testHooksUpdateStorage( |
|
418 | - array $sourceApplicableUsers, |
|
419 | - array $sourceApplicableGroups, |
|
420 | - array $updatedApplicableUsers, |
|
421 | - array $updatedApplicableGroups, |
|
422 | - array $expectedCalls, |
|
423 | - ): void { |
|
424 | - $storage = $this->makeTestStorageData(); |
|
425 | - $storage->setApplicableUsers($sourceApplicableUsers); |
|
426 | - $storage->setApplicableGroups($sourceApplicableGroups); |
|
427 | - $storage = $this->service->addStorage($storage); |
|
428 | - |
|
429 | - $storage->setApplicableUsers($updatedApplicableUsers); |
|
430 | - $storage->setApplicableGroups($updatedApplicableGroups); |
|
431 | - |
|
432 | - // reset calls |
|
433 | - self::$hookCalls = []; |
|
434 | - |
|
435 | - $this->service->updateStorage($storage); |
|
436 | - |
|
437 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
438 | - |
|
439 | - foreach ($expectedCalls as $index => $call) { |
|
440 | - $this->assertHookCall( |
|
441 | - self::$hookCalls[$index], |
|
442 | - $call[0], |
|
443 | - '/mountpoint', |
|
444 | - $call[1], |
|
445 | - $call[2] |
|
446 | - ); |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - public function testHooksRenameMountPoint(): void { |
|
452 | - $storage = $this->makeTestStorageData(); |
|
453 | - $storage->setApplicableUsers(['user1', 'user2']); |
|
454 | - $storage->setApplicableGroups(['group1', 'group2']); |
|
455 | - $storage = $this->service->addStorage($storage); |
|
456 | - |
|
457 | - $storage->setMountPoint('renamedMountpoint'); |
|
458 | - |
|
459 | - // reset calls |
|
460 | - self::$hookCalls = []; |
|
461 | - |
|
462 | - $this->service->updateStorage($storage); |
|
463 | - |
|
464 | - $expectedCalls = [ |
|
465 | - // deletes old mount |
|
466 | - [ |
|
467 | - Filesystem::signal_delete_mount, |
|
468 | - '/mountpoint', |
|
469 | - MountConfig::MOUNT_TYPE_USER, |
|
470 | - 'user1', |
|
471 | - ], |
|
472 | - [ |
|
473 | - Filesystem::signal_delete_mount, |
|
474 | - '/mountpoint', |
|
475 | - MountConfig::MOUNT_TYPE_USER, |
|
476 | - 'user2', |
|
477 | - ], |
|
478 | - [ |
|
479 | - Filesystem::signal_delete_mount, |
|
480 | - '/mountpoint', |
|
481 | - MountConfig::MOUNT_TYPE_GROUP, |
|
482 | - 'group1', |
|
483 | - ], |
|
484 | - [ |
|
485 | - Filesystem::signal_delete_mount, |
|
486 | - '/mountpoint', |
|
487 | - MountConfig::MOUNT_TYPE_GROUP, |
|
488 | - 'group2', |
|
489 | - ], |
|
490 | - // creates new one |
|
491 | - [ |
|
492 | - Filesystem::signal_create_mount, |
|
493 | - '/renamedMountpoint', |
|
494 | - MountConfig::MOUNT_TYPE_USER, |
|
495 | - 'user1', |
|
496 | - ], |
|
497 | - [ |
|
498 | - Filesystem::signal_create_mount, |
|
499 | - '/renamedMountpoint', |
|
500 | - MountConfig::MOUNT_TYPE_USER, |
|
501 | - 'user2', |
|
502 | - ], |
|
503 | - [ |
|
504 | - Filesystem::signal_create_mount, |
|
505 | - '/renamedMountpoint', |
|
506 | - MountConfig::MOUNT_TYPE_GROUP, |
|
507 | - 'group1', |
|
508 | - ], |
|
509 | - [ |
|
510 | - Filesystem::signal_create_mount, |
|
511 | - '/renamedMountpoint', |
|
512 | - MountConfig::MOUNT_TYPE_GROUP, |
|
513 | - 'group2', |
|
514 | - ], |
|
515 | - ]; |
|
516 | - |
|
517 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
518 | - |
|
519 | - foreach ($expectedCalls as $index => $call) { |
|
520 | - $this->assertHookCall( |
|
521 | - self::$hookCalls[$index], |
|
522 | - $call[0], |
|
523 | - $call[1], |
|
524 | - $call[2], |
|
525 | - $call[3] |
|
526 | - ); |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - public static function hooksDeleteStorageDataProvider(): array { |
|
531 | - return [ |
|
532 | - [ |
|
533 | - ['user1', 'user2'], |
|
534 | - ['group1', 'group2'], |
|
535 | - // expected hook calls |
|
536 | - [ |
|
537 | - [ |
|
538 | - Filesystem::signal_delete_mount, |
|
539 | - MountConfig::MOUNT_TYPE_USER, |
|
540 | - 'user1', |
|
541 | - ], |
|
542 | - [ |
|
543 | - Filesystem::signal_delete_mount, |
|
544 | - MountConfig::MOUNT_TYPE_USER, |
|
545 | - 'user2', |
|
546 | - ], |
|
547 | - [ |
|
548 | - Filesystem::signal_delete_mount, |
|
549 | - MountConfig::MOUNT_TYPE_GROUP, |
|
550 | - 'group1' |
|
551 | - ], |
|
552 | - [ |
|
553 | - Filesystem::signal_delete_mount, |
|
554 | - MountConfig::MOUNT_TYPE_GROUP, |
|
555 | - 'group2' |
|
556 | - ], |
|
557 | - ], |
|
558 | - ], |
|
559 | - [ |
|
560 | - // deleting "all" entry |
|
561 | - [], |
|
562 | - [], |
|
563 | - [ |
|
564 | - [ |
|
565 | - Filesystem::signal_delete_mount, |
|
566 | - MountConfig::MOUNT_TYPE_USER, |
|
567 | - 'all', |
|
568 | - ], |
|
569 | - ], |
|
570 | - ], |
|
571 | - ]; |
|
572 | - } |
|
573 | - |
|
574 | - #[\PHPUnit\Framework\Attributes\DataProvider('hooksDeleteStorageDataProvider')] |
|
575 | - public function testHooksDeleteStorage( |
|
576 | - array $sourceApplicableUsers, |
|
577 | - array $sourceApplicableGroups, |
|
578 | - array $expectedCalls, |
|
579 | - ): void { |
|
580 | - $storage = $this->makeTestStorageData(); |
|
581 | - $storage->setApplicableUsers($sourceApplicableUsers); |
|
582 | - $storage->setApplicableGroups($sourceApplicableGroups); |
|
583 | - $storage = $this->service->addStorage($storage); |
|
584 | - |
|
585 | - // reset calls |
|
586 | - self::$hookCalls = []; |
|
587 | - |
|
588 | - $this->service->removeStorage($storage->getId()); |
|
589 | - |
|
590 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
591 | - |
|
592 | - foreach ($expectedCalls as $index => $call) { |
|
593 | - $this->assertHookCall( |
|
594 | - self::$hookCalls[$index], |
|
595 | - $call[0], |
|
596 | - '/mountpoint', |
|
597 | - $call[1], |
|
598 | - $call[2] |
|
599 | - ); |
|
600 | - } |
|
601 | - } |
|
20 | + protected function setUp(): void { |
|
21 | + parent::setUp(); |
|
22 | + $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher); |
|
23 | + } |
|
24 | + |
|
25 | + protected function tearDown(): void { |
|
26 | + @unlink($this->dataDir . '/mount.json'); |
|
27 | + parent::tearDown(); |
|
28 | + } |
|
29 | + |
|
30 | + protected function makeTestStorageData() { |
|
31 | + return $this->makeStorageConfig([ |
|
32 | + 'mountPoint' => 'mountpoint', |
|
33 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
34 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
35 | + 'backendOptions' => [ |
|
36 | + 'option1' => 'value1', |
|
37 | + 'option2' => 'value2', |
|
38 | + 'password' => 'testPassword', |
|
39 | + ], |
|
40 | + 'applicableUsers' => [], |
|
41 | + 'applicableGroups' => [], |
|
42 | + 'priority' => 15, |
|
43 | + 'mountOptions' => [ |
|
44 | + 'preview' => false, |
|
45 | + ] |
|
46 | + ]); |
|
47 | + } |
|
48 | + |
|
49 | + public static function storageDataProvider(): array { |
|
50 | + return [ |
|
51 | + // all users |
|
52 | + [ |
|
53 | + [ |
|
54 | + 'mountPoint' => 'mountpoint', |
|
55 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
56 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
57 | + 'backendOptions' => [ |
|
58 | + 'option1' => 'value1', |
|
59 | + 'option2' => 'value2', |
|
60 | + 'password' => 'testPassword', |
|
61 | + ], |
|
62 | + 'applicableUsers' => [], |
|
63 | + 'applicableGroups' => [], |
|
64 | + 'priority' => 15, |
|
65 | + ], |
|
66 | + ], |
|
67 | + // some users |
|
68 | + [ |
|
69 | + [ |
|
70 | + 'mountPoint' => 'mountpoint', |
|
71 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
72 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
73 | + 'backendOptions' => [ |
|
74 | + 'option1' => 'value1', |
|
75 | + 'option2' => 'value2', |
|
76 | + 'password' => 'testPassword', |
|
77 | + ], |
|
78 | + 'applicableUsers' => ['user1', 'user2'], |
|
79 | + 'applicableGroups' => [], |
|
80 | + 'priority' => 15, |
|
81 | + ], |
|
82 | + ], |
|
83 | + // some groups |
|
84 | + [ |
|
85 | + [ |
|
86 | + 'mountPoint' => 'mountpoint', |
|
87 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
88 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
89 | + 'backendOptions' => [ |
|
90 | + 'option1' => 'value1', |
|
91 | + 'option2' => 'value2', |
|
92 | + 'password' => 'testPassword', |
|
93 | + ], |
|
94 | + 'applicableUsers' => [], |
|
95 | + 'applicableGroups' => ['group1', 'group2'], |
|
96 | + 'priority' => 15, |
|
97 | + ], |
|
98 | + ], |
|
99 | + // both users and groups |
|
100 | + [ |
|
101 | + [ |
|
102 | + 'mountPoint' => 'mountpoint', |
|
103 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
104 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
105 | + 'backendOptions' => [ |
|
106 | + 'option1' => 'value1', |
|
107 | + 'option2' => 'value2', |
|
108 | + 'password' => 'testPassword', |
|
109 | + ], |
|
110 | + 'applicableUsers' => ['user1', 'user2'], |
|
111 | + 'applicableGroups' => ['group1', 'group2'], |
|
112 | + 'priority' => 15, |
|
113 | + ], |
|
114 | + ], |
|
115 | + ]; |
|
116 | + } |
|
117 | + |
|
118 | + #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')] |
|
119 | + public function testAddStorage($storageParams): void { |
|
120 | + $storage = $this->makeStorageConfig($storageParams); |
|
121 | + $newStorage = $this->service->addStorage($storage); |
|
122 | + |
|
123 | + $baseId = $newStorage->getId(); |
|
124 | + |
|
125 | + $newStorage = $this->service->getStorage($baseId); |
|
126 | + |
|
127 | + $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint()); |
|
128 | + $this->assertEquals($storage->getBackend(), $newStorage->getBackend()); |
|
129 | + $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism()); |
|
130 | + $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions()); |
|
131 | + $this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
132 | + $this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
133 | + $this->assertEquals($storage->getPriority(), $newStorage->getPriority()); |
|
134 | + $this->assertEquals(0, $newStorage->getStatus()); |
|
135 | + |
|
136 | + $nextStorage = $this->service->addStorage($storage); |
|
137 | + $this->assertEquals($baseId + 1, $nextStorage->getId()); |
|
138 | + } |
|
139 | + |
|
140 | + #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')] |
|
141 | + public function testUpdateStorage($updatedStorageParams): void { |
|
142 | + $updatedStorage = $this->makeStorageConfig($updatedStorageParams); |
|
143 | + $storage = $this->makeStorageConfig([ |
|
144 | + 'mountPoint' => 'mountpoint', |
|
145 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
146 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
147 | + 'backendOptions' => [ |
|
148 | + 'option1' => 'value1', |
|
149 | + 'option2' => 'value2', |
|
150 | + 'password' => 'testPassword', |
|
151 | + ], |
|
152 | + 'applicableUsers' => [], |
|
153 | + 'applicableGroups' => [], |
|
154 | + 'priority' => 15, |
|
155 | + ]); |
|
156 | + |
|
157 | + $newStorage = $this->service->addStorage($storage); |
|
158 | + $id = $newStorage->getId(); |
|
159 | + |
|
160 | + $updatedStorage->setId($id); |
|
161 | + |
|
162 | + $this->service->updateStorage($updatedStorage); |
|
163 | + $newStorage = $this->service->getStorage($id); |
|
164 | + |
|
165 | + $this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint()); |
|
166 | + $this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']); |
|
167 | + $this->assertEqualsCanonicalizing($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
168 | + $this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
169 | + $this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority()); |
|
170 | + $this->assertEquals(0, $newStorage->getStatus()); |
|
171 | + } |
|
172 | + |
|
173 | + public static function hooksAddStorageDataProvider(): array { |
|
174 | + return [ |
|
175 | + // applicable all |
|
176 | + [ |
|
177 | + [], |
|
178 | + [], |
|
179 | + // expected hook calls |
|
180 | + [ |
|
181 | + [ |
|
182 | + Filesystem::signal_create_mount, |
|
183 | + MountConfig::MOUNT_TYPE_USER, |
|
184 | + 'all' |
|
185 | + ], |
|
186 | + ], |
|
187 | + ], |
|
188 | + // single user |
|
189 | + [ |
|
190 | + ['user1'], |
|
191 | + [], |
|
192 | + // expected hook calls |
|
193 | + [ |
|
194 | + [ |
|
195 | + Filesystem::signal_create_mount, |
|
196 | + MountConfig::MOUNT_TYPE_USER, |
|
197 | + 'user1', |
|
198 | + ], |
|
199 | + ], |
|
200 | + ], |
|
201 | + // single group |
|
202 | + [ |
|
203 | + [], |
|
204 | + ['group1'], |
|
205 | + // expected hook calls |
|
206 | + [ |
|
207 | + [ |
|
208 | + Filesystem::signal_create_mount, |
|
209 | + MountConfig::MOUNT_TYPE_GROUP, |
|
210 | + 'group1', |
|
211 | + ], |
|
212 | + ], |
|
213 | + ], |
|
214 | + // multiple users |
|
215 | + [ |
|
216 | + ['user1', 'user2'], |
|
217 | + [], |
|
218 | + [ |
|
219 | + [ |
|
220 | + Filesystem::signal_create_mount, |
|
221 | + MountConfig::MOUNT_TYPE_USER, |
|
222 | + 'user1', |
|
223 | + ], |
|
224 | + [ |
|
225 | + Filesystem::signal_create_mount, |
|
226 | + MountConfig::MOUNT_TYPE_USER, |
|
227 | + 'user2', |
|
228 | + ], |
|
229 | + ], |
|
230 | + ], |
|
231 | + // multiple groups |
|
232 | + [ |
|
233 | + [], |
|
234 | + ['group1', 'group2'], |
|
235 | + // expected hook calls |
|
236 | + [ |
|
237 | + [ |
|
238 | + Filesystem::signal_create_mount, |
|
239 | + MountConfig::MOUNT_TYPE_GROUP, |
|
240 | + 'group1' |
|
241 | + ], |
|
242 | + [ |
|
243 | + Filesystem::signal_create_mount, |
|
244 | + MountConfig::MOUNT_TYPE_GROUP, |
|
245 | + 'group2' |
|
246 | + ], |
|
247 | + ], |
|
248 | + ], |
|
249 | + // mixed groups and users |
|
250 | + [ |
|
251 | + ['user1', 'user2'], |
|
252 | + ['group1', 'group2'], |
|
253 | + // expected hook calls |
|
254 | + [ |
|
255 | + [ |
|
256 | + Filesystem::signal_create_mount, |
|
257 | + MountConfig::MOUNT_TYPE_USER, |
|
258 | + 'user1', |
|
259 | + ], |
|
260 | + [ |
|
261 | + Filesystem::signal_create_mount, |
|
262 | + MountConfig::MOUNT_TYPE_USER, |
|
263 | + 'user2', |
|
264 | + ], |
|
265 | + [ |
|
266 | + Filesystem::signal_create_mount, |
|
267 | + MountConfig::MOUNT_TYPE_GROUP, |
|
268 | + 'group1' |
|
269 | + ], |
|
270 | + [ |
|
271 | + Filesystem::signal_create_mount, |
|
272 | + MountConfig::MOUNT_TYPE_GROUP, |
|
273 | + 'group2' |
|
274 | + ], |
|
275 | + ], |
|
276 | + ], |
|
277 | + ]; |
|
278 | + } |
|
279 | + |
|
280 | + #[\PHPUnit\Framework\Attributes\DataProvider('hooksAddStorageDataProvider')] |
|
281 | + public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void { |
|
282 | + $storage = $this->makeTestStorageData(); |
|
283 | + $storage->setApplicableUsers($applicableUsers); |
|
284 | + $storage->setApplicableGroups($applicableGroups); |
|
285 | + $this->service->addStorage($storage); |
|
286 | + |
|
287 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
288 | + |
|
289 | + foreach ($expectedCalls as $index => $call) { |
|
290 | + $this->assertHookCall( |
|
291 | + self::$hookCalls[$index], |
|
292 | + $call[0], |
|
293 | + $storage->getMountPoint(), |
|
294 | + $call[1], |
|
295 | + $call[2] |
|
296 | + ); |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + public static function hooksUpdateStorageDataProvider(): array { |
|
301 | + return [ |
|
302 | + [ |
|
303 | + // nothing to multiple users and groups |
|
304 | + [], |
|
305 | + [], |
|
306 | + ['user1', 'user2'], |
|
307 | + ['group1', 'group2'], |
|
308 | + // expected hook calls |
|
309 | + [ |
|
310 | + // delete the "all entry" |
|
311 | + [ |
|
312 | + Filesystem::signal_delete_mount, |
|
313 | + MountConfig::MOUNT_TYPE_USER, |
|
314 | + 'all', |
|
315 | + ], |
|
316 | + [ |
|
317 | + Filesystem::signal_create_mount, |
|
318 | + MountConfig::MOUNT_TYPE_USER, |
|
319 | + 'user1', |
|
320 | + ], |
|
321 | + [ |
|
322 | + Filesystem::signal_create_mount, |
|
323 | + MountConfig::MOUNT_TYPE_USER, |
|
324 | + 'user2', |
|
325 | + ], |
|
326 | + [ |
|
327 | + Filesystem::signal_create_mount, |
|
328 | + MountConfig::MOUNT_TYPE_GROUP, |
|
329 | + 'group1' |
|
330 | + ], |
|
331 | + [ |
|
332 | + Filesystem::signal_create_mount, |
|
333 | + MountConfig::MOUNT_TYPE_GROUP, |
|
334 | + 'group2' |
|
335 | + ], |
|
336 | + ], |
|
337 | + ], |
|
338 | + [ |
|
339 | + // adding a user and a group |
|
340 | + ['user1'], |
|
341 | + ['group1'], |
|
342 | + ['user1', 'user2'], |
|
343 | + ['group1', 'group2'], |
|
344 | + // expected hook calls |
|
345 | + [ |
|
346 | + [ |
|
347 | + Filesystem::signal_create_mount, |
|
348 | + MountConfig::MOUNT_TYPE_USER, |
|
349 | + 'user2', |
|
350 | + ], |
|
351 | + [ |
|
352 | + Filesystem::signal_create_mount, |
|
353 | + MountConfig::MOUNT_TYPE_GROUP, |
|
354 | + 'group2' |
|
355 | + ], |
|
356 | + ], |
|
357 | + ], |
|
358 | + [ |
|
359 | + // removing a user and a group |
|
360 | + ['user1', 'user2'], |
|
361 | + ['group1', 'group2'], |
|
362 | + ['user1'], |
|
363 | + ['group1'], |
|
364 | + // expected hook calls |
|
365 | + [ |
|
366 | + [ |
|
367 | + Filesystem::signal_delete_mount, |
|
368 | + MountConfig::MOUNT_TYPE_USER, |
|
369 | + 'user2', |
|
370 | + ], |
|
371 | + [ |
|
372 | + Filesystem::signal_delete_mount, |
|
373 | + MountConfig::MOUNT_TYPE_GROUP, |
|
374 | + 'group2' |
|
375 | + ], |
|
376 | + ], |
|
377 | + ], |
|
378 | + [ |
|
379 | + // removing all |
|
380 | + ['user1'], |
|
381 | + ['group1'], |
|
382 | + [], |
|
383 | + [], |
|
384 | + // expected hook calls |
|
385 | + [ |
|
386 | + [ |
|
387 | + Filesystem::signal_delete_mount, |
|
388 | + MountConfig::MOUNT_TYPE_USER, |
|
389 | + 'user1', |
|
390 | + ], |
|
391 | + [ |
|
392 | + Filesystem::signal_delete_mount, |
|
393 | + MountConfig::MOUNT_TYPE_GROUP, |
|
394 | + 'group1' |
|
395 | + ], |
|
396 | + // create the "all" entry |
|
397 | + [ |
|
398 | + Filesystem::signal_create_mount, |
|
399 | + MountConfig::MOUNT_TYPE_USER, |
|
400 | + 'all' |
|
401 | + ], |
|
402 | + ], |
|
403 | + ], |
|
404 | + [ |
|
405 | + // no changes |
|
406 | + ['user1'], |
|
407 | + ['group1'], |
|
408 | + ['user1'], |
|
409 | + ['group1'], |
|
410 | + // no hook calls |
|
411 | + [] |
|
412 | + ] |
|
413 | + ]; |
|
414 | + } |
|
415 | + |
|
416 | + #[\PHPUnit\Framework\Attributes\DataProvider('hooksUpdateStorageDataProvider')] |
|
417 | + public function testHooksUpdateStorage( |
|
418 | + array $sourceApplicableUsers, |
|
419 | + array $sourceApplicableGroups, |
|
420 | + array $updatedApplicableUsers, |
|
421 | + array $updatedApplicableGroups, |
|
422 | + array $expectedCalls, |
|
423 | + ): void { |
|
424 | + $storage = $this->makeTestStorageData(); |
|
425 | + $storage->setApplicableUsers($sourceApplicableUsers); |
|
426 | + $storage->setApplicableGroups($sourceApplicableGroups); |
|
427 | + $storage = $this->service->addStorage($storage); |
|
428 | + |
|
429 | + $storage->setApplicableUsers($updatedApplicableUsers); |
|
430 | + $storage->setApplicableGroups($updatedApplicableGroups); |
|
431 | + |
|
432 | + // reset calls |
|
433 | + self::$hookCalls = []; |
|
434 | + |
|
435 | + $this->service->updateStorage($storage); |
|
436 | + |
|
437 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
438 | + |
|
439 | + foreach ($expectedCalls as $index => $call) { |
|
440 | + $this->assertHookCall( |
|
441 | + self::$hookCalls[$index], |
|
442 | + $call[0], |
|
443 | + '/mountpoint', |
|
444 | + $call[1], |
|
445 | + $call[2] |
|
446 | + ); |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + public function testHooksRenameMountPoint(): void { |
|
452 | + $storage = $this->makeTestStorageData(); |
|
453 | + $storage->setApplicableUsers(['user1', 'user2']); |
|
454 | + $storage->setApplicableGroups(['group1', 'group2']); |
|
455 | + $storage = $this->service->addStorage($storage); |
|
456 | + |
|
457 | + $storage->setMountPoint('renamedMountpoint'); |
|
458 | + |
|
459 | + // reset calls |
|
460 | + self::$hookCalls = []; |
|
461 | + |
|
462 | + $this->service->updateStorage($storage); |
|
463 | + |
|
464 | + $expectedCalls = [ |
|
465 | + // deletes old mount |
|
466 | + [ |
|
467 | + Filesystem::signal_delete_mount, |
|
468 | + '/mountpoint', |
|
469 | + MountConfig::MOUNT_TYPE_USER, |
|
470 | + 'user1', |
|
471 | + ], |
|
472 | + [ |
|
473 | + Filesystem::signal_delete_mount, |
|
474 | + '/mountpoint', |
|
475 | + MountConfig::MOUNT_TYPE_USER, |
|
476 | + 'user2', |
|
477 | + ], |
|
478 | + [ |
|
479 | + Filesystem::signal_delete_mount, |
|
480 | + '/mountpoint', |
|
481 | + MountConfig::MOUNT_TYPE_GROUP, |
|
482 | + 'group1', |
|
483 | + ], |
|
484 | + [ |
|
485 | + Filesystem::signal_delete_mount, |
|
486 | + '/mountpoint', |
|
487 | + MountConfig::MOUNT_TYPE_GROUP, |
|
488 | + 'group2', |
|
489 | + ], |
|
490 | + // creates new one |
|
491 | + [ |
|
492 | + Filesystem::signal_create_mount, |
|
493 | + '/renamedMountpoint', |
|
494 | + MountConfig::MOUNT_TYPE_USER, |
|
495 | + 'user1', |
|
496 | + ], |
|
497 | + [ |
|
498 | + Filesystem::signal_create_mount, |
|
499 | + '/renamedMountpoint', |
|
500 | + MountConfig::MOUNT_TYPE_USER, |
|
501 | + 'user2', |
|
502 | + ], |
|
503 | + [ |
|
504 | + Filesystem::signal_create_mount, |
|
505 | + '/renamedMountpoint', |
|
506 | + MountConfig::MOUNT_TYPE_GROUP, |
|
507 | + 'group1', |
|
508 | + ], |
|
509 | + [ |
|
510 | + Filesystem::signal_create_mount, |
|
511 | + '/renamedMountpoint', |
|
512 | + MountConfig::MOUNT_TYPE_GROUP, |
|
513 | + 'group2', |
|
514 | + ], |
|
515 | + ]; |
|
516 | + |
|
517 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
518 | + |
|
519 | + foreach ($expectedCalls as $index => $call) { |
|
520 | + $this->assertHookCall( |
|
521 | + self::$hookCalls[$index], |
|
522 | + $call[0], |
|
523 | + $call[1], |
|
524 | + $call[2], |
|
525 | + $call[3] |
|
526 | + ); |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + public static function hooksDeleteStorageDataProvider(): array { |
|
531 | + return [ |
|
532 | + [ |
|
533 | + ['user1', 'user2'], |
|
534 | + ['group1', 'group2'], |
|
535 | + // expected hook calls |
|
536 | + [ |
|
537 | + [ |
|
538 | + Filesystem::signal_delete_mount, |
|
539 | + MountConfig::MOUNT_TYPE_USER, |
|
540 | + 'user1', |
|
541 | + ], |
|
542 | + [ |
|
543 | + Filesystem::signal_delete_mount, |
|
544 | + MountConfig::MOUNT_TYPE_USER, |
|
545 | + 'user2', |
|
546 | + ], |
|
547 | + [ |
|
548 | + Filesystem::signal_delete_mount, |
|
549 | + MountConfig::MOUNT_TYPE_GROUP, |
|
550 | + 'group1' |
|
551 | + ], |
|
552 | + [ |
|
553 | + Filesystem::signal_delete_mount, |
|
554 | + MountConfig::MOUNT_TYPE_GROUP, |
|
555 | + 'group2' |
|
556 | + ], |
|
557 | + ], |
|
558 | + ], |
|
559 | + [ |
|
560 | + // deleting "all" entry |
|
561 | + [], |
|
562 | + [], |
|
563 | + [ |
|
564 | + [ |
|
565 | + Filesystem::signal_delete_mount, |
|
566 | + MountConfig::MOUNT_TYPE_USER, |
|
567 | + 'all', |
|
568 | + ], |
|
569 | + ], |
|
570 | + ], |
|
571 | + ]; |
|
572 | + } |
|
573 | + |
|
574 | + #[\PHPUnit\Framework\Attributes\DataProvider('hooksDeleteStorageDataProvider')] |
|
575 | + public function testHooksDeleteStorage( |
|
576 | + array $sourceApplicableUsers, |
|
577 | + array $sourceApplicableGroups, |
|
578 | + array $expectedCalls, |
|
579 | + ): void { |
|
580 | + $storage = $this->makeTestStorageData(); |
|
581 | + $storage->setApplicableUsers($sourceApplicableUsers); |
|
582 | + $storage->setApplicableGroups($sourceApplicableGroups); |
|
583 | + $storage = $this->service->addStorage($storage); |
|
584 | + |
|
585 | + // reset calls |
|
586 | + self::$hookCalls = []; |
|
587 | + |
|
588 | + $this->service->removeStorage($storage->getId()); |
|
589 | + |
|
590 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
591 | + |
|
592 | + foreach ($expectedCalls as $index => $call) { |
|
593 | + $this->assertHookCall( |
|
594 | + self::$hookCalls[$index], |
|
595 | + $call[0], |
|
596 | + '/mountpoint', |
|
597 | + $call[1], |
|
598 | + $call[2] |
|
599 | + ); |
|
600 | + } |
|
601 | + } |
|
602 | 602 | } |