From 7ccf5c0d9ecbf14a0dfa7b38909690a8657196ed Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Fri, 31 Aug 2012 07:51:54 +0000 Subject: [PATCH] =?UTF-8?q?Multimedia:=20branchement=20des=20requetes=20d'?= =?UTF-8?q?authentification=20sur=20le=20syst=C3=A8me=20d'authentification?= =?UTF-8?q?=20g=C3=A9n=C3=A9ral?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Class/Multimedia/AuthenticateRequest.php | 20 +++++++--------- .../AbonneControllerMultimediaTest.php | 24 +++++++++++++++++-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/library/Class/Multimedia/AuthenticateRequest.php b/library/Class/Multimedia/AuthenticateRequest.php index 5f5e28545d4..b44711b4840 100644 --- a/library/Class/Multimedia/AuthenticateRequest.php +++ b/library/Class/Multimedia/AuthenticateRequest.php @@ -53,12 +53,14 @@ class Class_Multimedia_AuthenticateRequest { || !($poste = $request->getParam('poste')) || !($site = $request->getParam('site'))) return $this->_error('MissingParameter'); - - if (!$user = Class_Users::getLoader()->findFirstBy(array('login' => $login))) - return $this->_error('UserNotFound'); - if (($user->getPassword() !== $password)) - return $this->_error('PasswordIsWrong'); + if (!ZendAfi_Auth::getInstance()->authenticateLoginPassword($login, $password)) { + if (Class_Users::findFirstBy(['login' => $login])) + return $this->_error('PasswordIsWrong'); + return $this->_error('UserNotFound'); + } + + $user = Class_Users::getIdentity(); if (!$user->isAbonnementValid()) return $this->_error('SubscriptionExpired'); @@ -121,15 +123,9 @@ class Class_Multimedia_AuthenticateRequest { } - /** @return Class_Multimedia_Device */ - public function getDevice() { - return $this->_device; - } - - /** * @param string $code - * @return Class_Multimedia_Device + * @return Class_Multimedia_AuthenticateRequest */ protected function _error($code) { $this->_error = $code; diff --git a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php index af40997c804..4b3d147ada8 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php @@ -58,14 +58,27 @@ trait TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles { abstract class AbonneControllerMultimediaAuthenticateTestCase extends AbstractControllerTestCase { - protected $_json; + protected $_json, $_auth; public function setUp() { parent::setUp(); - ZendAfi_Auth::getInstance()->clearIdentity(); + $this->_auth = Storm_Test_ObjectWrapper::mock() + ->whenCalled('authenticateLoginPassword') + ->answers(false) + ->whenCalled('hasIdentity') + ->answers(false) + ->whenCalled('getIdentity') + ->answers(null); + + ZendAfi_Auth::setInstance($this->_auth); } + public function tearDown() { + ZendAfi_Auth::setInstance(null); + parent::tearDown(); + } + /** * @param $url string * @return stdClass @@ -80,6 +93,13 @@ abstract class AbonneControllerMultimediaAuthenticateTestCase extends AbstractCo * @param $user Class_Users */ protected function _expectUserToLoad($user) { + $this->_auth + ->whenCalled('authenticateLoginPassword') + ->with($user->getLogin(), $user->getPassword()) + ->answers(true) + ->whenCalled('getIdentity') + ->answers($user); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') ->whenCalled('findFirstBy') ->with(array('login'=> $user->getLogin())) -- GitLab