@@ -35,6 +35,7 @@ protected function setUp(): void {
3535 $ this ->storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
3636 $ this ->storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (false );
3737 $ this ->storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturn (false );
38+ $ this ->storagesBackendChecker ->method ('isAllowedAdminBackend ' )->willReturn (true );
3839 }
3940
4041 /**
@@ -157,6 +158,7 @@ public function testMultipleBackendProviders() {
157158 public function testUserMountingBackends () {
158159 $ storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
159160 $ storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (true );
161+ $ storagesBackendChecker ->method ('isAllowedAdminBackend ' )->willReturn (true );
160162 $ storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturnCallback (function (Backend $ backend ) {
161163 $ backendAliases = $ backend ->getIdentifierAliases ();
162164 if (\in_array ('identifier:\User\Mount\Allowed ' , $ backendAliases , true ) || \in_array ('identifier_alias ' , $ backendAliases , true )) {
@@ -188,6 +190,87 @@ public function testUserMountingBackends() {
188190 $ service ->registerBackend ($ backendAlias );
189191 }
190192
193+ public function testAdminMountingBackends () {
194+ $ storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
195+ $ storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (true );
196+ $ storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturn (true );
197+ $ storagesBackendChecker ->method ('isAllowedAdminBackend ' )->willReturnCallback (function (Backend $ backend ) {
198+ $ backendAliases = $ backend ->getIdentifierAliases ();
199+ if (\in_array ('identifier:\User\Mount\Allowed ' , $ backendAliases , true ) || \in_array ('identifier_alias ' , $ backendAliases , true )) {
200+ return true ;
201+ }
202+ return false ;
203+ });
204+
205+ $ service = new StoragesBackendService ($ storagesBackendChecker );
206+
207+ $ backendAllowed = $ this ->getBackendMock ('\User\Mount\Allowed ' );
208+ $ backendAllowed ->expects ($ this ->never ())
209+ ->method ('removeVisibility ' );
210+ $ backendNotAllowed = $ this ->getBackendMock ('\User\Mount\NotAllowed ' );
211+ $ backendNotAllowed ->expects ($ this ->once ())
212+ ->method ('removeVisibility ' )
213+ ->with (IStoragesBackendService::VISIBILITY_ADMIN );
214+
215+ $ backendAlias = $ this ->getMockBuilder ('\OCP\Files\External\Backend\Backend ' )
216+ ->disableOriginalConstructor ()
217+ ->getMock ();
218+ $ backendAlias ->method ('getIdentifierAliases ' )
219+ ->willReturn (['identifier_real ' , 'identifier_alias ' ]);
220+ $ backendAlias ->expects ($ this ->never ())
221+ ->method ('removeVisibility ' );
222+
223+ $ service ->registerBackend ($ backendAllowed );
224+ $ service ->registerBackend ($ backendNotAllowed );
225+ $ service ->registerBackend ($ backendAlias );
226+ }
227+
228+ public function testAdminAndUserMountingBackends () {
229+ $ storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
230+ $ storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (true );
231+ $ storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturnCallback (function (Backend $ backend ) {
232+ $ backendAliases = $ backend ->getIdentifierAliases ();
233+ if (\in_array ('identifier:\User\Mount\Allowed ' , $ backendAliases , true ) || \in_array ('identifier_alias ' , $ backendAliases , true )) {
234+ return true ;
235+ }
236+ return false ;
237+ });
238+ $ storagesBackendChecker ->method ('isAllowedAdminBackend ' )->willReturnCallback (function (Backend $ backend ) {
239+ $ backendAliases = $ backend ->getIdentifierAliases ();
240+ if (\in_array ('identifier:\User\Mount\Allowed ' , $ backendAliases , true ) || \in_array ('identifier_alias ' , $ backendAliases , true )) {
241+ return true ;
242+ }
243+ return false ;
244+ });
245+
246+ $ service = new StoragesBackendService ($ storagesBackendChecker );
247+
248+ $ backendAllowed = $ this ->getBackendMock ('\User\Mount\Allowed ' );
249+ $ backendAllowed ->expects ($ this ->never ())
250+ ->method ('removeVisibility ' );
251+ $ backendNotAllowed = $ this ->getBackendMock ('\User\Mount\NotAllowed ' );
252+ $ backendNotAllowed ->expects ($ this ->exactly (2 ))
253+ ->method ('removeVisibility ' )
254+ ->with (
255+ $ this ->logicalOr (
256+ $ this ->identicalTo (IStoragesBackendService::VISIBILITY_ADMIN ),
257+ $ this ->identicalTo (IStoragesBackendService::VISIBILITY_PERSONAL )
258+ )
259+ );
260+
261+ $ backendAlias = $ this ->getMockBuilder ('\OCP\Files\External\Backend\Backend ' )
262+ ->disableOriginalConstructor ()
263+ ->getMock ();
264+ $ backendAlias ->method ('getIdentifierAliases ' )
265+ ->willReturn (['identifier_real ' , 'identifier_alias ' ]);
266+ $ backendAlias ->expects ($ this ->never ())
267+ ->method ('removeVisibility ' );
268+
269+ $ service ->registerBackend ($ backendAllowed );
270+ $ service ->registerBackend ($ backendNotAllowed );
271+ $ service ->registerBackend ($ backendAlias );
272+ }
273+
191274 public function testGetAvailableBackends () {
192275 $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
193276
0 commit comments