From ce09194d0571efd7c0867b03f8d2969b44b99433 Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Wed, 5 Jul 2023 11:46:37 +0000
Subject: [PATCH] hotline#181223 : Identity Provider : connection to Bokeh CAS
 v3 throw error

---
 VERSIONS_HOTLINE/181223                            |  1 +
 library/Class/WebService/Cas3.php                  |  5 +++++
 .../IdentityProviderAuthenticationCas3Test.php     | 14 +++++++++++---
 tests/scenarios/IdentityProvider/cas3ticket.xml    |  1 +
 4 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/181223

diff --git a/VERSIONS_HOTLINE/181223 b/VERSIONS_HOTLINE/181223
new file mode 100644
index 00000000000..443189ee529
--- /dev/null
+++ b/VERSIONS_HOTLINE/181223
@@ -0,0 +1 @@
+  - correctif #181223 : Administration: correction de la connexion via les fournisseur d'identité en CAS3
\ No newline at end of file
diff --git a/library/Class/WebService/Cas3.php b/library/Class/WebService/Cas3.php
index bfa69648b30..b464bb3c908 100644
--- a/library/Class/WebService/Cas3.php
+++ b/library/Class/WebService/Cas3.php
@@ -33,6 +33,11 @@ class Class_WebService_Cas3 extends Class_WebService_Cas2 {
         ? $this->_getValueForIdSite($body, $key)
         : $this->_getMappingValue($body, $key);
 
+    $valid_params = array_keys((new Class_Users)->getRawAttributes());
+    $this->_user_attributes = array_filter($this->_user_attributes,
+                                           fn($key) => in_array($key, $valid_params),
+                                           ARRAY_FILTER_USE_KEY);
+
     return $this;
   }
 
diff --git a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php
index c56a98053a5..f3f12aaa004 100644
--- a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php
+++ b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationCas3Test.php
@@ -87,6 +87,7 @@ abstract class IdentityProviderAuthenticationCas3BokehToBokehTestCase
     return ['nom' => 'lastname',
             'prenom' => 'firstname',
             'mail' => 'mail',
+            'libelle_bib' => 'site_label',
             'id_site' => 'site_code'];
   }
 
@@ -99,7 +100,7 @@ abstract class IdentityProviderAuthenticationCas3BokehToBokehTestCase
                     'prenom' => 'P.D.',
                     'password' => '1234',
                     'civilite' => "1",
-                    'date_naissance' => '2022-12-08',
+                    'naissance' => '2022-12-08',
                     'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE,
                     'id_site' => 1]);
   }
@@ -140,6 +141,7 @@ class IdentityProviderAuthenticationCas3WrongMappingTest
 
   protected function _getMapping() {
     return ['nom'  => 'badlastname',
+            'libelle_bib' => 'site_label',
             'prenom'  => 'firstname'];
   }
 
@@ -160,6 +162,12 @@ class IdentityProviderAuthenticationCas3WrongMappingTest
   public function userShouldBeRemotelyLoggedAsModoPortail() {
     $this->assertEquals('modo_portail', Class_Users::getIdentity()->getNomRole());
   }
+
+
+  /** @test */
+  public function userShouldNotHaveLibelleBibSet(){
+    $this->assertTrue(!array_key_exists('libelle_bib',Class_Users::getIdentity()->getRawAttributes()));
+  }
 }
 
 
@@ -378,7 +386,7 @@ class IdentityProviderAuthenticationCas3Bokeh2BokehWithAutoUpdateUsersTest
     return ['nom' => 'lastname',
             'prenom' => 'firstname',
             'mail' => 'mail',
-            'date_naissance' => 'birth_date',
+            'naissance' => 'birth_date',
             'idabon' => 'card_number',
             'id_sigb' => 'ils_number',
             'mail' => 'mail'];
@@ -390,7 +398,7 @@ class IdentityProviderAuthenticationCas3Bokeh2BokehWithAutoUpdateUsersTest
             ['Id', '98134'],
             ['Nom', 'Pouce'],
             ['Prenom', 'Tom'],
-            ['DateNaissance', '1978-08-02'],
+            ['Naissance', '1978-08-02'],
             ['Idabon', '123XPE'],
             ['IdSigb', '22345'],
             ['Mail', 'tom@pouce.fr'],
diff --git a/tests/scenarios/IdentityProvider/cas3ticket.xml b/tests/scenarios/IdentityProvider/cas3ticket.xml
index 2be1f805c68..bf9b67d964b 100644
--- a/tests/scenarios/IdentityProvider/cas3ticket.xml
+++ b/tests/scenarios/IdentityProvider/cas3ticket.xml
@@ -11,6 +11,7 @@
       <cas:ils_number>22345</cas:ils_number>
       <cas:birth_date>1978-08-02</cas:birth_date>
       <cas:postal_code>38123</cas:postal_code>
+      <cas:site_label>NY Public Library</cas:site_label>
       <cas:city>Laval</cas:city>
       <cas:affiliation>supremes</cas:affiliation>
       <cas:affiliation>temptations</cas:affiliation>
-- 
GitLab