diff --git a/lib/Auth/Source/Pica.php b/lib/Auth/Source/Pica.php index 6deb9da2d0510ed4454450e74be5a9c3add23dd1..9766405dd2860c775360ff541ce6aef8dc7f390a 100644 --- a/lib/Auth/Source/Pica.php +++ b/lib/Auth/Source/Pica.php @@ -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); } diff --git a/tests/PicaTest.php b/tests/PicaTest.php index a5b060b6c06f6fe923aa45b7e4a3424cab5f7dab..1ff87a9f2aeb3c219467540859ebb627c944d510 100644 --- a/tests/PicaTest.php +++ b/tests/PicaTest.php @@ -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