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
|
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\Auth;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Auth;
/**
* Tests for \SimpleSAML\Auth\State
*/
class StateTest extends TestCase
{
/**
* Test the getPersistentAuthData() function.
* @return void
*/
public function testGetPersistentAuthData(): void
{
$mandatory = [
'Attributes' => [],
'Expire' => 1234,
'LogoutState' => 'logoutState',
'AuthInstant' => 123456,
'RememberMe' => true,
'saml:sp:NameID' => 'nameID',
];
// check just mandatory parameters
$state = $mandatory;
$expected = $mandatory;
$this->assertEquals(
$expected,
Auth\State::getPersistentAuthData($state),
'Mandatory state attributes did not survive as expected' . print_r($expected, true)
);
// check missing mandatory parameters
unset($state['LogoutState']);
unset($state['RememberMe']);
$expected = $state;
$this->assertEquals(
$expected,
Auth\State::getPersistentAuthData($state),
'Some error occurred with missing mandatory parameters'
);
// check additional non-persistent parameters
$additional = [
'additional1' => 1,
'additional2' => 2,
];
$state = array_merge($mandatory, $additional);
$expected = $mandatory;
$this->assertEquals(
$expected,
Auth\State::getPersistentAuthData($state),
'Additional parameters survived'
);
// check additional persistent parameters
$additional['PersistentAuthData'] = ['additional1'];
$state = array_merge($mandatory, $additional);
$expected = $state;
unset($expected['additional2']);
unset($expected['PersistentAuthData']);
$this->assertEquals(
$expected,
Auth\State::getPersistentAuthData($state),
'Some error occurred with additional, persistent parameters'
);
// check only additional persistent parameters
$state = $additional;
$expected = $state;
unset($expected['additional2']);
unset($expected['PersistentAuthData']);
$this->assertEquals(
$expected,
Auth\State::getPersistentAuthData($state),
'Some error occurred with additional, persistent parameters, and no mandatory ones'
);
}
}
|