]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix tests 3825/head
authorBjoern Schiessle <bjoern@schiessle.org>
Thu, 23 Mar 2017 15:10:53 +0000 (16:10 +0100)
committerBjoern Schiessle <bjoern@schiessle.org>
Fri, 24 Mar 2017 10:27:01 +0000 (11:27 +0100)
calling getAbsoluteBundlePath() in the constructor makes other tests fail

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/dav/lib/CardDAV/SyncService.php
apps/dav/tests/unit/CardDAV/SyncServiceTest.php

index b0a4ce81e707ef890c757bedda9300bbcbeb8d0e..477e912a79708e3ebb0d27bc4035f60fd4ba4811 100644 (file)
@@ -26,6 +26,7 @@ namespace OCA\DAV\CardDAV;
 
 use OC\Accounts\AccountManager;
 use OCP\AppFramework\Http;
+use OCP\ICertificateManager;
 use OCP\ILogger;
 use OCP\IUser;
 use OCP\IUserManager;
@@ -68,12 +69,7 @@ class SyncService {
                $this->userManager = $userManager;
                $this->logger = $logger;
                $this->accountManager = $accountManager;
-
-               $certManager = \OC::$server->getCertificateManager(null);
-               $certPath = $certManager->getAbsoluteBundlePath();
-               if (file_exists($certPath)) {
-                       $this->certPath = $certPath;
-               }
+               $this->certPath = '';
        }
 
        /**
@@ -141,6 +137,28 @@ class SyncService {
                return $this->backend->getAddressBooksByUri($principal, $id);
        }
 
+       /**
+        * Check if there is a valid certPath we should use
+        *
+        * @return string
+        */
+       protected function getCertPath() {
+
+               // we already have a valid certPath
+               if ($this->certPath !== '') {
+                       return $this->certPath;
+               }
+
+               /** @var ICertificateManager $certManager */
+               $certManager = \OC::$server->getCertificateManager(null);
+               $certPath = $certManager->getAbsoluteBundlePath();
+               if (file_exists($certPath)) {
+                       $this->certPath = $certPath;
+               }
+
+               return $this->certPath;
+       }
+
        /**
         * @param string $url
         * @param string $userName
@@ -154,9 +172,10 @@ class SyncService {
                        'password' => $sharedSecret,
                ];
                $client = new Client($settings);
+               $certPath = $this->getCertPath();
                $client->setThrowExceptions(true);
 
-               if (strpos($url, 'http://') !== 0 && $this->certPath) {
+               if ($certPath !== '' && strpos($url, 'http://') !== 0) {
                        $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
                }
 
index de4e8ead4c0b6a0f25c81e6bcbb2caf94419843d..c06e48577437f0fcbb04b4d99142eed7f03f96a4 100644 (file)
@@ -179,7 +179,7 @@ class SyncServiceTest extends TestCase {
                $accountManager = $this->getMockBuilder('OC\Accounts\AccountManager')->disableOriginalConstructor()->getMock();
                /** @var SyncService | \PHPUnit_Framework_MockObject_MockObject $ss */
                $ss = $this->getMockBuilder(SyncService::class)
-                       ->setMethods(['ensureSystemAddressBookExists', 'requestSyncReport', 'download'])
+                       ->setMethods(['ensureSystemAddressBookExists', 'requestSyncReport', 'download', 'getCertPath'])
                        ->setConstructorArgs([$backend, $userManager, $logger, $accountManager])
                        ->getMock();
                $ss->method('requestSyncReport')->withAnyParameters()->willReturn(['response' => $response, 'token' => 'sync-token-1']);
@@ -189,6 +189,7 @@ class SyncServiceTest extends TestCase {
                        'statusCode' => 200,
                        'headers' => []
                ]);
+               $ss->method('getCertPath')->willReturn('');
                return $ss;
        }