1111
1212use OC \Federation \CloudFederationFactory ;
1313use OC \OCM \Model \OCMProvider ;
14+ use OCP \Constants ;
1415use OCP \Federation \ICloudFederationShare ;
1516use OCP \Federation \ICloudId ;
1617use OCP \Federation \ICloudIdManager ;
@@ -58,8 +59,24 @@ protected function setUp(): void {
5859 );
5960 }
6061
61- public function testExchangeTokenUsesLocalWebDavUri (): void {
62- $ this ->remoteProvider ->setCapabilities (['exchange-token ' ]);
62+ public static function protocolObjectProvider (): array {
63+ return [
64+ 'default permissions ' => [['protocol-object ' ], null , ['read ' ]],
65+ 'no permissions ' => [['protocol-object ' ], 0 , []],
66+ 'read ' => [['protocol-object ' ], Constants::PERMISSION_READ , ['read ' ]],
67+ 'share ' => [['protocol-object ' ], Constants::PERMISSION_SHARE , ['share ' ]],
68+ 'create ' => [['protocol-object ' ], Constants::PERMISSION_CREATE , ['write ' ]],
69+ 'update ' => [['protocol-object ' ], Constants::PERMISSION_UPDATE , ['write ' ]],
70+ 'create and update ' => [['protocol-object ' ], Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE , ['write ' ]],
71+ 'delete only ' => [['protocol-object ' ], Constants::PERMISSION_DELETE , []],
72+ 'all permissions ' => [['protocol-object ' ], Constants::PERMISSION_ALL , ['share ' , 'read ' , 'write ' ]],
73+ 'with token exchange ' => [['protocol-object ' , 'exchange-token ' ], Constants::PERMISSION_READ , ['read ' ]],
74+ ];
75+ }
76+
77+ #[DataProvider('protocolObjectProvider ' )]
78+ public function testProtocolObjectUsesLocalWebDavUri (array $ capabilities , ?int $ permissions , array $ expectedPermissions ): void {
79+ $ this ->remoteProvider ->setCapabilities ($ capabilities );
6380 $ localProvider = new OCMProvider ();
6481 $ resource = $ localProvider ->createNewResourceType ();
6582 $ resource ->setName ('file ' )->setProtocols (['webdav ' => '/public.php/webdav/ ' ]);
@@ -74,14 +91,14 @@ public function testExchangeTokenUsesLocalWebDavUri(): void {
7491 ->willReturn ('https://local.example/nextcloud/public.php/webdav/ ' );
7592 $ this ->logger ->expects ($ this ->never ())->method ('warning ' );
7693
77- $ share = $ this ->createShare ();
94+ $ share = $ this ->createShare ($ permissions );
7895
7996 $ this ->assertSame ([
8097 'name ' => 'webdav ' ,
8198 'webdav ' => [
8299 'uri ' => 'https://local.example/nextcloud/public.php/webdav/ ' ,
83100 'sharedSecret ' => 'share-secret ' ,
84- 'permissions ' => [ ' {http://open-cloud-mesh.org/ns}share-permissions ' ] ,
101+ 'permissions ' => $ expectedPermissions ,
85102 ],
86103 ], $ share ->getProtocol ());
87104 $ this ->assertSame ('share-secret ' , $ share ->getShareSecret ());
@@ -96,7 +113,7 @@ public static function missingLocalWebDavProvider(): array {
96113
97114 #[DataProvider('missingLocalWebDavProvider ' )]
98115 public function testMissingLocalWebDavUsesLegacyShare (bool $ hasFileResource , string $ exceptionMessage ): void {
99- $ this ->remoteProvider ->setCapabilities (['exchange-token ' ]);
116+ $ this ->remoteProvider ->setCapabilities (['protocol-object ' ]);
100117 $ localProvider = new OCMProvider ();
101118 if ($ hasFileResource ) {
102119 $ resource = $ localProvider ->createNewResourceType ();
@@ -117,17 +134,26 @@ public function testMissingLocalWebDavUsesLegacyShare(bool $hasFileResource, str
117134 $ this ->assertLegacyShare ($ this ->createShare ());
118135 }
119136
120- public function testLegacyShareDoesNotQueryLocalDiscovery (): void {
121- $ this ->remoteProvider ->setCapabilities (['shares ' ]);
137+ public static function legacyCapabilitiesProvider (): array {
138+ return [
139+ 'no capabilities ' => [[]],
140+ 'shares only ' => [['shares ' ]],
141+ 'token exchange only ' => [['exchange-token ' ]],
142+ ];
143+ }
144+
145+ #[DataProvider('legacyCapabilitiesProvider ' )]
146+ public function testLegacyShareDoesNotQueryLocalDiscovery (array $ capabilities ): void {
147+ $ this ->remoteProvider ->setCapabilities ($ capabilities );
122148 $ this ->discoveryService ->expects ($ this ->never ())->method ('getLocalOCMProvider ' );
123149 $ this ->urlGenerator ->expects ($ this ->never ())->method ('getAbsoluteURL ' );
124150 $ this ->logger ->expects ($ this ->never ())->method ('warning ' );
125151
126- $ this ->assertLegacyShare ($ this ->createShare ());
152+ $ this ->assertLegacyShare ($ this ->createShare (Constants:: PERMISSION_ALL ));
127153 }
128154
129- private function createShare (): ICloudFederationShare {
130- return $ this -> factory -> getCloudFederationShare (
155+ private function createShare (? int $ permissions = null ): ICloudFederationShare {
156+ $ arguments = [
131157 'recipient@remote.example ' ,
132158 'document.odt ' ,
133159 '' ,
@@ -139,7 +165,11 @@ private function createShare(): ICloudFederationShare {
139165 'share-secret ' ,
140166 'user ' ,
141167 'file ' ,
142- );
168+ ];
169+ if ($ permissions !== null ) {
170+ $ arguments [] = $ permissions ;
171+ }
172+ return $ this ->factory ->getCloudFederationShare (...$ arguments );
143173 }
144174
145175 private function assertLegacyShare (ICloudFederationShare $ share ): void {
0 commit comments