diff --git a/VERSIONS_HOTLINE/177152 b/VERSIONS_HOTLINE/177152 new file mode 100644 index 0000000000000000000000000000000000000000..4ea45b52a7a207cc809e36da24d4343a73d93e28 --- /dev/null +++ b/VERSIONS_HOTLINE/177152 @@ -0,0 +1 @@ + - correctif #177152 : CAS3 : import correct des dates au format UTC \ No newline at end of file diff --git a/library/Class/User/ILSSubscription.php b/library/Class/User/ILSSubscription.php index f23b4b10f2e19dc362d6fbef0bc9b640ba2cc2b2..741e2c9c79f45d9bb5d6a1ed4c070520416c6b27 100644 --- a/library/Class/User/ILSSubscription.php +++ b/library/Class/User/ILSSubscription.php @@ -95,7 +95,8 @@ class Class_User_ILSSubscription { public function ilsExpireIn() :string { - $date_expiry = new DateTime($this->_user->getDateFin()); + if (!($date_expiry = new DateTime($this->_user->getDateFin()))) + return ''; $today = new DateTime($this->getTimeSource()->dateYmd()); return $today->diff($date_expiry)->format("%r%a"); } diff --git a/library/Class/WebService/Cas3.php b/library/Class/WebService/Cas3.php index 58a219d0c1f6946c76659d8fb4dc07427f6f6cd4..bfa23383fccca42ac253e9c4643ce774d0967e1b 100644 --- a/library/Class/WebService/Cas3.php +++ b/library/Class/WebService/Cas3.php @@ -21,6 +21,7 @@ class Class_WebService_Cas3 extends Class_WebService_Cas2 { + use Trait_TimeSource; protected $_user_attributes = []; protected function _mappingResponse(string $body) :self { @@ -40,10 +41,16 @@ class Class_WebService_Cas3 extends Class_WebService_Cas2 { } - protected function _validateValue($value, string $function_name) { - return (($function_name == 'naissance') - && (strlen($value) <= 4)) - ? sprintf('%04d-01-01',$value) - : $value; + protected function _validateValue(?string $value, string $function_name): string { + if (!$value) + return ''; + + if (!(($function_name == 'naissance') ||($function_name == 'date_fin')) ) + return $value; + + if (strlen($value) <= 4) + return sprintf('%04d-01-01',$value); + + return self::tryFormatDate($value); } } diff --git a/library/Trait/TimeSource.php b/library/Trait/TimeSource.php index 03da053e5c87de65e8561d6edc38a8de1a2d1700..347c694afadf9288d8772623f81c1ce8238bd4ef 100644 --- a/library/Trait/TimeSource.php +++ b/library/Trait/TimeSource.php @@ -77,6 +77,18 @@ trait Trait_TimeSource { } + public static function tryFormatDate( string $date_str, string $return_format= 'Y-m-d'): string { + $date_str = str_replace( '.0Z', '', $date_str); + $formats=['Y','Y-m-d', 'Y/m/d', 'Ymd', 'YmdHis', 'd-m-Y', 'd/m/Y']; + + foreach ($formats as $format) { + if ($date = DateTime::createFromFormat($format, $date_str)) + return $date->format($return_format); + } + return ''; + } + + public static function addIntervalToDate($interval, $date){ $date= $date ? strtotime($date) diff --git a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php index 12b1cdab64ab89cc8dbed92e1ea9a504456208f4..3433f32ef6409aebeba32b2e4767570078522dd6 100644 --- a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php +++ b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php @@ -78,6 +78,7 @@ abstract class IdentityProviderAuthenticationCas3BokehToBokehTestCase extends Ab ]; } + protected function _addPdJames(){ $this->fixture(Class_Users::class, ['id' => 98134, @@ -95,7 +96,6 @@ abstract class IdentityProviderAuthenticationCas3BokehToBokehTestCase extends Ab abstract public function mappingDatas(); - /** * @test * @dataProvider mappingDatas @@ -153,6 +153,56 @@ class IdentityProviderAuthenticationCas3WrongMappingTest extends IdentityProvide +class IdentityProviderAuthenticationCas3Bokeh2BokehWithUTCDateTest extends IdentityProviderAuthenticationCas3BokehToBokehTestCase { + + public function setUp() { + parent::setUp(); + + $this->dispatch('/auth/login/provider/1?ticket=testticket'); + } + + + protected function _getAnswer() { + return file_get_contents(__DIR__.'/cas3archimed.xml'); + } + + + /** @test */ + public function userShouldBeRemotelyLogged() { + $this->assertTrue($this->_provider->isRemotelyLogged()); + } + + + public function mappingDatas() : array { + return [ + ['Nom', 'Pouce'], + ['Prenom' , 'Tom'], + ['Mail', 'tom@pouce.fr'], + ['IdSigb', '22345'], + ['NomRole', 'abonne'], + ['LibraryId', '3'], + ['LibelleBib', 'Annecy'], + ['DateFin', '2023-02-15'], + ['LibelleBib', 'Annecy'], + ['Naissance', '1972-02-14'], + ['CodePostal', '38123'], + ['Ville', 'Laval'], + ]; + } + + + /** + * @test + * @dataProvider mappingDatas + */ + public function userShouldGetMapping($key, $value) { + $this->assertEquals($value, Class_Users::getIdentity()->{'get' . $key}()); + } +} + + + + class IdentityProviderAuthenticationCas3Bokeh2BokehTest extends IdentityProviderAuthenticationCas3BokehToBokehTestCase { public function setUp() { @@ -229,6 +279,7 @@ class IdentityProviderAuthenticationCas3PMBToBokehTest extends IdentityProviderA ]; } + protected function _getAnswer() { return'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas"> <cas:authenticationSuccess> @@ -244,6 +295,7 @@ class IdentityProviderAuthenticationCas3PMBToBokehTest extends IdentityProviderA </cas:serviceResponse>'; } + public function mappingDatas() : array { return [ ['Nom', 'Pouce'], @@ -258,6 +310,7 @@ class IdentityProviderAuthenticationCas3PMBToBokehTest extends IdentityProviderA + class IdentityProviderAuthenticationCas3Bokeh2BokehWithoutAutoCreateUsersTest extends IdentityProviderAuthenticationCas3BokehToBokehTestCase { public function setUp() { @@ -336,6 +389,7 @@ class IdentityProviderAuthenticationCas3Bokeh2BokehWithAutoUpdateUsersTest exten ]; } + public function mappingDatas(){ return [ ['Id', '98134'], diff --git a/tests/scenarios/IdentityProvider/cas3archimed.xml b/tests/scenarios/IdentityProvider/cas3archimed.xml new file mode 100644 index 0000000000000000000000000000000000000000..982da6ed7ca5d0621ae16ecf08bb60ef5bd06802 --- /dev/null +++ b/tests/scenarios/IdentityProvider/cas3archimed.xml @@ -0,0 +1,19 @@ +<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas"> + <cas:authenticationSuccess> + <cas:user>mysuperid</cas:user> + <cas:proxyGrantingTicket>ST-a51b1ae3e8b2319bba4e90841a40cf4b</cas:proxyGrantingTicket> + <cas:attributes> + <cas:lastname>Pouce</cas:lastname> + <cas:firstname>Tom</cas:firstname> + <cas:mail>tom@pouce.fr</cas:mail> + <cas:expire_at>20230215000000.0Z</cas:expire_at> + <cas:card_number>123XPE</cas:card_number> + <cas:ils_number>22345</cas:ils_number> + <cas:birth_date>19720214000000.0Z</cas:birth_date> + <cas:postal_code>38123</cas:postal_code> + <cas:city>Laval</cas:city> + <cas:affiliation>supremes</cas:affiliation> + <cas:affiliation>temptations</cas:affiliation> + </cas:attributes> + </cas:authenticationSuccess> +</cas:serviceResponse>