/** * @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->manager->expects($this->once())->method('loadTwoFactorApp')->with('faulty2faapp'); $this->appManager->expects($this->once())->method('getAppInfo')->with('faulty2faapp')->will($this->returnValue(['two-factor-providers' => ['\\OCA\\MyFaulty2faApp\\DoesNotExist']])); $this->manager->getProviders($this->user); }
/** * Get the list of 2FA providers for the given user * * @param IUser $user * @return IProvider[] */ public function getProviders(IUser $user) { $allApps = $this->appManager->getEnabledAppsForUser($user); $providers = []; foreach ($allApps as $appId) { $info = $this->appManager->getAppInfo($appId); $providerClasses = $info['two-factor-providers']; foreach ($providerClasses as $class) { try { $this->loadTwoFactorApp($appId); $provider = OC::$server->query($class); $providers[$provider->getId()] = $provider; } catch (QueryException $exc) { // Provider class can not be resolved throw new Exception("Could not load two-factor auth provider {$class}"); } } } return array_filter($providers, function ($provider) use($user) { /* @var $provider IProvider */ return $provider->isTwoFactorAuthEnabledForUser($user); }); }