Commit f326b922 authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'hotline' into 'master'

Hotline

See merge request !3431
parents a2e99e87 8c56e4b2
Pipeline #9677 passed with stage
in 48 minutes and 38 seconds
- Hotline #101887 : Gestion des Domaines : Erreur sur lien des Types documents dans l'écran de test de domaine
\ No newline at end of file
- ticket #106412 : Version mobile : correction d'une erreur lorsqu'un abonné faisant partie d'un groupe dynamique se connectait
\ No newline at end of file
- ticket #107675 : Ressources numériques : Correction d'une erreur lors du SSO de certains fournisseurs utilisant les dates de naissance
\ No newline at end of file
- ticket #86543 : SIGB Koha : Prise en compte des contraintes de mot de passe fort
\ No newline at end of file
......@@ -1274,7 +1274,8 @@ class Class_Notice extends Storm_Model_Abstract {
->setTitle($title)
->setFacetCode(substr($facet, 0, 1))
->setUrlParams(['controller' => 'recherche',
->setUrlParams(['module' => 'opac',
'controller' => 'recherche',
'action' => 'simple',
'code_rebond' => $facet,
'facettes' => null,
......
......@@ -25,8 +25,6 @@ class Class_User_SearchCriteria_RoleLevel extends Class_SearchCriteria_Select {
public function buildElement() {
$this->_headScript();
if (!Class_Users::getIdentity())
return;
......@@ -41,6 +39,13 @@ class Class_User_SearchCriteria_RoleLevel extends Class_SearchCriteria_Select {
}
public function getElement() {
$this->_headScript();
return parent::getElement();
}
public function isAbonneSigb() {
return ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB == $this->_value;
}
......@@ -48,15 +53,15 @@ class Class_User_SearchCriteria_RoleLevel extends Class_SearchCriteria_Select {
protected function _headScript() {
$toggles = array_map(function($other)
{
return sprintf('formSelectToggleVisibilityForElement("#%s", $("#%s").closest("tr"), ["2"]);',
$this->getName(),
static::NAME_PREFIX . $other);
{
return sprintf('formSelectToggleVisibilityForElement("#%s", $("#%s").closest("tr"), ["2"]);',
$this->getName(),
static::NAME_PREFIX . $other);
},
['valid_subscription',
'end_subscription_days',
'statut',
'date_fin_start']);
['valid_subscription',
'end_subscription_days',
'statut',
'date_fin_start']);
Class_ScriptLoader::getInstance()->addJQueryReady(implode($toggles));
}
......
......@@ -476,7 +476,7 @@ class Class_Users extends Storm_Model_Abstract {
'role_level' => 0,
'idabon' => '',
'date_fin' => '',
'naissance' => '',
'naissance' => null,
'date_debut' => '',
'telephone' => '',
'mail' => '',
......@@ -1383,6 +1383,10 @@ class Class_Users extends Storm_Model_Abstract {
->getCurrentDateFormatInYmdHMS());
$this->setPassword((new Class_User_Password($this))->format());
if (null !== ($naissance = $this->getNaissance())
&& false === strtotime($naissance))
$this->setNaissance(null);
}
......
......@@ -41,6 +41,16 @@ class Class_WebService_SIGB_Koha_RestfulService
}
protected function _getErrorFromCode($error_code, $default_message) {
$error = ['password_too_short' => $this->_('Mot de passe trop court'),
'password_too_weak' => $this->_('Mot de passe trop faible')];
if (array_key_exists($error_code,$error))
return $default_message . " : " . $error[$error_code];
return $default_message;
}
public function providesSuggestions() {
return true;
}
......@@ -162,11 +172,22 @@ class Class_WebService_SIGB_Koha_RestfulService
public function saveEmprunteur($emprunteur) {
$this->restfulPut('auth/change_password',
$response = $this->restfulPut('auth/change_password',
['user_name' => $emprunteur->getLogin(),
'new_password' => $emprunteur->getPassword()]);
return $emprunteur;
if (null === ($json = json_decode($response,true))) {
throw new Class_WebService_Exception($this->_("saveEmprunteur() s'attends à une réponse au format JSON"));
}
if (!array_key_exists('reasons', $json)
|| !is_array($json['reasons'])
|| (!$reasons = array_keys($json['reasons'])))
return $emprunteur;
$error = implode(', ', array_map([$this, '_getErrorFromCode'],
$reasons, $reasons));
throw new Class_WebService_Exception($this->_('Erreur de mise à jour du mot de passe : %s', $error));
}
......
......@@ -88,7 +88,7 @@ class LesYeuxDoc_Config extends Class_DigitalResource_Config {
'prenom' => $user->getPrenom(),
'nom' => $user->getNom(),
'email' => $user->getMail(),
'dnaiss' => $user->getNaissance(),
'dnaiss' => ($date = $user->getNaissance()) ? $date : '',
'datout' => $user->getDateFin(),
'return_url' => $return_url];
......
......@@ -1892,6 +1892,8 @@ class CatalogueControllerActionTesterWithResultsPageTwoTest extends CatalogueCon
['id' => 21,
'titre_principal' => 'tales',
'auteur_principal' => 'marcus',
'type_doc' => Class_TypeDoc::LIVRE,
'facettes' => "T1",
'url_vignette' => 'http://image.org/marcus.jpg']);
$this->fixture('Class_Notice',
......@@ -1924,6 +1926,13 @@ class CatalogueControllerActionTesterWithResultsPageTwoTest extends CatalogueCon
}
/** @see https://forge.afi-sa.fr/issues/101887 */
/** @test */
public function rowShouldContainsLinkToSearchTypeWithNoAdmin() {
$this->assertXPath('//td/a[@href= "/recherche/simple/id_catalogue/6/code_rebond/T1"][not(contains(@href, "admin"))]');
}
/** @test */
public function rowShouldContainsLinkToTutuRecordInNewWindow() {
$this->assertXPathContentContains('//td/a[contains(@href, "/viewnotice/id_catalogue/6")][@target="_blank"]', 'tutu');
......
......@@ -864,6 +864,13 @@ class UsersControllerAddActionPostTest extends UsersControllerWithMarcusTestCase
}
/** @test */
public function birthDateShouldBeNull() {
$this->_postData();
$this->assertNull(Class_Users::findFirstBy(['login' => 'mdavis'])->getNaissance());
}
/** @test */
public function existingLoginShouldReturnError() {
$this->user_loader
......
......@@ -102,13 +102,21 @@ class AbonneControllerChangePasswordOnKohaWithRestfulTest
->whenCalled('putData')
->with('http://plage.com/cgi-bin/koha/rest.pl/auth/change_password',
['user_name' => 'testingtest',
'new_password' => 'ce1bnm2p'])
->answers(json_encode([['success' => ['password' => '$2a$08$o0BrhvBevJBbWcYJElH3IevoytrdwnkZUQLwNcxQt3GhAjtht3RoK']]]))
'new_password' => 'Ce1bnm2p'])
->answers(json_encode(['success' => 1, 'reasons' => []]))
->beStrict();
->whenCalled('putData')
->with('http://plage.com/cgi-bin/koha/rest.pl/auth/change_password',
['user_name' => 'testingtest',
'new_password' => 'test'])
->answers(json_encode(['success' => '0', 'reasons' => ['password_too_short' => 1]]))
$this->postDispatch('/abonne/edit', ['password' => 'ce1bnm2p',
'confirm_password' => 'ce1bnm2p']);
->whenCalled('putData')
->with('http://plage.com/cgi-bin/koha/rest.pl/auth/change_password',
['user_name' => 'testingtest',
'new_password' => 'testingsimple'])
->answers(json_encode(['success' => '0', 'reasons' => ['password_too_weak' => 1]]))
->beStrict();
}
......@@ -116,8 +124,28 @@ class AbonneControllerChangePasswordOnKohaWithRestfulTest
/** @test */
public function passwordShouldHaveBeenUpdatedToCe1bnm2p() {
$this->postDispatch('/abonne/edit', ['password' => 'Ce1bnm2p',
'confirm_password' => 'Ce1bnm2p']);
Class_Users::clearCache();
$this->assertEquals('ce1bnm2p', Class_Users::getIdentity()->getPassword());
$this->assertEquals('Ce1bnm2p', Class_Users::getIdentity()->getPassword());
}
/** @test */
public function shortPasswordShouldTriggerError() {
$this->postDispatch('/abonne/edit', ['password' => 'test',
'confirm_password' => 'test']);
Class_Users::clearCache();
$this->assertXPathContentContains('//ul[@class="errors"]//li',
"Mot de passe trop court");
}
/** @test */
public function weakPasswordShouldTriggerError() {
$this->postDispatch('/abonne/edit', ['password' => 'testingsimple',
'confirm_password' => 'testingsimple']);
Class_Users::clearCache();
$this->assertXPathContentContains('//ul[@class="errors"]//li',
"Mot de passe trop faible");
}
}
......
......@@ -21,7 +21,9 @@
require_once 'TelephoneAbstractControllerTestCase.php';
abstract class AbstractIndexControllerTelephoneWithModulesTest extends TelephoneAbstractControllerTestCase {
abstract class AbstractIndexControllerTelephoneWithModulesTest
extends TelephoneAbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
protected function _loginHook($account) {
......@@ -381,29 +383,35 @@ class IndexControllerTelephoneSimulationWithModulesTest extends AbstractIndexCon
class IndexControllerTelephoneWithModulesAndUserLoggedTest extends AbstractIndexControllerTelephoneWithModulesTest {
protected function _loginHook($account) {
$account->ROLE = "abonne_sigb";
$account->ROLE_LEVEL = 2;
$account->ID_USER = 54321;
$account->PSEUDO = "mario";
}
class IndexControllerTelephoneWithModulesAndUserLoggedTest
extends AbstractIndexControllerTelephoneWithModulesTest {
public function setUp() {
$emprunteur = Class_WebService_SIGB_Emprunteur::newInstance(2, 'mario')
->empruntsAddAll(array(Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire()))
->reservationsAddAll(array());
parent::setUp();
Class_Users::getLoader()
->newInstanceWithId(54321)
->setNom('Bros')
->setPrenom('Mario')
->setIdabon(23)
->setFicheSIGB(array('type_comm' => Class_IntBib::COM_NANOOK,
'fiche' => $emprunteur));
$emprunteur = Class_WebService_SIGB_Emprunteur::newInstance(2, 'mario')
->empruntsAddAll([Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire()])
->reservationsAddAll([]);
$this->fixture('Class_UserGroup',
['id' => 44,
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'filters' => json_encode(['search_role_level' => 2])]);
$mario = $this->fixture('Class_Users',
['id' => 54321,
'nom' => 'Bros',
'prenom' => 'Mario',
'login' => 'mariob',
'password' => 'superpass',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'id_site' => 1,
'idabon' => '00022D2D2',
'fiche_sigb' => ['type_comm' => Class_IntBib::COM_NANOOK,
'fiche' => $emprunteur]]);
ZendAfi_Auth::getInstance()->logUser($mario);
parent::setUp();
$this->dispatch('/');
}
......@@ -412,6 +420,16 @@ class IndexControllerTelephoneWithModulesAndUserLoggedTest extends AbstractIndex
public function formLoginShouldNotBeVisible() {
$this->assertNotXPath('//form[contains(@action, "boitelogin")]');
}
/**
* @see http://forge.afi-sa.fr/issues/106412
* @test
*/
public function pageShouldNotContainsUserCriteriaJavascript() {
$this->assertNotXPathContentContains('//script', 'formSelectToggleVisibilityForElement',
$this->_response->getBody());
}
}
......
......@@ -530,13 +530,16 @@ class KohaRestGetUserHistoryTest extends KohaRestfulTestCase {
class KohaRestfulChangePasswordTest extends KohaRestfulTestCase {
protected $_user, $_borrower;
public function setUp() {
parent::setUp();
$borrower = new Class_WebService_SIGB_Emprunteur('harlock', 'harlock');
$borrower->setService($this->service);
$this->_borrower = new Class_WebService_SIGB_Emprunteur('harlock', 'harlock');
$this->_borrower->setService($this->service);
$user = $this->fixture('Class_Users',
$this->_user = $this->fixture('Class_Users',
['id' => 34,
'login' => 'harlock',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
......@@ -544,33 +547,62 @@ class KohaRestfulChangePasswordTest extends KohaRestfulTestCase {
'password' => 'arcadia',
'idabon' => 'AO989IE']);
$user->setFicheSIGB(['fiche' => $borrower]);
$this->_user->setFicheSIGB(['fiche' => $this->_borrower]);
}
public function setPasswordWaitReply($password,$response){
$this->mock_web_client
->whenCalled('putData')
->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/rest.pl/auth/change_password',
['user_name' => 'harlock',
'new_password' => 'ce1snm2p'])
->answers(json_encode([['success' => ['password' => '$2a$08$o0BrhvBevJBbWcYJElH3IevoytrdwnkZUQLwNcxQt3GhAjtht3RoK']]]))
'new_password' => $password])
->answers($response)
->beStrict();
$user->setPassword('ce1snm2p');
$borrower->updateFromUser($user);
$user->save();
$this->_user->setPassword($password);
$this->_borrower->updateFromUser($this->_user);
Class_Users::clearCache();
$borrower->save();
$this->_borrower->save();
$this->_user->save();
}
/** @test */
public function userPasswordShouldBeCe1snm2p() {
$this->assertEquals('ce1snm2p', Class_Users::find(34)->getPassword());
public function withNotJSONReplyShouldNotUpdatePasswordAndTriggerException() {
$this->expectException(Class_WebService_Exception::class);
$password = 'tst';
$response = "NotAJSON";
$this->setPasswordWaitReply($password,$response);
$this->assertEquals('arcadia', Class_Users::find(34)->getPassword());
}
/** @test */
public function kohaShouldHaveBeenCalled() {
$this->assertTrue($this->mock_web_client->methodHasBeenCalled('putData'));
public function withPasswordTooShortShouldNotUpdatePasswordAndTriggerException() {
$this->expectException(Class_WebService_Exception::class);
$password = 'tst';
$response = ['success' => 0,
'reasons' => ['password_too_short' => 1] ];
$this->setPasswordWaitReply($password, json_encode($response));
$this->assertEquals('arcadia', Class_Users::find(34)->getPassword());
}
/** @test */
public function withPasswordTooWeakShouldNotUpdatePasswordAndTriggerException() {
$this->expectException(Class_WebService_Exception::class);
$password = 'testingsimplestuff';
$response = [ 'success' => 0, 'reasons' => ['password_too_weak' => 1] ];
$this->setPasswordWaitReply($password,json_encode($response));
$this->assertEquals('arcadia', Class_Users::find(34)->getPassword());
}
/** @test */
public function withValidPasswordShouldUpdateQuietly() {
$password = 'testingComplex35tUff!';
$response = [ 'success' => 1, 'reasons' => [] ];
$this->setPasswordWaitReply($password,json_encode($response));
$this->assertEquals($password, Class_Users::find(34)->getPassword());
}
}
\ 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