aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-11-29 21:13:55 +0100
committerGitHub <noreply@github.com>2017-11-29 21:13:55 +0100
commit87aa0723f8279d76a743fbe45004676b4a3526a7 (patch)
treea77ec1c73d0ede0c7fbd1fa401b089e16c6cb6af
parenta9eb0d4a4084d9590cb954f385af0137ce399ca3 (diff)
parentd24b6866b1624666af751dfd6cdb25e49c591edd (diff)
downloadnextcloud-server-87aa0723f8279d76a743fbe45004676b4a3526a7.tar.gz
nextcloud-server-87aa0723f8279d76a743fbe45004676b4a3526a7.zip
Merge pull request #7343 from nextcloud/fix_exception_on_unreachable_server_take2
Actually set the status so we don't cause another exception
-rw-r--r--apps/federation/lib/BackgroundJob/GetSharedSecret.php1
-rw-r--r--apps/federation/lib/BackgroundJob/RequestSharedSecret.php1
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php38
-rw-r--r--apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php38
4 files changed, 78 insertions, 0 deletions
diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
index 0c621aa40ea..6090f521fcc 100644
--- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
@@ -198,6 +198,7 @@ class GetSharedSecret extends Job {
$this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']);
}
} catch (ConnectException $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) {
$status = Http::STATUS_INTERNAL_SERVER_ERROR;
diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
index 09de76cba95..a201c9dccb6 100644
--- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
@@ -198,6 +198,7 @@ class RequestSharedSecret extends Job {
$this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']);
}
} catch (ConnectException $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) {
$status = Http::STATUS_INTERNAL_SERVER_ERROR;
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index fca64faebe4..2058b2592c8 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -28,6 +28,7 @@
namespace OCA\Federation\Tests\BackgroundJob;
+use GuzzleHttp\Exception\ConnectException;
use OCA\Federation\BackgroundJob\GetSharedSecret;
use OCA\Files_Sharing\Tests\TestCase;
use OCA\Federation\DbHandler;
@@ -277,4 +278,41 @@ class GetSharedSecretTest extends TestCase {
$this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
}
+
+ public function testRunConnectionError() {
+ $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(ConnectException::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 33133e3b12f..57a85f1be0b 100644
--- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
@@ -27,6 +27,7 @@
namespace OCA\Federation\Tests\BackgroundJob;
+use GuzzleHttp\Exception\ConnectException;
use OCA\Federation\BackgroundJob\RequestSharedSecret;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
@@ -262,4 +263,41 @@ class RequestSharedSecretTest extends TestCase {
$this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
}
+
+ public function testRunConnectionError() {
+ $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(ConnectException::class));
+
+ $this->dbHandler->expects($this->never())->method('addToken');
+
+ $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ }
}