|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* sysPass |
|
4
|
|
|
* |
|
5
|
|
|
* @author nuxsmin |
|
6
|
|
|
* @link https://syspass.org |
|
7
|
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of sysPass. |
|
10
|
|
|
* |
|
11
|
|
|
* sysPass is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* sysPass is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace SP\Tests\SP\Core\Acl; |
|
26
|
|
|
|
|
27
|
|
|
use PHPUnit\Framework\TestCase; |
|
28
|
|
|
use SP\Core\Acl\Acl; |
|
29
|
|
|
use SP\Core\Acl\ActionsInterface; |
|
30
|
|
|
use SP\Core\Context\ContextInterface; |
|
31
|
|
|
use SP\DataModel\ProfileData; |
|
32
|
|
|
use SP\Services\User\UserLoginResponse; |
|
33
|
|
|
use function SP\Tests\setupContext; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class AclTest |
|
37
|
|
|
* |
|
38
|
|
|
* @package SP\Tests\SP\Core\Acl |
|
39
|
|
|
*/ |
|
40
|
|
|
class AclTest extends TestCase |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var ContextInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
private $context; |
|
46
|
|
|
/** |
|
47
|
|
|
* @var Acl |
|
48
|
|
|
*/ |
|
49
|
|
|
private $acl; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @dataProvider actionsProvider |
|
53
|
|
|
* |
|
54
|
|
|
* @param $id |
|
55
|
|
|
* @param $expected |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testGetActionRoute($id, $expected) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertEquals($expected, Acl::getActionRoute($id)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* testGetActionRouteUnknown |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testGetActionRouteUnknown() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->assertEmpty(Acl::getActionRoute(10000)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @dataProvider actionsProvider |
|
72
|
|
|
* |
|
73
|
|
|
* @param $id |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testCheckUserAccessAdminApp($id) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->assertTrue($this->acl->checkUserAccess($id)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* testCheckUserAccessAccountView |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testCheckUserAccessAccountView() |
|
84
|
|
|
{ |
|
85
|
|
|
$userData = new UserLoginResponse(); |
|
86
|
|
|
$userData->setId(2); |
|
87
|
|
|
|
|
88
|
|
|
$userProfile = new ProfileData(); |
|
89
|
|
|
$userProfile->setAccView(true); |
|
90
|
|
|
|
|
91
|
|
|
$this->context->setUserData($userData); |
|
92
|
|
|
$this->context->setUserProfile($userProfile); |
|
93
|
|
|
|
|
94
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_VIEW]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param int[] $actionsId Masked action Id |
|
99
|
|
|
*/ |
|
100
|
|
|
private function checkUserAccess(array $actionsId) |
|
101
|
|
|
{ |
|
102
|
|
|
$actionsMask = array_merge([ |
|
103
|
|
|
ActionsInterface::ACCOUNT_REQUEST, |
|
104
|
|
|
ActionsInterface::NOTIFICATION, |
|
105
|
|
|
ActionsInterface::NOTIFICATION_VIEW, |
|
106
|
|
|
ActionsInterface::NOTIFICATION_SEARCH, |
|
107
|
|
|
ActionsInterface::NOTIFICATION_CHECK, |
|
108
|
|
|
], $actionsId); |
|
109
|
|
|
|
|
110
|
|
|
$actionsFalse = array_filter($this->actionsProvider(), function ($action) use ($actionsMask) { |
|
111
|
|
|
return !in_array($action[0], $actionsMask); |
|
112
|
|
|
}); |
|
113
|
|
|
|
|
114
|
|
|
$actionsTrue = array_filter($this->actionsProvider(), function ($action) use ($actionsMask) { |
|
115
|
|
|
return in_array($action[0], $actionsMask); |
|
116
|
|
|
}); |
|
117
|
|
|
|
|
118
|
|
|
foreach ($actionsFalse as $action) { |
|
119
|
|
|
$this->assertFalse($this->acl->checkUserAccess($action[0])); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
foreach ($actionsTrue as $action) { |
|
123
|
|
|
$this->assertTrue($this->acl->checkUserAccess($action[0])); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return array |
|
129
|
|
|
*/ |
|
130
|
|
|
public function actionsProvider() |
|
131
|
|
|
{ |
|
132
|
|
|
return [ |
|
133
|
|
|
[2, 'account/search'], |
|
134
|
|
|
[1, 'account/index'], |
|
135
|
|
|
[20, 'account/listFile'], |
|
136
|
|
|
[12, 'account/requestAccess'], |
|
137
|
|
|
[30, 'favorite/index'], |
|
138
|
|
|
[1201, 'wiki/index'], |
|
139
|
|
|
[5001, 'itemManager/index'], |
|
140
|
|
|
[101, 'category/index'], |
|
141
|
|
|
[301, 'client/index'], |
|
142
|
|
|
[1001, 'authToken/index'], |
|
143
|
|
|
[401, 'customField/index'], |
|
144
|
|
|
[501, 'publicLink/index'], |
|
145
|
|
|
[601, 'file/index'], |
|
146
|
|
|
[1301, 'accountManager/index'], |
|
147
|
|
|
[201, 'tag/index'], |
|
148
|
|
|
[1101, 'plugin/index'], |
|
149
|
|
|
[5002, 'accessManager/index'], |
|
150
|
|
|
[701, 'user/index'], |
|
151
|
|
|
[801, 'group/index'], |
|
152
|
|
|
[901, 'profile/index'], |
|
153
|
|
|
[1701, 'eventlog/index'], |
|
154
|
|
|
[1702, 'eventlog/search'], |
|
155
|
|
|
[1703, 'eventlog/clear'], |
|
156
|
|
|
[3, 'account/view'], |
|
157
|
|
|
[4, 'account/create'], |
|
158
|
|
|
[5, 'account/edit'], |
|
159
|
|
|
[6, 'account/delete'], |
|
160
|
|
|
[7, 'account/viewPass'], |
|
161
|
|
|
[8, 'account/editPass'], |
|
162
|
|
|
[9, 'account/restore'], |
|
163
|
|
|
[10, 'account/copy'], |
|
164
|
|
|
[11, 'account/copyPass'], |
|
165
|
|
|
[21, 'accountFile/view'], |
|
166
|
|
|
[22, 'accountFile/upload'], |
|
167
|
|
|
[23, 'accountFile/download'], |
|
168
|
|
|
[24, 'accountFile/delete'], |
|
169
|
|
|
[25, 'accountFile/search'], |
|
170
|
|
|
[26, 'accountFile/list'], |
|
171
|
|
|
[31, 'favorite/view'], |
|
172
|
|
|
[32, 'accountFavorite/mark'], |
|
173
|
|
|
[33, 'accountFavorite/unmark'], |
|
174
|
|
|
[40, 'account/viewHistory'], |
|
175
|
|
|
[41, 'account/viewPassHistory'], |
|
176
|
|
|
[42, 'account/copyPassHistory'], |
|
177
|
|
|
[1203, 'wiki/view'], |
|
178
|
|
|
[1204, 'wiki/create'], |
|
179
|
|
|
[1205, 'wiki/edit'], |
|
180
|
|
|
[1206, 'wiki/delete'], |
|
181
|
|
|
[103, 'category/view'], |
|
182
|
|
|
[104, 'category/create'], |
|
183
|
|
|
[105, 'category/edit'], |
|
184
|
|
|
[106, 'category/delete'], |
|
185
|
|
|
[102, 'category/search'], |
|
186
|
|
|
[303, 'client/view'], |
|
187
|
|
|
[304, 'client/create'], |
|
188
|
|
|
[305, 'client/edit'], |
|
189
|
|
|
[306, 'client/delete'], |
|
190
|
|
|
[302, 'client/search'], |
|
191
|
|
|
[1004, 'authToken/create'], |
|
192
|
|
|
[1003, 'authToken/view'], |
|
193
|
|
|
[1005, 'authToken/edit'], |
|
194
|
|
|
[1006, 'authToken/delete'], |
|
195
|
|
|
[1002, 'authToken/search'], |
|
196
|
|
|
[404, 'customField/create'], |
|
197
|
|
|
[403, 'customField/view'], |
|
198
|
|
|
[405, 'customField/edit'], |
|
199
|
|
|
[406, 'customField/delete'], |
|
200
|
|
|
[402, 'customField/search'], |
|
201
|
|
|
[504, 'publicLink/create'], |
|
202
|
|
|
[503, 'publicLink/view'], |
|
203
|
|
|
[506, 'publicLink/delete'], |
|
204
|
|
|
[507, 'publicLink/refresh'], |
|
205
|
|
|
[502, 'publicLink/search'], |
|
206
|
|
|
[603, 'file/view'], |
|
207
|
|
|
[605, 'file/download'], |
|
208
|
|
|
[606, 'file/delete'], |
|
209
|
|
|
[604, 'file/upload'], |
|
210
|
|
|
[602, 'file/search'], |
|
211
|
|
|
[1303, 'accountManager/view'], |
|
212
|
|
|
[1304, 'accountManager/delete'], |
|
213
|
|
|
[1302, 'accountManager/search'], |
|
214
|
|
|
[204, 'tag/create'], |
|
215
|
|
|
[203, 'tag/view'], |
|
216
|
|
|
[205, 'tag/edit'], |
|
217
|
|
|
[206, 'tag/delete'], |
|
218
|
|
|
[202, 'tag/search'], |
|
219
|
|
|
[1104, 'plugin/create'], |
|
220
|
|
|
[1103, 'plugin/view'], |
|
221
|
|
|
[1102, 'plugin/search'], |
|
222
|
|
|
[1105, 'plugin/enable'], |
|
223
|
|
|
[1106, 'plugin/disable'], |
|
224
|
|
|
[1107, 'plugin/reset'], |
|
225
|
|
|
[703, 'user/view'], |
|
226
|
|
|
[704, 'user/create'], |
|
227
|
|
|
[705, 'user/edit'], |
|
228
|
|
|
[706, 'user/delete'], |
|
229
|
|
|
[707, 'user/editPass'], |
|
230
|
|
|
[702, 'user/search'], |
|
231
|
|
|
[803, 'userGroup/view'], |
|
232
|
|
|
[804, 'userGroup/create'], |
|
233
|
|
|
[805, 'userGroup/edit'], |
|
234
|
|
|
[806, 'userGroup/delete'], |
|
235
|
|
|
[802, 'userGroup/search'], |
|
236
|
|
|
[903, 'userProfile/view'], |
|
237
|
|
|
[904, 'userProfile/create'], |
|
238
|
|
|
[905, 'userProfile/edit'], |
|
239
|
|
|
[906, 'userProfile/delete'], |
|
240
|
|
|
[902, 'userProfile/search'], |
|
241
|
|
|
[5010, 'userSettingsManager/index'], |
|
242
|
|
|
[5011, 'userSettings/general'], |
|
243
|
|
|
[1401, 'notification/index'], |
|
244
|
|
|
[1501, 'configManager/index'], |
|
245
|
|
|
[1502, 'configManager/general'], |
|
246
|
|
|
[1510, 'account/config'], |
|
247
|
|
|
[1520, 'wiki/config'], |
|
248
|
|
|
[1530, 'encryption/config'], |
|
249
|
|
|
[1531, 'encryption/updateHash'], |
|
250
|
|
|
[1532, 'encryption/createTempPass'], |
|
251
|
|
|
[1540, 'backup/config'], |
|
252
|
|
|
[1541, 'backup/backup'], |
|
253
|
|
|
[1550, 'import/config'], |
|
254
|
|
|
[1551, 'import/csv'], |
|
255
|
|
|
[1552, 'import/xml'], |
|
256
|
|
|
[1560, 'export/config'], |
|
257
|
|
|
[1561, 'export/export'], |
|
258
|
|
|
[1570, 'mail/config'], |
|
259
|
|
|
[1580, 'ldap/config'], |
|
260
|
|
|
[1581, 'ldap/sync'], |
|
261
|
|
|
[1311, 'accountHistoryManager/index'], |
|
262
|
|
|
[1314, 'accountHistoryManager/delete'], |
|
263
|
|
|
[1312, 'accountHistoryManager/search'], |
|
264
|
|
|
[1315, 'accountHistoryManager/restore'], |
|
265
|
|
|
[1403, 'notification/view'], |
|
266
|
|
|
[1404, 'notification/create'], |
|
267
|
|
|
[1405, 'notification/edit'], |
|
268
|
|
|
[1406, 'notification/delete'], |
|
269
|
|
|
[1407, 'notification/check'], |
|
270
|
|
|
[1402, 'notification/search'] |
|
271
|
|
|
]; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* testCheckUserAccessAdminAcc |
|
276
|
|
|
*/ |
|
277
|
|
|
public function testCheckUserAccessAdminAcc() |
|
278
|
|
|
{ |
|
279
|
|
|
$userData = new UserLoginResponse(); |
|
280
|
|
|
$userData->setId(2); |
|
281
|
|
|
$userData->setIsAdminAcc(true); |
|
|
|
|
|
|
282
|
|
|
|
|
283
|
|
|
$this->context->setUserData($userData); |
|
284
|
|
|
$this->context->setUserProfile(new ProfileData()); |
|
285
|
|
|
|
|
286
|
|
|
$this->checkUserAccess([ |
|
287
|
|
|
ActionsInterface::ACCOUNT_VIEW, |
|
288
|
|
|
ActionsInterface::ACCOUNT_VIEW_PASS, |
|
289
|
|
|
ActionsInterface::ACCOUNT_HISTORY_VIEW, |
|
290
|
|
|
ActionsInterface::ACCOUNT_EDIT, |
|
291
|
|
|
ActionsInterface::ACCOUNT_EDIT_PASS, |
|
292
|
|
|
ActionsInterface::ACCOUNT_CREATE, |
|
293
|
|
|
ActionsInterface::ACCOUNT_COPY, |
|
294
|
|
|
ActionsInterface::ACCOUNT_DELETE, |
|
295
|
|
|
ActionsInterface::ACCOUNT_FILE, |
|
296
|
|
|
ActionsInterface::ACCOUNTMGR, |
|
297
|
|
|
ActionsInterface::ACCOUNTMGR_SEARCH, |
|
298
|
|
|
ActionsInterface::ACCOUNTMGR_HISTORY, |
|
299
|
|
|
ActionsInterface::ACCOUNTMGR_HISTORY_SEARCH, |
|
300
|
|
|
ActionsInterface::ITEMS_MANAGE |
|
301
|
|
|
]); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* testCheckUserAccessAccountEdit |
|
306
|
|
|
*/ |
|
307
|
|
|
public function testCheckUserAccessAccountEdit() |
|
308
|
|
|
{ |
|
309
|
|
|
$userData = new UserLoginResponse(); |
|
310
|
|
|
$userData->setId(2); |
|
311
|
|
|
|
|
312
|
|
|
$userProfile = new ProfileData(); |
|
313
|
|
|
$userProfile->setAccEdit(true); |
|
314
|
|
|
|
|
315
|
|
|
$this->context->setUserData($userData); |
|
316
|
|
|
$this->context->setUserProfile($userProfile); |
|
317
|
|
|
|
|
318
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_EDIT, ActionsInterface::ACCOUNT_VIEW]); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* testCheckUserAccessAccountEditPass |
|
323
|
|
|
*/ |
|
324
|
|
|
public function testCheckUserAccessAccountEditPass() |
|
325
|
|
|
{ |
|
326
|
|
|
$userData = new UserLoginResponse(); |
|
327
|
|
|
$userData->setId(2); |
|
328
|
|
|
|
|
329
|
|
|
$userProfile = new ProfileData(); |
|
330
|
|
|
$userProfile->setAccEditPass(true); |
|
331
|
|
|
|
|
332
|
|
|
$this->context->setUserData($userData); |
|
333
|
|
|
$this->context->setUserProfile($userProfile); |
|
334
|
|
|
|
|
335
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_EDIT_PASS]); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* testCheckUserAccessAccountCreate |
|
340
|
|
|
*/ |
|
341
|
|
|
public function testCheckUserAccessAccountCreate() |
|
342
|
|
|
{ |
|
343
|
|
|
$userData = new UserLoginResponse(); |
|
344
|
|
|
$userData->setId(2); |
|
345
|
|
|
|
|
346
|
|
|
$userProfile = new ProfileData(); |
|
347
|
|
|
$userProfile->setAccAdd(true); |
|
348
|
|
|
|
|
349
|
|
|
$this->context->setUserData($userData); |
|
350
|
|
|
$this->context->setUserProfile($userProfile); |
|
351
|
|
|
|
|
352
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_CREATE]); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* testCheckUserAccessAccountCopy |
|
357
|
|
|
*/ |
|
358
|
|
|
public function testCheckUserAccessAccountCopy() |
|
359
|
|
|
{ |
|
360
|
|
|
$userData = new UserLoginResponse(); |
|
361
|
|
|
$userData->setId(2); |
|
362
|
|
|
|
|
363
|
|
|
$userProfile = new ProfileData(); |
|
364
|
|
|
$userProfile->setAccAdd(true); |
|
365
|
|
|
$userProfile->setAccView(true); |
|
366
|
|
|
|
|
367
|
|
|
$this->context->setUserData($userData); |
|
368
|
|
|
$this->context->setUserProfile($userProfile); |
|
369
|
|
|
|
|
370
|
|
|
$this->checkUserAccess([ |
|
371
|
|
|
ActionsInterface::ACCOUNT_COPY, |
|
372
|
|
|
ActionsInterface::ACCOUNT_VIEW, |
|
373
|
|
|
ActionsInterface::ACCOUNT_CREATE |
|
374
|
|
|
]); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* testCheckUserAccessAccountDelete |
|
379
|
|
|
*/ |
|
380
|
|
|
public function testCheckUserAccessAccountDelete() |
|
381
|
|
|
{ |
|
382
|
|
|
$userData = new UserLoginResponse(); |
|
383
|
|
|
$userData->setId(2); |
|
384
|
|
|
|
|
385
|
|
|
$userProfile = new ProfileData(); |
|
386
|
|
|
$userProfile->setAccDelete(true); |
|
387
|
|
|
|
|
388
|
|
|
$this->context->setUserData($userData); |
|
389
|
|
|
$this->context->setUserProfile($userProfile); |
|
390
|
|
|
|
|
391
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_DELETE]); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* testCheckUserAccessAccountFile |
|
396
|
|
|
*/ |
|
397
|
|
|
public function testCheckUserAccessAccountFile() |
|
398
|
|
|
{ |
|
399
|
|
|
$userData = new UserLoginResponse(); |
|
400
|
|
|
$userData->setId(2); |
|
401
|
|
|
|
|
402
|
|
|
$userProfile = new ProfileData(); |
|
403
|
|
|
$userProfile->setAccFiles(true); |
|
404
|
|
|
|
|
405
|
|
|
$this->context->setUserData($userData); |
|
406
|
|
|
$this->context->setUserProfile($userProfile); |
|
407
|
|
|
|
|
408
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_FILE]); |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* testCheckUserAccessConfigGeneral |
|
413
|
|
|
*/ |
|
414
|
|
|
public function testCheckUserAccessConfigGeneral() |
|
415
|
|
|
{ |
|
416
|
|
|
$userData = new UserLoginResponse(); |
|
417
|
|
|
$userData->setId(2); |
|
418
|
|
|
|
|
419
|
|
|
$userProfile = new ProfileData(); |
|
420
|
|
|
$userProfile->setConfigGeneral(true); |
|
421
|
|
|
|
|
422
|
|
|
$this->context->setUserData($userData); |
|
423
|
|
|
$this->context->setUserProfile($userProfile); |
|
424
|
|
|
|
|
425
|
|
|
$this->checkUserAccess([ |
|
426
|
|
|
ActionsInterface::CONFIG, |
|
427
|
|
|
ActionsInterface::CONFIG_GENERAL, |
|
428
|
|
|
ActionsInterface::PLUGIN, |
|
429
|
|
|
ActionsInterface::CONFIG_ACCOUNT, |
|
430
|
|
|
ActionsInterface::CONFIG_WIKI, |
|
431
|
|
|
ActionsInterface::CONFIG_LDAP, |
|
432
|
|
|
ActionsInterface::CONFIG_MAIL |
|
433
|
|
|
]); |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* testCheckUserAccessConfigImport |
|
438
|
|
|
*/ |
|
439
|
|
|
public function testCheckUserAccessConfigImport() |
|
440
|
|
|
{ |
|
441
|
|
|
$userData = new UserLoginResponse(); |
|
442
|
|
|
$userData->setId(2); |
|
443
|
|
|
|
|
444
|
|
|
$userProfile = new ProfileData(); |
|
445
|
|
|
$userProfile->setConfigImport(true); |
|
446
|
|
|
|
|
447
|
|
|
$this->context->setUserData($userData); |
|
448
|
|
|
$this->context->setUserProfile($userProfile); |
|
449
|
|
|
|
|
450
|
|
|
$this->checkUserAccess([ |
|
451
|
|
|
ActionsInterface::CONFIG, |
|
452
|
|
|
ActionsInterface::CONFIG_IMPORT |
|
453
|
|
|
]); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
/** |
|
457
|
|
|
* testCheckUserAccessCategory |
|
458
|
|
|
*/ |
|
459
|
|
|
public function testCheckUserAccessCategory() |
|
460
|
|
|
{ |
|
461
|
|
|
$userData = new UserLoginResponse(); |
|
462
|
|
|
$userData->setId(2); |
|
463
|
|
|
|
|
464
|
|
|
$userProfile = new ProfileData(); |
|
465
|
|
|
$userProfile->setMgmCategories(true); |
|
466
|
|
|
|
|
467
|
|
|
$this->context->setUserData($userData); |
|
468
|
|
|
$this->context->setUserProfile($userProfile); |
|
469
|
|
|
|
|
470
|
|
|
$this->checkUserAccess([ |
|
471
|
|
|
ActionsInterface::ITEMS_MANAGE, |
|
472
|
|
|
ActionsInterface::CATEGORY, |
|
473
|
|
|
ActionsInterface::CATEGORY_SEARCH, |
|
474
|
|
|
ActionsInterface::CATEGORY_VIEW, |
|
475
|
|
|
ActionsInterface::CATEGORY_CREATE, |
|
476
|
|
|
ActionsInterface::CATEGORY_EDIT, |
|
477
|
|
|
ActionsInterface::CATEGORY_DELETE |
|
478
|
|
|
]); |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
/** |
|
482
|
|
|
* testCheckUserAccessClient |
|
483
|
|
|
*/ |
|
484
|
|
|
public function testCheckUserAccessClient() |
|
485
|
|
|
{ |
|
486
|
|
|
$userData = new UserLoginResponse(); |
|
487
|
|
|
$userData->setId(2); |
|
488
|
|
|
|
|
489
|
|
|
$userProfile = new ProfileData(); |
|
490
|
|
|
$userProfile->setMgmCustomers(true); |
|
491
|
|
|
|
|
492
|
|
|
$this->context->setUserData($userData); |
|
493
|
|
|
$this->context->setUserProfile($userProfile); |
|
494
|
|
|
|
|
495
|
|
|
$this->checkUserAccess([ |
|
496
|
|
|
ActionsInterface::ITEMS_MANAGE, |
|
497
|
|
|
ActionsInterface::CLIENT, |
|
498
|
|
|
ActionsInterface::CLIENT_SEARCH, |
|
499
|
|
|
ActionsInterface::CLIENT_VIEW, |
|
500
|
|
|
ActionsInterface::CLIENT_CREATE, |
|
501
|
|
|
ActionsInterface::CLIENT_EDIT, |
|
502
|
|
|
ActionsInterface::CLIENT_DELETE |
|
503
|
|
|
]); |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
/** |
|
507
|
|
|
* testCheckUserAccessCustomField |
|
508
|
|
|
*/ |
|
509
|
|
|
public function testCheckUserAccessCustomField() |
|
510
|
|
|
{ |
|
511
|
|
|
$userData = new UserLoginResponse(); |
|
512
|
|
|
$userData->setId(2); |
|
513
|
|
|
|
|
514
|
|
|
$userProfile = new ProfileData(); |
|
515
|
|
|
$userProfile->setMgmCustomFields(true); |
|
516
|
|
|
|
|
517
|
|
|
$this->context->setUserData($userData); |
|
518
|
|
|
$this->context->setUserProfile($userProfile); |
|
519
|
|
|
|
|
520
|
|
|
$this->checkUserAccess([ |
|
521
|
|
|
ActionsInterface::ITEMS_MANAGE, |
|
522
|
|
|
ActionsInterface::CUSTOMFIELD, |
|
523
|
|
|
ActionsInterface::CUSTOMFIELD_SEARCH, |
|
524
|
|
|
ActionsInterface::CUSTOMFIELD_VIEW, |
|
525
|
|
|
ActionsInterface::CUSTOMFIELD_CREATE, |
|
526
|
|
|
ActionsInterface::CUSTOMFIELD_EDIT, |
|
527
|
|
|
ActionsInterface::CUSTOMFIELD_DELETE |
|
528
|
|
|
]); |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
/** |
|
532
|
|
|
* testCheckUserAccessPublicLink |
|
533
|
|
|
*/ |
|
534
|
|
|
public function testCheckUserAccessPublicLink() |
|
535
|
|
|
{ |
|
536
|
|
|
$userData = new UserLoginResponse(); |
|
537
|
|
|
$userData->setId(2); |
|
538
|
|
|
|
|
539
|
|
|
$userProfile = new ProfileData(); |
|
540
|
|
|
$userProfile->setMgmPublicLinks(true); |
|
541
|
|
|
|
|
542
|
|
|
$this->context->setUserData($userData); |
|
543
|
|
|
$this->context->setUserProfile($userProfile); |
|
544
|
|
|
|
|
545
|
|
|
$this->checkUserAccess([ |
|
546
|
|
|
ActionsInterface::ITEMS_MANAGE, |
|
547
|
|
|
ActionsInterface::PUBLICLINK, |
|
548
|
|
|
ActionsInterface::PUBLICLINK_SEARCH, |
|
549
|
|
|
ActionsInterface::PUBLICLINK_CREATE, |
|
550
|
|
|
ActionsInterface::PUBLICLINK_REFRESH, |
|
551
|
|
|
ActionsInterface::PUBLICLINK_VIEW, |
|
552
|
|
|
ActionsInterface::PUBLICLINK_EDIT, |
|
553
|
|
|
ActionsInterface::PUBLICLINK_DELETE |
|
554
|
|
|
]); |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
/** |
|
558
|
|
|
* testCheckUserAccessPublicLinkCreate |
|
559
|
|
|
*/ |
|
560
|
|
|
public function testCheckUserAccessPublicLinkCreate() |
|
561
|
|
|
{ |
|
562
|
|
|
$userData = new UserLoginResponse(); |
|
563
|
|
|
$userData->setId(2); |
|
564
|
|
|
|
|
565
|
|
|
$userProfile = new ProfileData(); |
|
566
|
|
|
$userProfile->setAccPublicLinks(true); |
|
567
|
|
|
|
|
568
|
|
|
$this->context->setUserData($userData); |
|
569
|
|
|
$this->context->setUserProfile($userProfile); |
|
570
|
|
|
|
|
571
|
|
|
$this->checkUserAccess([ |
|
572
|
|
|
ActionsInterface::PUBLICLINK_CREATE, |
|
573
|
|
|
ActionsInterface::PUBLICLINK_REFRESH |
|
574
|
|
|
]); |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
/** |
|
578
|
|
|
* testCheckUserAccessAccount |
|
579
|
|
|
*/ |
|
580
|
|
|
public function testCheckUserAccessAccount() |
|
581
|
|
|
{ |
|
582
|
|
|
$userData = new UserLoginResponse(); |
|
583
|
|
|
$userData->setId(2); |
|
584
|
|
|
|
|
585
|
|
|
$userProfile = new ProfileData(); |
|
586
|
|
|
$userProfile->setMgmAccounts(true); |
|
587
|
|
|
|
|
588
|
|
|
$this->context->setUserData($userData); |
|
589
|
|
|
$this->context->setUserProfile($userProfile); |
|
590
|
|
|
|
|
591
|
|
|
$this->checkUserAccess([ |
|
592
|
|
|
ActionsInterface::ITEMS_MANAGE, |
|
593
|
|
|
ActionsInterface::ACCOUNTMGR, |
|
594
|
|
|
ActionsInterface::ACCOUNTMGR_SEARCH, |
|
595
|
|
|
ActionsInterface::ACCOUNTMGR_HISTORY, |
|
596
|
|
|
ActionsInterface::ACCOUNTMGR_HISTORY_SEARCH |
|
597
|
|
|
]); |
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
/** |
|
601
|
|
|
* testCheckUserAccessFile |
|
602
|
|
|
*/ |
|
603
|
|
|
public function testCheckUserAccessFile() |
|
604
|
|
|
{ |
|
605
|
|
|
$userData = new UserLoginResponse(); |
|
606
|
|
|
$userData->setId(2); |
|
607
|
|
|
|
|
608
|
|
|
$userProfile = new ProfileData(); |
|
609
|
|
|
$userProfile->setMgmFiles(true); |
|
610
|
|
|
|
|
611
|
|
|
$this->context->setUserData($userData); |
|
612
|
|
|
$this->context->setUserProfile($userProfile); |
|
613
|
|
|
|
|
614
|
|
|
$this->checkUserAccess([ |
|
615
|
|
|
ActionsInterface::ITEMS_MANAGE, |
|
616
|
|
|
ActionsInterface::FILE, |
|
617
|
|
|
ActionsInterface::FILE_SEARCH, |
|
618
|
|
|
ActionsInterface::FILE_DELETE, |
|
619
|
|
|
ActionsInterface::FILE_VIEW, |
|
620
|
|
|
ActionsInterface::FILE_DOWNLOAD |
|
621
|
|
|
]); |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
/** |
|
625
|
|
|
* testCheckUserAccessTag |
|
626
|
|
|
*/ |
|
627
|
|
|
public function testCheckUserAccessTag() |
|
628
|
|
|
{ |
|
629
|
|
|
$userData = new UserLoginResponse(); |
|
630
|
|
|
$userData->setId(2); |
|
631
|
|
|
|
|
632
|
|
|
$userProfile = new ProfileData(); |
|
633
|
|
|
$userProfile->setMgmTags(true); |
|
634
|
|
|
|
|
635
|
|
|
$this->context->setUserData($userData); |
|
636
|
|
|
$this->context->setUserProfile($userProfile); |
|
637
|
|
|
|
|
638
|
|
|
$this->checkUserAccess([ |
|
639
|
|
|
ActionsInterface::ITEMS_MANAGE, |
|
640
|
|
|
ActionsInterface::TAG, |
|
641
|
|
|
ActionsInterface::TAG_SEARCH, |
|
642
|
|
|
ActionsInterface::TAG_VIEW, |
|
643
|
|
|
ActionsInterface::TAG_CREATE, |
|
644
|
|
|
ActionsInterface::TAG_EDIT, |
|
645
|
|
|
ActionsInterface::TAG_DELETE |
|
646
|
|
|
]); |
|
647
|
|
|
} |
|
648
|
|
|
|
|
649
|
|
|
/** |
|
650
|
|
|
* testCheckUserAccessConfigCrypt |
|
651
|
|
|
*/ |
|
652
|
|
|
public function testCheckUserAccessConfigCrypt() |
|
653
|
|
|
{ |
|
654
|
|
|
$userData = new UserLoginResponse(); |
|
655
|
|
|
$userData->setId(2); |
|
656
|
|
|
|
|
657
|
|
|
$userProfile = new ProfileData(); |
|
658
|
|
|
$userProfile->setConfigEncryption(true); |
|
659
|
|
|
|
|
660
|
|
|
$this->context->setUserData($userData); |
|
661
|
|
|
$this->context->setUserProfile($userProfile); |
|
662
|
|
|
|
|
663
|
|
|
$this->checkUserAccess([ |
|
664
|
|
|
ActionsInterface::CONFIG, |
|
665
|
|
|
ActionsInterface::CONFIG_CRYPT |
|
666
|
|
|
]); |
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
/** |
|
670
|
|
|
* testCheckUserAccessConfigBackup |
|
671
|
|
|
*/ |
|
672
|
|
|
public function testCheckUserAccessConfigBackup() |
|
673
|
|
|
{ |
|
674
|
|
|
$userData = new UserLoginResponse(); |
|
675
|
|
|
$userData->setId(2); |
|
676
|
|
|
|
|
677
|
|
|
$userProfile = new ProfileData(); |
|
678
|
|
|
$userProfile->setConfigBackup(true); |
|
679
|
|
|
|
|
680
|
|
|
$this->context->setUserData($userData); |
|
681
|
|
|
$this->context->setUserProfile($userProfile); |
|
682
|
|
|
|
|
683
|
|
|
$this->checkUserAccess([ |
|
684
|
|
|
ActionsInterface::CONFIG, |
|
685
|
|
|
ActionsInterface::CONFIG_BACKUP |
|
686
|
|
|
]); |
|
687
|
|
|
} |
|
688
|
|
|
|
|
689
|
|
|
/** |
|
690
|
|
|
* testCheckUserAccessUser |
|
691
|
|
|
*/ |
|
692
|
|
|
public function testCheckUserAccessUser() |
|
693
|
|
|
{ |
|
694
|
|
|
$userData = new UserLoginResponse(); |
|
695
|
|
|
$userData->setId(2); |
|
696
|
|
|
|
|
697
|
|
|
$userProfile = new ProfileData(); |
|
698
|
|
|
$userProfile->setMgmUsers(true); |
|
699
|
|
|
|
|
700
|
|
|
$this->context->setUserData($userData); |
|
701
|
|
|
$this->context->setUserProfile($userProfile); |
|
702
|
|
|
|
|
703
|
|
|
$this->checkUserAccess([ |
|
704
|
|
|
ActionsInterface::ACCESS_MANAGE, |
|
705
|
|
|
ActionsInterface::USER, |
|
706
|
|
|
ActionsInterface::USER_SEARCH, |
|
707
|
|
|
ActionsInterface::USER_VIEW, |
|
708
|
|
|
ActionsInterface::USER_CREATE, |
|
709
|
|
|
ActionsInterface::USER_EDIT, |
|
710
|
|
|
ActionsInterface::USER_DELETE, |
|
711
|
|
|
ActionsInterface::USER_EDIT_PASS |
|
712
|
|
|
]); |
|
713
|
|
|
} |
|
714
|
|
|
|
|
715
|
|
|
/** |
|
716
|
|
|
* testCheckUserAccessUserGroup |
|
717
|
|
|
*/ |
|
718
|
|
|
public function testCheckUserAccessUserGroup() |
|
719
|
|
|
{ |
|
720
|
|
|
$userData = new UserLoginResponse(); |
|
721
|
|
|
$userData->setId(2); |
|
722
|
|
|
|
|
723
|
|
|
$userProfile = new ProfileData(); |
|
724
|
|
|
$userProfile->setMgmGroups(true); |
|
725
|
|
|
|
|
726
|
|
|
$this->context->setUserData($userData); |
|
727
|
|
|
$this->context->setUserProfile($userProfile); |
|
728
|
|
|
|
|
729
|
|
|
$this->checkUserAccess([ |
|
730
|
|
|
ActionsInterface::ACCESS_MANAGE, |
|
731
|
|
|
ActionsInterface::GROUP, |
|
732
|
|
|
ActionsInterface::GROUP_SEARCH, |
|
733
|
|
|
ActionsInterface::GROUP_VIEW, |
|
734
|
|
|
ActionsInterface::GROUP_CREATE, |
|
735
|
|
|
ActionsInterface::GROUP_EDIT, |
|
736
|
|
|
ActionsInterface::GROUP_DELETE |
|
737
|
|
|
]); |
|
738
|
|
|
} |
|
739
|
|
|
|
|
740
|
|
|
/** |
|
741
|
|
|
* testCheckUserAccessUserProfile |
|
742
|
|
|
*/ |
|
743
|
|
|
public function testCheckUserAccessUserProfile() |
|
744
|
|
|
{ |
|
745
|
|
|
$userData = new UserLoginResponse(); |
|
746
|
|
|
$userData->setId(2); |
|
747
|
|
|
|
|
748
|
|
|
$userProfile = new ProfileData(); |
|
749
|
|
|
$userProfile->setMgmProfiles(true); |
|
750
|
|
|
|
|
751
|
|
|
$this->context->setUserData($userData); |
|
752
|
|
|
$this->context->setUserProfile($userProfile); |
|
753
|
|
|
|
|
754
|
|
|
$this->checkUserAccess([ |
|
755
|
|
|
ActionsInterface::ACCESS_MANAGE, |
|
756
|
|
|
ActionsInterface::PROFILE, |
|
757
|
|
|
ActionsInterface::PROFILE_SEARCH, |
|
758
|
|
|
ActionsInterface::PROFILE_VIEW, |
|
759
|
|
|
ActionsInterface::PROFILE_CREATE, |
|
760
|
|
|
ActionsInterface::PROFILE_EDIT, |
|
761
|
|
|
ActionsInterface::PROFILE_DELETE |
|
762
|
|
|
]); |
|
763
|
|
|
} |
|
764
|
|
|
|
|
765
|
|
|
/** |
|
766
|
|
|
* testCheckUserAccessAuthToken |
|
767
|
|
|
*/ |
|
768
|
|
|
public function testCheckUserAccessAuthToken() |
|
769
|
|
|
{ |
|
770
|
|
|
$userData = new UserLoginResponse(); |
|
771
|
|
|
$userData->setId(2); |
|
772
|
|
|
|
|
773
|
|
|
$userProfile = new ProfileData(); |
|
774
|
|
|
$userProfile->setMgmApiTokens(true); |
|
775
|
|
|
|
|
776
|
|
|
$this->context->setUserData($userData); |
|
777
|
|
|
$this->context->setUserProfile($userProfile); |
|
778
|
|
|
|
|
779
|
|
|
$this->checkUserAccess([ |
|
780
|
|
|
ActionsInterface::ACCESS_MANAGE, |
|
781
|
|
|
ActionsInterface::AUTHTOKEN, |
|
782
|
|
|
ActionsInterface::AUTHTOKEN_SEARCH, |
|
783
|
|
|
ActionsInterface::AUTHTOKEN_VIEW, |
|
784
|
|
|
ActionsInterface::AUTHTOKEN_CREATE, |
|
785
|
|
|
ActionsInterface::AUTHTOKEN_EDIT, |
|
786
|
|
|
ActionsInterface::AUTHTOKEN_DELETE |
|
787
|
|
|
]); |
|
788
|
|
|
} |
|
789
|
|
|
|
|
790
|
|
|
/** |
|
791
|
|
|
* testCheckUserAccessEventlog |
|
792
|
|
|
*/ |
|
793
|
|
|
public function testCheckUserAccessEventlog() |
|
794
|
|
|
{ |
|
795
|
|
|
$userData = new UserLoginResponse(); |
|
796
|
|
|
$userData->setId(2); |
|
797
|
|
|
|
|
798
|
|
|
$userProfile = new ProfileData(); |
|
799
|
|
|
$userProfile->setEvl(true); |
|
800
|
|
|
|
|
801
|
|
|
$this->context->setUserData($userData); |
|
802
|
|
|
$this->context->setUserProfile($userProfile); |
|
803
|
|
|
|
|
804
|
|
|
$this->checkUserAccess([ |
|
805
|
|
|
ActionsInterface::EVENTLOG, |
|
806
|
|
|
ActionsInterface::EVENTLOG_SEARCH, |
|
807
|
|
|
ActionsInterface::EVENTLOG_CLEAR |
|
808
|
|
|
]); |
|
809
|
|
|
} |
|
810
|
|
|
|
|
811
|
|
|
/** |
|
812
|
|
|
* testCheckUserAccessAccountViewPass |
|
813
|
|
|
*/ |
|
814
|
|
|
public function testCheckUserAccessAccountViewPass() |
|
815
|
|
|
{ |
|
816
|
|
|
$userData = new UserLoginResponse(); |
|
817
|
|
|
$userData->setId(2); |
|
818
|
|
|
|
|
819
|
|
|
$userProfile = new ProfileData(); |
|
820
|
|
|
$userProfile->setAccViewPass(true); |
|
821
|
|
|
|
|
822
|
|
|
$this->context->setUserData($userData); |
|
823
|
|
|
$this->context->setUserProfile($userProfile); |
|
824
|
|
|
|
|
825
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_VIEW_PASS, ActionsInterface::CUSTOMFIELD_VIEW_PASS]); |
|
826
|
|
|
} |
|
827
|
|
|
|
|
828
|
|
|
/** |
|
829
|
|
|
* testCheckUserAccessAccountHistoryView |
|
830
|
|
|
*/ |
|
831
|
|
|
public function testCheckUserAccessAccountHistoryView() |
|
832
|
|
|
{ |
|
833
|
|
|
$userData = new UserLoginResponse(); |
|
834
|
|
|
$userData->setId(2); |
|
835
|
|
|
|
|
836
|
|
|
$userProfile = new ProfileData(); |
|
837
|
|
|
$userProfile->setAccViewHistory(true); |
|
838
|
|
|
|
|
839
|
|
|
$this->context->setUserData($userData); |
|
840
|
|
|
$this->context->setUserProfile($userProfile); |
|
841
|
|
|
|
|
842
|
|
|
$this->assertTrue($this->acl->checkUserAccess(ActionsInterface::ACCOUNT_HISTORY_VIEW)); |
|
843
|
|
|
|
|
844
|
|
|
$this->checkUserAccess([ActionsInterface::ACCOUNT_HISTORY_VIEW]); |
|
845
|
|
|
} |
|
846
|
|
|
|
|
847
|
|
|
/** |
|
848
|
|
|
* @dataProvider actionsProvider |
|
849
|
|
|
* |
|
850
|
|
|
* @param $id |
|
851
|
|
|
*/ |
|
852
|
|
|
public function testGetActionInfo($id) |
|
853
|
|
|
{ |
|
854
|
|
|
$this->assertNotEmpty(Acl::getActionInfo($id)); |
|
855
|
|
|
} |
|
856
|
|
|
|
|
857
|
|
|
/** |
|
858
|
|
|
* testGetActionInfoUnknown |
|
859
|
|
|
*/ |
|
860
|
|
|
public function testGetActionInfoUnknown() |
|
861
|
|
|
{ |
|
862
|
|
|
$this->assertEmpty(Acl::getActionInfo(10000)); |
|
863
|
|
|
} |
|
864
|
|
|
|
|
865
|
|
|
/** |
|
866
|
|
|
* @throws \DI\DependencyException |
|
867
|
|
|
* @throws \DI\NotFoundException |
|
868
|
|
|
* @throws \SP\Core\Context\ContextException |
|
869
|
|
|
*/ |
|
870
|
|
|
protected function setUp() |
|
871
|
|
|
{ |
|
872
|
|
|
$dic = setupContext(); |
|
873
|
|
|
|
|
874
|
|
|
$this->acl = $dic->get(Acl::class); |
|
875
|
|
|
$this->context = $dic->get(ContextInterface::class); |
|
876
|
|
|
} |
|
877
|
|
|
} |
|
878
|
|
|
|