Commit fc677310 authored by Arthur Suzuki's avatar Arthur Suzuki

hotline#109495: fix hashing function used to generate auth token against koha community api

parent d946021e
Pipeline #10010 passed with stage
in 43 minutes and 26 seconds
- ticket #109495 : SIGB Koha : correctif sur connecteur à l'API communautaire
\ No newline at end of file
......@@ -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)))
......
......@@ -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();
}
......
......@@ -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]'])))
......
......@@ -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'));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment