ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilRBACTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program 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 General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 {
36  protected $backupGlobals = FALSE;
37 
38  protected function setUp()
39  {
40  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
41  ilUnitUtil::performInitialisation();
42  }
43 
50  public function testRbacFA()
51  {
52  global $rbacreview,$rbacadmin;
53 
54  // Protected
55  #$rbacadmin->setProtected(1,4,'y');
56  #$prot = $rbacreview->isProtected(8,4);
57  #$this->assertEquals($prot,true);
58  #$rbacadmin->setProtected(1,4,'n');
59  #$prot = $rbacreview->isProtected(8,4);
60  #$this->assertEquals($prot,false);
61 
62  $rbacreview->getRoleListByObject(8);
63  $rbacreview->getAssignableRoles();
64 
65 
66  $ass = $rbacreview->isAssignable(4,8);
67  $this->assertEquals($ass,true);
68 
69  $roles = $rbacreview->getRolesOfObject(8);
70 
71  $obj = $rbacreview->getObjectOfRole(4);
72  $this->assertEquals(8,$obj);
73  }
74 
79  public function testRbacUA()
80  {
81  global $rbacreview,$rbacadmin;
82 
83  $obj = ilUtil::_getObjectsByOperations('crs','join');
84 
85  $rbacreview->assignedUsers(4);
86  $rbacreview->assignedRoles(6);
87  }
88 
95  public function testRbacTA()
96  {
97  global $rbacreview,$rbacadmin;
98 
99  $sess_ops = $rbacreview->getOperationsOnTypeString('sess');
100 
101  $rbacadmin->assignOperationToObject($rbacreview->getTypeId('sess'),'7');
102  //$new_sess_ops = $rbacreview->getOperationsOnTypeString('sess');
103  //$this->assertEquals(array_merge($sess_ops,array(7)),$new_sess_ops);
104 
105  $rbacadmin->deassignOperationFromObject($rbacreview->getTypeId('sess'),'7');
106  $new_sess_ops = $rbacreview->getOperationsOnTypeString('sess');
107  $this->assertEquals($sess_ops,$new_sess_ops);
108  }
109 
114  public function testRbacPA()
115  {
116  global $rbacreview,$rbacadmin;
117 
118  $sess_ops = $rbacreview->getOperationsOnTypeString('cat');
119 
120  $rbacadmin->revokePermission(1,4);
121  $rbacadmin->grantPermission(4,array(2,3),1);
122 
123  }
124 
131  public function testConditions()
132  {
133  include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
134 
137 
138  $handler = new ilConditionHandler();
139  $handler->setTargetRefId(99999);
140  $handler->setTargetObjId(99998);
141  $handler->setTargetType('xxx');
142  $handler->setTriggerRefId(99997);
143  $handler->setTriggerObjId(99996);
144  $handler->setTriggerType('yyy');
145  $handler->setReferenceHandlingType(0);
146  $handler->enableAutomaticValidation(false);
147  $suc = $handler->storeCondition();
148  $this->assertEquals($suc,true);
149 
150  $suc = $handler->checkExists();
151  $this->assertEquals($suc,false);
152 
153  $suc = $handler->delete(99999);
154  $this->assertEquals($suc,true);
155 
156  // syntax check
157  $handler->deleteByObjId(-1);
158  $handler->deleteCondition(-1);
162  }
163 
167  public function testCache()
168  {
169  include_once './Services/AccessControl/classes/class.ilAccessHandler.php';
170 
171  $handler = new ilAccessHandler();
172  $handler->setResults(array(1,2,3));
173  $handler->storeCache();
174  $handler->readCache();
175  $res = $handler->getResults();
176 
177  $this->assertEquals(array(1,2,3),$res);
178  }
179 
187  public function testAssignUser()
188  {
189  global $rbacreview, $rbacadmin;
190  //assign User 15 to role 10
191  $rbacadmin->assignUser(10,15);
192 
193  $this->assertTrue($rbacreview->isAssigned(15,10));
194 
195  //Test double assign
196  $rbacadmin->assignUser(10,15);
197  }
198 
207  public function testDeassignUser()
208  {
209  global $rbacreview, $rbacadmin;
210  //deassign User 15 from role 10
211  $rbacadmin->deassignUser(10,15);
212 
213  $this->assertFalse($rbacreview->isAssigned(15,10));
214  }
215 
223  public function testGrantPermission()
224  {
225  global $rbacreview, $rbacadmin;
226  //grant permissions 10,20 and 30 for role 10 on object 60
227  $rbacadmin->grantPermission(10,array(10,20,30),60);
228 
229  $this->assertEquals($rbacreview->getActiveOperationsOfRole(60,10), array(10,20,30));
230  }
231 
241  public function testRevokePermission()
242  {
243  global $rbacreview, $rbacadmin, $ilDB;
244 
245  $req = $ilDB->query("SELECT ref.ref_id FROM object_reference AS ref LEFT JOIN object_data AS data ON data.obj_id = ref.obj_id WHERE data.type='seas';");
246 
247  $ref_id = 0;
248 
249  while($row = $ilDB->fetchAssoc($req))
250  {
251  $ref_id = $row["ref_id"];
252  }
253 
254  $req = $ilDB->query("SELECT obj_id FROM object_data WHERE type='role';");
255  $ilDB->fetchAssoc($req);//First role is protected. Dont use it!
256  $role1 = $ilDB->fetchAssoc($req)["obj_id"];
257  $role2 = $ilDB->fetchAssoc($req)["obj_id"];
258  $role3 = $ilDB->fetchAssoc($req)["obj_id"];
259 
260  //save normal operations
261  $opt1 = $rbacreview->getActiveOperationsOfRole($ref_id,$role1);
262  $opt2 = $rbacreview->getActiveOperationsOfRole($ref_id,$role2);
263  $opt3 = $rbacreview->getActiveOperationsOfRole($ref_id,$role3);
264 
265  $rbacadmin->grantPermission($role1, array(1,2,3,4,5), $ref_id);
266  $rbacadmin->grantPermission($role2, array(1,2,3,4,5), $ref_id);
267  //$this->assertEquals($rbacreview->getActiveOperationsOfRole($ref_id,$role1), array(1,2,3,4,5));
268  //$this->assertEquals($rbacreview->getActiveOperationsOfRole($ref_id,$role2), array(1,2,3,4,5));
269  $rbacadmin->revokePermission($ref_id);
270  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($ref_id,$role1));
271  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($ref_id,$role2));
272 
273 
274  $rbacadmin->grantPermission($role1, array(1,2,3,4,5), $ref_id);
275  //$this->assertEquals($rbacreview->getActiveOperationsOfRole($ref_id,$role1), array(1,2,3,4,5));
276  $rbacadmin->revokePermission($ref_id, $role1);
277  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($ref_id,$role1));
278 
279 
280  $rbacadmin->grantPermission($role2, array(1,2,3,4,5), $ref_id);
281  $rbacadmin->grantPermission($role3, array(1,2,3,4,5), $ref_id);
282  //$this->assertEquals($rbacreview->getActiveOperationsOfRole($ref_id,$role2), array(1,2,3,4,5));
283  //$this->assertEquals($rbacreview->getActiveOperationsOfRole($ref_id,$role3), array(1,2,3,4,5));
284  $rbacadmin->revokePermission($ref_id,0,false);
285  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($ref_id,$role2));
286  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($ref_id,$role3));
287 
288  $rbacadmin->grantPermission($role3, array(1,2,3,4,5), $ref_id);
289  //$this->assertEquals($rbacreview->getActiveOperationsOfRole($ref_id,$role3), array(1,2,3,4,5));
290  $rbacadmin->revokePermission($ref_id, $role3, false);
291  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($ref_id,$role3));
292 
293  //set normal operations
294  $rbacadmin->grantPermission($role1, $opt1, $ref_id);
295  $rbacadmin->grantPermission($role2, $opt2, $ref_id);
296  $rbacadmin->grantPermission($role3, $opt3, $ref_id);
297  }
298 
308  {
309  global $rbacreview, $rbacadmin, $tree, $ilDB;
310  $req = $ilDB->query("SELECT ref.ref_id FROM object_reference AS ref LEFT JOIN object_data AS data ON data.obj_id = ref.obj_id WHERE data.type='adm';");
311 
312  $ref_id = 0;
313 
314  while($row = $ilDB->fetchAssoc($req))
315  {
316  $ref_id = $row["ref_id"];
317  }
318 
319  $childs = $tree->getChildIds($ref_id);
320 
321  $req = $ilDB->query("SELECT obj_id FROM object_data WHERE type='role';");
322  $ilDB->fetchAssoc($req);//First role is protected. Dont use it!
323  $role = $ilDB->fetchAssoc($req)["obj_id"];
324 
325  $ops = array();
326 
327  foreach($childs as $id)
328  {
329  $ops[$id] = $rbacreview->getActiveOperationsOfRole($id,$role);//save normal operations
330  $rbacadmin->grantPermission($role, array(1,2,3,4,5),$id);
331  //$this->assertEquals($rbacreview->getActiveOperationsOfRole($id,$role), array(1,2,3,4,5));
332  }
333 
334  $rbacadmin->revokeSubtreePermissions($ref_id,$role);
335 
336  foreach($childs as $id)
337  {
338  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($id,$role));
339  $rbacadmin->grantPermission($role, $ops[$id],$id);//set normal operations
340  }
341  }
342 
351  public function testRevokePermissionList()
352  {
353  global $rbacreview, $rbacadmin;
354  $list = array(1001, 1003, 1005, 1007);
355 
356  foreach($list as $id)
357  {
358  $rbacadmin->grantPermission(123, array(1,2,3,4,5),$id);
359  }
360 
361  $rbacadmin->revokePermissionList($list, 123);
362 
363  foreach($list as $id)
364  {
365  $this->assertEmpty($rbacreview->getActiveOperationsOfRole($id,123));
366  }
367  }
368 
376  public function testSetRolePermission()
377  {
378  global $rbacreview, $rbacadmin;
379  $rbacadmin->deleteTemplate(1010);
380 
381  $rbacadmin->setRolePermission(1010,"a",array(10,11,13,15),1100);
382  $rbacadmin->setRolePermission(1010,"b",array(20,22,23,25),1100);
383 
384  $assert = array("a" => array(10,11,13,15),"b" => array(20,22,23,25));
385  $dest = $rbacreview->getAllOperationsOfRole(1010,1100);
386 
387  sort($dest["a"]);
388  sort($dest["b"]);
389 
390  $this->assertEquals($assert, $dest);
391 
392  $rbacadmin->deleteTemplate(1010);
393  }
394 
403  public function testDeleteRolePermission()
404  {
405  global $rbacreview, $rbacadmin;
406  $rbacadmin->deleteTemplate(1010);
407 
408  $rbacadmin->setRolePermission(1010,"a",array(10,11,13,15),1100);
409  $rbacadmin->setRolePermission(1010,"b",array(20,22,23,25),1100);
410 
411  $rbacadmin->deleteRolePermission(1010,1100);
412 
413  $this->assertEmpty($rbacreview->getAllOperationsOfRole(1010,1100));
414 
415  $rbacadmin->setRolePermission(1010,"a",array(10,11,13,15),1100);
416  $rbacadmin->setRolePermission(1010,"b",array(20,22,23,25),1100);
417 
418  $rbacadmin->deleteRolePermission(1010,1100, "a");
419 
420  $assert = array("b" => array(20,22,23,25));
421  $dest = $rbacreview->getAllOperationsOfRole(1010,1100);
422 
423  sort($dest["b"]);
424 
425  $this->assertEquals($assert, $dest);
426 
427  $rbacadmin->deleteTemplate(1010);
428  }
429 
439  {
440  global $rbacreview, $rbacadmin;
441  $rbacadmin->deleteTemplate(1010);
442  $rbacadmin->deleteTemplate(2020);
443 
444  $rbacadmin->setRolePermission(1010,"blub",array(10,11),1100);
445  $rbacadmin->setRolePermission(2020,"bulb",array(20,22),2200);
446 
447  $rbacadmin->copyRoleTemplatePermissions(1010,1100,2200,2020);
448 
449  $one = $rbacreview->getAllOperationsOfRole(1010,1100);
450  $two = $rbacreview->getAllOperationsOfRole(2020,2200);
451  sort($one["blub"]);
452  sort($two["blub"]);
453  $this->assertEquals($one, $two);
454  $rbacadmin->deleteTemplate(1010);
455  $rbacadmin->deleteTemplate(2020);
456  }
457 
469  public function testCopyRolePermissions()
470  {
471  global $rbacreview, $rbacadmin, $ilDB;
472 
473  $req = $ilDB->query("SELECT ref.ref_id FROM object_reference AS ref LEFT JOIN object_data AS data ON data.obj_id = ref.obj_id WHERE data.type='seas';");
474 
475  $seas = 0;
476 
477  while($row = $ilDB->fetchAssoc($req))
478  {
479  $seas = $row["ref_id"];
480  }
481 
482  $req = $ilDB->query("SELECT ref.ref_id FROM object_reference AS ref LEFT JOIN object_data AS data ON data.obj_id = ref.obj_id WHERE data.type='mail';");
483 
484  $mail = 0;
485 
486  while($row = $ilDB->fetchAssoc($req))
487  {
488  $mail = $row["ref_id"];
489  }
490 
491  $req = $ilDB->query("SELECT obj_id FROM object_data WHERE type='role';");
492  $ilDB->fetchAssoc($req);//First role is protected. Dont use it!
493  $role = $ilDB->fetchAssoc($req)["obj_id"];
494 
495  //save normal operations
496  $opt_mail = $rbacreview->getActiveOperationsOfRole($mail, $role);
497  $opt_seas = $rbacreview->getActiveOperationsOfRole($seas, $role);
498  $opt_temp_seas = $rbacreview->getAllOperationsOfRole($role, $seas);
499  $opt_temp_mail = $rbacreview->getAllOperationsOfRole($role, $mail);
500 
501  //set values
502  $rbacadmin->setRolePermission($role, "mail", array(1,2,3,4,5),$mail);
503  $rbacadmin->grantPermission($role, array(1,2,3,4,5), $mail);
504  $rbacadmin->setRolePermission($role, "seas", array(5,6,7,8,9),$seas);
505  $rbacadmin->grantPermission($role, array(5,6,7,8,9), $seas);
506 
507  $rbacadmin->copyRolePermissions($role,$seas,$mail, $role);
508  $this->assertEquals($rbacreview->getActiveOperationsOfRole($seas, $role),
509  $rbacreview->getActiveOperationsOfRole($mail, $role));
510 
511  //set normal operations
512  $rbacadmin->grantPermission($role,$opt_seas,$seas);
513  $rbacadmin->grantPermission($role,$opt_mail,$mail);
514 
515  $rbacadmin->deleteRolePermission($role,$mail);
516  $rbacadmin->deleteRolePermission($role,$seas);
517 
518  foreach($opt_temp_seas as $type => $opt)
519  {
520  $rbacadmin->setRolePermission($role, $type, $opt,$seas);
521  }
522 
523  foreach($opt_temp_mail as $type => $opt)
524  {
525  $rbacadmin->setRolePermission($role, $type, $opt,$mail);
526  }
527 
528  }
529 
539  {
540  global $rbacreview, $rbacadmin;
541  $rbacadmin->deleteTemplate(1010);
542  $rbacadmin->deleteTemplate(2020);
543  $rbacadmin->deleteTemplate(3030);
544 
545  $rbacadmin->setRolePermission(1010,"a",array(10,11,13,15),1100);
546  $rbacadmin->setRolePermission(2020,"a",array(11,12,13,16),2200);
547 
548  $rbacadmin->setRolePermission(1010,"b",array(20,22,23,25),1100);
549  $rbacadmin->setRolePermission(2020,"b",array(20,23,24,26),2200);
550 
551  $rbacadmin->setRolePermission(3030,"c",array(30,33),3300);
552  $rbacadmin->setRolePermission(3030,"a",array(30,33),3300);
553  $rbacadmin->setRolePermission(3030,"b",array(30,33),3300);
554 
555  $rbacadmin->copyRolePermissionIntersection(1010,1100,2020,2200,3300,3030);
556 
557  $intersect = array("a" => array(11,13), "b" => array(20,23));
558  $dest = $rbacreview->getAllOperationsOfRole(3030,3300);
559 
560  //sort
561  sort($dest["a"]);
562  sort($dest["b"]);
563 
564  $this->assertEquals($intersect, $dest);
565 
566  $rbacadmin->deleteTemplate(1010);
567  $rbacadmin->deleteTemplate(2020);
568  $rbacadmin->deleteTemplate(3030);
569  }
570 
580  public function testCopyRolePermissionUnion()
581  {
582  global $rbacreview, $rbacadmin;
583  $rbacadmin->deleteTemplate(1010);
584  $rbacadmin->deleteTemplate(2020);
585  $rbacadmin->deleteTemplate(3030);
586 
587  $rbacadmin->setRolePermission(1010,"a",array(10,11,13,15),1100);
588  $rbacadmin->setRolePermission(2020,"a",array(11,12,13,16),2200);
589 
590  $rbacadmin->setRolePermission(1010,"b",array(20,22,23,25),1100);
591  $rbacadmin->setRolePermission(2020,"b",array(20,23,24,26),2200);
592 
593  $rbacadmin->setRolePermission(1010,"c",array(30,33,34,35),1100);
594 
595  $rbacadmin->copyRolePermissionUnion(1010,1100,2020,2200,3030,3300);
596 
597  $union = array("a" => array(10,11,12,13,15,16), "b" => array(20,22,23,24,25,26), "c" => array(30,33,34,35));
598  $dest = $rbacreview->getAllOperationsOfRole(3030,3300);
599 
600  sort($dest["a"]);
601  sort($dest["b"]);
602  sort($dest["c"]);
603 
604  $this->assertEquals($union, $dest);
605 
606  $rbacadmin->deleteTemplate(1010);
607  $rbacadmin->deleteTemplate(2020);
608  $rbacadmin->deleteTemplate(3030);
609  }
610 
620  {
621  global $rbacreview, $rbacadmin;
622  $rbacadmin->deleteTemplate(1010);
623  $rbacadmin->deleteTemplate(2020);
624 
625  $rbacadmin->setRolePermission(1010,"a",array(10,11,13,15),1100);
626  $rbacadmin->setRolePermission(2020,"a",array(11,12,13,16),2200);
627 
628  $rbacadmin->setRolePermission(1010,"b",array(20,22,23,25),1100);
629  $rbacadmin->setRolePermission(2020,"b",array(20,23,24,26),2200);
630 
631  $rbacadmin->setRolePermission(2020,"c",array(30,33,34,35),2200);
632 
633  $rbacadmin->copyRolePermissionSubtract(1010,1100,2020,2200);
634 
635  $subtract = array("a" => array(12,16), "b" => array(24,26), "c" => array(30,33,34,35));
636  $dest = $rbacreview->getAllOperationsOfRole(2020,2200);
637 
638  sort($dest["a"]);
639  sort($dest["b"]);
640  sort($dest["c"]);
641 
642  $this->assertEquals($subtract, $dest);
643 
644  $rbacadmin->deleteTemplate(1010);
645  $rbacadmin->deleteTemplate(2020);
646  }
647 
655  public function testAssignOperationToObject()
656  {
657  global $rbacreview, $rbacadmin;
658 
659  $rbacadmin->assignOperationToObject(1001,10);
660  $rbacadmin->assignOperationToObject(1001,20);
661 
662  $this->assertEquals($rbacreview->getOperationsOnType(1001), array(10,20));
663  }
664 
672  {
673  global $rbacreview, $rbacadmin;
674  $rbacadmin->deassignOperationFromObject(1001,10);
675 
676  $this->assertEquals($rbacreview->getOperationsOnType(1001), array(20));
677 
678  $rbacadmin->deassignOperationFromObject(1001,20);
679 
680  $this->assertEmpty($rbacreview->getOperationsOnType(1001));
681  }
682 
683 }
684 ?>
testRbacPA()
test rbac_pa IL_Init
Definition: ilRBACTest.php:114
static _getConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_type="")
get all conditions of target object
testGrantPermission()
Test grant Permission Method DB: rbac_pa.
Definition: ilRBACTest.php:223
testCopyRoleTemplatePermissions()
Test Copy Role Template Permission Method DB: rbac_template.
Definition: ilRBACTest.php:438
testRevokePermission()
Test revoke Permission Method DB: rbac_pa.
Definition: ilRBACTest.php:241
static _getObjectsByOperations($a_obj_type, $a_operation, $a_usr_id=0, $limit=0)
Get all objects of a specific type and check access This function is not recursive, instead it parses the serialized rbac_pa entries.
testAssignUser()
Test Assign User Method DB: rbac_ua.
Definition: ilRBACTest.php:187
static _getConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
get all conditions of trigger object
testSetRolePermission()
Test Set Role Permission Method DB: rbac_template.
Definition: ilRBACTest.php:376
testCopyRolePermissions()
Test Method DB: rbac_template DB: rbac_pa.
Definition: ilRBACTest.php:469
testRevokePermissionList()
Test revokePermissionList Method DB: rbac_pa.
Definition: ilRBACTest.php:351
testCache()
IL_Init
Definition: ilRBACTest.php:167
testRbacUA()
test rbac_ua IL_Init
Definition: ilRBACTest.php:79
testAssignOperationToObject()
Test assignOperationToObject Method DB: rbac_ta.
Definition: ilRBACTest.php:655
Unit tests for tree table needsInstalledILIAS.
Definition: ilRBACTest.php:34
testConditions()
test preconditions IL_Init
Definition: ilRBACTest.php:131
testDeassignUser()
Test deassign user Method DB: rbac_ua.
Definition: ilRBACTest.php:207
static _getDistinctTargetRefIds()
Get all target ref ids.
static _deleteTargetConditionsByRefId($a_target_ref_id)
Delete conditions by target ref id Note: only conditions on the target type are deleted Conditions on...
Create styles array
The data for the language used.
Handles conditions for accesses to different ILIAS objects.
testRbacTA()
rbac ta test IL_Init
Definition: ilRBACTest.php:95
$ref_id
Definition: sahs_server.php:39
testCopyRolePermissionUnion()
Test Copy Role Permission Union Method DB: rbac_template.
Definition: ilRBACTest.php:580
testRbacFA()
RBAC FA tests IL_Init.
Definition: ilRBACTest.php:50
global $ilDB
testCopyRolePermissionIntersection()
Test Copy Role Permission Intersection Method DB: rbac_template.
Definition: ilRBACTest.php:538
testCopyRolePermissionSubtract()
Test Copy Role Permission Subtract Method DB: rbac_template.
Definition: ilRBACTest.php:619
testDeassignOperationFromObject()
Test deassignOperationFromObject Method ilRbacReview $rbacreview ilRbacAdmin $rbacadmin testAssign...
Definition: ilRBACTest.php:671
testRevokeSubtreePermissions()
Test revokeSubtreePermissions Method DB: rbac_pa.
Definition: ilRBACTest.php:307
testDeleteRolePermission()
Test Delete Role Permission Method DB: rbac_template.
Definition: ilRBACTest.php:403
Class ilAccessHandler.