summaryrefslogtreecommitdiffstats
path: root/apps/federation
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-12-11 15:07:08 +0100
committerMorris Jobke <hey@morrisjobke.de>2017-12-11 18:14:01 +0100
commit2c2e1c4c7a94cdd3319c029e22e616df0853310e (patch)
tree9f83f04d1ed392cc26dfd750fad87c353e02f7d7 /apps/federation
parentba3c608a00f3834f743de5a0cd82ddae3825d458 (diff)
downloadnextcloud-server-2c2e1c4c7a94cdd3319c029e22e616df0853310e.tar.gz
nextcloud-server-2c2e1c4c7a94cdd3319c029e22e616df0853310e.zip
Catch the errors related to untrusted self signed certificates for federation
* Added tests Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/federation')
-rw-r--r--apps/federation/lib/BackgroundJob/GetSharedSecret.php7
-rw-r--r--apps/federation/lib/BackgroundJob/RequestSharedSecret.php7
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php38
-rw-r--r--apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php38
4 files changed, 88 insertions, 2 deletions
diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
index 6090f521fcc..92bb31e369e 100644
--- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
@@ -32,6 +32,8 @@ namespace OCA\Federation\BackgroundJob;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Exception\RequestException;
+use GuzzleHttp\Ring\Exception\RingException;
use OC\BackgroundJob\JobList;
use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
@@ -197,7 +199,10 @@ class GetSharedSecret extends Job {
} else {
$this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']);
}
- } catch (ConnectException $e) {
+ } catch (RequestException $e) {
+ $status = -1; // There is no status code if we could not connect
+ $this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
+ } catch (RingException $e) {
$status = -1; // There is no status code if we could not connect
$this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
} catch (\Exception $e) {
diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
index a201c9dccb6..ad7504da7ad 100644
--- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
@@ -33,6 +33,8 @@ namespace OCA\Federation\BackgroundJob;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Exception\RequestException;
+use GuzzleHttp\Ring\Exception\RingException;
use OC\BackgroundJob\JobList;
use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
@@ -197,7 +199,10 @@ class RequestSharedSecret extends Job {
} else {
$this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']);
}
- } catch (ConnectException $e) {
+ } catch (RequestException $e) {
+ $status = -1; // There is no status code if we could not connect
+ $this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
+ } catch (RingException $e) {
$status = -1; // There is no status code if we could not connect
$this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
} catch (\Exception $e) {
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index 2058b2592c8..1e264919e78 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -29,6 +29,7 @@ namespace OCA\Federation\Tests\BackgroundJob;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Ring\Exception\RingException;
use OCA\Federation\BackgroundJob\GetSharedSecret;
use OCA\Files_Sharing\Tests\TestCase;
use OCA\Federation\DbHandler;
@@ -315,4 +316,41 @@ class GetSharedSecretTest extends TestCase {
$this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
}
+
+ public function testRunRingException() {
+ $target = 'targetURL';
+ $source = 'sourceURL';
+ $token = 'token';
+
+ $argument = ['url' => $target, 'token' => $token];
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(42);
+
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('/')
+ ->willReturn($source);
+ $this->httpClient->expects($this->once())->method('get')
+ ->with(
+ $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json',
+ [
+ 'query' =>
+ [
+ 'url' => $source,
+ 'token' => $token
+ ],
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ]
+ )->willThrowException($this->createMock(RingException::class));
+
+ $this->dbHandler->expects($this->never())->method('addToken');
+ $this->trustedServers->expects($this->never())->method('addSharedSecret');
+
+ $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+
+ $this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ }
}
diff --git a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
index 57a85f1be0b..20610f1f0fb 100644
--- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
@@ -28,6 +28,7 @@ namespace OCA\Federation\Tests\BackgroundJob;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Ring\Exception\RingException;
use OCA\Federation\BackgroundJob\RequestSharedSecret;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
@@ -300,4 +301,41 @@ class RequestSharedSecretTest extends TestCase {
$this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
$this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
}
+
+ public function testRunRingException() {
+ $target = 'targetURL';
+ $source = 'sourceURL';
+ $token = 'token';
+
+ $argument = ['url' => $target, 'token' => $token];
+
+ $this->timeFactory->method('getTime')->willReturn(42);
+
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('/')
+ ->willReturn($source);
+
+ $this->httpClient
+ ->expects($this->once())
+ ->method('post')
+ ->with(
+ $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json',
+ [
+ 'body' =>
+ [
+ 'url' => $source,
+ 'token' => $token
+ ],
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ]
+ )->willThrowException($this->createMock(RingException::class));
+
+ $this->dbHandler->expects($this->never())->method('addToken');
+
+ $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ }
}