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
|
<?php
namespace Tests\Icinga\Module\Director\Restriction;
use Icinga\Module\Director\Restriction\MatchingFilter;
use Icinga\Module\Director\Test\BaseTestCase;
use Icinga\User;
class MatchingFilterTest extends BaseTestCase
{
public function testUserWithNoRestrictionHasNoFilter()
{
$user = new User('dummy');
$this->assertEquals(
'',
(string) MatchingFilter::forUser($user, 'some/name', 'prop')
);
}
public function testSimpleRestrictionRendersCorrectly()
{
$this->assertEquals(
'prop = a*',
(string) MatchingFilter::forPatterns(['a*'], 'prop')
);
}
public function testMultipleRestrictionsAreCombinedWithOr()
{
$this->assertEquals(
'prop = a* | prop = *b',
(string) MatchingFilter::forPatterns(['a*', '*b'], 'prop')
);
}
public function testUserWithMultipleRestrictionsWorksFine()
{
$user = new User('dummy');
$user->setRestrictions([
'some/name' => ['a*', '*b'],
'some/thing' => ['else']
]);
$this->assertEquals(
'prop = a* | prop = *b',
(string) MatchingFilter::forUser($user, 'some/name', 'prop')
);
}
public function testSingleRestrictionAllowsForPipes()
{
$this->assertEquals(
'prop = a* | prop = *b',
(string) MatchingFilter::forPatterns(['a*|*b'], 'prop')
);
}
}
|