Fixed authdefault
This commit is contained in:
parent
a14d9c4da0
commit
ebf2b301d6
|
@ -232,17 +232,17 @@
|
|||
|
||||
/* (1) Si entrepot requis, mais manquant
|
||||
---------------------------------------------------------*/
|
||||
if( in_array('warehouse', $expected) && !isset($_SESSION['WAREHOUSE']['id']) )
|
||||
if( in_array('warehouse', $expected) && ( self::auth() < 1 || !isset($_SESSION['WAREHOUSE']['id']) ) )
|
||||
return Err::PermissionError;
|
||||
|
||||
/* (2) Si admin requis, mais manquant
|
||||
---------------------------------------------------------*/
|
||||
if( in_array('admin', $expected) && !isset($_SESSION['ADMIN']['id']) )
|
||||
if( in_array('admin', $expected) && ( self::auth() != 2 || !isset($_SESSION['ADMIN']['id']) ) )
|
||||
return Err::PermissionError;
|
||||
|
||||
/* (3) Si SATS requis, mais manquant
|
||||
---------------------------------------------------------*/
|
||||
if( in_array('sats', $expected) && !isset($_SESSION['SATS']['id']) )
|
||||
if( in_array('sats', $expected) && ( self::auth() < 3 || !isset($_SESSION['SATS']['id']) ) )
|
||||
return Err::TokenError;
|
||||
|
||||
/* (4) On retire 'warehouse', 'admin' et 'sats' de @expected
|
||||
|
|
|
@ -167,6 +167,10 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1];
|
||||
$_SESSION['WAREHOUSE'] = [
|
||||
'id' => 1,
|
||||
'modules' => []
|
||||
];
|
||||
$err = $asd::permission('unknown_module', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::DisabledModule);
|
||||
|
@ -180,6 +184,7 @@
|
|||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1];
|
||||
$_SESSION['WAREHOUSE'] = [
|
||||
'id' => 1,
|
||||
'modules' => ['known_module']
|
||||
];
|
||||
$err = $asd::permission('known_module', $perm);
|
||||
|
@ -194,6 +199,10 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1];
|
||||
$_SESSION['WAREHOUSE'] = [
|
||||
'id' => 1,
|
||||
'modules' => []
|
||||
];
|
||||
$err = $asd::permission('modulenameDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
@ -271,6 +280,7 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1];
|
||||
$_SESSION['WAREHOUSE']['id'] = 1; // have id
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
@ -283,6 +293,8 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1, 2];
|
||||
$_SESSION['WAREHOUSE']['id'] = 1;
|
||||
$_SESSION['ADMIN']['id'] = 1;
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
@ -295,6 +307,9 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1, 2, 3];
|
||||
$_SESSION['WAREHOUSE']['id'] = 1;
|
||||
$_SESSION['ADMIN']['id'] = 1;
|
||||
$_SESSION['SATS']['id'] = 1;
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
@ -311,6 +326,8 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1, 2]; // 2 = admin
|
||||
$_SESSION['WAREHOUSE']['id'] = 1;
|
||||
$_SESSION['ADMIN']['id'] = 1;
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
@ -323,6 +340,9 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1, 2, 3]; // 2 = sats
|
||||
$_SESSION['WAREHOUSE']['id'] = 1;
|
||||
$_SESSION['ADMIN']['id'] = 1;
|
||||
$_SESSION['SATS']['id'] = 1;
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
@ -335,12 +355,44 @@
|
|||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1, 2, 3]; // 2 = sats
|
||||
$_SESSION['WAREHOUSE']['id'] = 1;
|
||||
$_SESSION['ADMIN']['id'] = 1;
|
||||
$_SESSION['SATS']['id'] = 1;
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->not->toBe(Err::Success);
|
||||
|
||||
});
|
||||
|
||||
it('pass when (\'admin\' OR \'sats\') required and have only \'admin\'', function(){
|
||||
|
||||
$perm = [['admin'], ['sats']];
|
||||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1, 2]; // 2 = admin
|
||||
$_SESSION['WAREHOUSE']['id'] = 1;
|
||||
$_SESSION['ADMIN']['id'] = 1;
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
||||
});
|
||||
|
||||
it('pass when (\'admin\' OR \'sats\') required and have only \'sats\'', function(){
|
||||
|
||||
$perm = [['admin'], ['sats']];
|
||||
|
||||
$asd = new AuthSystemDefault();
|
||||
$_SESSION['AUTH'] = [1, 2, 3]; // 2 = sats
|
||||
$_SESSION['WAREHOUSE']['id'] = 1;
|
||||
$_SESSION['ADMIN']['id'] = 1;
|
||||
$_SESSION['SATS']['id'] = 1;
|
||||
$err = $asd::permission('moduleDefault', $perm);
|
||||
expect($err)->toBeAnInstanceOf('error\\core\\Error');
|
||||
expect($err->get())->toBe(Err::Success);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue