1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud |
4
|
|
|
* |
5
|
|
|
* @author Michael Gapczynski |
6
|
|
|
* @copyright 2012 Michael Gapczynski [email protected] |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public |
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
class Test_Share extends \Test\TestCase { |
23
|
|
|
|
24
|
|
|
protected $itemType; |
25
|
|
|
protected $userBackend; |
26
|
|
|
protected $user1; |
27
|
|
|
protected $user2; |
28
|
|
|
protected $user3; |
29
|
|
|
protected $user4; |
30
|
|
|
protected $user5; |
31
|
|
|
protected $user6; |
32
|
|
|
protected $groupAndUser; |
33
|
|
|
protected $groupBackend; |
34
|
|
|
protected $group1; |
35
|
|
|
protected $group2; |
36
|
|
|
protected $resharing; |
37
|
|
|
protected $dateInFuture; |
38
|
|
|
protected $dateInPast; |
39
|
|
|
|
40
|
|
|
protected function setUp() { |
41
|
|
|
parent::setUp(); |
42
|
|
|
|
43
|
|
|
OC_User::clearBackends(); |
44
|
|
|
OC_User::useBackend('dummy'); |
45
|
|
|
$this->user1 = $this->getUniqueID('user1_'); |
46
|
|
|
$this->user2 = $this->getUniqueID('user2_'); |
47
|
|
|
$this->user3 = $this->getUniqueID('user3_'); |
48
|
|
|
$this->user4 = $this->getUniqueID('user4_'); |
49
|
|
|
$this->user5 = $this->getUniqueID('user5_'); |
50
|
|
|
$this->user6 = $this->getUniqueID('user6_'); |
51
|
|
|
$this->groupAndUser = $this->getUniqueID('groupAndUser_'); |
52
|
|
|
OC_User::createUser($this->user1, 'pass'); |
53
|
|
|
OC_User::createUser($this->user2, 'pass'); |
54
|
|
|
OC_User::createUser($this->user3, 'pass'); |
55
|
|
|
OC_User::createUser($this->user4, 'pass'); |
56
|
|
|
OC_User::createUser($this->user5, 'pass'); |
57
|
|
|
OC_User::createUser($this->user6, 'pass'); // no group |
58
|
|
|
OC_User::createUser($this->groupAndUser, 'pass'); |
59
|
|
|
OC_User::setUserId($this->user1); |
60
|
|
|
OC_Group::clearBackends(); |
61
|
|
|
OC_Group::useBackend(new OC_Group_Dummy); |
62
|
|
|
$this->group1 = $this->getUniqueID('group1_'); |
63
|
|
|
$this->group2 = $this->getUniqueID('group2_'); |
64
|
|
|
OC_Group::createGroup($this->group1); |
65
|
|
|
OC_Group::createGroup($this->group2); |
66
|
|
|
OC_Group::createGroup($this->groupAndUser); |
67
|
|
|
OC_Group::addToGroup($this->user1, $this->group1); |
68
|
|
|
OC_Group::addToGroup($this->user2, $this->group1); |
69
|
|
|
OC_Group::addToGroup($this->user3, $this->group1); |
70
|
|
|
OC_Group::addToGroup($this->user2, $this->group2); |
71
|
|
|
OC_Group::addToGroup($this->user4, $this->group2); |
72
|
|
|
OC_Group::addToGroup($this->user2, $this->groupAndUser); |
73
|
|
|
OC_Group::addToGroup($this->user3, $this->groupAndUser); |
74
|
|
|
OCP\Share::registerBackend('test', 'Test_Share_Backend'); |
75
|
|
|
OC_Hook::clear('OCP\\Share'); |
76
|
|
|
OC::registerShareHooks(); |
77
|
|
|
$this->resharing = OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes'); |
78
|
|
|
OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes'); |
79
|
|
|
|
80
|
|
|
// 20 Minutes in the past, 20 minutes in the future. |
81
|
|
|
$now = time(); |
82
|
|
|
$dateFormat = 'Y-m-d H:i:s'; |
83
|
|
|
$this->dateInPast = date($dateFormat, $now - 20 * 60); |
84
|
|
|
$this->dateInFuture = date($dateFormat, $now + 20 * 60); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
protected function tearDown() { |
88
|
|
|
$query = OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `item_type` = ?'); |
89
|
|
|
$query->execute(array('test')); |
90
|
|
|
OC_Appconfig::setValue('core', 'shareapi_allow_resharing', $this->resharing); |
91
|
|
|
|
92
|
|
|
OC_User::deleteUser($this->user1); |
93
|
|
|
OC_User::deleteUser($this->user2); |
94
|
|
|
OC_User::deleteUser($this->user3); |
95
|
|
|
OC_User::deleteUser($this->user4); |
96
|
|
|
OC_User::deleteUser($this->user5); |
97
|
|
|
OC_User::deleteUser($this->user6); |
98
|
|
|
OC_User::deleteUser($this->groupAndUser); |
99
|
|
|
|
100
|
|
|
OC_Group::deleteGroup($this->group1); |
101
|
|
|
OC_Group::deleteGroup($this->group2); |
102
|
|
|
OC_Group::deleteGroup($this->groupAndUser); |
103
|
|
|
|
104
|
|
|
$this->logout(); |
105
|
|
|
parent::tearDown(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
protected function setHttpHelper($httpHelper) { |
109
|
|
|
\OC::$server->registerService('HTTPHelper', function () use ($httpHelper) { |
110
|
|
|
return $httpHelper; |
111
|
|
|
}); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testShareInvalidShareType() { |
115
|
|
|
$message = 'Share type foobar is not valid for test.txt'; |
116
|
|
|
try { |
117
|
|
|
OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, \OCP\Constants::PERMISSION_READ); |
118
|
|
|
} catch (Exception $exception) { |
119
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testInvalidItemType() { |
124
|
|
|
$message = 'Sharing backend for foobar not found'; |
125
|
|
|
try { |
126
|
|
|
OCP\Share::shareItem('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ); |
127
|
|
|
$this->fail('Exception was expected: '.$message); |
128
|
|
|
} catch (Exception $exception) { |
129
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
130
|
|
|
} |
131
|
|
|
try { |
132
|
|
|
OCP\Share::getItemsSharedWith('foobar'); |
133
|
|
|
$this->fail('Exception was expected: '.$message); |
134
|
|
|
} catch (Exception $exception) { |
135
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
136
|
|
|
} |
137
|
|
|
try { |
138
|
|
|
OCP\Share::getItemSharedWith('foobar', 'test.txt'); |
139
|
|
|
$this->fail('Exception was expected: '.$message); |
140
|
|
|
} catch (Exception $exception) { |
141
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
142
|
|
|
} |
143
|
|
|
try { |
144
|
|
|
OCP\Share::getItemSharedWithBySource('foobar', 'test.txt'); |
145
|
|
|
$this->fail('Exception was expected: '.$message); |
146
|
|
|
} catch (Exception $exception) { |
147
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
148
|
|
|
} |
149
|
|
|
try { |
150
|
|
|
OCP\Share::getItemShared('foobar', 'test.txt'); |
151
|
|
|
$this->fail('Exception was expected: '.$message); |
152
|
|
|
} catch (Exception $exception) { |
153
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
154
|
|
|
} |
155
|
|
|
try { |
156
|
|
|
OCP\Share::unshare('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2); |
157
|
|
|
$this->fail('Exception was expected: '.$message); |
158
|
|
|
} catch (Exception $exception) { |
159
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
160
|
|
|
} |
161
|
|
|
try { |
162
|
|
|
OCP\Share::setPermissions('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_UPDATE); |
163
|
|
|
$this->fail('Exception was expected: '.$message); |
164
|
|
|
} catch (Exception $exception) { |
165
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
protected function shareUserOneTestFileWithUserTwo() { |
170
|
|
|
OC_User::setUserId($this->user1); |
171
|
|
|
$this->assertTrue( |
172
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ), |
173
|
|
|
'Failed asserting that user 1 successfully shared text.txt with user 2.' |
174
|
|
|
); |
175
|
|
|
$this->assertContains( |
176
|
|
|
'test.txt', |
177
|
|
|
OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
178
|
|
|
'Failed asserting that test.txt is a shared file of user 1.' |
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
OC_User::setUserId($this->user2); |
182
|
|
|
$this->assertContains( |
183
|
|
|
'test.txt', |
184
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
185
|
|
|
'Failed asserting that user 2 has access to test.txt after initial sharing.' |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
protected function shareUserTestFileAsLink() { |
190
|
|
|
OC_User::setUserId($this->user1); |
191
|
|
|
$result = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); |
192
|
|
|
$this->assertTrue(is_string($result)); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param string $sharer |
197
|
|
|
* @param string $receiver |
198
|
|
|
*/ |
199
|
|
|
protected function shareUserTestFileWithUser($sharer, $receiver) { |
200
|
|
|
OC_User::setUserId($sharer); |
201
|
|
|
$this->assertTrue( |
202
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $receiver, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE), |
203
|
|
|
'Failed asserting that ' . $sharer . ' successfully shared text.txt with ' . $receiver . '.' |
204
|
|
|
); |
205
|
|
|
$this->assertContains( |
206
|
|
|
'test.txt', |
207
|
|
|
OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
208
|
|
|
'Failed asserting that test.txt is a shared file of ' . $sharer . '.' |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
OC_User::setUserId($receiver); |
212
|
|
|
$this->assertContains( |
213
|
|
|
'test.txt', |
214
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
215
|
|
|
'Failed asserting that ' . $receiver . ' has access to test.txt after initial sharing.' |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function testShareWithUser() { |
220
|
|
|
// Invalid shares |
221
|
|
|
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner'; |
222
|
|
|
try { |
223
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, \OCP\Constants::PERMISSION_READ); |
224
|
|
|
$this->fail('Exception was expected: '.$message); |
225
|
|
|
} catch (Exception $exception) { |
226
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
227
|
|
|
} |
228
|
|
|
$message = 'Sharing test.txt failed, because the user foobar does not exist'; |
229
|
|
|
try { |
230
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', \OCP\Constants::PERMISSION_READ); |
231
|
|
|
$this->fail('Exception was expected: '.$message); |
232
|
|
|
} catch (Exception $exception) { |
233
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
234
|
|
|
} |
235
|
|
|
$message = 'Sharing foobar failed, because the sharing backend for test could not find its source'; |
236
|
|
|
try { |
237
|
|
|
OCP\Share::shareItem('test', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ); |
238
|
|
|
$this->fail('Exception was expected: '.$message); |
239
|
|
|
} catch (Exception $exception) { |
240
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
// Valid share |
244
|
|
|
$this->shareUserOneTestFileWithUserTwo(); |
245
|
|
|
|
246
|
|
|
// Attempt to share again |
247
|
|
|
OC_User::setUserId($this->user1); |
248
|
|
|
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2; |
249
|
|
|
try { |
250
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ); |
251
|
|
|
$this->fail('Exception was expected: '.$message); |
252
|
|
|
} catch (Exception $exception) { |
253
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
// Attempt to share back |
257
|
|
|
OC_User::setUserId($this->user2); |
258
|
|
|
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; |
259
|
|
|
try { |
260
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, \OCP\Constants::PERMISSION_READ); |
261
|
|
|
$this->fail('Exception was expected: '.$message); |
262
|
|
|
} catch (Exception $exception) { |
263
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
// Unshare |
267
|
|
|
OC_User::setUserId($this->user1); |
268
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); |
269
|
|
|
|
270
|
|
|
// Attempt reshare without share permission |
271
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ)); |
272
|
|
|
OC_User::setUserId($this->user2); |
273
|
|
|
$message = 'Sharing test.txt failed, because resharing is not allowed'; |
274
|
|
|
try { |
275
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ); |
276
|
|
|
$this->fail('Exception was expected: '.$message); |
277
|
|
|
} catch (Exception $exception) { |
278
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
// Owner grants share and update permission |
282
|
|
|
OC_User::setUserId($this->user1); |
283
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE)); |
284
|
|
|
|
285
|
|
|
// Attempt reshare with escalated permissions |
286
|
|
|
OC_User::setUserId($this->user2); |
287
|
|
|
$message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2; |
288
|
|
|
try { |
289
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE); |
290
|
|
|
$this->fail('Exception was expected: '.$message); |
291
|
|
|
} catch (Exception $exception) { |
292
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
// Valid reshare |
296
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE)); |
297
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); |
298
|
|
|
OC_User::setUserId($this->user3); |
299
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); |
300
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
301
|
|
|
|
302
|
|
|
// Attempt to escalate permissions |
303
|
|
|
OC_User::setUserId($this->user2); |
304
|
|
|
$message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to '.$this->user2; |
305
|
|
|
try { |
306
|
|
|
OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE); |
307
|
|
|
$this->fail('Exception was expected: '.$message); |
308
|
|
|
} catch (Exception $exception) { |
309
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
// Remove update permission |
313
|
|
|
OC_User::setUserId($this->user1); |
314
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE)); |
315
|
|
|
OC_User::setUserId($this->user2); |
316
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
317
|
|
|
OC_User::setUserId($this->user3); |
318
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
319
|
|
|
|
320
|
|
|
// Remove share permission |
321
|
|
|
OC_User::setUserId($this->user1); |
322
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ)); |
323
|
|
|
OC_User::setUserId($this->user2); |
324
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
325
|
|
|
OC_User::setUserId($this->user3); |
326
|
|
|
$this->assertSame(array(), OCP\Share::getItemSharedWith('test', 'test.txt')); |
327
|
|
|
|
328
|
|
|
// Reshare again, and then have owner unshare |
329
|
|
|
OC_User::setUserId($this->user1); |
330
|
|
|
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE)); |
331
|
|
|
OC_User::setUserId($this->user2); |
332
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ)); |
333
|
|
|
OC_User::setUserId($this->user1); |
334
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); |
335
|
|
|
OC_User::setUserId($this->user2); |
336
|
|
|
$this->assertSame(array(), OCP\Share::getItemSharedWith('test', 'test.txt')); |
337
|
|
|
OC_User::setUserId($this->user3); |
338
|
|
|
$this->assertSame(array(), OCP\Share::getItemSharedWith('test', 'test.txt')); |
339
|
|
|
|
340
|
|
|
// Attempt target conflict |
341
|
|
|
OC_User::setUserId($this->user1); |
342
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ)); |
343
|
|
|
OC_User::setUserId($this->user3); |
344
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ)); |
345
|
|
|
|
346
|
|
|
OC_User::setUserId($this->user2); |
347
|
|
|
$to_test = OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET); |
348
|
|
|
$this->assertEquals(2, count($to_test)); |
349
|
|
|
$this->assertTrue(in_array('test.txt', $to_test)); |
350
|
|
|
$this->assertTrue(in_array('test1.txt', $to_test)); |
351
|
|
|
|
352
|
|
|
// Unshare from self |
353
|
|
|
$this->assertTrue(OCP\Share::unshareFromSelf('test', 'test.txt')); |
354
|
|
|
$this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
355
|
|
|
|
356
|
|
|
// Unshare from self via source |
357
|
|
|
$this->assertTrue(OCP\Share::unshareFromSelf('test', 'share.txt', true)); |
358
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
359
|
|
|
|
360
|
|
|
OC_User::setUserId($this->user1); |
361
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ)); |
362
|
|
|
OC_User::setUserId($this->user3); |
363
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ)); |
364
|
|
|
|
365
|
|
|
OC_User::setUserId($this->user2); |
366
|
|
|
$to_test = OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET); |
367
|
|
|
$this->assertEquals(2, count($to_test)); |
368
|
|
|
$this->assertTrue(in_array('test.txt', $to_test)); |
369
|
|
|
$this->assertTrue(in_array('test1.txt', $to_test)); |
370
|
|
|
|
371
|
|
|
// Remove user |
372
|
|
|
OC_User::setUserId($this->user1); |
373
|
|
|
OC_User::deleteUser($this->user1); |
374
|
|
|
OC_User::setUserId($this->user2); |
375
|
|
|
$this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
public function testShareWithUserExpirationExpired() { |
379
|
|
|
OC_User::setUserId($this->user1); |
380
|
|
|
$this->shareUserOneTestFileWithUserTwo(); |
381
|
|
|
$this->shareUserTestFileAsLink(); |
382
|
|
|
|
383
|
|
|
// manipulate share table and set expire date to the past |
384
|
|
|
$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); |
385
|
|
|
$query->bindValue(1, new \DateTime($this->dateInPast), 'datetime'); |
386
|
|
|
$query->bindValue(2, 'test'); |
387
|
|
|
$query->bindValue(3, 'test.txt'); |
388
|
|
|
$query->bindValue(4, $this->user1); |
389
|
|
|
$query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK); |
390
|
|
|
$query->execute(); |
391
|
|
|
|
392
|
|
|
$shares = OCP\Share::getItemsShared('test'); |
393
|
|
|
$this->assertSame(1, count($shares)); |
394
|
|
|
$share = reset($shares); |
395
|
|
|
$this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
public function testGetShareFromOutsideFilesFolder() { |
399
|
|
|
OC_User::setUserId($this->user1); |
400
|
|
|
$view = new \OC\Files\View('/' . $this->user1 . '/'); |
401
|
|
|
$view->mkdir('files/test'); |
402
|
|
|
$view->mkdir('files/test/sub'); |
403
|
|
|
|
404
|
|
|
$view->mkdir('files_trashbin'); |
405
|
|
|
$view->mkdir('files_trashbin/files'); |
406
|
|
|
|
407
|
|
|
$fileInfo = $view->getFileInfo('files/test/sub'); |
408
|
|
|
$fileId = $fileInfo->getId(); |
409
|
|
|
|
410
|
|
|
$this->assertTrue( |
411
|
|
|
OCP\Share::shareItem('folder', $fileId, OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ), |
412
|
|
|
'Failed asserting that user 1 successfully shared "test/sub" with user 2.' |
413
|
|
|
); |
414
|
|
|
|
415
|
|
|
$result = OCP\Share::getItemShared('folder', $fileId, Test_Share_Backend::FORMAT_SOURCE); |
416
|
|
|
$this->assertNotEmpty($result); |
417
|
|
|
|
418
|
|
|
$result = OCP\Share::getItemSharedWithUser('folder', $fileId, $this->user2); |
419
|
|
|
$this->assertNotEmpty($result); |
420
|
|
|
|
421
|
|
|
$result = OCP\Share::getItemsSharedWithUser('folder', $this->user2); |
422
|
|
|
$this->assertNotEmpty($result); |
423
|
|
|
|
424
|
|
|
// move to trash (keeps file id) |
425
|
|
|
$view->rename('files/test', 'files_trashbin/files/test'); |
426
|
|
|
|
427
|
|
|
$result = OCP\Share::getItemShared('folder', $fileId, Test_Share_Backend::FORMAT_SOURCE); |
428
|
|
|
$this->assertEmpty($result, 'Share must not be returned for files outside of "files"'); |
429
|
|
|
|
430
|
|
|
$result = OCP\Share::getItemSharedWithUser('folder', $fileId, $this->user2); |
431
|
|
|
$this->assertEmpty($result, 'Share must not be returned for files outside of "files"'); |
432
|
|
|
|
433
|
|
|
$result = OCP\Share::getItemsSharedWithUser('folder', $this->user2); |
434
|
|
|
$this->assertEmpty($result, 'Share must not be returned for files outside of "files"'); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
public function testSetExpireDateInPast() { |
438
|
|
|
OC_User::setUserId($this->user1); |
439
|
|
|
$this->shareUserOneTestFileWithUserTwo(); |
440
|
|
|
$this->shareUserTestFileAsLink(); |
441
|
|
|
|
442
|
|
|
$setExpireDateFailed = false; |
443
|
|
|
try { |
444
|
|
|
$this->assertTrue( |
445
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast, ''), |
446
|
|
|
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' |
447
|
|
|
); |
448
|
|
|
} catch (\Exception $e) { |
449
|
|
|
$setExpireDateFailed = true; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
$this->assertTrue($setExpireDateFailed); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
public function testShareWithUserExpirationValid() { |
456
|
|
|
OC_User::setUserId($this->user1); |
457
|
|
|
$this->shareUserOneTestFileWithUserTwo(); |
458
|
|
|
$this->shareUserTestFileAsLink(); |
459
|
|
|
|
460
|
|
|
|
461
|
|
|
$this->assertTrue( |
462
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''), |
463
|
|
|
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' |
464
|
|
|
); |
465
|
|
|
|
466
|
|
|
$shares = OCP\Share::getItemsShared('test'); |
467
|
|
|
$this->assertSame(2, count($shares)); |
468
|
|
|
|
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/* |
472
|
|
|
* if user is in a group excluded from resharing, then the share permission should |
473
|
|
|
* be removed |
474
|
|
|
*/ |
475
|
|
|
public function testShareWithUserAndUserIsExcludedFromResharing() { |
476
|
|
|
|
477
|
|
|
OC_User::setUserId($this->user1); |
478
|
|
|
$this->assertTrue( |
479
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, \OCP\Constants::PERMISSION_ALL), |
480
|
|
|
'Failed asserting that user 1 successfully shared text.txt with user 4.' |
481
|
|
|
); |
482
|
|
|
$this->assertContains( |
483
|
|
|
'test.txt', |
484
|
|
|
OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
485
|
|
|
'Failed asserting that test.txt is a shared file of user 1.' |
486
|
|
|
); |
487
|
|
|
|
488
|
|
|
// exclude group2 from sharing |
489
|
|
|
\OC_Appconfig::setValue('core', 'shareapi_exclude_groups_list', $this->group2); |
490
|
|
|
\OC_Appconfig::setValue('core', 'shareapi_exclude_groups', "yes"); |
491
|
|
|
|
492
|
|
|
OC_User::setUserId($this->user4); |
493
|
|
|
|
494
|
|
|
$share = OCP\Share::getItemSharedWith('test', 'test.txt'); |
495
|
|
|
|
496
|
|
|
$this->assertSame(\OCP\Constants::PERMISSION_ALL & ~\OCP\Constants::PERMISSION_SHARE, $share['permissions'], |
497
|
|
|
'Failed asserting that user 4 is excluded from re-sharing'); |
498
|
|
|
|
499
|
|
|
\OC_Appconfig::deleteKey('core', 'shareapi_exclude_groups_list'); |
500
|
|
|
\OC_Appconfig::deleteKey('core', 'shareapi_exclude_groups'); |
501
|
|
|
|
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
public function testSharingAFolderThatIsSharedWithAGroupOfTheOwner() { |
505
|
|
|
OC_User::setUserId($this->user1); |
506
|
|
|
$view = new \OC\Files\View('/' . $this->user1 . '/'); |
507
|
|
|
$view->mkdir('files/test'); |
508
|
|
|
$view->mkdir('files/test/sub1'); |
509
|
|
|
$view->mkdir('files/test/sub1/sub2'); |
510
|
|
|
|
511
|
|
|
$fileInfo = $view->getFileInfo('files/test/sub1'); |
512
|
|
|
$fileId = $fileInfo->getId(); |
513
|
|
|
|
514
|
|
|
$this->assertTrue( |
515
|
|
|
OCP\Share::shareItem('folder', $fileId, OCP\Share::SHARE_TYPE_GROUP, $this->group1, \OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_CREATE), |
516
|
|
|
'Failed asserting that user 1 successfully shared "test/sub1" with group 1.' |
517
|
|
|
); |
518
|
|
|
|
519
|
|
|
$result = OCP\Share::getItemShared('folder', $fileId, Test_Share_Backend::FORMAT_SOURCE); |
520
|
|
|
$this->assertNotEmpty($result); |
521
|
|
|
$this->assertEquals(\OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_CREATE, $result['permissions']); |
522
|
|
|
|
523
|
|
|
$fileInfo = $view->getFileInfo('files/test/sub1/sub2'); |
524
|
|
|
$fileId = $fileInfo->getId(); |
525
|
|
|
|
526
|
|
|
$this->assertTrue( |
527
|
|
|
OCP\Share::shareItem('folder', $fileId, OCP\Share::SHARE_TYPE_USER, $this->user4, \OCP\Constants::PERMISSION_READ), |
528
|
|
|
'Failed asserting that user 1 successfully shared "test/sub1/sub2" with user 4.' |
529
|
|
|
); |
530
|
|
|
|
531
|
|
|
$result = OCP\Share::getItemShared('folder', $fileId, Test_Share_Backend::FORMAT_SOURCE); |
532
|
|
|
$this->assertNotEmpty($result); |
533
|
|
|
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
protected function shareUserOneTestFileWithGroupOne() { |
537
|
|
|
OC_User::setUserId($this->user1); |
538
|
|
|
$this->assertTrue( |
539
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, \OCP\Constants::PERMISSION_READ), |
540
|
|
|
'Failed asserting that user 1 successfully shared text.txt with group 1.' |
541
|
|
|
); |
542
|
|
|
$this->assertContains( |
543
|
|
|
'test.txt', |
544
|
|
|
OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
545
|
|
|
'Failed asserting that test.txt is a shared file of user 1.' |
546
|
|
|
); |
547
|
|
|
|
548
|
|
|
OC_User::setUserId($this->user2); |
549
|
|
|
$this->assertContains( |
550
|
|
|
'test.txt', |
551
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
552
|
|
|
'Failed asserting that user 2 has access to test.txt after initial sharing.' |
553
|
|
|
); |
554
|
|
|
|
555
|
|
|
OC_User::setUserId($this->user3); |
556
|
|
|
$this->assertContains( |
557
|
|
|
'test.txt', |
558
|
|
|
OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
559
|
|
|
'Failed asserting that user 3 has access to test.txt after initial sharing.' |
560
|
|
|
); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
public function testShareWithGroup() { |
564
|
|
|
// Invalid shares |
565
|
|
|
$message = 'Sharing test.txt failed, because the group foobar does not exist'; |
566
|
|
|
try { |
567
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', \OCP\Constants::PERMISSION_READ); |
568
|
|
|
$this->fail('Exception was expected: '.$message); |
569
|
|
|
} catch (Exception $exception) { |
570
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
571
|
|
|
} |
572
|
|
|
$policy = OC_Appconfig::getValue('core', 'shareapi_only_share_with_group_members', 'no'); |
573
|
|
|
OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes'); |
574
|
|
|
$message = 'Sharing test.txt failed, because '.$this->user1.' is not a member of the group '.$this->group2; |
575
|
|
|
try { |
576
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, \OCP\Constants::PERMISSION_READ); |
577
|
|
|
$this->fail('Exception was expected: '.$message); |
578
|
|
|
} catch (Exception $exception) { |
579
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
580
|
|
|
} |
581
|
|
|
OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', $policy); |
582
|
|
|
|
583
|
|
|
// Valid share |
584
|
|
|
$this->shareUserOneTestFileWithGroupOne(); |
585
|
|
|
|
586
|
|
|
// Attempt to share again |
587
|
|
|
OC_User::setUserId($this->user1); |
588
|
|
|
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1; |
589
|
|
|
try { |
590
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, \OCP\Constants::PERMISSION_READ); |
591
|
|
|
$this->fail('Exception was expected: '.$message); |
592
|
|
|
} catch (Exception $exception) { |
593
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
// Attempt to share back to owner of group share |
597
|
|
|
OC_User::setUserId($this->user2); |
598
|
|
|
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; |
599
|
|
|
try { |
600
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, \OCP\Constants::PERMISSION_READ); |
601
|
|
|
$this->fail('Exception was expected: '.$message); |
602
|
|
|
} catch (Exception $exception) { |
603
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
// Attempt to share back to group |
607
|
|
|
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1; |
608
|
|
|
try { |
609
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, \OCP\Constants::PERMISSION_READ); |
610
|
|
|
$this->fail('Exception was expected: '.$message); |
611
|
|
|
} catch (Exception $exception) { |
612
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
// Attempt to share back to member of group |
616
|
|
|
$message ='Sharing test.txt failed, because this item is already shared with '.$this->user3; |
617
|
|
|
try { |
618
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ); |
619
|
|
|
$this->fail('Exception was expected: '.$message); |
620
|
|
|
} catch (Exception $exception) { |
621
|
|
|
$this->assertEquals($message, $exception->getMessage()); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
// Unshare |
625
|
|
|
OC_User::setUserId($this->user1); |
626
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); |
627
|
|
|
|
628
|
|
|
// Valid share with same person - user then group |
629
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_SHARE)); |
630
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE)); |
631
|
|
|
OC_User::setUserId($this->user2); |
632
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
633
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_SHARE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
634
|
|
|
OC_User::setUserId($this->user3); |
635
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
636
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
637
|
|
|
|
638
|
|
|
// Valid reshare |
639
|
|
|
OC_User::setUserId($this->user2); |
640
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, \OCP\Constants::PERMISSION_READ)); |
641
|
|
|
OC_User::setUserId($this->user4); |
642
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
643
|
|
|
|
644
|
|
|
// Unshare from user only |
645
|
|
|
OC_User::setUserId($this->user1); |
646
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); |
647
|
|
|
OC_User::setUserId($this->user2); |
648
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
649
|
|
|
OC_User::setUserId($this->user4); |
650
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
651
|
|
|
|
652
|
|
|
// Valid share with same person - group then user |
653
|
|
|
OC_User::setUserId($this->user1); |
654
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE)); |
655
|
|
|
OC_User::setUserId($this->user2); |
656
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
657
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
658
|
|
|
|
659
|
|
|
// Unshare from group only |
660
|
|
|
OC_User::setUserId($this->user1); |
661
|
|
|
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); |
662
|
|
|
OC_User::setUserId($this->user2); |
663
|
|
|
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS)); |
664
|
|
|
|
665
|
|
|
// Attempt user specific target conflict |
666
|
|
|
OC_User::setUserId($this->user3); |
667
|
|
|
\OCP\Util::connectHook('OCP\\Share', 'post_shared', 'DummyHookListener', 'listen'); |
668
|
|
|
|
669
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE)); |
670
|
|
|
$this->assertEquals(OCP\Share::SHARE_TYPE_GROUP, DummyHookListener::$shareType); |
|
|
|
|
671
|
|
|
OC_User::setUserId($this->user2); |
672
|
|
|
$to_test = OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET); |
673
|
|
|
$this->assertEquals(2, count($to_test)); |
674
|
|
|
$this->assertTrue(in_array('test.txt', $to_test)); |
675
|
|
|
$this->assertTrue(in_array('test1.txt', $to_test)); |
676
|
|
|
|
677
|
|
|
// Valid reshare |
678
|
|
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE)); |
679
|
|
|
OC_User::setUserId($this->user4); |
680
|
|
|
$this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
681
|
|
|
|
682
|
|
|
// Remove user from group |
683
|
|
|
OC_Group::removeFromGroup($this->user2, $this->group1); |
684
|
|
|
OC_User::setUserId($this->user2); |
685
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
686
|
|
|
OC_User::setUserId($this->user4); |
687
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
688
|
|
|
|
689
|
|
|
// Add user to group |
690
|
|
|
OC_Group::addToGroup($this->user4, $this->group1); |
691
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
692
|
|
|
|
693
|
|
|
// Unshare from self |
694
|
|
|
$this->assertTrue(OCP\Share::unshareFromSelf('test', 'test.txt')); |
695
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
696
|
|
|
OC_User::setUserId($this->user2); |
697
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
698
|
|
|
|
699
|
|
|
// Unshare from self via source |
700
|
|
|
OC_User::setUserId($this->user1); |
701
|
|
|
$this->assertTrue(OCP\Share::unshareFromSelf('test', 'share.txt', true)); |
702
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
703
|
|
|
|
704
|
|
|
// Remove group |
705
|
|
|
OC_Group::deleteGroup($this->group1); |
706
|
|
|
OC_User::setUserId($this->user4); |
707
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); |
708
|
|
|
OC_User::setUserId($this->user3); |
709
|
|
|
$this->assertEquals(array(), OCP\Share::getItemsShared('test')); |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* Test that unsharing from group will also delete all |
714
|
|
|
* child entries |
715
|
|
|
*/ |
716
|
|
|
public function testShareWithGroupThenUnshare() { |
717
|
|
|
OC_User::setUserId($this->user5); |
718
|
|
|
OCP\Share::shareItem( |
719
|
|
|
'test', |
720
|
|
|
'test.txt', |
721
|
|
|
OCP\Share::SHARE_TYPE_GROUP, |
722
|
|
|
$this->group1, |
723
|
|
|
\OCP\Constants::PERMISSION_ALL |
724
|
|
|
); |
725
|
|
|
|
726
|
|
|
$targetUsers = array($this->user1, $this->user2, $this->user3); |
727
|
|
|
|
728
|
|
View Code Duplication |
foreach($targetUsers as $targetUser) { |
|
|
|
|
729
|
|
|
OC_User::setUserId($targetUser); |
730
|
|
|
$items = OCP\Share::getItemsSharedWithUser( |
731
|
|
|
'test', |
732
|
|
|
$targetUser, |
733
|
|
|
Test_Share_Backend::FORMAT_TARGET |
734
|
|
|
); |
735
|
|
|
$this->assertEquals(1, count($items)); |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
OC_User::setUserId($this->user5); |
739
|
|
|
OCP\Share::unshare( |
740
|
|
|
'test', |
741
|
|
|
'test.txt', |
742
|
|
|
OCP\Share::SHARE_TYPE_GROUP, |
743
|
|
|
$this->group1 |
744
|
|
|
); |
745
|
|
|
|
746
|
|
|
// verify that all were deleted |
747
|
|
View Code Duplication |
foreach($targetUsers as $targetUser) { |
|
|
|
|
748
|
|
|
OC_User::setUserId($targetUser); |
749
|
|
|
$items = OCP\Share::getItemsSharedWithUser( |
750
|
|
|
'test', |
751
|
|
|
$targetUser, |
752
|
|
|
Test_Share_Backend::FORMAT_TARGET |
753
|
|
|
); |
754
|
|
|
$this->assertEquals(0, count($items)); |
755
|
|
|
} |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
public function testShareWithGroupAndUserBothHaveTheSameId() { |
759
|
|
|
|
760
|
|
|
$this->shareUserTestFileWithUser($this->user1, $this->groupAndUser); |
761
|
|
|
|
762
|
|
|
OC_User::setUserId($this->groupAndUser); |
763
|
|
|
|
764
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
765
|
|
|
'"groupAndUser"-User does not see the file but it was shared with him'); |
766
|
|
|
|
767
|
|
|
OC_User::setUserId($this->user2); |
768
|
|
|
$this->assertEquals(array(), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
769
|
|
|
'User2 sees test.txt but it was only shared with the user "groupAndUser" and not with group'); |
770
|
|
|
|
771
|
|
|
OC_User::setUserId($this->user1); |
772
|
|
|
$this->assertTrue(OCP\Share::unshareAll('test', 'test.txt')); |
773
|
|
|
|
774
|
|
|
$this->assertTrue( |
775
|
|
|
OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->groupAndUser, \OCP\Constants::PERMISSION_READ), |
776
|
|
|
'Failed asserting that user 1 successfully shared text.txt with group 1.' |
777
|
|
|
); |
778
|
|
|
|
779
|
|
|
OC_User::setUserId($this->groupAndUser); |
780
|
|
|
$this->assertEquals(array(), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
781
|
|
|
'"groupAndUser"-User sees test.txt but it was only shared with the group "groupAndUser" and not with the user'); |
782
|
|
|
|
783
|
|
|
OC_User::setUserId($this->user2); |
784
|
|
|
$this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), |
785
|
|
|
'User2 does not see test.txt but it was shared with the group "groupAndUser"'); |
786
|
|
|
|
787
|
|
|
OC_User::setUserId($this->user1); |
788
|
|
|
$this->assertTrue(OCP\Share::unshareAll('test', 'test.txt')); |
789
|
|
|
|
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
/** |
793
|
|
|
* @param boolean|string $token |
794
|
|
|
* @return array |
795
|
|
|
*/ |
796
|
|
|
protected function getShareByValidToken($token) { |
797
|
|
|
$row = OCP\Share::getShareByToken($token); |
|
|
|
|
798
|
|
|
$this->assertInternalType( |
799
|
|
|
'array', |
800
|
|
|
$row, |
801
|
|
|
"Failed asserting that a share for token $token exists." |
802
|
|
|
); |
803
|
|
|
return $row; |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
public function testGetItemSharedWithUser() { |
807
|
|
|
OC_User::setUserId($this->user1); |
808
|
|
|
|
809
|
|
|
//add dummy values to the share table |
810
|
|
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (' |
811
|
|
|
.' `item_type`, `item_source`, `item_target`, `share_type`,' |
812
|
|
|
.' `share_with`, `uid_owner`) VALUES (?,?,?,?,?,?)'); |
813
|
|
|
$args = array('test', 99, 'target1', OCP\Share::SHARE_TYPE_USER, $this->user2, $this->user1); |
814
|
|
|
$query->execute($args); |
815
|
|
|
$args = array('test', 99, 'target2', OCP\Share::SHARE_TYPE_USER, $this->user4, $this->user1); |
816
|
|
|
$query->execute($args); |
817
|
|
|
$args = array('test', 99, 'target3', OCP\Share::SHARE_TYPE_USER, $this->user3, $this->user2); |
818
|
|
|
$query->execute($args); |
819
|
|
|
$args = array('test', 99, 'target4', OCP\Share::SHARE_TYPE_USER, $this->user3, $this->user4); |
820
|
|
|
$query->execute($args); |
821
|
|
|
$args = array('test', 99, 'target4', OCP\Share::SHARE_TYPE_USER, $this->user6, $this->user4); |
822
|
|
|
$query->execute($args); |
823
|
|
|
|
824
|
|
|
|
825
|
|
|
$result1 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user2, $this->user1); |
826
|
|
|
$this->assertSame(1, count($result1)); |
827
|
|
|
$this->verifyResult($result1, array('target1')); |
828
|
|
|
|
829
|
|
|
$result2 = \OCP\Share::getItemSharedWithUser('test', 99, null, $this->user1); |
830
|
|
|
$this->assertSame(2, count($result2)); |
831
|
|
|
$this->verifyResult($result2, array('target1', 'target2')); |
832
|
|
|
|
833
|
|
|
$result3 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user3); |
834
|
|
|
$this->assertSame(2, count($result3)); |
835
|
|
|
$this->verifyResult($result3, array('target3', 'target4')); |
836
|
|
|
|
837
|
|
|
$result4 = \OCP\Share::getItemSharedWithUser('test', 99, null, null); |
838
|
|
|
$this->assertSame(5, count($result4)); // 5 because target4 appears twice |
839
|
|
|
$this->verifyResult($result4, array('target1', 'target2', 'target3', 'target4')); |
840
|
|
|
|
841
|
|
|
$result6 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user6, null); |
842
|
|
|
$this->assertSame(1, count($result6)); |
843
|
|
|
$this->verifyResult($result6, array('target4')); |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
public function testGetItemSharedWithUserFromGroupShare() { |
847
|
|
|
OC_User::setUserId($this->user1); |
848
|
|
|
|
849
|
|
|
//add dummy values to the share table |
850
|
|
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (' |
851
|
|
|
.' `item_type`, `item_source`, `item_target`, `share_type`,' |
852
|
|
|
.' `share_with`, `uid_owner`) VALUES (?,?,?,?,?,?)'); |
853
|
|
|
$args = array('test', 99, 'target1', OCP\Share::SHARE_TYPE_GROUP, $this->group1, $this->user1); |
854
|
|
|
$query->execute($args); |
855
|
|
|
$args = array('test', 99, 'target2', OCP\Share::SHARE_TYPE_GROUP, $this->group2, $this->user1); |
856
|
|
|
$query->execute($args); |
857
|
|
|
$args = array('test', 99, 'target3', OCP\Share::SHARE_TYPE_GROUP, $this->group1, $this->user2); |
858
|
|
|
$query->execute($args); |
859
|
|
|
$args = array('test', 99, 'target4', OCP\Share::SHARE_TYPE_GROUP, $this->group1, $this->user4); |
860
|
|
|
$query->execute($args); |
861
|
|
|
|
862
|
|
|
// user2 is in group1 and group2 |
863
|
|
|
$result1 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user2, $this->user1); |
864
|
|
|
$this->assertSame(2, count($result1)); |
865
|
|
|
$this->verifyResult($result1, array('target1', 'target2')); |
866
|
|
|
|
867
|
|
|
$result2 = \OCP\Share::getItemSharedWithUser('test', 99, null, $this->user1); |
868
|
|
|
$this->assertSame(2, count($result2)); |
869
|
|
|
$this->verifyResult($result2, array('target1', 'target2')); |
870
|
|
|
|
871
|
|
|
// user3 is in group1 and group2 |
872
|
|
|
$result3 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user3); |
873
|
|
|
$this->assertSame(3, count($result3)); |
874
|
|
|
$this->verifyResult($result3, array('target1', 'target3', 'target4')); |
875
|
|
|
|
876
|
|
|
$result4 = \OCP\Share::getItemSharedWithUser('test', 99, null, null); |
877
|
|
|
$this->assertSame(4, count($result4)); |
878
|
|
|
$this->verifyResult($result4, array('target1', 'target2', 'target3', 'target4')); |
879
|
|
|
|
880
|
|
|
$result6 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user6, null); |
881
|
|
|
$this->assertSame(0, count($result6)); |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
public function verifyResult($result, $expected) { |
885
|
|
|
foreach ($result as $r) { |
886
|
|
|
if (in_array($r['item_target'], $expected)) { |
887
|
|
|
$key = array_search($r['item_target'], $expected); |
888
|
|
|
unset($expected[$key]); |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
$this->assertEmpty($expected, 'did not found all expected values'); |
892
|
|
|
} |
893
|
|
|
|
894
|
|
|
public function testShareItemWithLink() { |
895
|
|
|
OC_User::setUserId($this->user1); |
896
|
|
|
$token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); |
897
|
|
|
$this->assertInternalType( |
898
|
|
|
'string', |
899
|
|
|
$token, |
900
|
|
|
'Failed asserting that user 1 successfully shared text.txt as link with token.' |
901
|
|
|
); |
902
|
|
|
|
903
|
|
|
// testGetShareByTokenNoExpiration |
904
|
|
|
$row = $this->getShareByValidToken($token); |
905
|
|
|
$this->assertEmpty( |
906
|
|
|
$row['expiration'], |
907
|
|
|
'Failed asserting that the returned row does not have an expiration date.' |
908
|
|
|
); |
909
|
|
|
|
910
|
|
|
// testGetShareByTokenExpirationValid |
911
|
|
|
$this->assertTrue( |
912
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''), |
913
|
|
|
'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.' |
914
|
|
|
); |
915
|
|
|
$row = $this->getShareByValidToken($token); |
916
|
|
|
$this->assertNotEmpty( |
917
|
|
|
$row['expiration'], |
918
|
|
|
'Failed asserting that the returned row has an expiration date.' |
919
|
|
|
); |
920
|
|
|
|
921
|
|
|
// manipulate share table and set expire date to the past |
922
|
|
|
$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); |
923
|
|
|
$query->bindValue(1, new \DateTime($this->dateInPast), 'datetime'); |
924
|
|
|
$query->bindValue(2, 'test'); |
925
|
|
|
$query->bindValue(3, 'test.txt'); |
926
|
|
|
$query->bindValue(4, $this->user1); |
927
|
|
|
$query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK); |
928
|
|
|
$query->execute(); |
929
|
|
|
|
930
|
|
|
$this->assertFalse( |
931
|
|
|
OCP\Share::getShareByToken($token), |
|
|
|
|
932
|
|
|
'Failed asserting that an expired share could not be found.' |
933
|
|
|
); |
934
|
|
|
} |
935
|
|
|
|
936
|
|
|
public function testShareItemWithLinkAndDefaultExpireDate() { |
937
|
|
|
OC_User::setUserId($this->user1); |
938
|
|
|
|
939
|
|
|
\OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes'); |
940
|
|
|
\OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2'); |
941
|
|
|
|
942
|
|
|
$token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); |
943
|
|
|
$this->assertInternalType( |
944
|
|
|
'string', |
945
|
|
|
$token, |
946
|
|
|
'Failed asserting that user 1 successfully shared text.txt as link with token.' |
947
|
|
|
); |
948
|
|
|
|
949
|
|
|
// share should have default expire date |
950
|
|
|
|
951
|
|
|
$row = $this->getShareByValidToken($token); |
952
|
|
|
$this->assertNotEmpty( |
953
|
|
|
$row['expiration'], |
954
|
|
|
'Failed asserting that the returned row has an default expiration date.' |
955
|
|
|
); |
956
|
|
|
|
957
|
|
|
\OC_Appconfig::deleteKey('core', 'shareapi_default_expire_date'); |
958
|
|
|
\OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days'); |
959
|
|
|
|
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
public function testUnshareAll() { |
963
|
|
|
$this->shareUserTestFileWithUser($this->user1, $this->user2); |
964
|
|
|
$this->shareUserTestFileWithUser($this->user2, $this->user3); |
965
|
|
|
$this->shareUserTestFileWithUser($this->user3, $this->user4); |
966
|
|
|
$this->shareUserOneTestFileWithGroupOne(); |
967
|
|
|
|
968
|
|
|
OC_User::setUserId($this->user1); |
969
|
|
|
$this->assertEquals( |
970
|
|
|
array('test.txt', 'test.txt'), |
971
|
|
|
OCP\Share::getItemsShared('test', Test_Share_Backend::FORMAT_SOURCE), |
972
|
|
|
'Failed asserting that the test.txt file is shared exactly two times by user1.' |
973
|
|
|
); |
974
|
|
|
|
975
|
|
|
OC_User::setUserId($this->user2); |
976
|
|
|
$this->assertEquals( |
977
|
|
|
array('test.txt'), |
978
|
|
|
OCP\Share::getItemsShared('test', Test_Share_Backend::FORMAT_SOURCE), |
979
|
|
|
'Failed asserting that the test.txt file is shared exactly once by user2.' |
980
|
|
|
); |
981
|
|
|
|
982
|
|
|
OC_User::setUserId($this->user3); |
983
|
|
|
$this->assertEquals( |
984
|
|
|
array('test.txt'), |
985
|
|
|
OCP\Share::getItemsShared('test', Test_Share_Backend::FORMAT_SOURCE), |
986
|
|
|
'Failed asserting that the test.txt file is shared exactly once by user3.' |
987
|
|
|
); |
988
|
|
|
|
989
|
|
|
$this->assertTrue( |
990
|
|
|
OCP\Share::unshareAll('test', 'test.txt'), |
991
|
|
|
'Failed asserting that user 3 successfully unshared all shares of the test.txt share.' |
992
|
|
|
); |
993
|
|
|
|
994
|
|
|
$this->assertEquals( |
995
|
|
|
array(), |
996
|
|
|
OCP\Share::getItemsShared('test'), |
997
|
|
|
'Failed asserting that the share of the test.txt file by user 3 has been removed.' |
998
|
|
|
); |
999
|
|
|
|
1000
|
|
|
OC_User::setUserId($this->user1); |
1001
|
|
|
$this->assertEquals( |
1002
|
|
|
array(), |
1003
|
|
|
OCP\Share::getItemsShared('test'), |
1004
|
|
|
'Failed asserting that both shares of the test.txt file by user 1 have been removed.' |
1005
|
|
|
); |
1006
|
|
|
|
1007
|
|
|
OC_User::setUserId($this->user2); |
1008
|
|
|
$this->assertEquals( |
1009
|
|
|
array(), |
1010
|
|
|
OCP\Share::getItemsShared('test'), |
1011
|
|
|
'Failed asserting that the share of the test.txt file by user 2 has been removed.' |
1012
|
|
|
); |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
|
|
/** |
1016
|
|
|
* @dataProvider checkPasswordProtectedShareDataProvider |
1017
|
|
|
* @param $expected |
1018
|
|
|
* @param $item |
1019
|
|
|
*/ |
1020
|
|
|
public function testCheckPasswordProtectedShare($expected, $item) { |
1021
|
|
|
\OC::$server->getSession()->set('public_link_authenticated', 100); |
1022
|
|
|
$result = \OCP\Share::checkPasswordProtectedShare($item); |
1023
|
|
|
$this->assertEquals($expected, $result); |
1024
|
|
|
} |
1025
|
|
|
|
1026
|
|
|
function checkPasswordProtectedShareDataProvider() { |
1027
|
|
|
return array( |
1028
|
|
|
array(true, array()), |
1029
|
|
|
array(true, array('share_with' => null)), |
1030
|
|
|
array(true, array('share_with' => '')), |
1031
|
|
|
array(true, array('share_with' => '1234567890', 'share_type' => '1')), |
1032
|
|
|
array(true, array('share_with' => '1234567890', 'share_type' => 1)), |
1033
|
|
|
array(true, array('share_with' => '1234567890', 'share_type' => '3', 'id' => 100)), |
1034
|
|
|
array(true, array('share_with' => '1234567890', 'share_type' => 3, 'id' => 100)), |
1035
|
|
|
array(false, array('share_with' => '1234567890', 'share_type' => '3', 'id' => 101)), |
1036
|
|
|
array(false, array('share_with' => '1234567890', 'share_type' => 3, 'id' => 101)), |
1037
|
|
|
); |
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
/** |
1041
|
|
|
* @dataProvider urls |
1042
|
|
|
*/ |
1043
|
|
|
function testRemoveProtocolFromUrl($url, $expectedResult) { |
1044
|
|
|
$share = new \OC\Share\Share(); |
1045
|
|
|
$result = \Test_Helper::invokePrivate($share, 'removeProtocolFromUrl', array($url)); |
1046
|
|
|
$this->assertSame($expectedResult, $result); |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
|
|
function urls() { |
1050
|
|
|
return array( |
1051
|
|
|
array('http://owncloud.org', 'owncloud.org'), |
1052
|
|
|
array('https://owncloud.org', 'owncloud.org'), |
1053
|
|
|
array('owncloud.org', 'owncloud.org'), |
1054
|
|
|
); |
1055
|
|
|
} |
1056
|
|
|
|
1057
|
|
|
public function dataRemoteShareUrlCalls() { |
1058
|
|
|
return [ |
1059
|
|
|
['admin@localhost', 'localhost'], |
1060
|
|
|
['admin@https://localhost', 'localhost'], |
1061
|
|
|
['admin@http://localhost', 'localhost'], |
1062
|
|
|
['admin@localhost/subFolder', 'localhost/subFolder'], |
1063
|
|
|
]; |
1064
|
|
|
} |
1065
|
|
|
|
1066
|
|
|
/** |
1067
|
|
|
* @dataProvider dataRemoteShareUrlCalls |
1068
|
|
|
* |
1069
|
|
|
* @param string $shareWith |
1070
|
|
|
* @param string $urlHost |
1071
|
|
|
*/ |
1072
|
|
|
public function testRemoteShareUrlCalls($shareWith, $urlHost) { |
1073
|
|
|
$oldHttpHelper = \OC::$server->query('HTTPHelper'); |
1074
|
|
|
$httpHelperMock = $this->getMockBuilder('OC\HttpHelper') |
1075
|
|
|
->disableOriginalConstructor() |
1076
|
|
|
->getMock(); |
1077
|
|
|
$this->setHttpHelper($httpHelperMock); |
1078
|
|
|
|
1079
|
|
|
$httpHelperMock->expects($this->at(0)) |
1080
|
|
|
->method('post') |
1081
|
|
|
->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything()) |
1082
|
|
|
->willReturn(['success' => false, 'result' => 'Exception']); |
1083
|
|
|
$httpHelperMock->expects($this->at(1)) |
1084
|
|
|
->method('post') |
1085
|
|
|
->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything()) |
1086
|
|
|
->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); |
1087
|
|
|
|
1088
|
|
|
\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith, \OCP\Constants::PERMISSION_READ); |
1089
|
|
|
$shares = \OCP\Share::getItemShared('test', 'test.txt'); |
1090
|
|
|
$share = array_shift($shares); |
1091
|
|
|
|
1092
|
|
|
$httpHelperMock->expects($this->at(0)) |
1093
|
|
|
->method('post') |
1094
|
|
|
->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) |
1095
|
|
|
->willReturn(['success' => false, 'result' => 'Exception']); |
1096
|
|
|
$httpHelperMock->expects($this->at(1)) |
1097
|
|
|
->method('post') |
1098
|
|
|
->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) |
1099
|
|
|
->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); |
1100
|
|
|
|
1101
|
|
|
\OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith); |
1102
|
|
|
$this->setHttpHelper($oldHttpHelper); |
1103
|
|
|
} |
1104
|
|
|
|
1105
|
|
|
/** |
1106
|
|
|
* @dataProvider dataProviderTestGroupItems |
1107
|
|
|
* @param array $ungrouped |
1108
|
|
|
* @param array $grouped |
1109
|
|
|
*/ |
1110
|
|
|
function testGroupItems($ungrouped, $grouped) { |
1111
|
|
|
|
1112
|
|
|
$result = DummyShareClass::groupItemsTest($ungrouped); |
1113
|
|
|
|
1114
|
|
|
$this->compareArrays($grouped, $result); |
1115
|
|
|
|
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
function compareArrays($result, $expectedResult) { |
1119
|
|
|
foreach ($expectedResult as $key => $value) { |
1120
|
|
|
if (is_array($value)) { |
1121
|
|
|
$this->compareArrays($result[$key], $value); |
1122
|
|
|
} else { |
1123
|
|
|
$this->assertSame($value, $result[$key]); |
1124
|
|
|
} |
1125
|
|
|
} |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
|
function dataProviderTestGroupItems() { |
1129
|
|
|
return array( |
1130
|
|
|
// one array with one share |
1131
|
|
|
array( |
1132
|
|
|
array( // input |
1133
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_ALL, 'item_target' => 't1')), |
1134
|
|
|
array( // expected result |
1135
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_ALL, 'item_target' => 't1'))), |
1136
|
|
|
// two shares both point to the same source |
1137
|
|
|
array( |
1138
|
|
|
array( // input |
1139
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ, 'item_target' => 't1'), |
1140
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't1'), |
1141
|
|
|
), |
1142
|
|
|
array( // expected result |
1143
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't1', |
1144
|
|
|
'grouped' => array( |
1145
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ, 'item_target' => 't1'), |
1146
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't1'), |
1147
|
|
|
) |
1148
|
|
|
), |
1149
|
|
|
) |
1150
|
|
|
), |
1151
|
|
|
// two shares both point to the same source but with different targets |
1152
|
|
|
array( |
1153
|
|
|
array( // input |
1154
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ, 'item_target' => 't1'), |
1155
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't2'), |
1156
|
|
|
), |
1157
|
|
|
array( // expected result |
1158
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ, 'item_target' => 't1'), |
1159
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't2'), |
1160
|
|
|
) |
1161
|
|
|
), |
1162
|
|
|
// three shares two point to the same source |
1163
|
|
|
array( |
1164
|
|
|
array( // input |
1165
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ, 'item_target' => 't1'), |
1166
|
|
|
array('item_source' => 2, 'permissions' => \OCP\Constants::PERMISSION_CREATE, 'item_target' => 't2'), |
1167
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't1'), |
1168
|
|
|
), |
1169
|
|
|
array( // expected result |
1170
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't1', |
1171
|
|
|
'grouped' => array( |
1172
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_READ, 'item_target' => 't1'), |
1173
|
|
|
array('item_source' => 1, 'permissions' => \OCP\Constants::PERMISSION_UPDATE, 'item_target' => 't1'), |
1174
|
|
|
) |
1175
|
|
|
), |
1176
|
|
|
array('item_source' => 2, 'permissions' => \OCP\Constants::PERMISSION_CREATE, 'item_target' => 't2'), |
1177
|
|
|
) |
1178
|
|
|
), |
1179
|
|
|
); |
1180
|
|
|
} |
1181
|
|
|
|
1182
|
|
|
/** |
1183
|
|
|
* Ensure that we do not allow removing a an expiration date from a link share if this |
1184
|
|
|
* is enforced by the settings. |
1185
|
|
|
*/ |
1186
|
|
|
public function testClearExpireDateWhileEnforced() { |
1187
|
|
|
OC_User::setUserId($this->user1); |
1188
|
|
|
|
1189
|
|
|
\OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes'); |
1190
|
|
|
\OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2'); |
1191
|
|
|
\OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes'); |
1192
|
|
|
|
1193
|
|
|
$token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); |
1194
|
|
|
$this->assertInternalType( |
1195
|
|
|
'string', |
1196
|
|
|
$token, |
1197
|
|
|
'Failed asserting that user 1 successfully shared text.txt as link with token.' |
1198
|
|
|
); |
1199
|
|
|
|
1200
|
|
|
$setExpireDateFailed = false; |
1201
|
|
|
try { |
1202
|
|
|
$this->assertTrue( |
1203
|
|
|
OCP\Share::setExpirationDate('test', 'test.txt', '', ''), |
1204
|
|
|
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' |
1205
|
|
|
); |
1206
|
|
|
} catch (\Exception $e) { |
1207
|
|
|
$setExpireDateFailed = true; |
1208
|
|
|
} |
1209
|
|
|
|
1210
|
|
|
$this->assertTrue($setExpireDateFailed); |
1211
|
|
|
|
1212
|
|
|
\OC_Appconfig::deleteKey('core', 'shareapi_default_expire_date'); |
1213
|
|
|
\OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days'); |
1214
|
|
|
\OC_Appconfig::deleteKey('core', 'shareapi_enforce_expire_date'); |
1215
|
|
|
} |
1216
|
|
|
|
1217
|
|
|
/** |
1218
|
|
|
* Cannot set password is there is no user |
1219
|
|
|
* |
1220
|
|
|
* @expectedException Exception |
1221
|
|
|
* @expectedExceptionMessage User not logged in |
1222
|
|
|
*/ |
1223
|
|
|
public function testSetPasswordNoUser() { |
1224
|
|
|
$userSession = $this->getMockBuilder('\OCP\IUserSession') |
1225
|
|
|
->disableOriginalConstructor() |
1226
|
|
|
->getMock(); |
1227
|
|
|
|
1228
|
|
|
$connection = $this->getMockBuilder('\OC\DB\Connection') |
1229
|
|
|
->disableOriginalConstructor() |
1230
|
|
|
->getMock(); |
1231
|
|
|
|
1232
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig') |
1233
|
|
|
->disableOriginalConstructor() |
1234
|
|
|
->getMock(); |
1235
|
|
|
|
1236
|
|
|
\OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); |
1237
|
|
|
} |
1238
|
|
|
|
1239
|
|
|
public function testPasswords() { |
1240
|
|
|
$pass = 'secret'; |
1241
|
|
|
|
1242
|
|
|
$this->shareUserTestFileAsLink(); |
1243
|
|
|
|
1244
|
|
|
$userSession = \OC::$server->getUserSession(); |
1245
|
|
|
$connection = \OC::$server->getDatabaseConnection(); |
1246
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig') |
1247
|
|
|
->disableOriginalConstructor() |
1248
|
|
|
->getMock(); |
1249
|
|
|
|
1250
|
|
|
// Find the share ID in the db |
1251
|
|
|
$qb = $connection->createQueryBuilder(); |
1252
|
|
|
$qb->select('`id`') |
1253
|
|
|
->from('`*PREFIX*share`') |
1254
|
|
|
->where('`item_type` = :type') |
1255
|
|
|
->andWhere('`item_source` = :source') |
1256
|
|
|
->andWhere('`uid_owner` = :owner') |
1257
|
|
|
->andWhere('`share_type` = :share_type') |
1258
|
|
|
->setParameter('type', 'test') |
1259
|
|
|
->setParameter('source', 'test.txt') |
1260
|
|
|
->setParameter('owner', $this->user1) |
1261
|
|
|
->setParameter('share_type', \OCP\Share::SHARE_TYPE_LINK); |
1262
|
|
|
|
1263
|
|
|
$res = $qb->execute()->fetchAll(); |
1264
|
|
|
$this->assertCount(1, $res); |
1265
|
|
|
$id = $res[0]['id']; |
1266
|
|
|
|
1267
|
|
|
// Set password on share |
1268
|
|
|
$res = \OC\Share\Share::setPassword($userSession, $connection, $config, $id, $pass); |
|
|
|
|
1269
|
|
|
$this->assertTrue($res); |
1270
|
|
|
|
1271
|
|
|
// Fetch the hash from the database |
1272
|
|
|
$qb = $connection->createQueryBuilder(); |
1273
|
|
|
$qb->select('`share_with`') |
1274
|
|
|
->from('`*PREFIX*share`') |
1275
|
|
|
->where('`id` = :id') |
1276
|
|
|
->setParameter('id', $id); |
1277
|
|
|
$hash = $qb->execute()->fetch()['share_with']; |
1278
|
|
|
|
1279
|
|
|
$hasher = \OC::$server->getHasher(); |
1280
|
|
|
|
1281
|
|
|
// Verify hash |
1282
|
|
|
$this->assertTrue($hasher->verify($pass, $hash)); |
1283
|
|
|
} |
1284
|
|
|
|
1285
|
|
|
/** |
1286
|
|
|
* Test setting a password when everything is fine |
1287
|
|
|
*/ |
1288
|
|
|
public function testSetPassword() { |
1289
|
|
|
$user = $this->getMockBuilder('\OCP\IUser') |
1290
|
|
|
->disableOriginalConstructor() |
1291
|
|
|
->getMock(); |
1292
|
|
|
$user->method('getUID')->willReturn('user'); |
1293
|
|
|
|
1294
|
|
|
$userSession = $this->getMockBuilder('\OCP\IUserSession') |
1295
|
|
|
->disableOriginalConstructor() |
1296
|
|
|
->getMock(); |
1297
|
|
|
$userSession->method('getUser')->willReturn($user); |
1298
|
|
|
|
1299
|
|
|
|
1300
|
|
|
$ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') |
1301
|
|
|
->disableOriginalConstructor() |
1302
|
|
|
->getMock(); |
1303
|
|
|
$qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder') |
1304
|
|
|
->disableOriginalConstructor() |
1305
|
|
|
->getMock(); |
1306
|
|
|
$qb->method('update')->will($this->returnSelf()); |
1307
|
|
|
$qb->method('set')->will($this->returnSelf()); |
1308
|
|
|
$qb->method('where')->will($this->returnSelf()); |
1309
|
|
|
$qb->method('andWhere')->will($this->returnSelf()); |
1310
|
|
|
$qb->method('select')->will($this->returnSelf()); |
1311
|
|
|
$qb->method('from')->will($this->returnSelf()); |
1312
|
|
|
$qb->method('setParameter')->will($this->returnSelf()); |
1313
|
|
|
$qb->method('expr')->willReturn($ex); |
1314
|
|
|
|
1315
|
|
|
$ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') |
1316
|
|
|
->disableOriginalConstructor() |
1317
|
|
|
->getMock(); |
1318
|
|
|
$ret->method('fetch')->willReturn(['uid_owner' => 'user']); |
1319
|
|
|
$qb->method('execute')->willReturn($ret); |
1320
|
|
|
|
1321
|
|
|
|
1322
|
|
|
$connection = $this->getMockBuilder('\OC\DB\Connection') |
1323
|
|
|
->disableOriginalConstructor() |
1324
|
|
|
->getMock(); |
1325
|
|
|
$connection->method('createQueryBuilder')->willReturn($qb); |
1326
|
|
|
|
1327
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig') |
1328
|
|
|
->disableOriginalConstructor() |
1329
|
|
|
->getMock(); |
1330
|
|
|
|
1331
|
|
|
|
1332
|
|
|
$res = \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); |
1333
|
|
|
|
1334
|
|
|
$this->assertTrue($res); |
1335
|
|
|
} |
1336
|
|
|
|
1337
|
|
|
/** |
1338
|
|
|
* @expectedException Exception |
1339
|
|
|
* @expectedExceptionMessage Cannot remove password |
1340
|
|
|
* |
1341
|
|
|
* Test removing a password when password is enforced |
1342
|
|
|
*/ |
1343
|
|
|
public function testSetPasswordRemove() { |
1344
|
|
|
$user = $this->getMockBuilder('\OCP\IUser') |
1345
|
|
|
->disableOriginalConstructor() |
1346
|
|
|
->getMock(); |
1347
|
|
|
$user->method('getUID')->willReturn('user'); |
1348
|
|
|
|
1349
|
|
|
$userSession = $this->getMockBuilder('\OCP\IUserSession') |
1350
|
|
|
->disableOriginalConstructor() |
1351
|
|
|
->getMock(); |
1352
|
|
|
$userSession->method('getUser')->willReturn($user); |
1353
|
|
|
|
1354
|
|
|
|
1355
|
|
|
$ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') |
1356
|
|
|
->disableOriginalConstructor() |
1357
|
|
|
->getMock(); |
1358
|
|
|
$qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder') |
1359
|
|
|
->disableOriginalConstructor() |
1360
|
|
|
->getMock(); |
1361
|
|
|
$qb->method('update')->will($this->returnSelf()); |
1362
|
|
|
$qb->method('select')->will($this->returnSelf()); |
1363
|
|
|
$qb->method('from')->will($this->returnSelf()); |
1364
|
|
|
$qb->method('set')->will($this->returnSelf()); |
1365
|
|
|
$qb->method('where')->will($this->returnSelf()); |
1366
|
|
|
$qb->method('andWhere')->will($this->returnSelf()); |
1367
|
|
|
$qb->method('setParameter')->will($this->returnSelf()); |
1368
|
|
|
$qb->method('expr')->willReturn($ex); |
1369
|
|
|
|
1370
|
|
|
$ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') |
1371
|
|
|
->disableOriginalConstructor() |
1372
|
|
|
->getMock(); |
1373
|
|
|
$ret->method('fetch')->willReturn(['uid_owner' => 'user']); |
1374
|
|
|
$qb->method('execute')->willReturn($ret); |
1375
|
|
|
|
1376
|
|
|
|
1377
|
|
|
$connection = $this->getMockBuilder('\OC\DB\Connection') |
1378
|
|
|
->disableOriginalConstructor() |
1379
|
|
|
->getMock(); |
1380
|
|
|
$connection->method('createQueryBuilder')->willReturn($qb); |
1381
|
|
|
|
1382
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig') |
1383
|
|
|
->disableOriginalConstructor() |
1384
|
|
|
->getMock(); |
1385
|
|
|
$config->method('getAppValue')->willReturn('yes'); |
1386
|
|
|
|
1387
|
|
|
\OC\Share\Share::setPassword($userSession, $connection, $config, 1, ''); |
1388
|
|
|
} |
1389
|
|
|
|
1390
|
|
|
/** |
1391
|
|
|
* @expectedException Exception |
1392
|
|
|
* @expectedExceptionMessage Share not found |
1393
|
|
|
* |
1394
|
|
|
* Test modification of invaid share |
1395
|
|
|
*/ |
1396
|
|
View Code Duplication |
public function testSetPasswordInvalidShare() { |
1397
|
|
|
$user = $this->getMockBuilder('\OCP\IUser') |
1398
|
|
|
->disableOriginalConstructor() |
1399
|
|
|
->getMock(); |
1400
|
|
|
$user->method('getUID')->willReturn('user'); |
1401
|
|
|
|
1402
|
|
|
$userSession = $this->getMockBuilder('\OCP\IUserSession') |
1403
|
|
|
->disableOriginalConstructor() |
1404
|
|
|
->getMock(); |
1405
|
|
|
$userSession->method('getUser')->willReturn($user); |
1406
|
|
|
|
1407
|
|
|
|
1408
|
|
|
$ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') |
1409
|
|
|
->disableOriginalConstructor() |
1410
|
|
|
->getMock(); |
1411
|
|
|
$qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder') |
1412
|
|
|
->disableOriginalConstructor() |
1413
|
|
|
->getMock(); |
1414
|
|
|
$qb->method('update')->will($this->returnSelf()); |
1415
|
|
|
$qb->method('set')->will($this->returnSelf()); |
1416
|
|
|
$qb->method('where')->will($this->returnSelf()); |
1417
|
|
|
$qb->method('andWhere')->will($this->returnSelf()); |
1418
|
|
|
$qb->method('select')->will($this->returnSelf()); |
1419
|
|
|
$qb->method('from')->will($this->returnSelf()); |
1420
|
|
|
$qb->method('setParameter')->will($this->returnSelf()); |
1421
|
|
|
$qb->method('expr')->willReturn($ex); |
1422
|
|
|
|
1423
|
|
|
$ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') |
1424
|
|
|
->disableOriginalConstructor() |
1425
|
|
|
->getMock(); |
1426
|
|
|
$ret->method('fetch')->willReturn([]); |
1427
|
|
|
$qb->method('execute')->willReturn($ret); |
1428
|
|
|
|
1429
|
|
|
|
1430
|
|
|
$connection = $this->getMockBuilder('\OC\DB\Connection') |
1431
|
|
|
->disableOriginalConstructor() |
1432
|
|
|
->getMock(); |
1433
|
|
|
$connection->method('createQueryBuilder')->willReturn($qb); |
1434
|
|
|
|
1435
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig') |
1436
|
|
|
->disableOriginalConstructor() |
1437
|
|
|
->getMock(); |
1438
|
|
|
|
1439
|
|
|
|
1440
|
|
|
\OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); |
1441
|
|
|
} |
1442
|
|
|
|
1443
|
|
|
/** |
1444
|
|
|
* @expectedException Exception |
1445
|
|
|
* @expectedExceptionMessage Cannot update share of a different user |
1446
|
|
|
* |
1447
|
|
|
* Test modification of share of another user |
1448
|
|
|
*/ |
1449
|
|
View Code Duplication |
public function testSetPasswordShareOtherUser() { |
1450
|
|
|
$user = $this->getMockBuilder('\OCP\IUser') |
1451
|
|
|
->disableOriginalConstructor() |
1452
|
|
|
->getMock(); |
1453
|
|
|
$user->method('getUID')->willReturn('user'); |
1454
|
|
|
|
1455
|
|
|
$userSession = $this->getMockBuilder('\OCP\IUserSession') |
1456
|
|
|
->disableOriginalConstructor() |
1457
|
|
|
->getMock(); |
1458
|
|
|
$userSession->method('getUser')->willReturn($user); |
1459
|
|
|
|
1460
|
|
|
|
1461
|
|
|
$ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') |
1462
|
|
|
->disableOriginalConstructor() |
1463
|
|
|
->getMock(); |
1464
|
|
|
$qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder') |
1465
|
|
|
->disableOriginalConstructor() |
1466
|
|
|
->getMock(); |
1467
|
|
|
$qb->method('update')->will($this->returnSelf()); |
1468
|
|
|
$qb->method('set')->will($this->returnSelf()); |
1469
|
|
|
$qb->method('where')->will($this->returnSelf()); |
1470
|
|
|
$qb->method('andWhere')->will($this->returnSelf()); |
1471
|
|
|
$qb->method('select')->will($this->returnSelf()); |
1472
|
|
|
$qb->method('from')->will($this->returnSelf()); |
1473
|
|
|
$qb->method('setParameter')->will($this->returnSelf()); |
1474
|
|
|
$qb->method('expr')->willReturn($ex); |
1475
|
|
|
|
1476
|
|
|
$ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') |
1477
|
|
|
->disableOriginalConstructor() |
1478
|
|
|
->getMock(); |
1479
|
|
|
$ret->method('fetch')->willReturn(['uid_owner' => 'user2']); |
1480
|
|
|
$qb->method('execute')->willReturn($ret); |
1481
|
|
|
|
1482
|
|
|
|
1483
|
|
|
$connection = $this->getMockBuilder('\OC\DB\Connection') |
1484
|
|
|
->disableOriginalConstructor() |
1485
|
|
|
->getMock(); |
1486
|
|
|
$connection->method('createQueryBuilder')->willReturn($qb); |
1487
|
|
|
|
1488
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig') |
1489
|
|
|
->disableOriginalConstructor() |
1490
|
|
|
->getMock(); |
1491
|
|
|
|
1492
|
|
|
|
1493
|
|
|
\OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); |
1494
|
|
|
} |
1495
|
|
|
|
1496
|
|
|
} |
1497
|
|
|
|
1498
|
|
|
class DummyShareClass extends \OC\Share\Share { |
1499
|
|
|
public static function groupItemsTest($items) { |
1500
|
|
|
return parent::groupItems($items, 'test'); |
|
|
|
|
1501
|
|
|
} |
1502
|
|
|
} |
1503
|
|
|
|
1504
|
|
|
class DummyHookListener { |
1505
|
|
|
static $shareType = null; |
1506
|
|
|
|
1507
|
|
|
public static function listen($params) { |
1508
|
|
|
self::$shareType = $params['shareType']; |
1509
|
|
|
} |
1510
|
|
|
} |
1511
|
|
|
|
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.