Commit 9a4dcff9 authored by David Maus's avatar David Maus
Browse files

Handle authentication module runtime errors

* lib/Auth/Source/Pica.php (login): Handle authentication module runtime
  errors.
  (getAuthenticationModule): Declare protected to ease unit test.
parent cbfcacd5
......@@ -60,7 +60,11 @@ class sspmod_pica_Auth_Source_Pica extends sspmod_core_Auth_UserPassBase
protected function login ($username, $password)
{
$module = $this->getAuthenticationModule();
$attributes = $module->authenticate($username, $password);
try {
$attributes = $module->authenticate($username, $password);
} catch (RuntimeException $error) {
throw new SimpleSAML_Error_AuthSource('pica', $error->getMessage(), $error);
}
if ($attributes === false) {
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
}
......@@ -118,7 +122,7 @@ class sspmod_pica_Auth_Source_Pica extends sspmod_core_Auth_UserPassBase
*
* @return Auth\AuthenticationInterface
*/
private function getAuthenticationModule ()
protected function getAuthenticationModule ()
{
return call_user_func($this->factory);
}
......
......@@ -48,4 +48,30 @@ class PicaTest extends TestCase
->getMock();
$source->createAuthenticationModuleFactory($config);
}
/**
* @expectedException SimpleSAML_Error_AuthSource
*/
public function testExceptionOnAuthenticationModuleRuntimeError ()
{
$module = $this->getMockForAbstractClass('HAB\Pica\Auth\AuthenticationInterface');
$module
->expects($this->any())
->method('authenticate')
->will($this->throwException(new RuntimeException()));
$source = $this
->getMockBuilder('sspmod_pica_Auth_Source_Pica')
->disableOriginalConstructor()
->setMethods(array('getAuthenticationModule'))
->getMock();
$source
->expects($this->any())
->method('getAuthenticationModule')
->will($this->returnValue($module));
$method = new ReflectionMethod($source, 'login');
$method->setAccessible(true);
$method->invoke($source, 'foo', 'bar');
}
}
\ 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