From d24b6866b1624666af751dfd6cdb25e49c591edd Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 29 Nov 2017 16:28:38 +0100 Subject: Actually set the status so we don't cause another exception * And add tests so I don't mess up again Signed-off-by: Roeland Jago Douma --- .../tests/BackgroundJob/GetSharedSecretTest.php | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'apps/federation/tests/BackgroundJob/GetSharedSecretTest.php') 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')); + } } -- cgit v1.2.3