Commit ebbd5650 authored by Laurent's avatar Laurent

Merge branch 'dev#105247_insep_flora_initialisation_d_un_mot_de_passe_crypte' into 'master'

dev #105247 Flora : handles password crypt & authentication

See merge request !3571
parents 256c9575 2d115616
Pipeline #10635 passed with stage
in 45 minutes and 36 seconds
- ticket #105247 : SIGB Flora : mots de passes cryptés et authentification gérés entièrement par Bokeh
\ No newline at end of file
......@@ -147,6 +147,11 @@ class Class_Cosmogramme_Integration extends Storm_Model_Abstract {
}
public function isFlora() {
return $this->getBib()->isFlora();
}
public function isKoha() {
return $this->getBib()->isKoha();
}
......
......@@ -135,6 +135,9 @@ class Class_Cosmogramme_Integration_Record_Patron {
$enreg['ROLE_LEVEL'] = ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB;
$enreg['STATUT'] = 0;
if ($this->_integration->isFlora())
unset($enreg['PASSWORD']);
return $enreg;
}
......
......@@ -236,6 +236,7 @@ class Class_IntBib extends Storm_Model_Abstract {
return array_keys(self::$COM_CLASSES);
}
public static function detectService($id_type) {
if (isset(self::$COM_CLASSES[$id_type]))
return self::$COM_CLASSES[$id_type];
......@@ -419,6 +420,11 @@ class Class_IntBib extends Storm_Model_Abstract {
}
public function isFlora() {
return static::SIGB_FLORA == $this->getSigb();
}
public function beCommKoha() {
return $this->setCommSigb(static::COM_KOHA);
}
......
......@@ -72,4 +72,7 @@ class Class_WebService_SIGB_Flora_GetBorrowerIdentityResponseReader extends Clas
}
public function endNUMERO_CARTE($content) {
$this->_emprunteur->setCodeBarres($content);
}
}
......@@ -38,6 +38,13 @@ class Class_WebService_SIGB_Flora_Service extends Class_WebService_SIGB_Abstract
}
public function saveEmprunteur($emprunteur) {
$user = Class_Users::findFirstBy(['login' => $emprunteur->getLogin()]);
$user->setPassword((new Class_Crypt())->blowFishHashOf($user->getPassword()))
->save();
}
public function __destruct(){
$this->disconnect();
}
......@@ -55,6 +62,11 @@ class Class_WebService_SIGB_Flora_Service extends Class_WebService_SIGB_Abstract
}
public function providesChangePasswordService() {
return true;
}
protected function _httpGetBorrowerMethod($method, $barcode, $options = []) {
if (!$this->_borrower_id) {
$xml = $this->httpGet(['method' => 'communication.identifyBorrower',
......
......@@ -62,6 +62,9 @@ class ZendAfi_Controller_Router_RewriteWithoutBaseUrl extends Zend_Controller_Ro
* @return Zend_Controller_Request_Abstract Request object
*/
public function route(Zend_Controller_Request_Abstract $request) {
if (!BASE_URL)
return parent::route($request);
$path_info = $request->getPathInfo();
if ('/' != BASE_URL && 0 === strpos($path_info, BASE_URL))
$request->setPathInfo(str_replace(BASE_URL, '', $path_info));
......
......@@ -53,7 +53,7 @@ class Intonation_View_Search_Facets extends ZendAfi_View_Helper_Facettes {
: $rubrique;
return $this->_tag('li',
$this->_tag('b', $rubrique, ($onclick ? ['onclick' => $onclick] : ''))
$this->_tag('b', $rubrique, ($onclick ? ['onclick' => $onclick] : []))
. $this->listeFacettesElementHTML($type, $facets[$type], $url, (boolean) $onclick),
['class' => 'facette_titre facet_type_' . $type]);
}
......
......@@ -98,8 +98,11 @@ abstract class FloraTestCase extends ModelTestCase {
'login' => 'paulg',
'password' => 'secret',
'idabon' => 'carte123',
'id_int_bib' => 1])
->beAbonneSIGB();
'id_int_bib' => 1,
'bib' => $this->fixture('Class_Bib',
['id' => 1,
'libelle' => 'Annecy']),
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
ZendAfi_Auth::getInstance()->logUser($this->_paul);
......@@ -161,7 +164,8 @@ class FloraGetEmprunteurTest extends FloraTestCase {
['endDate', '2021-01-22'],
['codePostal', '74000'],
['ville', 'ANNECY'],
['email', 'paul.gluhon@mail.fr']
['email', 'paul.gluhon@mail.fr'],
['codeBarres', 'carte123']
];
}
......@@ -263,7 +267,6 @@ class FloraGetEmprunteurTest extends FloraTestCase {
call_user_func([$this->_emprunteur->getReservations()[1],
$attribute]));
}
}
......@@ -360,6 +363,7 @@ class FloraGetNoticeCirculationTest extends FloraTestCase {
class FloraHoldTitleCirculationInvisible extends FloraTestCase {
/** @test */
public function withSuccessfullRequestShouldAnswerStatutTrue() {
......@@ -389,4 +393,116 @@ class FloraHoldTitleCirculationInvisible extends FloraTestCase {
$this->assertEquals(['statut' => false, 'erreur' => 'Could not hold'],
$response);
}
}
class FloraPatronIntegrationTest extends ModelTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_IntBib',
['id' => 75,
'sigb' => Class_IntBib::SIGB_FLORA,
'nom_court' => 'Le 75'
]);
$this->fixture('Class_IntProfilDonnees',
['id' => 75,
'libelle' => 'Patrons',
'accents' => Class_IntProfilDonnees::ENCODING_UTF8,
'type_fichier' => Class_IntProfilDonnees::FT_PATRONS,
'format' => Class_IntProfilDonnees::FORMAT_PIPED_ASCII,
'attributs' => [1 => ['champs' => 'IDABON;ID_SIGB;NOM;PRENOM;MAIL;NAISSANCE']]]);
$integration = $this->fixture('Class_Cosmogramme_Integration',
['id' => 1,
'bib' => Class_IntBib::find(75),
'profil_donnees' => Class_IntProfilDonnees::find(75),
'type_operation' => Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL,
'traite' => 'non',
'fichier' => 'patrons.txt',
'pointeur_reprise' => 0]);
$this->_record_patron = (new Class_Cosmogramme_Integration_Record_Patron($integration))
->import(['IDABON' => 'abon123',
'ID_SIGB' => 123,
'NOM' => 'Brun',
'PRENOM' => 'Ours',
'MAIL' => 'obrun@pomdapi.fr',
'NAISSANCE' => '1975-01-01'],
['IDABON', 'ID_SIGB', 'NOM', 'PRENOM', 'MAIL', 'NAISSANCE'],
false);
$this->_ours = Class_Users::findFirstBy(['id_sigb' => 123]);
}
/** @test */
public function nomShouldBeBrun() {
$this->assertEquals('Brun', $this->_ours->getNom());
}
/** @test */
public function passwordShouldBeEmpty() {
$this->assertEmpty($this->_ours->getPassword());
}
/** @test */
public function importShouldNotResetPassword() {
$this->_ours->setPassword('thisisasecret')->save();
Class_Users::clearCache();
$this->_record_patron->import(['IDABON' => 'abon123',
'ID_SIGB' => 123,
'NOM' => 'Petit',
'PRENOM' => 'Ours',
'MAIL' => 'pbrun@pomdapi.fr',
'NAISSANCE' => '1975-01-01'],
['IDABON', 'ID_SIGB', 'NOM', 'PRENOM', 'MAIL', 'NAISSANCE'],
false);
$ours = Class_Users::findFirstBy(['id_sigb' => 123]);
$this->assertArraySubset(['nom' => 'Petit',
'password' => 'thisisasecret'],
$ours->getRawAttributes());
}
}
class FloraSaveEmprunteurTest extends FloraTestCase {
public function setUp() {
parent::setUp();
$emprunteur = $this->_service->getEmprunteur($this->_paul);
$this->_paul->setPassword('thisisasecret');
$emprunteur->updateFromUser($this->_paul)->save();
Class_Crypt::setPhpCommand($this->mock()
->whenCalled('password_hash')
->willDo(function($pass, $crypt) { return 'crypted_' . $pass; }));
$this->_service->saveEmprunteur($emprunteur);
}
/** @test */
public function paulPasswordShouldBeBlowfish() {
Class_Users::clearCache();
$saved_paul = Class_Users::findFirstBy(['idabon' => 'carte123']);
$this->assertEquals('crypted_thisisasecret',
$saved_paul->getPassword());
}
/** @test */
public function serviceShoulProvidesChangePasswordService() {
$this->assertTrue($this->_service->providesChangePasswordService());
}
}
\ No newline at end of file
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