These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | require_once('vendor/autoload.php'); |
||
4 | |||
5 | use PhpAbac\Abac; |
||
6 | |||
7 | $users = include('tests/fixtures/users.php'); |
||
8 | $vehicles = include('tests/fixtures/vehicles.php'); |
||
9 | |||
10 | $abac = new Abac([__DIR__.'/tests/fixtures/policy_rules.yml']); |
||
11 | |||
12 | putenv('SERVICE_STATE=OPEN'); |
||
13 | |||
14 | $user1Nationality = $abac->enforce('nationality-access', $users[3], null, [ |
||
15 | 'cache_result' => true, |
||
16 | 'cache_lifetime' => 100, |
||
17 | 'cache_driver' => 'memory' |
||
18 | ]); |
||
19 | |||
20 | if ($user1Nationality === true) { |
||
21 | echo("GRANTED : The user 1 is able to be nationalized\n"); |
||
22 | } else { |
||
23 | echo("FAIL : The system didn't grant access\n"); |
||
24 | } |
||
25 | |||
26 | $user2Nationality = $abac->enforce('nationality-access', $users[0]); |
||
27 | if ($user2Nationality !== true) { |
||
28 | echo("DENIED : The user 2 is not able to be nationalized because he hasn't done his JAPD\n"); |
||
29 | } else { |
||
30 | echo("FAIL : The system didn't deny access\n"); |
||
31 | } |
||
32 | |||
33 | $user1Vehicle = $abac->enforce('vehicle-homologation', $users[0], $vehicles[0], [ |
||
34 | 'dynamic_attributes' => ['proprietaire' => 1] |
||
35 | ]); |
||
36 | if($user1Vehicle === true) { |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
37 | echo("GRANTED : The vehicle 1 is able to be approved for the user 1\n"); |
||
38 | } else { |
||
39 | echo("FAIL : The system didn't grant access\n"); |
||
40 | } |
||
41 | $user3Vehicle = $abac->enforce('vehicle-homologation', $users[2], $vehicles[1], [ |
||
42 | 'dynamic_attributes' => ['proprietaire' => 3] |
||
43 | ]); |
||
44 | if(!$user3Vehicle !== true) { |
||
0 ignored issues
–
show
|
|||
45 | echo("DENIED : The vehicle 2 is not approved for the user 3 because its last technical review is too old\n"); |
||
46 | } else { |
||
47 | echo("FAIL : The system didn't deny access\n"); |
||
48 | } |
||
49 | $user4Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
||
50 | 'dynamic_attributes' => ['proprietaire' => 4] |
||
51 | ]); |
||
52 | if($user4Vehicle !== true) { |
||
0 ignored issues
–
show
|
|||
53 | echo("DENIED : The vehicle 4 is not able to be approved for the user 4 because he has no driving license\n"); |
||
54 | } else { |
||
55 | echo("FAIL : The system didn't deny access\n"); |
||
56 | } |
||
57 | $user5Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
||
58 | 'dynamic_attributes' => ['proprietaire' => 1] |
||
59 | ]); |
||
60 | if($user5Vehicle !== true) { |
||
0 ignored issues
–
show
|
|||
61 | echo("DENIED : The vehicle 4 is not able to be approved for the user 2 because he doesn't own the vehicle\n"); |
||
62 | } else { |
||
63 | echo("FAIL : The system didn't deny access\n"); |
||
64 | } |
||
65 |