mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
fail hard if 2fa provider can not be loaded (#25061)
This commit is contained in:
parent
f7c41fa4e6
commit
5daa9a5417
2 changed files with 27 additions and 4 deletions
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace OC\Authentication\TwoFactorAuth;
|
||||
|
||||
use Exception;
|
||||
use OC;
|
||||
use OC\App\AppManager;
|
||||
use OCP\AppFramework\QueryException;
|
||||
|
|
@ -112,7 +113,8 @@ class Manager {
|
|||
$provider = OC::$server->query($class);
|
||||
$providers[$provider->getId()] = $provider;
|
||||
} catch (QueryException $exc) {
|
||||
// Provider class can not be resolved, ignore it
|
||||
// Provider class can not be resolved
|
||||
throw new Exception("Could not load two-factor auth provider $class");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,11 +85,32 @@ class ManagerTest extends TestCase {
|
|||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage Could not load two-factor auth provider \OCA\MyFaulty2faApp\DoesNotExist
|
||||
*/
|
||||
public function testFailHardIfProviderCanNotBeLoaded() {
|
||||
$this->appManager->expects($this->once())
|
||||
->method('getEnabledAppsForUser')
|
||||
->with($this->user)
|
||||
->will($this->returnValue(['faulty2faapp']));
|
||||
|
||||
$this->appManager->expects($this->once())
|
||||
->method('getAppInfo')
|
||||
->with('faulty2faapp')
|
||||
->will($this->returnValue([
|
||||
'two-factor-providers' => [
|
||||
'\OCA\MyFaulty2faApp\DoesNotExist',
|
||||
],
|
||||
]));
|
||||
|
||||
$this->manager->getProviders($this->user);
|
||||
}
|
||||
|
||||
public function testIsTwoFactorAuthenticated() {
|
||||
$this->prepareProviders();
|
||||
|
||||
$user = $this->getMock('\OCP\IUser');
|
||||
$user->expects($this->once())
|
||||
$this->user->expects($this->once())
|
||||
->method('getUID')
|
||||
->will($this->returnValue('user123'));
|
||||
$this->config->expects($this->once())
|
||||
|
|
@ -97,7 +118,7 @@ class ManagerTest extends TestCase {
|
|||
->with('user123', 'core', 'two_factor_auth_disabled', 0)
|
||||
->will($this->returnValue(0));
|
||||
|
||||
$this->assertTrue($this->manager->isTwoFactorAuthenticated($user));
|
||||
$this->assertTrue($this->manager->isTwoFactorAuthenticated($this->user));
|
||||
}
|
||||
|
||||
public function testGetProvider() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue