-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[stable32] fix(sharing): Adapt share suggestions to match trusted servers configs #55642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f94d30c
da82f6f
d384071
35c7690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 8465-8465.js.license |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,17 +10,20 @@ | |
| use OC\Collaboration\Collaborators\RemotePlugin; | ||
| use OC\Collaboration\Collaborators\SearchResult; | ||
| use OC\Federation\CloudIdManager; | ||
| use OCA\Federation\TrustedServers; | ||
| use OCP\Collaboration\Collaborators\SearchResultType; | ||
| use OCP\Contacts\IManager; | ||
| use OCP\EventDispatcher\IEventDispatcher; | ||
| use OCP\Federation\ICloudIdManager; | ||
| use OCP\IAppConfig; | ||
| use OCP\ICacheFactory; | ||
| use OCP\IConfig; | ||
| use OCP\IURLGenerator; | ||
| use OCP\IUser; | ||
| use OCP\IUserManager; | ||
| use OCP\IUserSession; | ||
| use OCP\Share\IShare; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Test\TestCase; | ||
|
|
||
| class RemotePluginTest extends TestCase { | ||
|
|
@@ -36,6 +39,9 @@ class RemotePluginTest extends TestCase { | |
| /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ | ||
| protected $cloudIdManager; | ||
|
|
||
| protected IAppConfig|MockObject $appConfig; | ||
| protected ICloudIdManager|MockObject $trustedServers; | ||
|
|
||
| /** @var RemotePlugin */ | ||
| protected $plugin; | ||
|
|
||
|
|
@@ -55,6 +61,8 @@ protected function setUp(): void { | |
| $this->createMock(IURLGenerator::class), | ||
| $this->createMock(IUserManager::class), | ||
| ); | ||
| $this->appConfig = $this->createMock(IAppConfig::class); | ||
| $this->trustedServers = $this->createMock(TrustedServers::class); | ||
| $this->searchResult = new SearchResult(); | ||
| } | ||
|
|
||
|
|
@@ -67,7 +75,7 @@ public function instantiatePlugin() { | |
| $userSession->expects($this->any()) | ||
| ->method('getUser') | ||
| ->willReturn($user); | ||
| $this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->userManager, $userSession); | ||
| $this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->userManager, $userSession, $this->appConfig, $this->trustedServers); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -141,6 +149,77 @@ public function testSplitUserRemoteError($id): void { | |
| $this->plugin->splitUserRemote($id); | ||
| } | ||
|
|
||
| public function testTrustedServerMetadata(): void { | ||
| $this->config->expects($this->any()) | ||
| ->method('getAppValue') | ||
| ->willReturnCallback( | ||
| function ($appName, $key, $default) { | ||
| if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { | ||
| return 'yes'; | ||
| } | ||
| return $default; | ||
| } | ||
| ); | ||
|
|
||
| $this->trustedServers->expects($this->any()) | ||
| ->method('isTrustedServer') | ||
| ->willReturnCallback(function ($serverUrl) { | ||
| return $serverUrl === 'trustedserver.com'; | ||
| }); | ||
|
|
||
| $this->instantiatePlugin(); | ||
|
|
||
| $this->contactsManager->expects($this->any()) | ||
| ->method('search') | ||
| ->willReturn([]); | ||
|
|
||
| $this->plugin->search('[email protected]', 2, 0, $this->searchResult); | ||
| $result = $this->searchResult->asArray(); | ||
|
|
||
| $this->assertNotEmpty($result['exact']['remotes']); | ||
| $this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']); | ||
| } | ||
|
|
||
| public function testEmailSearchInContacts(): void { | ||
| $this->config->expects($this->any()) | ||
| ->method('getAppValue') | ||
| ->willReturnCallback( | ||
| function ($appName, $key, $default) { | ||
| if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { | ||
| return 'yes'; | ||
| } | ||
| return $default; | ||
| } | ||
| ); | ||
|
|
||
| $this->trustedServers->expects($this->any()) | ||
| ->method('isTrustedServer') | ||
| ->willReturnCallback(function ($serverUrl) { | ||
| return $serverUrl === 'trustedserver.com'; | ||
| }); | ||
|
|
||
| $this->instantiatePlugin(); | ||
|
|
||
| $this->contactsManager->expects($this->once()) | ||
| ->method('search') | ||
| ->with('[email protected]', ['CLOUD', 'FN', 'EMAIL']) | ||
| ->willReturn([ | ||
| [ | ||
| 'FN' => 'John Doe', | ||
| 'EMAIL' => '[email protected]', | ||
| 'CLOUD' => '[email protected]', | ||
| 'UID' => 'john-contact-id' | ||
| ] | ||
| ]); | ||
|
|
||
| $this->plugin->search('[email protected]', 2, 0, $this->searchResult); | ||
| $result = $this->searchResult->asArray(); | ||
|
|
||
| $this->assertNotEmpty($result['exact']['remotes']); | ||
| $this->assertEquals('[email protected]', $result['exact']['remotes'][0]['value']['shareWith']); | ||
| $this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']); | ||
| } | ||
|
|
||
| public static function dataGetRemote() { | ||
| return [ | ||
| ['test', [], true, ['remotes' => [], 'exact' => ['remotes' => []]], false, true], | ||
|
|
@@ -149,15 +228,15 @@ public static function dataGetRemote() { | |
| 'test@remote', | ||
| [], | ||
| true, | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote', 'isTrustedServer' => false], 'uuid' => 'test', 'name' => 'test']]]], | ||
| false, | ||
| true, | ||
| ], | ||
| [ | ||
| 'test@remote', | ||
| [], | ||
| false, | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote', 'isTrustedServer' => false], 'uuid' => 'test', 'name' => 'test']]]], | ||
| false, | ||
| true, | ||
| ], | ||
|
|
@@ -183,7 +262,7 @@ public static function dataGetRemote() { | |
| ], | ||
| ], | ||
| true, | ||
| ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => []]], | ||
| ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost', 'isTrustedServer' => false]]], 'exact' => ['remotes' => []]], | ||
| false, | ||
| true, | ||
| ], | ||
|
|
@@ -235,7 +314,7 @@ public static function dataGetRemote() { | |
| ], | ||
| ], | ||
| true, | ||
| ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], | ||
| ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost', 'isTrustedServer' => false]]], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote', 'isTrustedServer' => false], 'uuid' => 'test', 'name' => 'test']]]], | ||
| false, | ||
| true, | ||
| ], | ||
|
|
@@ -261,7 +340,7 @@ public static function dataGetRemote() { | |
| ], | ||
| ], | ||
| false, | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote', 'isTrustedServer' => false], 'uuid' => 'test', 'name' => 'test']]]], | ||
| false, | ||
| true, | ||
| ], | ||
|
|
@@ -287,7 +366,7 @@ public static function dataGetRemote() { | |
| ], | ||
| ], | ||
| true, | ||
| ['remotes' => [], 'exact' => ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]]]], | ||
| ['remotes' => [], 'exact' => ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost', 'isTrustedServer' => false]]]]], | ||
| true, | ||
| true, | ||
| ], | ||
|
|
@@ -313,7 +392,7 @@ public static function dataGetRemote() { | |
| ], | ||
| ], | ||
| false, | ||
| ['remotes' => [], 'exact' => ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]]]], | ||
| ['remotes' => [], 'exact' => ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost', 'isTrustedServer' => false]]]]], | ||
| true, | ||
| true, | ||
| ], | ||
|
|
@@ -340,7 +419,7 @@ public static function dataGetRemote() { | |
| ], | ||
| ], | ||
| false, | ||
| ['remotes' => [], 'exact' => ['remotes' => [['name' => 'User Name @ Localhost', 'label' => 'User Name @ Localhost (user name@localhost)', 'uuid' => 'uid3', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'user name@localhost', 'server' => 'localhost']]]]], | ||
| ['remotes' => [], 'exact' => ['remotes' => [['name' => 'User Name @ Localhost', 'label' => 'User Name @ Localhost (user name@localhost)', 'uuid' => 'uid3', 'type' => '', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'user name@localhost', 'server' => 'localhost', 'isTrustedServer' => false]]]]], | ||
| true, | ||
| true, | ||
| ], | ||
|
|
@@ -367,7 +446,7 @@ public static function dataGetRemote() { | |
| ], | ||
| ], | ||
| false, | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'user space (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'user space@remote', 'server' => 'remote'], 'uuid' => 'user space', 'name' => 'user space']]]], | ||
| ['remotes' => [], 'exact' => ['remotes' => [['label' => 'user space (remote)', 'value' => ['shareType' => IShare::TYPE_REMOTE, 'shareWith' => 'user space@remote', 'server' => 'remote', 'isTrustedServer' => false], 'uuid' => 'user space', 'name' => 'user space']]]], | ||
| false, | ||
| true, | ||
| ], | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.