From 82a1f1dc351e54ef46c821f1ebf23084b10058fb Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 25 May 2020 15:03:52 +0200 Subject: [PATCH] Do not read certificate bundle from data dir by default Before the resources/config/ca-bundle.crt was only used when the list of custom certificates was empty and the instance was not installed. But it should also be used when the list is empty and the instance is installed. This is inverting the logic to stop if the instance is not installed to use the default bundle. And it also does this when the list is empty. Signed-off-by: Morris Jobke --- lib/private/Http/Client/Client.php | 22 +++++++++++----------- tests/lib/Http/Client/ClientTest.php | 5 ++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php index 0dde56b28f969..2cf5332d0c683 100644 --- a/lib/private/Http/Client/Client.php +++ b/lib/private/Http/Client/Client.php @@ -93,18 +93,18 @@ private function getRequestOptions() { } private function getCertBundle() { - if ($this->certificateManager->listCertificates() !== []) { - return $this->certificateManager->getAbsoluteBundlePath(); - } else { - // If the instance is not yet setup we need to use the static path as - // $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate - // a view - if ($this->config->getSystemValue('installed', false)) { - return $this->certificateManager->getAbsoluteBundlePath(null); - } else { - return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'; - } + // If the instance is not yet setup we need to use the static path as + // $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate + // a view + if ($this->config->getSystemValue('installed', false) === false) { + return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'; } + + if ($this->certificateManager->listCertificates() === []) { + return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'; + } + + return $this->certificateManager->getAbsoluteBundlePath(); } /** diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index ea825266198f7..54d6cc465a9a0 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -260,9 +260,8 @@ public function testSetDefaultOptionsWithNotInstalled() { ->with('installed', false) ->willReturn(false); $this->certificateManager - ->expects($this->once()) - ->method('listCertificates') - ->willReturn([]); + ->expects($this->never()) + ->method('listCertificates'); $this->assertEquals([ 'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',