diff --git a/VERSIONS_HOTLINE/109495 b/VERSIONS_HOTLINE/109495 new file mode 100644 index 0000000000000000000000000000000000000000..493d855b15f7f5e929b2d115a71ae674fabc1e33 --- /dev/null +++ b/VERSIONS_HOTLINE/109495 @@ -0,0 +1 @@ + - ticket #109495 : SIGB Koha : correctif sur connecteur à l'API communautaire \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Koha/CommunityService.php b/library/Class/WebService/SIGB/Koha/CommunityService.php index 9aec73cad17f8e14276ecfd42c5fed0677d7f157..432c50c5fd9f56786eb9f98f59ee903f277e3b83 100644 --- a/library/Class/WebService/SIGB/Koha/CommunityService.php +++ b/library/Class/WebService/SIGB/Koha/CommunityService.php @@ -58,6 +58,12 @@ class Class_WebService_SIGB_Koha_CommunityService } + protected function _getAuthForEmprunteur($emprunteur) { + return [$emprunteur->getLogin(), + $emprunteur->getPreviousPassword()]; + } + + public function providesChangePasswordService() { return true; } @@ -69,21 +75,20 @@ class Class_WebService_SIGB_Koha_CommunityService $password = $emprunteur->getPassword(); $datas = ['password' => $password, 'password_2' => $password]; - $auth_token = md5($emprunteur->getLogin(). - ":".$emprunteur->getPreviousPassword()); + + $auth = $this->_getAuthForEmprunteur($emprunteur); $response = $this->getWebClient() ->postRawDataResponse($url, - json_encode($datas), - Zend_Http_Client::ENC_URLENCODED, - ['headers' => - ['Authorization' => 'Basic '.$auth_token ]]); + json_encode($datas), + Zend_Http_Client::ENC_URLENCODED, + ['auth' => $auth]); if ($response->isError()) throw new Class_WebService_Exception($this->_('Erreur de mise à jour du mot de passe : %s', $response->getMessage())); if ($response->isSuccessful() - && '' == ($body = $response->getRawBody())) + && '""' == ($body = $response->getRawBody())) return $emprunteur; if (null === ($json = json_decode($body,TRUE))) diff --git a/library/Class/WebService/SimpleWebClient.php b/library/Class/WebService/SimpleWebClient.php index 247b85e1e34890da985d86465d969dc158518433..33c88238c60781885c8caa86f5eb873c616d0ab2 100644 --- a/library/Class/WebService/SimpleWebClient.php +++ b/library/Class/WebService/SimpleWebClient.php @@ -93,6 +93,9 @@ class Class_WebService_SimpleWebClient { if (isset($options['headers'])) $httpClient->setHeaders($options['headers']); + if (isset($options['auth'])) + $httpClient->setAuth($options['auth']['user'], $options['auth']['password']); + return $httpClient->request(); } diff --git a/tests/application/modules/opac/controllers/AbonneControllerChangePasswordTest.php b/tests/application/modules/opac/controllers/AbonneControllerChangePasswordTest.php index 9bb78275ac2dff2672a2a247e2e908d5eb14e8ad..dcf21e85d72e3795f44e4f0d617799337635386d 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerChangePasswordTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerChangePasswordTest.php @@ -159,7 +159,9 @@ class AbonneControllerChangePasswordOnKohaWithCommunityServiceTest public function setUp() { parent::setUp(); - $auth_token=md5($this->_patron->getLogin().":".$this->_patron->getPassword()); + $auth = [$this->_patron->getLogin(), + $this->_patron->getPassword()]; + $this->_web_client ->whenCalled('open_url') ->with('http://plage.com/cgi-bin/koha/ilsdi.pl?service=AuthenticatePatron&username=ml34&password=achanger') @@ -170,8 +172,7 @@ class AbonneControllerChangePasswordOnKohaWithCommunityServiceTest json_encode(['password' => 'Ce1bnm2p', 'password_2' => 'Ce1bnm2p']), Zend_Http_Client::ENC_URLENCODED, - ['headers' => - ['Authorization' => 'Basic ' . $auth_token]]) + ['auth' => $auth ]) ->answers(new Zend_Http_Response(200,[],'')) ->whenCalled('postRawDataResponse') @@ -180,8 +181,7 @@ class AbonneControllerChangePasswordOnKohaWithCommunityServiceTest json_encode(['password' => 'test', 'password_2' => 'test']), Zend_Http_Client::ENC_URLENCODED, - ['headers' => - ['Authorization' => 'Basic ' . $auth_token]]) + ['auth' => $auth ]) ->answers(new Zend_Http_Response(200, [], json_encode(['error' => 'Password length (4) is shorter than required (5)']))) @@ -191,8 +191,7 @@ class AbonneControllerChangePasswordOnKohaWithCommunityServiceTest json_encode(['password' => 'testingsimple', 'password_2' => 'testingsimple']), Zend_Http_Client::ENC_URLENCODED, - ['headers' => - ['Authorization' => 'Basic ' . $auth_token]]) + ['auth' => $auth ]) ->answers(new Zend_Http_Response(200, [], json_encode(['error' => '[Passwords is too weak]']))) diff --git a/tests/library/Class/WebService/SIGB/KohaCommunityTest.php b/tests/library/Class/WebService/SIGB/KohaCommunityTest.php index 5f99ec03cd4c04bbb2dd52cb2dbcbcdf4d987455..5a3a0b4bfbecbb7b6a863298dda880f6a15f2f73 100644 --- a/tests/library/Class/WebService/SIGB/KohaCommunityTest.php +++ b/tests/library/Class/WebService/SIGB/KohaCommunityTest.php @@ -82,14 +82,15 @@ class KohaCommunityServiceChangePasswordWSTest extends KohaCommunityTestCase { public function setParamsAndResponse($password,$http_response) { - $auth_token=md5($this->user->getLogin().":".$this->user->getPassword()); + $auth=[$this->user->getLogin(), + $this->user->getPassword()]; + $this->mock_web_client ->whenCalled('postRawDataResponse') ->with('http://cat-aficg55.biblibre.com/api/v1/patrons/96138/password', json_encode(['password' => $password, 'password_2' => $password]), Zend_Http_Client::ENC_URLENCODED, - ['headers' => - ['Authorization' => 'Basic ' . $auth_token]]) + ['auth'=> $auth]) ->answers($http_response) ->whenCalled('open_url') ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=GetPatronInfo&patron_id=96138&show_contact=1&show_loans=0&show_holds=1') @@ -106,7 +107,7 @@ class KohaCommunityServiceChangePasswordWSTest extends KohaCommunityTestCase { /** @test */ public function userValidPasswordShouldBeUpdated() { - $http_response = new Zend_Http_Response(200,[],''); + $http_response = new Zend_Http_Response(200,[],'""'); $this->setParamsAndResponse('7estIng!',$http_response); $this->assertEquals('7estIng!',$this->user->getPassword()); } @@ -152,7 +153,7 @@ class KohaCommunityServiceChangePasswordWSTest extends KohaCommunityTestCase { /** @test */ public function kohaShouldHaveBeenCalled() { - $http_response = new Zend_Http_Response(200,[],''); + $http_response = new Zend_Http_Response(200,[],'""'); $this->setParamsAndResponse('7estIng!',$http_response); $this->assertTrue($this->mock_web_client->methodHasBeenCalled('postRawDataResponse')); }