diff --git a/library/Class/User/Password.php b/library/Class/User/Password.php index 9ef9bfe53ba92d8be6709e9f6c414cc38982a5cc..6e3c8e230a82e0809c87f939a6da2518a7545e8c 100644 --- a/library/Class/User/Password.php +++ b/library/Class/User/Password.php @@ -29,11 +29,43 @@ class Class_User_Password { public function format() { - $crypt = new Class_Crypt(); - $pass = $this->_user->getPassword(); + return $this->shouldHash() + ? $this->asBlowFish() + : $this->password(); + } + + + public function shouldHash() { + return $this->hasRoleLevel() && !$this->isPatron() && !$this->isBlowFish(); + } + + + public function password() { + return $this->_user->getPassword(); + } + + + public function isPatron() { + return $this->_user->isAbonne(); + } + + + public function hasRoleLevel() { + return $this->_user->hasRoleLevel(); + } + + + public function isBlowFish() { + return $this->crypt()->isBlowFish($this->password()); + } + + + public function asBlowFish() { + return $this->crypt()->blowFishHashOf($this->password()); + } + - return ($this->_user->isAbonne() || $crypt->isBlowFish($pass)) - ? $pass - : $crypt->blowFishHashOf($pass); + public function crypt() { + return new Class_Crypt(); } } diff --git a/tests/application/modules/opac/controllers/MultimediaControllerTest.php b/tests/application/modules/opac/controllers/MultimediaControllerTest.php index 7bb1f5039962303c66f0fbd2d8e38d9f9a9eb7a7..22fa897a70ec6efea747767a3e705b9d6428a83a 100644 --- a/tests/application/modules/opac/controllers/MultimediaControllerTest.php +++ b/tests/application/modules/opac/controllers/MultimediaControllerTest.php @@ -105,10 +105,10 @@ abstract class MultimediaControllerAuthenticateTestCase extends MultimediaContro /** * @param $user Class_Users */ - protected function _expectUserToLoad($user) { + protected function _expectUserToLoad($user, $pass=null) { $this->_auth ->whenCalled('authenticateLoginPassword') - ->with($user->getLogin(), $user->getPassword(), ['auth_sigb', 'auth_db']) + ->with($user->getLogin(), $pass ? $pass : $user->getPassword(), ['auth_sigb', 'auth_db']) ->willDo( function() use ($user) { $this->_auth @@ -215,7 +215,7 @@ class MultimediaControllerAuthenticateInviteNonAfiMultimediaTest extends Multime public function setUp() { parent::setUp(); $user = MultimediaControllerUsersFixtures::getInvite(); - $this->_expectUserToLoad($user); + $this->_expectUserToLoad($user, 'invite'); $this->_json = $this->getJson('/multimedia/authenticate/login/invite/password/invite'); } @@ -225,7 +225,6 @@ class MultimediaControllerAuthenticateInviteNonAfiMultimediaTest extends Multime public function shouldReturnSubscriptionExpired() { $this->assertEquals('SubscriptionExpired', $this->_json->error); } - } @@ -233,7 +232,7 @@ class MultimediaControllerAuthenticateInviteAfiMultimediaTest extends Multimedia public function setUp() { parent::setUp(); $user = MultimediaControllerUsersFixtures::getInvite(); - $this->_expectUserToLoad($user); + $this->_expectUserToLoad($user, 'invite'); $this->_expectGroupForUser($user, 'Abonne multimedia'); $this->_json = $this->getJson('/multimedia/authenticate/login/invite/password/invite'); diff --git a/tests/library/Class/WebService/SIGB/CarthameTest.php b/tests/library/Class/WebService/SIGB/CarthameTest.php index 66293b684a06f6b616f23f161bfe63bec67959cc..91100a3aa05280091a7d37fb39173b28dfa4c455 100644 --- a/tests/library/Class/WebService/SIGB/CarthameTest.php +++ b/tests/library/Class/WebService/SIGB/CarthameTest.php @@ -218,6 +218,9 @@ class CarthameKarviPickupLocationsTest extends CarthameOperationTestCase { $user = $this->fixture('Class_Users', ['id' => 34, 'login' => '90100000119049', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'id_site' => 3, + 'idabon' => '90100000119049', 'password' => 'pass']); $item = $this->fixture('Class_Exemplaire', @@ -388,6 +391,9 @@ class CarthameEmprunteurPatrickBTest extends CarthameOperationTestCase { ['id' => 56, 'login' => 'pbarroca', 'password' => '1974', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => 'pbarroca', + 'id_site' => 3, 'int_bib' => $library]); ZendAfi_Auth::getInstance()->logUser($user); diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php index c1a66ec1b44de5f22bf9dc35a25be13fe6417720..32ddda29a2d271af734bb2c9a2bf0730e99b17fb 100644 --- a/tests/library/Class/WebService/SIGB/KohaTest.php +++ b/tests/library/Class/WebService/SIGB/KohaTest.php @@ -658,6 +658,9 @@ class KohaGetEmprunteurJeanAndreWithIdSIGBTest extends KohaTestCase { ['id' => 43, 'login' => 'JEAN', 'password' => 'zork', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => 'Jean', + 'id_site' => 3, 'id_sigb' => '01234'])); } @@ -1146,17 +1149,20 @@ class KohaAuthenticateWSTest extends KohaTestCase { ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=GetPatronInfo&patron_id=96138&show_contact=1&show_loans=1&show_holds=1') ->answers(KohaFixtures::xmlGetPatronInfoDupont()); - $this->emprunteur = $this->service->getEmprunteur( $this->user = $this->fixture('Class_Users', - [ - 'id' => 10, - 'login' => 'john', - 'password' => '1989'])); + $this->user = $this->fixture('Class_Users', ['id' => 10, + 'login' => 'john', + 'password' => '1989', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => 'john', + 'id_site' => 3]); + + $this->emprunteur = $this->service->getEmprunteur($this->user); $this->emprunteur->updateUser($this->user); } public function expectedUser() { - return [[ 'nom', 'DUPONT'], + return [['nom', 'DUPONT'], ['prenom' ,'Jean'], ['login' , 'john'], ['password' , '1989'],