1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Vincent Petry <vincent@nextcloud.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_Sharing\Tests;
use OC\KnownUser\KnownUserService;
use OC\Share20\Manager;
use OC\Share20\ShareDisableChecker;
use OCA\Files_Sharing\Capabilities;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share\IProviderFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Class CapabilitiesTest
*
* @group DB
*/
class CapabilitiesTest extends \Test\TestCase {
/**
* Test for the general part in each return statement and assert.
* Strip of the general part on the way.
*
* @param string[] $data Capabilities
* @return string[]
*/
private function getFilesSharingPart(array $data) {
$this->assertArrayHasKey('files_sharing', $data);
return $data['files_sharing'];
}
/**
* Create a mock config object and insert the values in $map to the getAppValue
* function. Then obtain the capabilities and extract the first few
* levels in the array
*
* @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
* @return string[]
*/
private function getResults(array $map) {
$config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock();
$config->method('getAppValue')->willReturnMap($map);
$shareManager = new Manager(
$this->createMock(LoggerInterface::class),
$config,
$this->createMock(ISecureRandom::class),
$this->createMock(IHasher::class),
$this->createMock(IMountManager::class),
$this->createMock(IGroupManager::class),
$this->createMock(IL10N::class),
$this->createMock(IFactory::class),
$this->createMock(IProviderFactory::class),
$this->createMock(IUserManager::class),
$this->createMock(IRootFolder::class),
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IMailer::class),
$this->createMock(IURLGenerator::class),
$this->createMock(\OC_Defaults::class),
$this->createMock(IEventDispatcher::class),
$this->createMock(IUserSession::class),
$this->createMock(KnownUserService::class),
$this->createMock(ShareDisableChecker::class)
);
$cap = new Capabilities($config, $shareManager);
$result = $this->getFilesSharingPart($cap->getCapabilities());
return $result;
}
public function testEnabledSharingAPI() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
];
$result = $this->getResults($map);
$this->assertTrue($result['api_enabled']);
$this->assertArrayHasKey('public', $result);
$this->assertArrayHasKey('user', $result);
$this->assertArrayHasKey('resharing', $result);
}
public function testDisabledSharingAPI() {
$map = [
['core', 'shareapi_enabled', 'yes', 'no'],
];
$result = $this->getResults($map);
$this->assertFalse($result['api_enabled']);
$this->assertFalse($result['public']['enabled']);
$this->assertFalse($result['user']['send_mail']);
$this->assertFalse($result['resharing']);
}
public function testNoLinkSharing() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'no'],
];
$result = $this->getResults($map);
$this->assertIsArray($result['public']);
$this->assertFalse($result['public']['enabled']);
}
public function testOnlyLinkSharing() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertIsArray($result['public']);
$this->assertTrue($result['public']['enabled']);
}
public function testLinkPassword() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
['core', 'shareapi_enforce_links_password', 'no', 'yes'],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('password', $result['public']);
$this->assertArrayHasKey('enforced', $result['public']['password']);
$this->assertTrue($result['public']['password']['enforced']);
}
public function testLinkNoPassword() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
['core', 'shareapi_enforce_links_password', 'no', 'no'],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('password', $result['public']);
$this->assertArrayHasKey('enforced', $result['public']['password']);
$this->assertFalse($result['public']['password']['enforced']);
}
public function testLinkNoExpireDate() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_default_expire_date', 'no', 'no'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('expire_date', $result['public']);
$this->assertIsArray($result['public']['expire_date']);
$this->assertFalse($result['public']['expire_date']['enabled']);
}
public function testLinkExpireDate() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('expire_date', $result['public']);
$this->assertIsArray($result['public']['expire_date']);
$this->assertTrue($result['public']['expire_date']['enabled']);
$this->assertArrayHasKey('days', $result['public']['expire_date']);
$this->assertFalse($result['public']['expire_date']['enforced']);
}
public function testLinkExpireDateEnforced() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('expire_date', $result['public']);
$this->assertIsArray($result['public']['expire_date']);
$this->assertTrue($result['public']['expire_date']['enforced']);
}
public function testLinkSendMail() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_allow_public_notification', 'no', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertTrue($result['public']['send_mail']);
}
public function testLinkNoSendMail() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_allow_public_notification', 'no', 'no'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertFalse($result['public']['send_mail']);
}
public function testResharing() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_resharing', 'yes', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertTrue($result['resharing']);
}
public function testNoResharing() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_resharing', 'yes', 'no'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertFalse($result['resharing']);
}
public function testLinkPublicUpload() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertTrue($result['public']['upload']);
$this->assertTrue($result['public']['upload_files_drop']);
}
public function testLinkNoPublicUpload() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_allow_public_upload', 'yes', 'no'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
];
$result = $this->getResults($map);
$this->assertFalse($result['public']['upload']);
$this->assertFalse($result['public']['upload_files_drop']);
}
public function testNoGroupSharing() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_group_sharing', 'yes', 'no'],
];
$result = $this->getResults($map);
$this->assertFalse($result['group_sharing']);
}
public function testGroupSharing() {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
];
$result = $this->getResults($map);
$this->assertTrue($result['group_sharing']);
}
public function testFederatedSharingIncoming() {
$map = [
['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'yes'],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('federation', $result);
$this->assertTrue($result['federation']['incoming']);
}
public function testFederatedSharingNoIncoming() {
$map = [
['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'no'],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('federation', $result);
$this->assertFalse($result['federation']['incoming']);
}
public function testFederatedSharingOutgoing() {
$map = [
['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'yes'],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('federation', $result);
$this->assertTrue($result['federation']['outgoing']);
}
public function testFederatedSharingNoOutgoing() {
$map = [
['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'no'],
];
$result = $this->getResults($map);
$this->assertArrayHasKey('federation', $result);
$this->assertFalse($result['federation']['outgoing']);
}
public function testFederatedSharingExpirationDate() {
$result = $this->getResults([]);
$this->assertArrayHasKey('federation', $result);
$this->assertEquals(['enabled' => true], $result['federation']['expire_date']);
$this->assertEquals(['enabled' => true], $result['federation']['expire_date_supported']);
}
}
|