summaryrefslogtreecommitdiffstats
path: root/apps/federation/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2018-04-20 15:53:10 +0200
committerMorris Jobke <hey@morrisjobke.de>2018-05-29 15:34:32 +0200
commit58be1f1b2f02ff6aace5424556b3ff27d0d8da5e (patch)
tree2bf0feb5c614235c37b8360b8e849ddb14d3f68a /apps/federation/tests
parentaf2ecbbd5a81d8e1621ecda1784a99adb0fc43dd (diff)
downloadnextcloud-server-58be1f1b2f02ff6aace5424556b3ff27d0d8da5e.tar.gz
nextcloud-server-58be1f1b2f02ff6aace5424556b3ff27d0d8da5e.zip
improve error reporting and move format parameter to the options
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/federation/tests')
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php34
-rw-r--r--apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php38
-rw-r--r--apps/federation/tests/Controller/OCSAuthAPIControllerTest.php3
3 files changed, 18 insertions, 57 deletions
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index 1e264919e78..d195c81de31 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -32,7 +32,6 @@ use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Ring\Exception\RingException;
use OCA\Federation\BackgroundJob\GetSharedSecret;
use OCA\Files_Sharing\Tests\TestCase;
-use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -68,9 +67,6 @@ class GetSharedSecretTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject|TrustedServers */
private $trustedServers;
- /** @var \PHPUnit_Framework_MockObject_MockObject|DbHandler */
- private $dbHandler;
-
/** @var \PHPUnit_Framework_MockObject_MockObject|ILogger */
private $logger;
@@ -95,8 +91,6 @@ class GetSharedSecretTest extends TestCase {
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
$this->trustedServers = $this->getMockBuilder(TrustedServers::class)
->disableOriginalConstructor()->getMock();
- $this->dbHandler = $this->getMockBuilder(DbHandler::class)
- ->disableOriginalConstructor()->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)->getMock();
$this->response = $this->getMockBuilder(IResponse::class)->getMock();
$this->discoverService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
@@ -111,7 +105,6 @@ class GetSharedSecretTest extends TestCase {
$this->jobList,
$this->trustedServers,
$this->logger,
- $this->dbHandler,
$this->discoverService,
$this->timeFactory
);
@@ -133,7 +126,6 @@ class GetSharedSecretTest extends TestCase {
$this->jobList,
$this->trustedServers,
$this->logger,
- $this->dbHandler,
$this->discoverService,
$this->timeFactory
]
@@ -198,12 +190,13 @@ class GetSharedSecretTest extends TestCase {
->willReturn($source);
$this->httpClient->expects($this->once())->method('get')
->with(
- $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json',
+ $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret',
[
'query' =>
[
'url' => $source,
- 'token' => $token
+ 'token' => $token,
+ 'format' => 'json',
],
'timeout' => 3,
'connect_timeout' => 3,
@@ -213,15 +206,6 @@ class GetSharedSecretTest extends TestCase {
$this->response->expects($this->once())->method('getStatusCode')
->willReturn($statusCode);
- if (
- $statusCode !== Http::STATUS_OK
- && $statusCode !== Http::STATUS_FORBIDDEN
- ) {
- $this->dbHandler->expects($this->never())->method('addToken');
- } else {
- $this->dbHandler->expects($this->once())->method('addToken')->with($target, '');
- }
-
if ($statusCode === Http::STATUS_OK) {
$this->response->expects($this->once())->method('getBody')
->willReturn('{"ocs":{"data":{"sharedSecret":"secret"}}}');
@@ -297,19 +281,19 @@ class GetSharedSecretTest extends TestCase {
->willReturn($source);
$this->httpClient->expects($this->once())->method('get')
->with(
- $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json',
+ $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret',
[
'query' =>
[
'url' => $source,
- 'token' => $token
+ 'token' => $token,
+ 'format' => 'json',
],
'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]);
@@ -334,19 +318,19 @@ class GetSharedSecretTest extends TestCase {
->willReturn($source);
$this->httpClient->expects($this->once())->method('get')
->with(
- $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json',
+ $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret',
[
'query' =>
[
'url' => $source,
- 'token' => $token
+ 'token' => $token,
+ 'format' => 'json',
],
'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]);
diff --git a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
index 20610f1f0fb..45bed657ef8 100644
--- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
@@ -30,7 +30,6 @@ 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;
use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -57,9 +56,6 @@ class RequestSharedSecretTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject|IURLGenerator */
private $urlGenerator;
- /** @var \PHPUnit_Framework_MockObject_MockObject|DbHandler */
- private $dbHandler;
-
/** @var \PHPUnit_Framework_MockObject_MockObject|TrustedServers */
private $trustedServers;
@@ -87,8 +83,6 @@ class RequestSharedSecretTest extends TestCase {
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
$this->trustedServers = $this->getMockBuilder(TrustedServers::class)
->disableOriginalConstructor()->getMock();
- $this->dbHandler = $this->getMockBuilder(DbHandler::class)
- ->disableOriginalConstructor()->getMock();
$this->response = $this->getMockBuilder(IResponse::class)->getMock();
$this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
$this->logger = $this->createMock(ILogger::class);
@@ -102,7 +96,6 @@ class RequestSharedSecretTest extends TestCase {
$this->urlGenerator,
$this->jobList,
$this->trustedServers,
- $this->dbHandler,
$this->discoveryService,
$this->logger,
$this->timeFactory
@@ -124,7 +117,6 @@ class RequestSharedSecretTest extends TestCase {
$this->urlGenerator,
$this->jobList,
$this->trustedServers,
- $this->dbHandler,
$this->discoveryService,
$this->logger,
$this->timeFactory
@@ -190,12 +182,13 @@ class RequestSharedSecretTest extends TestCase {
->willReturn($source);
$this->httpClient->expects($this->once())->method('post')
->with(
- $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json',
+ $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret',
[
'body' =>
[
'url' => $source,
- 'token' => $token
+ 'token' => $token,
+ 'format' => 'json',
],
'timeout' => 3,
'connect_timeout' => 3,
@@ -205,17 +198,6 @@ class RequestSharedSecretTest extends TestCase {
$this->response->expects($this->once())->method('getStatusCode')
->willReturn($statusCode);
- if (
- $statusCode !== Http::STATUS_OK
- && $statusCode !== Http::STATUS_FORBIDDEN
- ) {
- $this->dbHandler->expects($this->never())->method('addToken');
- }
-
- if ($statusCode === Http::STATUS_FORBIDDEN) {
- $this->dbHandler->expects($this->once())->method('addToken')->with($target, '');
- }
-
$this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
if (
$statusCode !== Http::STATUS_OK
@@ -284,20 +266,19 @@ class RequestSharedSecretTest extends TestCase {
->expects($this->once())
->method('post')
->with(
- $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json',
+ $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret',
[
'body' =>
[
'url' => $source,
- 'token' => $token
+ 'token' => $token,
+ 'format' => 'json',
],
'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'));
}
@@ -321,20 +302,19 @@ class RequestSharedSecretTest extends TestCase {
->expects($this->once())
->method('post')
->with(
- $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json',
+ $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret',
[
'body' =>
[
'url' => $source,
- 'token' => $token
+ 'token' => $token,
+ 'format' => 'json',
],
'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'));
}
diff --git a/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php b/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
index b489bc16e50..7fb84c8bad2 100644
--- a/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
+++ b/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
@@ -176,13 +176,10 @@ class OCSAuthAPIControllerTest extends TestCase {
->willReturn('secret');
$this->trustedServers->expects($this->once())
->method('addSharedSecret')->willReturn($url, 'secret');
- $this->dbHandler->expects($this->once())
- ->method('addToken')->with($url, '');
} else {
$this->secureRandom->expects($this->never())->method('getMediumStrengthGenerator');
$this->secureRandom->expects($this->never())->method('generate');
$this->trustedServers->expects($this->never())->method('addSharedSecret');
- $this->dbHandler->expects($this->never())->method('addToken');
}
try {