From a40d64ff7fdf65049a1a60196761fa743728e2da Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 16 Jun 2016 10:08:49 +0200 Subject: [PATCH 1/2] load 2FA provider apps before querying classes --- .../Authentication/TwoFactorAuth/Manager.php | 13 +++++++++++++ .../Authentication/TwoFactorAuth/ManagerTest.php | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 805735bd1b..6ca4fd065a 100644 --- a/lib/private/Authentication/TwoFactorAuth/Manager.php +++ b/lib/private/Authentication/TwoFactorAuth/Manager.php @@ -24,6 +24,7 @@ namespace OC\Authentication\TwoFactorAuth; use Exception; use OC; use OC\App\AppManager; +use OC_App; use OCP\AppFramework\QueryException; use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\IConfig; @@ -110,6 +111,7 @@ class Manager { $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) { @@ -125,6 +127,17 @@ class Manager { }); } + /** + * Load an app by ID if it has not been loaded yet + * + * @param string $appId + */ + protected function loadTwoFactorApp($appId) { + if (!OC_App::isAppLoaded($appId)) { + OC_App::loadApp($appId); + } + } + /** * Verify the given challenge * diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index 363229b01b..283ba7f942 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -55,7 +55,10 @@ class ManagerTest extends TestCase { $this->session = $this->getMock('\OCP\ISession'); $this->config = $this->getMock('\OCP\IConfig'); - $this->manager = new Manager($this->appManager, $this->session, $this->config); + $this->manager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager') + ->setConstructorArgs([$this->appManager, $this->session, $this->config]) + ->setMethods(['loadTwoFactorApp']) // Do not actually load the apps + ->getMock(); $this->fakeProvider = $this->getMock('\OCP\Authentication\TwoFactorAuth\IProvider'); $this->fakeProvider->expects($this->any()) From 3521f974db2cf7bebac66ab4c987bb3c67d5d02f Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 16 Jun 2016 11:07:44 +0200 Subject: [PATCH 2/2] assert app is loaded in unit tests --- tests/lib/Authentication/TwoFactorAuth/ManagerTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index 283ba7f942..586fd3aaa2 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -86,6 +86,10 @@ class ManagerTest extends TestCase { '\OCA\MyCustom2faApp\FakeProvider', ], ])); + + $this->manager->expects($this->once()) + ->method('loadTwoFactorApp') + ->with('mycustom2faapp'); } /** @@ -97,6 +101,9 @@ class ManagerTest extends TestCase { ->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')