Skip to content

Commit 80b04bd

Browse files
authored
Merge pull request #56501 from nextcloud/fix/lookup-trusted-server-filter
fix(sharing): Add isTrustedServer flag to lookup results
2 parents 29325b4 + 40246d9 commit 80b04bd

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

lib/private/Collaboration/Collaborators/LookupPlugin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace OC\Collaboration\Collaborators;
88

9+
use OCA\Federation\TrustedServers;
910
use OCP\Collaboration\Collaborators\ISearchPlugin;
1011
use OCP\Collaboration\Collaborators\ISearchResult;
1112
use OCP\Collaboration\Collaborators\SearchResultType;
@@ -26,6 +27,7 @@ public function __construct(
2627
IUserSession $userSession,
2728
private ICloudIdManager $cloudIdManager,
2829
private LoggerInterface $logger,
30+
private ?TrustedServers $trustedServers,
2931
) {
3032
$currentUserCloudId = $userSession->getUser()->getCloudId();
3133
$this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote();
@@ -82,6 +84,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
8284
'shareType' => IShare::TYPE_REMOTE,
8385
'globalScale' => $isGlobalScaleEnabled,
8486
'shareWith' => $lookup['federationId'],
87+
'server' => $remote,
88+
'isTrustedServer' => $this->trustedServers?->isTrustedServer($remote) ?? false,
8589
],
8690
'extra' => $lookup,
8791
];

tests/lib/Collaboration/Collaborators/LookupPluginTest.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ protected function setUp(): void {
5757
if ($cloudId === '[email protected]') {
5858
return new CloudId('[email protected]', 'user', 'myNextcloud.net');
5959
}
60+
if (str_contains($cloudId, '@enceladus.moon')) {
61+
[$user, $remote] = explode('@', $cloudId, 2);
62+
return new CloudId($cloudId, $user, $remote);
63+
}
6064
return new CloudId('[email protected]', 'user', 'someNextcloud.net');
6165
});
6266

@@ -66,7 +70,8 @@ protected function setUp(): void {
6670
$this->clientService,
6771
$this->userSession,
6872
$this->cloudIdManager,
69-
$this->logger
73+
$this->logger,
74+
null
7075
);
7176
}
7277

@@ -286,7 +291,9 @@ public static function dataSearchEnableDisableLookupServer(): array {
286291
'value' => [
287292
'shareType' => IShare::TYPE_REMOTE,
288293
'globalScale' => true,
289-
'shareWith' => $fedIDs[0]
294+
'shareWith' => $fedIDs[0],
295+
'server' => 'enceladus.moon',
296+
'isTrustedServer' => false,
290297
],
291298
'extra' => ['federationId' => $fedIDs[0]],
292299
],
@@ -295,7 +302,9 @@ public static function dataSearchEnableDisableLookupServer(): array {
295302
'value' => [
296303
'shareType' => IShare::TYPE_REMOTE,
297304
'globalScale' => true,
298-
'shareWith' => $fedIDs[1]
305+
'shareWith' => $fedIDs[1],
306+
'server' => 'enceladus.moon',
307+
'isTrustedServer' => false,
299308
],
300309
'extra' => ['federationId' => $fedIDs[1]],
301310
],
@@ -304,7 +313,9 @@ public static function dataSearchEnableDisableLookupServer(): array {
304313
'value' => [
305314
'shareType' => IShare::TYPE_REMOTE,
306315
'globalScale' => true,
307-
'shareWith' => $fedIDs[2]
316+
'shareWith' => $fedIDs[2],
317+
'server' => 'enceladus.moon',
318+
'isTrustedServer' => false,
308319
],
309320
'extra' => ['federationId' => $fedIDs[2]],
310321
],
@@ -328,7 +339,9 @@ public static function dataSearchEnableDisableLookupServer(): array {
328339
'value' => [
329340
'shareType' => IShare::TYPE_REMOTE,
330341
'globalScale' => true,
331-
'shareWith' => $fedIDs[0]
342+
'shareWith' => $fedIDs[0],
343+
'server' => 'enceladus.moon',
344+
'isTrustedServer' => false,
332345
],
333346
'extra' => ['federationId' => $fedIDs[0]],
334347
],
@@ -337,7 +350,9 @@ public static function dataSearchEnableDisableLookupServer(): array {
337350
'value' => [
338351
'shareType' => IShare::TYPE_REMOTE,
339352
'globalScale' => true,
340-
'shareWith' => $fedIDs[1]
353+
'shareWith' => $fedIDs[1],
354+
'server' => 'enceladus.moon',
355+
'isTrustedServer' => false,
341356
],
342357
'extra' => ['federationId' => $fedIDs[1]],
343358
],
@@ -346,7 +361,9 @@ public static function dataSearchEnableDisableLookupServer(): array {
346361
'value' => [
347362
'shareType' => IShare::TYPE_REMOTE,
348363
'globalScale' => true,
349-
'shareWith' => $fedIDs[2]
364+
'shareWith' => $fedIDs[2],
365+
'server' => 'enceladus.moon',
366+
'isTrustedServer' => false,
350367
],
351368
'extra' => ['federationId' => $fedIDs[2]],
352369
],
@@ -460,7 +477,9 @@ public static function searchDataProvider(): array {
460477
'value' => [
461478
'shareType' => IShare::TYPE_REMOTE,
462479
'globalScale' => true,
463-
'shareWith' => $fedIDs[0]
480+
'shareWith' => $fedIDs[0],
481+
'server' => 'enceladus.moon',
482+
'isTrustedServer' => false,
464483
],
465484
'extra' => ['federationId' => $fedIDs[0]],
466485
],
@@ -469,7 +488,9 @@ public static function searchDataProvider(): array {
469488
'value' => [
470489
'shareType' => IShare::TYPE_REMOTE,
471490
'globalScale' => true,
472-
'shareWith' => $fedIDs[1]
491+
'shareWith' => $fedIDs[1],
492+
'server' => 'enceladus.moon',
493+
'isTrustedServer' => false,
473494
],
474495
'extra' => ['federationId' => $fedIDs[1]],
475496
],
@@ -478,7 +499,9 @@ public static function searchDataProvider(): array {
478499
'value' => [
479500
'shareType' => IShare::TYPE_REMOTE,
480501
'globalScale' => true,
481-
'shareWith' => $fedIDs[2]
502+
'shareWith' => $fedIDs[2],
503+
'server' => 'enceladus.moon',
504+
'isTrustedServer' => false,
482505
],
483506
'extra' => ['federationId' => $fedIDs[2]],
484507
],

0 commit comments

Comments
 (0)