2020 */
2121namespace Test \Files \External ;
2222
23+ use OC \Files \External \StoragesBackendChecker ;
2324use OC \Files \External \StoragesBackendService ;
2425use OCP \Files \External \IStoragesBackendService ;
26+ use OCP \Files \External \Backend \Backend ;
2527use OCP \IConfig ;
2628use PHPUnit \Framework \MockObject \MockObject ;
2729
2830class StoragesBackendServiceTest extends \Test \TestCase {
29- /** @var \OCP\IConfig */
30- protected $ config ;
31+ /** @var StoragesBackendChecker */
32+ protected $ storagesBackendChecker ;
3133
3234 protected function setUp (): void {
33- $ this ->config = $ this ->createMock ('\OCP\IConfig ' );
34- $ this ->config
35- ->method ('getAppValue ' )
36- ->willReturnMap ([
37- ['files_external ' , 'user_mounting_backends ' , '' , '' ]
38- ]);
35+ $ this ->storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
36+ $ this ->storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (false );
37+ $ this ->storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturn (false );
3938 }
4039
4140 /**
@@ -67,7 +66,7 @@ protected function getAuthMechanismMock($class) {
6766 }
6867
6968 public function testRegisterBackend () {
70- $ service = new StoragesBackendService ($ this ->config );
69+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
7170
7271 $ backend = $ this ->getBackendMock ('\Foo\Bar ' );
7372
@@ -94,7 +93,7 @@ public function testRegisterBackend() {
9493 }
9594
9695 public function testBackendProvider () {
97- $ service = new StoragesBackendService ($ this ->config );
96+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
9897
9998 $ backend1 = $ this ->getBackendMock ('\Foo\Bar ' );
10099 $ backend2 = $ this ->getBackendMock ('\Bar\Foo ' );
@@ -112,7 +111,7 @@ public function testBackendProvider() {
112111 }
113112
114113 public function testAuthMechanismProvider () {
115- $ service = new StoragesBackendService ($ this ->config );
114+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
116115
117116 $ backend1 = $ this ->getAuthMechanismMock ('\Foo\Bar ' );
118117 $ backend2 = $ this ->getAuthMechanismMock ('\Bar\Foo ' );
@@ -130,7 +129,7 @@ public function testAuthMechanismProvider() {
130129 }
131130
132131 public function testMultipleBackendProviders () {
133- $ service = new StoragesBackendService ($ this ->config );
132+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
134133
135134 $ backend1a = $ this ->getBackendMock ('\Foo\Bar ' );
136135 $ backend1b = $ this ->getBackendMock ('\Bar\Foo ' );
@@ -156,15 +155,17 @@ public function testMultipleBackendProviders() {
156155 }
157156
158157 public function testUserMountingBackends () {
159- $ config = $ this ->createMock (IConfig::class);
160- $ config ->expects ($ this ->exactly (2 ))
161- ->method ('getAppValue ' )
162- ->willReturnMap ([
163- ['files_external ' , 'allow_user_mounting ' , 'no ' , 'yes ' ],
164- ['files_external ' , 'user_mounting_backends ' , '' , 'identifier:\User\Mount\Allowed,identifier_alias ' ]
165- ]);
166-
167- $ service = new StoragesBackendService ($ config );
158+ $ storagesBackendChecker = $ this ->createMock (StoragesBackendChecker::class);
159+ $ storagesBackendChecker ->method ('isUserMountingAllowed ' )->willReturn (true );
160+ $ storagesBackendChecker ->method ('isAllowedUserBackend ' )->willReturnCallback (function (Backend $ backend ) {
161+ $ backendAliases = $ backend ->getIdentifierAliases ();
162+ if (\in_array ('identifier:\User\Mount\Allowed ' , $ backendAliases , true ) || \in_array ('identifier_alias ' , $ backendAliases , true )) {
163+ return true ;
164+ }
165+ return false ;
166+ });
167+
168+ $ service = new StoragesBackendService ($ storagesBackendChecker );
168169
169170 $ backendAllowed = $ this ->getBackendMock ('\User\Mount\Allowed ' );
170171 $ backendAllowed ->expects ($ this ->never ())
@@ -188,7 +189,7 @@ public function testUserMountingBackends() {
188189 }
189190
190191 public function testGetAvailableBackends () {
191- $ service = new StoragesBackendService ($ this ->config );
192+ $ service = new StoragesBackendService ($ this ->storagesBackendChecker );
192193
193194 $ backendAvailable = $ this ->getBackendMock ('\Backend\Available ' );
194195 $ backendAvailable ->expects ($ this ->once ())
0 commit comments