]> source.dussan.org Git - nextcloud-server.git/commitdiff
Automatic creation of Identity manager
authorJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 07:44:28 +0000 (09:44 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 07:45:11 +0000 (09:45 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
core/Application.php
lib/private/AppFramework/DependencyInjection/DIContainer.php
lib/private/Security/IdentityProof/Manager.php
tests/lib/Security/IdentityProof/ManagerTest.php

index 5a2bc477fee568a79f6743907dce1b69cb6ecfe3..5fafb0441f0be8b6a0385b6d5e4d05531292d314 100644 (file)
@@ -30,7 +30,6 @@
 
 namespace OC\Core;
 
-use OC\Security\IdentityProof\Manager;
 use OCP\AppFramework\App;
 use OCP\Util;
 
@@ -49,11 +48,5 @@ class Application extends App {
                $container->registerService('defaultMailAddress', function () {
                        return Util::getDefaultEmailAddress('lostpassword-noreply');
                });
-               $container->registerService(Manager::class, function () {
-                       return new Manager(
-                               \OC::$server->getAppDataDir('identityproof'),
-                               \OC::$server->getCrypto()
-                       );
-               });
        }
 }
index 04747485c13321084452dbd189e5cb130e375cf0..d24836228cc633c1f92e511f18f1b76234435f0f 100644 (file)
@@ -165,7 +165,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
 
                $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
                        return new \OC\Security\IdentityProof\Manager(
-                               $this->getServer()->getAppDataDir('identityproof'),
+                               $this->getServer()->query(\OC\Files\AppData\Factory::class),
                                $this->getServer()->getCrypto()
                        );
                });
index d2a9e57e3387e646f48cb4e65f8204a4632da8f1..73edac5f7478e4837b49a18f23422b1bd3e7267a 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace OC\Security\IdentityProof;
 
+use OC\Files\AppData\Factory;
 use OCP\Files\IAppData;
 use OCP\IUser;
 use OCP\Security\ICrypto;
@@ -32,12 +33,12 @@ class Manager {
        private $crypto;
 
        /**
-        * @param IAppData $appData
+        * @param Factory $appDataFactory
         * @param ICrypto $crypto
         */
-       public function __construct(IAppData $appData,
+       public function __construct(Factory $appDataFactory,
                                                                ICrypto $crypto) {
-               $this->appData = $appData;
+               $this->appData = $appDataFactory->get('identityproof');
                $this->crypto = $crypto;
        }
 
index 2925dea5ec5b2392d59c9504ddd209f3cb44b0a0..b46ca30705a14694b1bf6ec71a0b5ec8abc8ab59 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace Test\Security\IdentityProof;
 
+use OC\Files\AppData\Factory;
 use OC\Security\IdentityProof\Key;
 use OC\Security\IdentityProof\Manager;
 use OCP\Files\IAppData;
@@ -31,6 +32,8 @@ use OCP\Security\ICrypto;
 use Test\TestCase;
 
 class ManagerTest extends TestCase  {
+       /** @var Factory|\PHPUnit_Framework_MockObject_MockObject */
+       private $factory;
        /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
        private $appData;
        /** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */
@@ -40,11 +43,19 @@ class ManagerTest extends TestCase  {
 
        public function setUp() {
                parent::setUp();
+
+               /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
+               $this->factory = $this->createMock(Factory::class);
                $this->appData = $this->createMock(IAppData::class);
+               $this->factory->expects($this->any())
+                       ->method('get')
+                       ->with('identityproof')
+                       ->willReturn($this->appData);
+
                $this->crypto = $this->createMock(ICrypto::class);
                $this->manager = $this->getMockBuilder(Manager::class)
                        ->setConstructorArgs([
-                               $this->appData,
+                               $this->factory,
                                $this->crypto
                        ])
                        ->setMethods(['generateKeyPair'])
@@ -151,12 +162,12 @@ class ManagerTest extends TestCase  {
 
        public function testGenerateKeyPair() {
                $manager = new Manager(
-                       $this->appData,
+                       $this->factory,
                        $this->crypto
                );
                $data = 'MyTestData';
 
-               list($resultPublicKey, $resultPrivateKey) = $this->invokePrivate($manager, 'generateKeyPair');
+               list($resultPublicKey, $resultPrivateKey) = self::invokePrivate($manager, 'generateKeyPair');
                openssl_sign($data, $signature, $resultPrivateKey);
                $details = openssl_pkey_get_details(openssl_pkey_get_public($resultPublicKey));