1010use OC \Collaboration \Collaborators \RemotePlugin ;
1111use OC \Collaboration \Collaborators \SearchResult ;
1212use OC \Federation \CloudIdManager ;
13+ use OCA \Federation \TrustedServers ;
1314use OCP \Collaboration \Collaborators \SearchResultType ;
1415use OCP \Contacts \IManager ;
1516use OCP \EventDispatcher \IEventDispatcher ;
1617use OCP \Federation \ICloudIdManager ;
18+ use OCP \IAppConfig ;
1719use OCP \ICacheFactory ;
1820use OCP \IConfig ;
1921use OCP \IURLGenerator ;
2022use OCP \IUser ;
2123use OCP \IUserManager ;
2224use OCP \IUserSession ;
2325use OCP \Share \IShare ;
26+ use PHPUnit \Framework \MockObject \MockObject ;
2427use Test \TestCase ;
2528
2629class RemotePluginTest extends TestCase {
@@ -36,6 +39,9 @@ class RemotePluginTest extends TestCase {
3639 /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */
3740 protected $ cloudIdManager ;
3841
42+ protected IAppConfig |MockObject $ appConfig ;
43+ protected ICloudIdManager |MockObject $ trustedServers ;
44+
3945 /** @var RemotePlugin */
4046 protected $ plugin ;
4147
@@ -55,6 +61,8 @@ protected function setUp(): void {
5561 $ this ->createMock (IURLGenerator::class),
5662 $ this ->createMock (IUserManager::class),
5763 );
64+ $ this ->appConfig = $ this ->createMock (IAppConfig::class);
65+ $ this ->trustedServers = $ this ->createMock (TrustedServers::class);
5866 $ this ->searchResult = new SearchResult ();
5967 }
6068
@@ -67,7 +75,7 @@ public function instantiatePlugin() {
6775 $ userSession ->expects ($ this ->any ())
6876 ->method ('getUser ' )
6977 ->willReturn ($ user );
70- $ this ->plugin = new RemotePlugin ($ this ->contactsManager , $ this ->cloudIdManager , $ this ->config , $ this ->userManager , $ userSession );
78+ $ this ->plugin = new RemotePlugin ($ this ->contactsManager , $ this ->cloudIdManager , $ this ->config , $ this ->userManager , $ userSession, $ this -> appConfig , $ this -> trustedServers );
7179 }
7280
7381 /**
@@ -141,6 +149,37 @@ public function testSplitUserRemoteError($id): void {
141149 $ this ->plugin ->splitUserRemote ($ id );
142150 }
143151
152+ public function testTrustedServerMetadata (): void {
153+ $ this ->config ->expects ($ this ->any ())
154+ ->method ('getAppValue ' )
155+ ->willReturnCallback (
156+ function ($ appName , $ key , $ default ) {
157+ if ($ appName === 'core ' && $ key === 'shareapi_allow_share_dialog_user_enumeration ' ) {
158+ return 'yes ' ;
159+ }
160+ return $ default ;
161+ }
162+ );
163+
164+ $ this ->trustedServers ->expects ($ this ->any ())
165+ ->method ('isTrustedServer ' )
166+ ->willReturnCallback (function ($ serverUrl ) {
167+ return $ serverUrl === 'trustedserver.com ' ;
168+ });
169+
170+ $ this ->instantiatePlugin ();
171+
172+ $ this ->contactsManager ->expects ($ this ->any ())
173+ ->method ('search ' )
174+ ->willReturn ([]);
175+
176+ $ this ->
plugin ->
search (
'[email protected] ' ,
2 ,
0 ,
$ this ->
searchResult );
177+ $ result = $ this ->searchResult ->asArray ();
178+
179+ $ this ->assertNotEmpty ($ result ['exact ' ]['remotes ' ]);
180+ $ this ->assertTrue ($ result ['exact ' ]['remotes ' ][0 ]['value ' ]['isTrustedServer ' ]);
181+ }
182+
144183 public static function dataGetRemote () {
145184 return [
146185 ['test ' , [], true , ['remotes ' => [], 'exact ' => ['remotes ' => []]], false , true ],
@@ -149,15 +188,15 @@ public static function dataGetRemote() {
149188 'test@remote ' ,
150189 [],
151190 true ,
152- ['remotes ' => [], 'exact ' => ['remotes ' => [['label ' => 'test (remote) ' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'test@remote ' , 'server ' => 'remote ' ], 'uuid ' => 'test ' , 'name ' => 'test ' ]]]],
191+ ['remotes ' => [], 'exact ' => ['remotes ' => [['label ' => 'test (remote) ' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'test@remote ' , 'server ' => 'remote ' , ' isTrustedServer ' => false ], 'uuid ' => 'test ' , 'name ' => 'test ' ]]]],
153192 false ,
154193 true ,
155194 ],
156195 [
157196 'test@remote ' ,
158197 [],
159198 false ,
160- ['remotes ' => [], 'exact ' => ['remotes ' => [['label ' => 'test (remote) ' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'test@remote ' , 'server ' => 'remote ' ], 'uuid ' => 'test ' , 'name ' => 'test ' ]]]],
199+ ['remotes ' => [], 'exact ' => ['remotes ' => [['label ' => 'test (remote) ' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'test@remote ' , 'server ' => 'remote ' , ' isTrustedServer ' => false ], 'uuid ' => 'test ' , 'name ' => 'test ' ]]]],
161200 false ,
162201 true ,
163202 ],
@@ -183,7 +222,7 @@ public static function dataGetRemote() {
183222 ],
184223 ],
185224 true ,
186- ['remotes ' => [['name ' => 'User @ Localhost ' , 'label ' => 'User @ Localhost (username@localhost) ' , 'uuid ' => 'uid1 ' , 'type ' => '' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'username@localhost ' , 'server ' => 'localhost ' ]]], 'exact ' => ['remotes ' => []]],
225+ ['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 ' => []]],
187226 false ,
188227 true ,
189228 ],
@@ -235,7 +274,7 @@ public static function dataGetRemote() {
235274 ],
236275 ],
237276 true ,
238- ['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 ' ]]]],
277+ ['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 ' ]]]],
239278 false ,
240279 true ,
241280 ],
@@ -261,7 +300,7 @@ public static function dataGetRemote() {
261300 ],
262301 ],
263302 false ,
264- ['remotes ' => [], 'exact ' => ['remotes ' => [['label ' => 'test (remote) ' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'test@remote ' , 'server ' => 'remote ' ], 'uuid ' => 'test ' , 'name ' => 'test ' ]]]],
303+ ['remotes ' => [], 'exact ' => ['remotes ' => [['label ' => 'test (remote) ' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'test@remote ' , 'server ' => 'remote ' , ' isTrustedServer ' => false ], 'uuid ' => 'test ' , 'name ' => 'test ' ]]]],
265304 false ,
266305 true ,
267306 ],
@@ -287,7 +326,7 @@ public static function dataGetRemote() {
287326 ],
288327 ],
289328 true ,
290- ['remotes ' => [], 'exact ' => ['remotes ' => [['name ' => 'User @ Localhost ' , 'label ' => 'User @ Localhost (username@localhost) ' , 'uuid ' => 'uid1 ' , 'type ' => '' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'username@localhost ' , 'server ' => 'localhost ' ]]]]],
329+ ['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 ]]]]],
291330 true ,
292331 true ,
293332 ],
@@ -313,7 +352,7 @@ public static function dataGetRemote() {
313352 ],
314353 ],
315354 false ,
316- ['remotes ' => [], 'exact ' => ['remotes ' => [['name ' => 'User @ Localhost ' , 'label ' => 'User @ Localhost (username@localhost) ' , 'uuid ' => 'uid1 ' , 'type ' => '' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'username@localhost ' , 'server ' => 'localhost ' ]]]]],
355+ ['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 ]]]]],
317356 true ,
318357 true ,
319358 ],
@@ -340,7 +379,7 @@ public static function dataGetRemote() {
340379 ],
341380 ],
342381 false ,
343- ['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 ' ]]]]],
382+ ['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 ]]]]],
344383 true ,
345384 true ,
346385 ],
@@ -367,7 +406,7 @@ public static function dataGetRemote() {
367406 ],
368407 ],
369408 false ,
370- ['remotes ' => [], 'exact ' => ['remotes ' => [['label ' => 'user space (remote) ' , 'value ' => ['shareType ' => IShare::TYPE_REMOTE , 'shareWith ' => 'user space@remote ' , 'server ' => 'remote ' ], 'uuid ' => 'user space ' , 'name ' => 'user space ' ]]]],
409+ ['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 ' ]]]],
371410 false ,
372411 true ,
373412 ],
0 commit comments