|
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\Services\Account; |
|
26
|
|
|
|
|
27
|
|
|
use SP\Core\Acl\Acl; |
|
28
|
|
|
use SP\Core\Context\ContextInterface; |
|
29
|
|
|
use SP\Core\Context\StatelessContext; |
|
30
|
|
|
use SP\DataModel\Dto\AccountAclDto; |
|
31
|
|
|
use SP\DataModel\Dto\AccountDetailsResponse; |
|
32
|
|
|
use SP\Services\Account\AccountAcl; |
|
33
|
|
|
use SP\Services\Account\AccountAclService; |
|
34
|
|
|
use SP\Services\Account\AccountService; |
|
35
|
|
|
use SP\Services\User\UserLoginResponse; |
|
36
|
|
|
use SP\Storage\Database\DatabaseConnectionData; |
|
37
|
|
|
use SP\Tests\DatabaseTestCase; |
|
38
|
|
|
use function SP\Tests\setupContext; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Class AccountAclServiceTest |
|
42
|
|
|
* |
|
43
|
|
|
* @package SP\Tests\Services |
|
44
|
|
|
*/ |
|
45
|
|
|
class AccountAclServiceTest extends DatabaseTestCase |
|
46
|
|
|
{ |
|
47
|
|
|
/** |
|
48
|
|
|
* @var \Closure |
|
49
|
|
|
*/ |
|
50
|
|
|
private static $service; |
|
51
|
|
|
/** |
|
52
|
|
|
* @var AccountService |
|
53
|
|
|
*/ |
|
54
|
|
|
private static $accountService; |
|
55
|
|
|
/** |
|
56
|
|
|
* @var StatelessContext |
|
57
|
|
|
*/ |
|
58
|
|
|
private static $context; |
|
59
|
|
|
/** |
|
60
|
|
|
* @var array |
|
61
|
|
|
*/ |
|
62
|
|
|
private static $actions = [ |
|
63
|
|
|
Acl::ACCOUNT_SEARCH, |
|
64
|
|
|
Acl::ACCOUNT_VIEW, |
|
65
|
|
|
Acl::ACCOUNT_VIEW_PASS, |
|
66
|
|
|
Acl::ACCOUNT_HISTORY_VIEW, |
|
67
|
|
|
Acl::ACCOUNT_CREATE, |
|
68
|
|
|
Acl::ACCOUNT_EDIT, |
|
69
|
|
|
Acl::ACCOUNT_EDIT_PASS, |
|
70
|
|
|
Acl::ACCOUNT_EDIT_RESTORE, |
|
71
|
|
|
Acl::ACCOUNT_COPY, |
|
72
|
|
|
Acl::ACCOUNT_COPY_PASS, |
|
73
|
|
|
Acl::ACCOUNT_DELETE |
|
74
|
|
|
]; |
|
75
|
|
|
/** |
|
76
|
|
|
* @var AccountDetailsResponse |
|
77
|
|
|
*/ |
|
78
|
|
|
protected $account; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @throws \DI\NotFoundException |
|
82
|
|
|
* @throws \SP\Core\Context\ContextException |
|
83
|
|
|
* @throws \DI\DependencyException |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function setUpBeforeClass() |
|
86
|
|
|
{ |
|
87
|
|
|
$dic = setupContext(); |
|
88
|
|
|
|
|
89
|
|
|
self::$dataset = 'syspass_accountAcl.xml'; |
|
90
|
|
|
|
|
91
|
|
|
// Datos de conexión a la BBDD |
|
92
|
|
|
self::$databaseConnectionData = $dic->get(DatabaseConnectionData::class); |
|
93
|
|
|
|
|
94
|
|
|
self::$context = $dic->get(ContextInterface::class); |
|
95
|
|
|
|
|
96
|
|
|
// Es necesario utilizar una función anónima para evitar la fijación |
|
97
|
|
|
// de los datos del contexto |
|
98
|
|
|
self::$service = function () use ($dic) { |
|
99
|
|
|
return new AccountAclService($dic); |
|
100
|
|
|
}; |
|
101
|
|
|
|
|
102
|
|
|
self::$accountService = $dic->get(AccountService::class); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* testSaveAclInCache |
|
107
|
|
|
*/ |
|
108
|
|
|
public function testSaveAclInCache() |
|
109
|
|
|
{ |
|
110
|
|
|
/** @var AccountAclService $service */ |
|
111
|
|
|
$service = self::$service->call($this); |
|
112
|
|
|
|
|
113
|
|
|
$accountAcl = new AccountAcl(10); |
|
114
|
|
|
$accountAcl->setAccountId(1); |
|
115
|
|
|
$accountAcl->setCompiledAccountAccess(true); |
|
116
|
|
|
$accountAcl->setCompiledShowAccess(true); |
|
117
|
|
|
$accountAcl->setResultView(true); |
|
118
|
|
|
$accountAcl->setResultEdit(true); |
|
119
|
|
|
$accountAcl->setShowCopy(true); |
|
120
|
|
|
$accountAcl->setShowPermission(true); |
|
121
|
|
|
$accountAcl->setShowLink(false); |
|
122
|
|
|
$accountAcl->setShowView(true); |
|
123
|
|
|
$accountAcl->setShowViewPass(true); |
|
124
|
|
|
$accountAcl->setShowRestore(true); |
|
125
|
|
|
$accountAcl->setShowHistory(true); |
|
126
|
|
|
$accountAcl->setShowDelete(true); |
|
127
|
|
|
$accountAcl->setShowEdit(true); |
|
128
|
|
|
$accountAcl->setShowEditPass(true); |
|
129
|
|
|
$accountAcl->setShowFiles(true); |
|
130
|
|
|
$accountAcl->setShowDetails(true); |
|
131
|
|
|
$accountAcl->setShowPass(true); |
|
132
|
|
|
|
|
133
|
|
|
$service->saveAclInCache($accountAcl); |
|
134
|
|
|
|
|
135
|
|
|
$result = $service->getAclFromCache(1, 10); |
|
136
|
|
|
|
|
137
|
|
|
$this->assertInstanceOf(AccountAcl::class, $result); |
|
138
|
|
|
$this->assertEquals($accountAcl, $result); |
|
139
|
|
|
|
|
140
|
|
|
$accountAcl->reset(); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertNotEquals($accountAcl, $result); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* testClearAcl |
|
147
|
|
|
*/ |
|
148
|
|
|
public function testClearAcl() |
|
149
|
|
|
{ |
|
150
|
|
|
/** @var AccountAclService $service */ |
|
151
|
|
|
$service = self::$service->call($this); |
|
152
|
|
|
|
|
153
|
|
|
$accountAcl = new AccountAcl(10); |
|
154
|
|
|
$accountAcl->setAccountId(1); |
|
155
|
|
|
|
|
156
|
|
|
$service->saveAclInCache($accountAcl); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertTrue(AccountAclService::clearAcl(1)); |
|
159
|
|
|
|
|
160
|
|
|
$this->assertFalse(AccountAclService::clearAcl(2)); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
165
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
166
|
|
|
* @throws \SP\Repositories\NoSuchItemException |
|
167
|
|
|
*/ |
|
168
|
|
|
public function testGetAclAdmin() |
|
169
|
|
|
{ |
|
170
|
|
|
$this->checkAllowAll($this->setUpAccountEnvironment(1, 1, 1, 1)); |
|
171
|
|
|
$this->checkAllowAll($this->setUpAccountEnvironment(2, 1, 1, 1)); |
|
172
|
|
|
|
|
173
|
|
|
$accountAcl = new \SP\Services\Account\AccountAcl(0); |
|
174
|
|
|
$accountAcl->setCompiledAccountAccess(true); |
|
175
|
|
|
$accountAcl->setCompiledShowAccess(true); |
|
176
|
|
|
$accountAcl->setResultView(true); |
|
177
|
|
|
$accountAcl->setResultEdit(true); |
|
178
|
|
|
$accountAcl->setShowCopy(true); |
|
179
|
|
|
$accountAcl->setShowPermission(true); |
|
180
|
|
|
$accountAcl->setShowLink(false); |
|
181
|
|
|
$accountAcl->setShowView(true); |
|
182
|
|
|
$accountAcl->setShowViewPass(true); |
|
183
|
|
|
$accountAcl->setShowRestore(true); |
|
184
|
|
|
$accountAcl->setShowHistory(true); |
|
185
|
|
|
$accountAcl->setShowDelete(true); |
|
186
|
|
|
$accountAcl->setShowEdit(true); |
|
187
|
|
|
$accountAcl->setShowEditPass(true); |
|
188
|
|
|
$accountAcl->setShowFiles(true); |
|
189
|
|
|
$accountAcl->setShowDetails(true); |
|
190
|
|
|
$accountAcl->setShowPass(true); |
|
191
|
|
|
|
|
192
|
|
|
$this->checkForUserByExample($this->setUpAccountEnvironment(1, 1, 1, 0, 1), $accountAcl); |
|
193
|
|
|
$this->checkForUserByExample($this->setUpAccountEnvironment(2, 1, 1, 0, 1), $accountAcl); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @param AccountAclDto $accountAclDto |
|
198
|
|
|
* |
|
199
|
|
|
* @param bool $should |
|
200
|
|
|
* |
|
201
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
202
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
203
|
|
|
*/ |
|
204
|
|
|
private function checkAllowAll(AccountAclDto $accountAclDto, $should = true) |
|
205
|
|
|
{ |
|
206
|
|
|
self::$context |
|
207
|
|
|
->getUserProfile() |
|
208
|
|
|
->reset() |
|
209
|
|
|
->setAccAdd($should) |
|
210
|
|
|
->setAccView($should) |
|
211
|
|
|
->setAccViewPass($should) |
|
212
|
|
|
->setAccEdit($should) |
|
213
|
|
|
->setAccEditPass($should) |
|
214
|
|
|
->setAccFiles($should) |
|
215
|
|
|
->setAccDelete($should) |
|
216
|
|
|
->setAccPermission($should) |
|
217
|
|
|
->setAccViewHistory($should); |
|
218
|
|
|
|
|
219
|
|
|
$accountAcl = (new AccountAcl(0)) |
|
220
|
|
|
->setCompiledAccountAccess(true) |
|
221
|
|
|
->setCompiledShowAccess(true) |
|
222
|
|
|
->setResultView($should) |
|
223
|
|
|
->setResultEdit($should) |
|
224
|
|
|
->setResultView(true) |
|
225
|
|
|
->setResultEdit(true) |
|
226
|
|
|
->setShowCopy(true) |
|
227
|
|
|
->setShowPermission(true) |
|
228
|
|
|
->setShowLink(true) |
|
229
|
|
|
->setShowView(true) |
|
230
|
|
|
->setShowViewPass(true) |
|
231
|
|
|
->setShowRestore(true) |
|
232
|
|
|
->setShowHistory(true) |
|
233
|
|
|
->setShowDelete(true) |
|
234
|
|
|
->setShowEdit(true) |
|
235
|
|
|
->setShowEditPass(true) |
|
236
|
|
|
->setShowFiles(true) |
|
237
|
|
|
->setShowDetails(true) |
|
238
|
|
|
->setShowPass(true); |
|
239
|
|
|
|
|
240
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @param AccountAclDto $accountAclDto |
|
245
|
|
|
* |
|
246
|
|
|
* @param AccountAcl $accountAclExample |
|
247
|
|
|
* |
|
248
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
249
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
250
|
|
|
*/ |
|
251
|
|
|
private function checkForUserByExample(AccountAclDto $accountAclDto, AccountAcl $accountAclExample) |
|
252
|
|
|
{ |
|
253
|
|
|
/** @var AccountAclService $service */ |
|
254
|
|
|
$service = self::$service->call($this); |
|
255
|
|
|
|
|
256
|
|
|
foreach (self::$actions as $action) { |
|
257
|
|
|
$accountAclExample->setActionId($action); |
|
258
|
|
|
|
|
259
|
|
|
$accountAcl = $service->getAcl($action, $accountAclDto); |
|
260
|
|
|
|
|
261
|
|
|
$this->assertInstanceOf(\SP\Services\Account\AccountAcl::class, $accountAcl); |
|
262
|
|
|
$this->assertTrue($accountAcl->isCompiledAccountAccess()); |
|
263
|
|
|
$this->assertTrue($accountAcl->isCompiledShowAccess()); |
|
264
|
|
|
|
|
265
|
|
|
$this->assertEquals($accountAclExample->isResultView(), $accountAcl->isResultView()); |
|
266
|
|
|
$this->assertEquals($accountAclExample->isResultEdit(), $accountAcl->isResultEdit()); |
|
267
|
|
|
|
|
268
|
|
|
if ($action !== Acl::ACCOUNT_CREATE |
|
269
|
|
|
&& $action !== Acl::ACCOUNT_COPY_PASS |
|
270
|
|
|
) { |
|
271
|
|
|
$this->assertEquals($accountAclExample->checkAccountAccess($action), $accountAcl->checkAccountAccess($action)); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
if ($action === Acl::ACCOUNT_VIEW |
|
275
|
|
|
|| $action === Acl::ACCOUNT_HISTORY_VIEW |
|
276
|
|
|
|| $action === Acl::ACCOUNT_DELETE |
|
277
|
|
|
) { |
|
278
|
|
|
$this->assertEquals($accountAclExample->isShowDetails(), $accountAcl->isShowDetails()); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
if ($action === Acl::ACCOUNT_CREATE |
|
282
|
|
|
|| $action === Acl::ACCOUNT_COPY |
|
283
|
|
|
) { |
|
284
|
|
|
$this->assertEquals($accountAclExample->isShowPass(), $accountAcl->isShowPass()); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
if ($action === Acl::ACCOUNT_EDIT |
|
288
|
|
|
|| $action === Acl::ACCOUNT_VIEW |
|
289
|
|
|
|| $action === Acl::ACCOUNT_HISTORY_VIEW |
|
290
|
|
|
) { |
|
291
|
|
|
$this->assertEquals($accountAclExample->isShowFiles(), $accountAcl->isShowFiles()); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
if ($action === Acl::ACCOUNT_SEARCH |
|
295
|
|
|
|| $action === Acl::ACCOUNT_VIEW |
|
296
|
|
|
|| $action === Acl::ACCOUNT_VIEW_PASS |
|
297
|
|
|
|| $action === Acl::ACCOUNT_HISTORY_VIEW |
|
298
|
|
|
|| $action === Acl::ACCOUNT_EDIT |
|
299
|
|
|
) { |
|
300
|
|
|
$this->assertEquals($accountAclExample->isShowViewPass(), $accountAcl->isShowViewPass()); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
if ($action === Acl::ACCOUNT_EDIT |
|
304
|
|
|
|| $action === Acl::ACCOUNT_CREATE |
|
305
|
|
|
|| $action === Acl::ACCOUNT_COPY |
|
306
|
|
|
) { |
|
307
|
|
|
$this->assertEquals($accountAclExample->isShowSave(), $accountAcl->isShowSave()); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
if ($action === Acl::ACCOUNT_SEARCH |
|
311
|
|
|
|| $action === Acl::ACCOUNT_VIEW |
|
312
|
|
|
) { |
|
313
|
|
|
$this->assertEquals($accountAclExample->isShowEdit(), $accountAcl->isShowEdit()); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
if ($action === Acl::ACCOUNT_EDIT |
|
317
|
|
|
|| $action === Acl::ACCOUNT_VIEW |
|
318
|
|
|
) { |
|
319
|
|
|
$this->assertEquals($accountAclExample->isShowEditPass(), $accountAcl->isShowEditPass()); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
if ($action === Acl::ACCOUNT_SEARCH |
|
323
|
|
|
|| $action === Acl::ACCOUNT_DELETE |
|
324
|
|
|
|| $action === Acl::ACCOUNT_EDIT |
|
325
|
|
|
) { |
|
326
|
|
|
$this->assertEquals($accountAclExample->isShowDelete(), $accountAcl->isShowDelete()); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
if ($action === Acl::ACCOUNT_HISTORY_VIEW) { |
|
330
|
|
|
$this->assertEquals($accountAclExample->isShowRestore(), $accountAcl->isShowRestore()); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
$this->assertEquals($accountAclExample->isShowLink(), $accountAcl->isShowLink()); |
|
334
|
|
|
|
|
335
|
|
|
if ($action === Acl::ACCOUNT_VIEW |
|
336
|
|
|
|| $action === Acl::ACCOUNT_HISTORY_VIEW |
|
337
|
|
|
) { |
|
338
|
|
|
$this->assertEquals($accountAclExample->isShowHistory(), $accountAcl->isShowHistory()); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
if ($action === Acl::ACCOUNT_SEARCH |
|
342
|
|
|
|| $action === Acl::ACCOUNT_VIEW |
|
343
|
|
|
|| $action === Acl::ACCOUNT_EDIT |
|
344
|
|
|
) { |
|
345
|
|
|
$this->assertEquals($accountAclExample->isShowCopy(), $accountAcl->isShowCopy()); |
|
346
|
|
|
} |
|
347
|
|
|
} |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* @param $accountId |
|
352
|
|
|
* @param $userId |
|
353
|
|
|
* @param $groupId |
|
354
|
|
|
* |
|
355
|
|
|
* @param int $isAdminApp |
|
356
|
|
|
* @param int $isAdminAcc |
|
357
|
|
|
* |
|
358
|
|
|
* @return AccountAclDto |
|
359
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
360
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
361
|
|
|
* @throws \SP\Repositories\NoSuchItemException |
|
362
|
|
|
*/ |
|
363
|
|
|
private function setUpAccountEnvironment($accountId, $userId, $groupId, $isAdminApp = 0, $isAdminAcc = 0) |
|
364
|
|
|
{ |
|
365
|
|
|
AccountAclService::$useCache = false; |
|
366
|
|
|
|
|
367
|
|
|
if ($this->account === null || $this->account->getId() !== $accountId) { |
|
368
|
|
|
$this->account = self::$accountService->getById($accountId); |
|
369
|
|
|
self::$accountService->withUsersById($this->account); |
|
370
|
|
|
self::$accountService->withUserGroupsById($this->account); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
$userData = new UserLoginResponse(); |
|
374
|
|
|
$userData->setId($userId); |
|
375
|
|
|
$userData->setIsAdminApp($isAdminApp); |
|
376
|
|
|
$userData->setIsAdminAcc($isAdminAcc); |
|
377
|
|
|
$userData->setUserGroupId($groupId); |
|
378
|
|
|
|
|
379
|
|
|
self::$context->setUserData($userData); |
|
380
|
|
|
|
|
381
|
|
|
return AccountAclDto::makeFromAccount($this->account); |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
386
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
387
|
|
|
* @throws \SP\Repositories\NoSuchItemException |
|
388
|
|
|
*/ |
|
389
|
|
|
public function testGetAclUser() |
|
390
|
|
|
{ |
|
391
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(1, 2, 2); |
|
392
|
|
|
|
|
393
|
|
|
$this->checkView($accountAclDto); |
|
394
|
|
|
$this->checkViewPass($accountAclDto); |
|
395
|
|
|
$this->checkDelete($accountAclDto); |
|
396
|
|
|
$this->checkEditPass($accountAclDto); |
|
397
|
|
|
$this->checkEditAndRestore($accountAclDto); |
|
398
|
|
|
$this->checkPermissions($accountAclDto); |
|
399
|
|
|
$this->checkViewFiles($accountAclDto); |
|
400
|
|
|
|
|
401
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(1, 3, 3); |
|
402
|
|
|
|
|
403
|
|
|
$this->checkView($accountAclDto); |
|
404
|
|
|
$this->checkViewPass($accountAclDto); |
|
405
|
|
|
$this->checkDelete($accountAclDto); |
|
406
|
|
|
$this->checkEditPass($accountAclDto); |
|
407
|
|
|
$this->checkEditAndRestore($accountAclDto); |
|
408
|
|
|
$this->checkPermissions($accountAclDto); |
|
409
|
|
|
$this->checkViewFiles($accountAclDto); |
|
410
|
|
|
|
|
411
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(1, 4, 3); |
|
412
|
|
|
$should = ['view' => false, 'edit' => false]; |
|
413
|
|
|
|
|
414
|
|
|
$this->checkView($accountAclDto, $should); |
|
415
|
|
|
$this->checkViewPass($accountAclDto, $should); |
|
416
|
|
|
$this->checkDelete($accountAclDto, $should); |
|
417
|
|
|
$this->checkEditPass($accountAclDto, $should); |
|
418
|
|
|
$this->checkEditAndRestore($accountAclDto, $should); |
|
419
|
|
|
$this->checkPermissions($accountAclDto, $should); |
|
420
|
|
|
$this->checkViewFiles($accountAclDto, $should); |
|
421
|
|
|
|
|
422
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(2, 1, 1); |
|
423
|
|
|
|
|
424
|
|
|
$this->checkView($accountAclDto); |
|
425
|
|
|
$this->checkViewPass($accountAclDto); |
|
426
|
|
|
$this->checkDelete($accountAclDto); |
|
427
|
|
|
$this->checkEditPass($accountAclDto); |
|
428
|
|
|
$this->checkEditAndRestore($accountAclDto); |
|
429
|
|
|
$this->checkPermissions($accountAclDto); |
|
430
|
|
|
$this->checkViewFiles($accountAclDto); |
|
431
|
|
|
|
|
432
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(2, 2, 2); |
|
433
|
|
|
|
|
434
|
|
|
$this->checkView($accountAclDto); |
|
435
|
|
|
$this->checkViewPass($accountAclDto); |
|
436
|
|
|
$this->checkDelete($accountAclDto); |
|
437
|
|
|
$this->checkEditPass($accountAclDto); |
|
438
|
|
|
$this->checkEditAndRestore($accountAclDto); |
|
439
|
|
|
$this->checkPermissions($accountAclDto); |
|
440
|
|
|
$this->checkViewFiles($accountAclDto); |
|
441
|
|
|
|
|
442
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(2, 3, 3); |
|
443
|
|
|
$should = ['view' => true, 'edit' => false]; |
|
444
|
|
|
|
|
445
|
|
|
$this->checkView($accountAclDto, $should); |
|
446
|
|
|
$this->checkViewPass($accountAclDto, $should); |
|
447
|
|
|
$this->checkDelete($accountAclDto, $should, true, false); |
|
448
|
|
|
$this->checkEditPass($accountAclDto, $should, true, false); |
|
449
|
|
|
$this->checkEditAndRestore($accountAclDto, $should, true, false); |
|
450
|
|
|
$this->checkPermissions($accountAclDto, $should); |
|
451
|
|
|
$this->checkViewFiles($accountAclDto, $should); |
|
452
|
|
|
|
|
453
|
|
|
|
|
454
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(2, 4, 3); |
|
455
|
|
|
$should = ['view' => true, 'edit' => false]; |
|
456
|
|
|
|
|
457
|
|
|
$this->checkView($accountAclDto, $should); |
|
458
|
|
|
$this->checkViewPass($accountAclDto, $should); |
|
459
|
|
|
$this->checkDelete($accountAclDto, $should, true, false); |
|
460
|
|
|
$this->checkEditPass($accountAclDto, $should, true, false); |
|
461
|
|
|
$this->checkEditAndRestore($accountAclDto, $should, true, false); |
|
462
|
|
|
$this->checkPermissions($accountAclDto, $should); |
|
463
|
|
|
$this->checkViewFiles($accountAclDto, $should); |
|
464
|
|
|
|
|
465
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(2, 5, 4); |
|
466
|
|
|
$should = ['view' => false, 'edit' => false]; |
|
467
|
|
|
|
|
468
|
|
|
$this->checkView($accountAclDto, $should); |
|
469
|
|
|
$this->checkViewPass($accountAclDto, $should); |
|
470
|
|
|
$this->checkDelete($accountAclDto, $should); |
|
471
|
|
|
$this->checkEditPass($accountAclDto, $should); |
|
472
|
|
|
$this->checkEditAndRestore($accountAclDto, $should); |
|
473
|
|
|
$this->checkPermissions($accountAclDto, $should); |
|
474
|
|
|
$this->checkViewFiles($accountAclDto, $should); |
|
475
|
|
|
|
|
476
|
|
|
$accountAclDto = $this->setUpAccountEnvironment(2, 1, 1); |
|
477
|
|
|
|
|
478
|
|
|
$this->checkView($accountAclDto); |
|
479
|
|
|
$this->checkViewPass($accountAclDto); |
|
480
|
|
|
$this->checkDelete($accountAclDto); |
|
481
|
|
|
$this->checkEditPass($accountAclDto); |
|
482
|
|
|
$this->checkEditAndRestore($accountAclDto); |
|
483
|
|
|
$this->checkPermissions($accountAclDto); |
|
484
|
|
|
$this->checkViewFiles($accountAclDto); |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* @param AccountAclDto $accountAclDto |
|
489
|
|
|
* |
|
490
|
|
|
* @param array $should Sets view and edit status |
|
491
|
|
|
* @param bool $profile Sets profile action status |
|
492
|
|
|
* @param bool $acl Sets ACL expected result |
|
493
|
|
|
* |
|
494
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
495
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
496
|
|
|
*/ |
|
497
|
|
|
private function checkView(AccountAclDto $accountAclDto, $should = ['view' => true, 'edit' => true], $profile = true, $acl = true) |
|
498
|
|
|
{ |
|
499
|
|
|
$userProfile = self::$context |
|
500
|
|
|
->getUserProfile() |
|
501
|
|
|
->reset() |
|
502
|
|
|
->setAccView($profile); |
|
503
|
|
|
|
|
504
|
|
|
$accountAcl = (new AccountAcl(0)) |
|
505
|
|
|
->setCompiledAccountAccess(true) |
|
506
|
|
|
->setCompiledShowAccess(true) |
|
507
|
|
|
->setResultView($should['view']) |
|
508
|
|
|
->setResultEdit($should['edit']) |
|
509
|
|
|
->setShowDetails($acl); |
|
510
|
|
|
|
|
511
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
512
|
|
|
|
|
513
|
|
|
// Checks if ACL returns false when profile action is granted and account access is denied |
|
514
|
|
|
if ($should['view'] === false && $should['edit'] === false) { |
|
515
|
|
|
$userProfile->setAccView(true); |
|
516
|
|
|
$accountAcl->setShowDetails(false); |
|
517
|
|
|
|
|
518
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
519
|
|
|
} elseif ($profile === true) { // Checks ACL when profile action is denied |
|
520
|
|
|
$userProfile->setAccView(false); |
|
521
|
|
|
$accountAcl->setShowDetails(false); |
|
522
|
|
|
|
|
523
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
524
|
|
|
} |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
/** |
|
528
|
|
|
* @param AccountAclDto $accountAclDto |
|
529
|
|
|
* |
|
530
|
|
|
* @param array $should |
|
531
|
|
|
* |
|
532
|
|
|
* @param bool $profile |
|
533
|
|
|
* @param bool $acl |
|
534
|
|
|
* |
|
535
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
536
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
537
|
|
|
*/ |
|
538
|
|
|
private function checkViewPass(AccountAclDto $accountAclDto, $should = ['view' => true, 'edit' => true], $profile = true, $acl = true) |
|
539
|
|
|
{ |
|
540
|
|
|
$userProfile = self::$context |
|
541
|
|
|
->getUserProfile() |
|
542
|
|
|
->reset() |
|
543
|
|
|
->setAccViewPass($profile); |
|
544
|
|
|
|
|
545
|
|
|
$accountAcl = (new AccountAcl(0)) |
|
546
|
|
|
->setCompiledAccountAccess(true) |
|
547
|
|
|
->setCompiledShowAccess(true) |
|
548
|
|
|
->setResultView($should['view']) |
|
549
|
|
|
->setResultEdit($should['edit']) |
|
550
|
|
|
->setShowViewPass($acl); |
|
551
|
|
|
|
|
552
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
553
|
|
|
|
|
554
|
|
|
// Checks if ACL returns false when profile action is granted and account access is denied |
|
555
|
|
|
if ($should['view'] === false && $should['edit'] === false) { |
|
556
|
|
|
$userProfile->setAccViewPass(true); |
|
557
|
|
|
$accountAcl->setShowViewPass(false); |
|
558
|
|
|
|
|
559
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
560
|
|
|
} elseif ($profile === true && $acl === true) { // Checks ACL when profile action is denied |
|
561
|
|
|
$userProfile->setAccViewPass(false); |
|
562
|
|
|
$accountAcl->setShowViewPass(false); |
|
563
|
|
|
|
|
564
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
565
|
|
|
} |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
/** |
|
569
|
|
|
* @param AccountAclDto $accountAclDto |
|
570
|
|
|
* |
|
571
|
|
|
* @param array $should |
|
572
|
|
|
* |
|
573
|
|
|
* @param bool $profile |
|
574
|
|
|
* @param bool $acl |
|
575
|
|
|
* |
|
576
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
577
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
578
|
|
|
*/ |
|
579
|
|
|
private function checkDelete(AccountAclDto $accountAclDto, $should = ['view' => true, 'edit' => true], $profile = true, $acl = true) |
|
580
|
|
|
{ |
|
581
|
|
|
$userProfile = self::$context |
|
582
|
|
|
->getUserProfile() |
|
583
|
|
|
->reset() |
|
584
|
|
|
->setAccDelete($profile); |
|
585
|
|
|
|
|
586
|
|
|
$accountAcl = (new AccountAcl(0)) |
|
587
|
|
|
->setCompiledAccountAccess(true) |
|
588
|
|
|
->setCompiledShowAccess(true) |
|
589
|
|
|
->setResultView($should['view']) |
|
590
|
|
|
->setResultEdit($should['edit']) |
|
591
|
|
|
->setShowDelete($acl); |
|
592
|
|
|
|
|
593
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
594
|
|
|
|
|
595
|
|
|
// Checks if ACL returns false when profile action is granted and account access is denied |
|
596
|
|
|
if ($should['view'] === false && $should['edit'] === false) { |
|
597
|
|
|
$userProfile->setAccDelete(true); |
|
598
|
|
|
$accountAcl->setShowDelete(false); |
|
599
|
|
|
|
|
600
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
601
|
|
|
} elseif ($profile === true) { // Checks ACL when profile action is denied |
|
602
|
|
|
$userProfile->setAccDelete(false); |
|
603
|
|
|
$accountAcl->setShowDelete(false); |
|
604
|
|
|
|
|
605
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
606
|
|
|
} |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
/** |
|
610
|
|
|
* @param AccountAclDto $accountAclDto |
|
611
|
|
|
* |
|
612
|
|
|
* @param array $should |
|
613
|
|
|
* |
|
614
|
|
|
* @param bool $profile |
|
615
|
|
|
* @param bool $acl |
|
616
|
|
|
* |
|
617
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
618
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
619
|
|
|
*/ |
|
620
|
|
|
private function checkEditPass(AccountAclDto $accountAclDto, $should = ['view' => true, 'edit' => true], $profile = true, $acl = true) |
|
621
|
|
|
{ |
|
622
|
|
|
$userProfile = self::$context |
|
623
|
|
|
->getUserProfile() |
|
624
|
|
|
->reset() |
|
625
|
|
|
->setAccEditPass($profile); |
|
626
|
|
|
|
|
627
|
|
|
$accountAcl = (new AccountAcl(0)) |
|
628
|
|
|
->setCompiledAccountAccess(true) |
|
629
|
|
|
->setCompiledShowAccess(true) |
|
630
|
|
|
->setResultView($should['view']) |
|
631
|
|
|
->setResultEdit($should['edit']) |
|
632
|
|
|
->setShowEditPass($acl); |
|
633
|
|
|
|
|
634
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
635
|
|
|
|
|
636
|
|
|
// Checks if ACL returns false when profile action is granted and account access is denied |
|
637
|
|
|
if ($should['view'] === false && $should['edit'] === false) { |
|
638
|
|
|
$userProfile->setAccEditPass(true); |
|
639
|
|
|
$accountAcl->setShowEditPass(false); |
|
640
|
|
|
|
|
641
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
642
|
|
|
} elseif ($profile === true) { // Checks ACL when profile action is denied |
|
643
|
|
|
$userProfile->setAccEditPass(false); |
|
644
|
|
|
$accountAcl->setShowEditPass(false); |
|
645
|
|
|
|
|
646
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
647
|
|
|
} |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
/** |
|
651
|
|
|
* @param AccountAclDto $accountAclDto |
|
652
|
|
|
* |
|
653
|
|
|
* @param array $should |
|
654
|
|
|
* |
|
655
|
|
|
* @param bool $profile |
|
656
|
|
|
* @param bool $acl |
|
657
|
|
|
* |
|
658
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
659
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
660
|
|
|
*/ |
|
661
|
|
|
private function checkEditAndRestore(AccountAclDto $accountAclDto, $should = ['view' => true, 'edit' => true], $profile = true, $acl = true) |
|
662
|
|
|
{ |
|
663
|
|
|
$userProfile = self::$context |
|
664
|
|
|
->getUserProfile() |
|
665
|
|
|
->reset() |
|
666
|
|
|
->setAccEdit($profile); |
|
667
|
|
|
|
|
668
|
|
|
$accountAcl = (new AccountAcl(0)) |
|
669
|
|
|
->setCompiledAccountAccess(true) |
|
670
|
|
|
->setCompiledShowAccess(true) |
|
671
|
|
|
->setResultView($should['view']) |
|
672
|
|
|
->setResultEdit($should['edit']) |
|
673
|
|
|
->setShowEdit($acl) |
|
674
|
|
|
->setShowRestore($acl); |
|
675
|
|
|
|
|
676
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
677
|
|
|
|
|
678
|
|
|
// Checks if ACL returns false when profile action is granted and account access is denied |
|
679
|
|
|
if ($should['view'] === false && $should['edit'] === false) { |
|
680
|
|
|
$userProfile->setAccEdit(true); |
|
681
|
|
|
$accountAcl->setShowEdit(false) |
|
682
|
|
|
->setShowRestore(false); |
|
683
|
|
|
|
|
684
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
685
|
|
|
} elseif ($profile === true) { // Checks ACL when profile action is denied |
|
686
|
|
|
$userProfile->setAccEdit(false); |
|
687
|
|
|
$accountAcl->setShowEdit(false) |
|
688
|
|
|
->setShowRestore(false); |
|
689
|
|
|
|
|
690
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
691
|
|
|
} |
|
692
|
|
|
} |
|
693
|
|
|
|
|
694
|
|
|
/** |
|
695
|
|
|
* @param AccountAclDto $accountAclDto |
|
696
|
|
|
* |
|
697
|
|
|
* @param array $should |
|
698
|
|
|
* |
|
699
|
|
|
* @param bool $profile |
|
700
|
|
|
* @param bool $acl |
|
701
|
|
|
* |
|
702
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
703
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
704
|
|
|
*/ |
|
705
|
|
|
private function checkPermissions(AccountAclDto $accountAclDto, $should = ['view' => true, 'edit' => true], $profile = true, $acl = true) |
|
706
|
|
|
{ |
|
707
|
|
|
$userProfile = self::$context |
|
708
|
|
|
->getUserProfile() |
|
709
|
|
|
->reset() |
|
710
|
|
|
->setAccPermission($profile); |
|
711
|
|
|
|
|
712
|
|
|
$accountAcl = (new AccountAcl(0)) |
|
713
|
|
|
->setCompiledAccountAccess(true) |
|
714
|
|
|
->setCompiledShowAccess(true) |
|
715
|
|
|
->setResultView($should['view']) |
|
716
|
|
|
->setResultEdit($should['edit']) |
|
717
|
|
|
->setShowPermission($acl); |
|
718
|
|
|
|
|
719
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
720
|
|
|
|
|
721
|
|
|
// Checks if ACL returns false when profile action is granted and account access is denied |
|
722
|
|
|
if ($should['view'] === false && $should['edit'] === false) { |
|
723
|
|
|
$userProfile->setAccPermission(true); |
|
724
|
|
|
$accountAcl->setShowPermission(false); |
|
725
|
|
|
|
|
726
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
727
|
|
|
} elseif ($profile === true) { // Checks ACL when profile action is denied |
|
728
|
|
|
$userProfile->setAccPermission(false); |
|
729
|
|
|
$accountAcl->setShowPermission(false); |
|
730
|
|
|
|
|
731
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
732
|
|
|
} |
|
733
|
|
|
} |
|
734
|
|
|
|
|
735
|
|
|
/** |
|
736
|
|
|
* @param AccountAclDto $accountAclDto |
|
737
|
|
|
* |
|
738
|
|
|
* @param array $should |
|
739
|
|
|
* |
|
740
|
|
|
* @param bool $profile |
|
741
|
|
|
* @param bool $acl |
|
742
|
|
|
* |
|
743
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
744
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
745
|
|
|
*/ |
|
746
|
|
|
private function checkViewFiles(AccountAclDto $accountAclDto, $should = ['view' => true, 'edit' => true], $profile = true, $acl = true) |
|
747
|
|
|
{ |
|
748
|
|
|
$userProfile = self::$context |
|
749
|
|
|
->getUserProfile() |
|
750
|
|
|
->reset() |
|
751
|
|
|
->setAccFiles($profile); |
|
752
|
|
|
|
|
753
|
|
|
$accountAcl = (new \SP\Services\Account\AccountAcl(0)) |
|
754
|
|
|
->setCompiledAccountAccess(true) |
|
755
|
|
|
->setCompiledShowAccess(true) |
|
756
|
|
|
->setResultView($should['view']) |
|
757
|
|
|
->setResultEdit($should['edit']) |
|
758
|
|
|
->setShowFiles($acl); |
|
759
|
|
|
|
|
760
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
761
|
|
|
|
|
762
|
|
|
// Checks if ACL returns false when profile action is granted and account access is denied |
|
763
|
|
|
if ($should['view'] === false && $should['edit'] === false) { |
|
764
|
|
|
$userProfile->setAccFiles(true); |
|
765
|
|
|
$accountAcl->setShowFiles(false); |
|
766
|
|
|
|
|
767
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
768
|
|
|
} elseif ($profile === true) { // Checks ACL when profile action is denied |
|
769
|
|
|
$userProfile->setAccFiles(false); |
|
770
|
|
|
$accountAcl->setShowFiles(false); |
|
771
|
|
|
|
|
772
|
|
|
$this->checkForUserByExample($accountAclDto, $accountAcl); |
|
773
|
|
|
} |
|
774
|
|
|
} |
|
775
|
|
|
|
|
776
|
|
|
/** |
|
777
|
|
|
* testGetAclFromCache |
|
778
|
|
|
*/ |
|
779
|
|
|
public function testGetAclFromCache() |
|
780
|
|
|
{ |
|
781
|
|
|
/** @var AccountAclService $service */ |
|
782
|
|
|
$service = self::$service->call($this); |
|
783
|
|
|
|
|
784
|
|
|
$this->assertNull($service->getAclFromCache(1, 10)); |
|
785
|
|
|
} |
|
786
|
|
|
} |
|
787
|
|
|
|