Skip to content
Snippets Groups Projects
Commit 8de0e0f3 authored by llaffont's avatar llaffont
Browse files

Authentification: échec si données renvoyées par le SIGB insuffisantes

parent 04dd4391
Branches
Tags
No related merge requests found
......@@ -55,11 +55,8 @@ class ZendAfi_Auth_Adapter_CommSigb implements Zend_Auth_Adapter_Interface {
->beAbonneSIGB();
$result = $this->authenticateUserFromSIGB($user);
if (!$result->isValid())
return $result;
$user->save();
$this->_authenticated_user = $user;
if ($result->isValid())
$this->_authenticated_user = $user;
return $result;
}
......@@ -84,6 +81,10 @@ class ZendAfi_Auth_Adapter_CommSigb implements Zend_Auth_Adapter_Interface {
->setNom($emprunteur->getNom())
->setPrenom($emprunteur->getPrenom())
->setMail($emprunteur->getEmail());
if (!$user->save())
continue;
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $user->getLogin());
}
......
......@@ -19,8 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class AuthCommSigbAuthenticationWithoutWebServicesTest extends Storm_Test_ModelTestCase {
abstract class AuthCommSigbTestCase extends Storm_Test_ModelTestCase {
public function setUp() {
parent::setUp();
......@@ -31,6 +30,15 @@ class AuthCommSigbAuthenticationWithoutWebServicesTest extends Storm_Test_ModelT
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_IntBib')
->whenCalled('findAllBy')
->answers([]);
}
}
class AuthCommSigbAuthenticationWithoutWebServicesTest extends AuthCommSigbTestCase {
public function setUp() {
parent::setUp();
$this->_adapter = (new ZendAfi_Auth_Adapter_CommSigb())
->setIdentity('zork_sigb')
......@@ -52,12 +60,11 @@ class AuthCommSigbAuthenticationWithoutWebServicesTest extends Storm_Test_ModelT
abstract class AuthCommSigbWithWebServicesAndAbonneZorkTestCase extends Storm_Test_ModelTestCase {
abstract class AuthCommSigbWithWebServicesAndAbonneZorkTestCase extends AuthCommSigbTestCase {
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_IntBib')
->whenCalled('findAllBy')
Class_IntBib::whenCalled('findAllBy')
->with(['comm_sigb' => Class_IntBib::allCommSigbCodes()])
->answers([Class_IntBib::newInstanceWithId(1)
->setCommSigb(Class_IntBib::COM_NANOOK),
......@@ -97,11 +104,11 @@ class AuthCommSigbSuccessfullAuthenticationTest extends AuthCommSigbWithWebServi
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users')
->whenCalled('save')
->willDo(function($user) {
$user->setId(23);
return true; });
Class_Users::whenCalled('save')->willDo(
function($user) {
$user->setId(23);
return true;
});
$this->_adapter = (new ZendAfi_Auth_Adapter_CommSigb())
->setIdentity('zork_sigb')
......@@ -134,4 +141,38 @@ class AuthCommSigbSuccessfullAuthenticationTest extends AuthCommSigbWithWebServi
$this->assertEquals('zork@gmail.com', $result->MAIL);
}
}
class AuthCommSigbAuthenticationSetupInvalidUserTest extends AuthCommSigbWithWebServicesAndAbonneZorkTestCase {
public function setUp() {
parent::setUp();
Class_Users::whenCalled('save')->answers(true);
$this->opsys
->whenCalled('getEmprunteur')
->answers(Class_WebService_SIGB_Emprunteur::newInstance(null)
->beValid());
$this->_adapter = (new ZendAfi_Auth_Adapter_CommSigb())
->setIdentity('zork_sigb')
->setCredential('secret');
$this->_authenticate_result = $this->_adapter->authenticate();
}
/** @test */
public function authenticateZorkShouldNotBeValid() {
$this->assertFalse($this->_authenticate_result->isValid());
}
/** @test */
public function noUserShouldHaveBeenSaved() {
$this->assertFalse(Class_Users::methodHasBeenCalled('save'));
}
}
?>
\ No newline at end of file
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