This file is indexed.

/usr/share/phpgacl/test_suite/unit_tests.php is in phpgacl 3.3.7-7.3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<?php
class phpgacl_api_test extends gacl_test_case {
    
    /** VERSION **/
    
    function get_version() {
        $result = $this->gacl_api->get_version();
        //$expected = '/^[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}$/i';
		$expected = '/^[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}[a-zA-Z]{0,1}[0-9]{0,1}$/i';
		
        $this->assertRegexp($expected, $result, 'Version incorrect.');
    }
    function get_schema_version() {
        $result = $this->gacl_api->get_schema_version();
        $expected = '/^[0-9]{1,2}.[0-9]{1,2}$/i';
		
        $this->assertRegexp($expected, $result, 'Schema Version incorrect.');
    }
	
	/** GENERAL **/
	
    function count_all() {
		//Create array
		$arr = array(
			'Level1a' => array(
				'Level2a' => array(
					'Level3a' => 1,
					'Level3b' => 2
				),
				'Level2b' => 3,
			),
			'Level1b' => 4,
			'Level1c' => array(
				'Level2c' => array(
					'Level3c' => 5,
					'Level3d' => 6
				),
				'Level2d' => 7,
			),
			'Level1d' => 8
		);
		
		//Keep in mind count_all only counts actual values. So array()'s don't count as +1        
		$result = $this->gacl_api->count_all($arr);
		
        $this->assertEquals(8, $result, 'Incorrect array count, Should be 8.');
    }
	
	/** ACO SECTION **/
	
    function get_object_section_section_id_aco() {
        $result = $this->gacl_api->get_object_section_section_id('unit_test', 'unit_test', 'ACO');
        $message = 'get_object_section_section_id failed';
		
        $this->assert($result, $message);
        
        return $result;
    }
    
    function add_object_section_aco() {
        $result = $this->gacl_api->add_object_section('unit_test', 'unit_test', 999, 0, 'ACO');
        $message = 'add_object_section failed';
		
        $this->assert($result, $message);
    }
    
    function del_object_section_aco() {
        $result = $this->gacl_api->del_object_section($this->get_object_section_section_id_aco(), 'ACO');
        $message = 'del_object_section failed';
        $this->assert($result, $message);
    }
    
    /** ACO **/
    
    function get_object_id_aco() {
        $result = $this->gacl_api->get_object_id('unit_test','enable_tests', 'ACO');
        $message = 'get_object_id failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function add_object_aco() {
        $result = $this->gacl_api->add_object('unit_test', 'Enable - Tests', 'enable_tests', 999, 0, 'ACO');
        $message = 'add_object failed';
        $this->assert($result, $message);
    }
    
    function del_object_aco() {
        $result = $this->gacl_api->del_object($this->get_object_id_aco(), 'ACO');
        $message = 'del_object failed';
        $this->assert($result, $message);
    }
	
	/** ARO SECTION **/
	
    function get_object_section_section_id_aro() {
        $result = $this->gacl_api->get_object_section_section_id('unit_test', 'unit_test', 'ARO');
        $this->_aco_section_id = $result;
        $message = 'get_object_section_section_id failed';
        $this->assert($result >= 0, $message);
        
        return $result;
    }
    
    function add_object_section_aro() {
        $result = $this->gacl_api->add_object_section('unit_test', 'unit_test', 999, 0, 'ARO');
        $message = 'add_object_section failed';
        $this->assert($result, $message);
    }
    
    function edit_object_section_aro() {
		$object_id = $this->get_object_section_section_id_aro();
		
        $rename_result = $this->gacl_api->edit_object_section($object_id, 'unit_test_tmp', 'unit_test_tmp', 999, 0, 'ARO');
		$rename2_result = $this->gacl_api->edit_object_section($object_id, 'unit_test', 'unit_test', 999, 0, 'ARO');
		
		if ($rename_result === TRUE AND $rename2_result === TRUE) {
			$result = TRUE;
		} else {
			$result = FALSE;
		}
		
        $message = 'edit_object_section failed';
        $this->assert($result, $message);
    }

    function del_object_section_aro() {
        $result = $this->gacl_api->del_object_section($this->get_object_section_section_id_aro(), 'ARO');
        $message = 'del_object_section failed';
        $this->assert($result, $message);
    }
    
    /** ARO **/
    
    function get_object_id_aro() {
        $result = $this->gacl_api->get_object_id('unit_test','john_doe', 'ARO');
        $message = 'get_object_id failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function get_object2_id_aro() {
        $result = $this->gacl_api->get_object_id('unit_test','jane_doe', 'ARO');
        $message = 'get_object2_id failed';
        $this->assert($result, $message);
        
        return $result;
    }
	
    function add_object_aro() {
        $result = $this->gacl_api->add_object('unit_test', 'John Doe', 'john_doe', 999, 0, 'ARO');
        $message = 'add_object failed';
        $this->assert($result, $message);
    }    
    function del_object_aro() {
        $result = $this->gacl_api->del_object($this->get_object_id_aro(), 'ARO');
        $message = 'del_object failed';
        $this->assert($result, $message);
    }
	
    function add_object2_aro() {
        $result = $this->gacl_api->add_object('unit_test', 'Jane Doe', 'jane_doe', 998, 0, 'ARO');
        $message = 'add_object2 failed';
        $this->assert($result, $message);
    }
    function del_object2_aro() {
        $result = $this->gacl_api->del_object($this->get_object2_id_aro(), 'ARO');
        $message = 'del_object2 failed';
        $this->assert($result, $message);
    }
	
	/** AXO SECTION **/
	
    function get_object_section_section_id_axo() {
        $result = $this->gacl_api->get_object_section_section_id('unit_test', 'unit_test', 'AXO');
        $message = 'get_object_section_section_id failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function add_object_section_axo() {
        $result = $this->gacl_api->add_object_section('unit_test', 'unit_test', 999, 0, 'AXO');
        $this->_aco_section_id = $result;
        $message = 'add_object_section failed';
        $this->assert($result, $message);
    }
    
    function del_object_section_axo() {
        $result = $this->gacl_api->del_object_section($this->get_object_section_section_id_axo(), 'AXO');
        $message = 'del_object_section failed';
        $this->assert($result, $message);
    }
    
    /** AXO **/
    
    function get_object_id_axo() {
        $result = $this->gacl_api->get_object_id('unit_test','object_1', 'AXO');
        $message = 'get_object_id failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function add_object_axo() {
        $result = $this->gacl_api->add_object('unit_test', 'Object 1', 'object_1', 999, 0, 'AXO');
        $message = 'add_object failed';
        $this->assert($result, $message);
    }
    
    function del_object_axo() {
        $result = $this->gacl_api->del_object($this->get_object_id_axo(), 'AXO');
        $message = 'del_object failed';
        $this->assert($result, $message);
    }
	
	/** ARO GROUP **/
	
    function get_group_id_parent_aro() {
        $result = $this->gacl_api->get_group_id(NULL, 'ARO Group 1', 'ARO');
        $message = 'get_group_id_parent_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function get_group_id_child_aro() {
        $result = $this->gacl_api->get_group_id(NULL, 'ARO Group 2', 'ARO');
        $message = 'get_group_id_child_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function get_group_parent_id_aro() {
        $parent_id = $this->gacl_api->get_group_parent_id($this->get_group_id_child_aro(), 'ARO');
		//Make sure it matches with the actual parent.
		if ($parent_id === $this->get_group_id_parent_aro() ) {
			$result = TRUE;
		} else {
			$result = FALSE;
		}
        $message = 'get_group_parent_id_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
	
    function get_group_data_aro() {
        list($id, $parent_id, $value, $name, $lft, $rgt) = $this->gacl_api->get_group_data($this->get_group_id_parent_aro(), 'ARO');
		//Check all values in the resulting array.
		if ( $id > 0 AND $parent_id >= 0 AND strlen($name) > 0 AND $lft >= 1 AND $rgt > 1) {
			$result = TRUE;
		} else  {
			$result = FALSE;
		}
        $message = 'get_group_data_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
	
    function get_parent_group_objects_aro() {
        $group_objects = $this->gacl_api->get_group_objects($this->get_group_id_parent_aro(), 'ARO');
		if (count($group_objects, COUNT_RECURSIVE) == 2 AND $group_objects['unit_test'][0] == 'john_doe') {
			$result = TRUE;
		} else {
			$result = FALSE;
		}
        $message = 'get_parent_group_objects_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
	
    function get_parent_group_objects_recurse_aro() {
        $group_objects = $this->gacl_api->get_group_objects($this->get_group_id_parent_aro(), 'ARO', 'RECURSE');
		
		switch (TRUE) {
			case count($group_objects) != 1:
			case !isset($group_objects['unit_test']):
			case count($group_objects['unit_test']) != 2:
			case !in_array('john_doe', $group_objects['unit_test']):
			case !in_array('jane_doe', $group_objects['unit_test']):
				$result = FALSE;
				break;
			default:
				$result = TRUE;
		}
		
        $message = 'get_parent_group_objects_recurse_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
	
    function add_group_parent_aro() {
        $result = $this->gacl_api->add_group('group_1', 'ARO Group 1', 0, 'ARO');
        $message = 'add_group_parent_aro failed';
        $this->assert($result, $message);
    }
    
    function edit_group_parent_aro() {
		$group_id = $this->get_group_id_parent_aro();
		
        $first_rename = $this->gacl_api->edit_group($group_id, 'group_1_tmp', 'ARO Group 1 - tmp', 0, 'ARO');
		$second_rename = $this->gacl_api->edit_group($group_id,'group_1', 'ARO Group 1', 0, 'ARO');
		$reparent_to_self = $this->gacl_api->edit_group($group_id,'group_1', 'ARO Group 1', $group_id, 'ARO');
		
		if ($first_rename === TRUE AND $second_rename === TRUE AND $reparent_to_self === FALSE) {
			$result = TRUE;
		} else {
			$result = FALSE;
		}
        $message = 'edit_group_parent_aro failed';
        $this->assert($result, $message);
    }

    function del_group_parent_reparent_aro() {
		$this->add_group_parent_aro();
		$this->add_group_child_aro();
		$this->add_parent_group_object_aro();
		$this->add_child_group_object_aro();

        $result = $this->gacl_api->del_group($this->get_group_id_parent_aro(), TRUE, 'ARO');
		
		$this->del_child_group_object_aro();
		$this->del_group_child_aro();

        $message = 'del_group_parent_no_reparent_aro failed';
        $this->assert($result, $message);
    }

    function del_group_parent_no_reparent_aro() {
		$this->add_group_parent_aro();
		$this->add_group_child_aro();
		$this->add_parent_group_object_aro();
		$this->add_child_group_object_aro();
		
        $result = $this->gacl_api->del_group($this->get_group_id_parent_aro(), FALSE, 'ARO');
		
        $message = 'del_group_parent_reparent_aro failed';
        $this->assert($result, $message);
    }


    function del_group_parent_aro() {
        $result = $this->gacl_api->del_group($this->get_group_id_parent_aro(), TRUE, 'ARO');
        $message = 'del_group_parent_aro failed';
        $this->assert($result, $message);
    }
    
    function add_group_child_aro() {
        $result = $this->gacl_api->add_group('group_2', 'ARO Group 2', $this->get_group_id_parent_aro(), 'ARO');
        $message = 'add_group_child failed';
        $this->assert($result, $message);
    }
    
    function del_group_child_aro() {
        $result = $this->gacl_api->del_group($this->get_group_id_child_aro(), TRUE, 'ARO');
        $message = 'del_group failed';
        $this->assert($result, $message);
    }
    
    function add_parent_group_object_aro() {
        $result = $this->gacl_api->add_group_object($this->get_group_id_parent_aro(), 'unit_test', 'john_doe', 'ARO');
        $message = 'add_parent_group_object failed';
        $this->assert($result, $message);
    }
    function del_parent_group_object_aro() {
        $result = $this->gacl_api->del_group_object($this->get_group_id_parent_aro(), 'unit_test', 'john_doe', 'ARO');
        $message = 'del_group_object failed';
        $this->assert($result, $message);
    }
	
    function add_child_group_object_aro() {
        $result = $this->gacl_api->add_group_object($this->get_group_id_child_aro(), 'unit_test', 'jane_doe', 'ARO');
        $message = 'add_child_group_object failed';
        $this->assert($result, $message);
    }
    function del_child_group_object_aro() {
        $result = $this->gacl_api->del_group_object($this->get_group_id_child_aro(), 'unit_test', 'jane_doe', 'ARO');
        $message = 'del_child_group_object failed';
        $this->assert($result, $message);
    }
	
	/** AXO GROUP **/
	
    function get_group_id_parent_axo() {
        $result = $this->gacl_api->get_group_id(NULL, 'AXO Group 1', 'AXO');
        $message = 'get_group_id_parent_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function get_group_id_child_axo() {
        $result = $this->gacl_api->get_group_id(NULL, 'AXO Group 2', 'AXO');
        $message = 'get_group_id_child_axo failed';
        $this->assert($result, $message);
        
        return $result;
    }
    
    function get_group_parent_id_axo() {
        $parent_id = $this->gacl_api->get_group_parent_id($this->get_group_id_child_axo(), 'AXO');
		//Make sure it matches with the actual parent.
		if ($parent_id === $this->get_group_id_parent_axo() ) {
			$result = TRUE;
		} else {
			$result = FALSE;
		}
        $message = 'get_group_parent_id_aro failed';
        $this->assert($result, $message);
        
        return $result;
    }
	
    function get_group_data_axo() {
        list($id, $parent_id, $value, $name, $lft, $rgt) = $this->gacl_api->get_group_data($this->get_group_id_parent_axo(), 'AXO');
		//Check all values in the resulting array.
		if ( $id > 0 AND $parent_id >= 0 AND strlen($name) > 0 AND $lft >= 1 AND $rgt > 1) {
			$result = TRUE;
		} else  {
			$result = FALSE;
		}
        $message = 'get_group_data_axo failed';
        $this->assert($result, $message);
        
        return $result;
    }
	
    function add_group_parent_axo() {
        $result = $this->gacl_api->add_group('group_1', 'AXO Group 1', 0, 'AXO');
        $message = 'add_group failed';
        $this->assert($result, $message);
    }
    
    function del_group_parent_axo() {
        $result = $this->gacl_api->del_group($this->get_group_id_parent_axo(), TRUE, 'AXO');
        $message = 'del_group failed';
        $this->assert($result, $message);
    }
    
    function add_group_child_axo() {
        $result = $this->gacl_api->add_group('group_2', 'AXO Group 2', $this->get_group_id_parent_axo(), 'AXO');
        $message = 'add_group failed';
        $this->assert($result, $message);
    }
    
    function del_group_child_axo() {
        $result = $this->gacl_api->del_group($this->get_group_id_child_axo(), TRUE, 'AXO');
        $message = 'del_group failed';
        $this->assert($result, $message);
    }
    
    function add_group_object_axo() {
        $result = $this->gacl_api->add_group_object($this->get_group_id_parent_axo(), 'unit_test', 'object_1', 'AXO');
        $message = 'add_group_object failed';
        $this->assert($result, $message);
    }
    
    function del_group_object_axo() {
        $result = $this->gacl_api->del_group_object($this->get_group_id_parent_axo(), 'unit_test', 'object_1', 'AXO');
        $message = 'del_group_object failed';
        $this->assert($result, $message);
    }
}

// initialise test suite
$suite = new gacl_test_suite;

//This comes in handy.
//$suite->gacl_api->db->debug=TRUE;

// general
$suite->addTest(new phpgacl_api_test('get_version'));
$suite->addTest(new phpgacl_api_test('get_schema_version'));

$suite->addTest(new phpgacl_api_test('count_all'));

// build structure
$suite->addTest(new phpgacl_api_test('add_object_section_aco'));
$suite->addTest(new phpgacl_api_test('get_object_section_section_id_aco'));
$suite->addTest(new phpgacl_api_test('add_object_aco'));
$suite->addTest(new phpgacl_api_test('get_object_id_aco'));

$suite->addTest(new phpgacl_api_test('add_object_section_aro'));
$suite->addTest(new phpgacl_api_test('get_object_section_section_id_aco'));
$suite->addTest(new phpgacl_api_test('add_object_aro'));
//Test the below with ACLs as well... I haven't gotten around to that just yet.
$suite->addTest(new phpgacl_api_test('edit_object_section_aro'));
$suite->addTest(new phpgacl_api_test('get_object_id_aro'));
$suite->addTest(new phpgacl_api_test('add_object2_aro'));
$suite->addTest(new phpgacl_api_test('get_object2_id_aro'));

$suite->addTest(new phpgacl_api_test('add_object_section_axo'));
$suite->addTest(new phpgacl_api_test('get_object_section_section_id_axo'));
$suite->addTest(new phpgacl_api_test('add_object_axo'));
$suite->addTest(new phpgacl_api_test('get_object_id_axo'));

$suite->addTest(new phpgacl_api_test('add_group_parent_aro'));
$suite->addTest(new phpgacl_api_test('edit_group_parent_aro'));
$suite->addTest(new phpgacl_api_test('get_group_id_parent_aro'));
$suite->addTest(new phpgacl_api_test('get_group_data_aro')); 
$suite->addTest(new phpgacl_api_test('add_group_child_aro'));
$suite->addTest(new phpgacl_api_test('get_group_id_child_aro'));
$suite->addTest(new phpgacl_api_test('get_group_parent_id_aro'));

$suite->addTest(new phpgacl_api_test('add_parent_group_object_aro'));
//Try adding twice. Both times should return true.
$suite->addTest(new phpgacl_api_test('add_parent_group_object_aro'));
$suite->addTest(new phpgacl_api_test('add_child_group_object_aro'));

$suite->addTest(new phpgacl_api_test('get_parent_group_objects_aro'));
$suite->addTest(new phpgacl_api_test('get_parent_group_objects_recurse_aro'));


$suite->addTest(new phpgacl_api_test('add_group_parent_axo'));
$suite->addTest(new phpgacl_api_test('get_group_id_parent_axo'));
$suite->addTest(new phpgacl_api_test('get_group_data_axo')); 
$suite->addTest(new phpgacl_api_test('add_group_child_axo'));
$suite->addTest(new phpgacl_api_test('get_group_id_child_axo'));
$suite->addTest(new phpgacl_api_test('add_group_object_axo'));
$suite->addTest(new phpgacl_api_test('get_group_parent_id_axo'));


// clean up...
$suite->addTest(new phpgacl_api_test('del_parent_group_object_aro'));
$suite->addTest(new phpgacl_api_test('del_child_group_object_aro'));
$suite->addTest(new phpgacl_api_test('del_group_child_aro'));
$suite->addTest(new phpgacl_api_test('del_group_parent_aro'));

$suite->addTest(new phpgacl_api_test('del_group_object_axo'));
$suite->addTest(new phpgacl_api_test('del_group_child_axo'));
$suite->addTest(new phpgacl_api_test('del_group_parent_axo'));

$suite->addTest(new phpgacl_api_test('del_object_aco'));
$suite->addTest(new phpgacl_api_test('del_object_section_aco'));

//Test group reparenting - Order of this test is important.
$suite->addTest(new phpgacl_api_test('del_group_parent_no_reparent_aro'));
$suite->addTest(new phpgacl_api_test('del_group_parent_reparent_aro'));

$suite->addTest(new phpgacl_api_test('del_object_aro'));
$suite->addTest(new phpgacl_api_test('del_object2_aro'));
$suite->addTest(new phpgacl_api_test('del_object_section_aro'));

$suite->addTest(new phpgacl_api_test('del_object_axo'));
$suite->addTest(new phpgacl_api_test('del_object_section_axo'));

// run tests
echo '<p>Running API tests... ';
$suite->run($result);
echo '<b>Done</b></p>';

unset ($suite);

// done.

?>