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 | $visas = include('tests/fixtures/visas.php'); |
||
8 | $users = include('tests/fixtures/users.php'); |
||
9 | $vehicles = include('tests/fixtures/vehicles.php'); |
||
10 | |||
11 | $abac = new Abac([__DIR__.'/tests/fixtures/policy_rules.yml']); |
||
12 | |||
13 | putenv('SERVICE_STATE=OPEN'); |
||
14 | |||
15 | $user1Nationality = $abac->enforce('nationality-access', $users[3], null, [ |
||
16 | 'cache_result' => true, |
||
17 | 'cache_lifetime' => 100, |
||
18 | 'cache_driver' => 'memory' |
||
19 | ]); |
||
20 | |||
21 | if ($user1Nationality === true) { |
||
22 | echo("GRANTED : The user 1 is able to be nationalized\n"); |
||
23 | } else { |
||
24 | echo("FAIL : The system didn't grant access\n"); |
||
25 | } |
||
26 | |||
27 | $user2Nationality = $abac->enforce('nationality-access', $users[0]); |
||
28 | if ($user2Nationality !== true) { |
||
29 | echo("DENIED : The user 2 is not able to be nationalized because he hasn't done his JAPD\n"); |
||
30 | } else { |
||
31 | echo("FAIL : The system didn't deny access\n"); |
||
32 | } |
||
33 | |||
34 | $user1Vehicle = $abac->enforce('vehicle-homologation', $users[0], $vehicles[0], [ |
||
35 | 'dynamic_attributes' => ['proprietaire' => 1] |
||
36 | ]); |
||
37 | if($user1Vehicle === true) { |
||
38 | echo("GRANTED : The vehicle 1 is able to be approved for the user 1\n"); |
||
39 | } else { |
||
40 | echo("FAIL : The system didn't grant access\n"); |
||
41 | } |
||
42 | $user3Vehicle = $abac->enforce('vehicle-homologation', $users[2], $vehicles[1], [ |
||
43 | 'dynamic_attributes' => ['proprietaire' => 3] |
||
44 | ]); |
||
45 | if(!$user3Vehicle !== true) { |
||
46 | echo("DENIED : The vehicle 2 is not approved for the user 3 because its last technical review is too old\n"); |
||
47 | } else { |
||
48 | echo("FAIL : The system didn't deny access\n"); |
||
49 | } |
||
50 | $user4Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
||
51 | 'dynamic_attributes' => ['proprietaire' => 4] |
||
52 | ]); |
||
53 | if($user4Vehicle !== true) { |
||
54 | echo("DENIED : The vehicle 4 is not able to be approved for the user 4 because he has no driving license\n"); |
||
55 | } else { |
||
56 | echo("FAIL : The system didn't deny access\n"); |
||
57 | } |
||
58 | $user5Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
||
59 | 'dynamic_attributes' => ['proprietaire' => 1] |
||
60 | ]); |
||
61 | if($user5Vehicle !== true) { |
||
62 | echo("DENIED : The vehicle 4 is not able to be approved for the user 2 because he doesn't own the vehicle\n"); |
||
63 | } else { |
||
64 | echo("FAIL : The system didn't deny access\n"); |
||
65 | } |
||
66 | $userTravel1 = $abac->enforce('travel-to-usa', $users[0]); |
||
67 | if($userTravel1 !== true) { |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
68 | echo("DENIED: The user 1 is not allowed to travel to the USA because he doesn't have an US visa\n"); |
||
69 | } else { |
||
70 | echo('FAIL: The system didn\'t deny access'); |
||
71 | } |
||
72 | $userTravel2 = $abac->enforce('travel-to-usa', $users[1]); |
||
73 | if($userTravel2 === true) { |
||
0 ignored issues
–
show
|
|||
74 | echo("GRANTED: The user 2 is allowed to travel to the USA\n"); |
||
75 | } else { |
||
76 | echo('FAIL: The system didn\'t deny access'); |
||
77 | } |