]> source.dussan.org Git - nextcloud-server.git/commitdiff
load 2FA provider apps before querying classes
authorChristoph Wurst <christoph@owncloud.com>
Thu, 16 Jun 2016 08:08:49 +0000 (10:08 +0200)
committerChristoph Wurst <christoph@owncloud.com>
Thu, 16 Jun 2016 08:12:16 +0000 (10:12 +0200)
lib/private/Authentication/TwoFactorAuth/Manager.php
tests/lib/Authentication/TwoFactorAuth/ManagerTest.php

index 805735bd1b83aca48d9743d60a924046da76b49c..6ca4fd065a6ad9d77147e02b79d6f80d826c5488 100644 (file)
@@ -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
         *
index 363229b01bc4ae5044d8bd6dd16edab7829e745e..283ba7f9424eae327a75ea96fc8df6bc6c871737 100644 (file)
@@ -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())