aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/tests/BackgroundJob
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation/tests/BackgroundJob')
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php142
-rw-r--r--apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php159
2 files changed, 113 insertions, 188 deletions
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index 55db5cb744f..943bdf352de 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -1,28 +1,10 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Federation\Tests\BackgroundJob;
@@ -36,8 +18,10 @@ use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
+use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@@ -49,32 +33,16 @@ use Psr\Log\LoggerInterface;
*/
class GetSharedSecretTest extends TestCase {
- /** @var \PHPUnit\Framework\MockObject\MockObject|IClient */
- private $httpClient;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IClientService */
- private $httpClientService;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IJobList */
- private $jobList;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator */
- private $urlGenerator;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|TrustedServers */
- private $trustedServers;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface */
- private $logger;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IResponse */
- private $response;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IDiscoveryService */
- private $discoverService;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|ITimeFactory */
- private $timeFactory;
+ private MockObject&IClient $httpClient;
+ private MockObject&IClientService $httpClientService;
+ private MockObject&IJobList $jobList;
+ private MockObject&IURLGenerator $urlGenerator;
+ private MockObject&TrustedServers $trustedServers;
+ private MockObject&LoggerInterface $logger;
+ private MockObject&IResponse $response;
+ private MockObject&IDiscoveryService $discoverService;
+ private MockObject&ITimeFactory $timeFactory;
+ private MockObject&IConfig $config;
private GetSharedSecret $getSharedSecret;
@@ -91,6 +59,7 @@ class GetSharedSecretTest extends TestCase {
$this->response = $this->getMockBuilder(IResponse::class)->getMock();
$this->discoverService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
$this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->config = $this->createMock(IConfig::class);
$this->discoverService->expects($this->any())->method('discover')->willReturn([]);
$this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient);
@@ -102,18 +71,14 @@ class GetSharedSecretTest extends TestCase {
$this->trustedServers,
$this->logger,
$this->discoverService,
- $this->timeFactory
+ $this->timeFactory,
+ $this->config,
);
}
- /**
- * @dataProvider dataTestExecute
- *
- * @param bool $isTrustedServer
- * @param bool $retainBackgroundJob
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestExecute')]
public function testExecute(bool $isTrustedServer, bool $retainBackgroundJob): void {
- /** @var GetSharedSecret |\PHPUnit\Framework\MockObject\MockObject $getSharedSecret */
+ /** @var GetSharedSecret&MockObject $getSharedSecret */
$getSharedSecret = $this->getMockBuilder(GetSharedSecret::class)
->setConstructorArgs(
[
@@ -123,10 +88,13 @@ class GetSharedSecretTest extends TestCase {
$this->trustedServers,
$this->logger,
$this->discoverService,
- $this->timeFactory
+ $this->timeFactory,
+ $this->config,
]
- )->setMethods(['parentStart'])->getMock();
- $this->invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
+ )
+ ->onlyMethods(['parentStart'])
+ ->getMock();
+ self::invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
$this->trustedServers->expects($this->once())->method('isTrustedServer')
->with('url')->willReturn($isTrustedServer);
@@ -135,7 +103,7 @@ class GetSharedSecretTest extends TestCase {
} else {
$getSharedSecret->expects($this->never())->method('parentStart');
}
- $this->invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]);
+ self::invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]);
$this->jobList->expects($this->once())->method('remove');
$this->timeFactory->method('getTime')->willReturn(42);
@@ -158,7 +126,7 @@ class GetSharedSecretTest extends TestCase {
$getSharedSecret->start($this->jobList);
}
- public function dataTestExecute() {
+ public static function dataTestExecute(): array {
return [
[true, true],
[true, false],
@@ -166,12 +134,8 @@ class GetSharedSecretTest extends TestCase {
];
}
- /**
- * @dataProvider dataTestRun
- *
- * @param int $statusCode
- */
- public function testRun($statusCode) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')]
+ public function testRun(int $statusCode): void {
$target = 'targetURL';
$source = 'sourceURL';
$token = 'token';
@@ -187,14 +151,14 @@ class GetSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/shared-secret',
[
- 'query' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'query' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
+ 'verify' => true,
]
)->willReturn($this->response);
@@ -210,18 +174,18 @@ class GetSharedSecretTest extends TestCase {
$this->trustedServers->expects($this->never())->method('addSharedSecret');
}
- $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->getSharedSecret, 'run', [$argument]);
if (
$statusCode !== Http::STATUS_OK
&& $statusCode !== Http::STATUS_FORBIDDEN
) {
- $this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob'));
} else {
- $this->assertFalse($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ $this->assertFalse(self::invokePrivate($this->getSharedSecret, 'retainJob'));
}
}
- public function dataTestRun() {
+ public static function dataTestRun(): array {
return [
[Http::STATUS_OK],
[Http::STATUS_FORBIDDEN],
@@ -229,7 +193,7 @@ class GetSharedSecretTest extends TestCase {
];
}
- public function testRunExpired() {
+ public function testRunExpired(): void {
$target = 'targetURL';
$source = 'sourceURL';
$token = 'token';
@@ -256,10 +220,10 @@ class GetSharedSecretTest extends TestCase {
TrustedServers::STATUS_FAILURE
);
- $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->getSharedSecret, 'run', [$argument]);
}
- public function testRunConnectionError() {
+ public function testRunConnectionError(): void {
$target = 'targetURL';
$source = 'sourceURL';
$token = 'token';
@@ -278,21 +242,21 @@ class GetSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/shared-secret',
[
- 'query' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'query' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
+ 'verify' => true,
]
)->willThrowException($this->createMock(ConnectException::class));
$this->trustedServers->expects($this->never())->method('addSharedSecret');
- $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->getSharedSecret, 'run', [$argument]);
- $this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob'));
}
}
diff --git a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
index 059348aa8ab..6ef579c7483 100644
--- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
@@ -1,27 +1,10 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Federation\Tests\BackgroundJob;
@@ -34,6 +17,7 @@ use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
+use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
use PHPUnit\Framework\MockObject\MockObject;
@@ -41,49 +25,31 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class RequestSharedSecretTest extends TestCase {
- /** @var MockObject|IClientService */
- private $httpClientService;
-
- /** @var MockObject|IClient */
- private $httpClient;
-
- /** @var MockObject|IJobList */
- private $jobList;
-
- /** @var MockObject|IURLGenerator */
- private $urlGenerator;
-
- /** @var MockObject|TrustedServers */
- private $trustedServers;
-
- /** @var MockObject|IResponse */
- private $response;
-
- /** @var MockObject|IDiscoveryService */
- private $discoveryService;
-
- /** @var MockObject|LoggerInterface */
- private $logger;
-
- /** @var MockObject|ITimeFactory */
- private $timeFactory;
-
- /** @var RequestSharedSecret */
- private $requestSharedSecret;
+ private IClientService&MockObject $httpClientService;
+ private IClient&MockObject $httpClient;
+ private IJobList&MockObject $jobList;
+ private IURLGenerator&MockObject $urlGenerator;
+ private TrustedServers&MockObject $trustedServers;
+ private IResponse&MockObject $response;
+ private IDiscoveryService&MockObject $discoveryService;
+ private LoggerInterface&MockObject $logger;
+ private ITimeFactory&MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private RequestSharedSecret $requestSharedSecret;
protected function setUp(): void {
parent::setUp();
$this->httpClientService = $this->createMock(IClientService::class);
- $this->httpClient = $this->getMockBuilder(IClient::class)->getMock();
- $this->jobList = $this->getMockBuilder(IJobList::class)->getMock();
- $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
- $this->trustedServers = $this->getMockBuilder(TrustedServers::class)
- ->disableOriginalConstructor()->getMock();
- $this->response = $this->getMockBuilder(IResponse::class)->getMock();
- $this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
+ $this->httpClient = $this->createMock(IClient::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->trustedServers = $this->createMock(TrustedServers::class);
+ $this->response = $this->createMock(IResponse::class);
+ $this->discoveryService = $this->createMock(IDiscoveryService::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->config = $this->createMock(IConfig::class);
$this->discoveryService->expects($this->any())->method('discover')->willReturn([]);
$this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient);
@@ -95,19 +61,15 @@ class RequestSharedSecretTest extends TestCase {
$this->trustedServers,
$this->discoveryService,
$this->logger,
- $this->timeFactory
+ $this->timeFactory,
+ $this->config,
);
}
- /**
- * @dataProvider dataTestStart
- *
- * @param bool $isTrustedServer
- * @param bool $retainBackgroundJob
- */
- public function testStart($isTrustedServer, $retainBackgroundJob) {
- /** @var RequestSharedSecret |MockObject $requestSharedSecret */
- $requestSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\RequestSharedSecret')
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestStart')]
+ public function testStart(bool $isTrustedServer, bool $retainBackgroundJob): void {
+ /** @var RequestSharedSecret&MockObject $requestSharedSecret */
+ $requestSharedSecret = $this->getMockBuilder(RequestSharedSecret::class)
->setConstructorArgs(
[
$this->httpClientService,
@@ -116,10 +78,13 @@ class RequestSharedSecretTest extends TestCase {
$this->trustedServers,
$this->discoveryService,
$this->logger,
- $this->timeFactory
+ $this->timeFactory,
+ $this->config,
]
- )->setMethods(['parentStart'])->getMock();
- $this->invokePrivate($requestSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
+ )
+ ->onlyMethods(['parentStart'])
+ ->getMock();
+ self::invokePrivate($requestSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
$this->trustedServers->expects($this->once())->method('isTrustedServer')
->with('url')->willReturn($isTrustedServer);
@@ -128,7 +93,7 @@ class RequestSharedSecretTest extends TestCase {
} else {
$requestSharedSecret->expects($this->never())->method('parentStart');
}
- $this->invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]);
+ self::invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]);
$this->jobList->expects($this->once())->method('remove');
$this->timeFactory->method('getTime')->willReturn(42);
@@ -152,7 +117,7 @@ class RequestSharedSecretTest extends TestCase {
$requestSharedSecret->start($this->jobList);
}
- public function dataTestStart() {
+ public static function dataTestStart(): array {
return [
[true, true],
[true, false],
@@ -160,11 +125,7 @@ class RequestSharedSecretTest extends TestCase {
];
}
- /**
- * @dataProvider dataTestRun
- *
- * @param int $statusCode
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')]
public function testRun(int $statusCode, int $attempt = 0): void {
$target = 'targetURL';
$source = 'sourceURL';
@@ -180,32 +141,32 @@ class RequestSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret',
[
- 'body' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'body' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
+ 'verify' => true,
]
)->willReturn($this->response);
$this->response->expects($this->once())->method('getStatusCode')
->willReturn($statusCode);
- $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->requestSharedSecret, 'run', [$argument]);
if (
$statusCode !== Http::STATUS_OK
&& ($statusCode !== Http::STATUS_FORBIDDEN || $attempt < 5)
) {
- $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob'));
} else {
- $this->assertFalse($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ $this->assertFalse(self::invokePrivate($this->requestSharedSecret, 'retainJob'));
}
}
- public function dataTestRun() {
+ public static function dataTestRun(): array {
return [
[Http::STATUS_OK],
[Http::STATUS_FORBIDDEN, 5],
@@ -214,7 +175,7 @@ class RequestSharedSecretTest extends TestCase {
];
}
- public function testRunExpired() {
+ public function testRunExpired(): void {
$target = 'targetURL';
$source = 'sourceURL';
$token = 'token';
@@ -241,10 +202,10 @@ class RequestSharedSecretTest extends TestCase {
TrustedServers::STATUS_FAILURE
);
- $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->requestSharedSecret, 'run', [$argument]);
}
- public function testRunConnectionError() {
+ public function testRunConnectionError(): void {
$target = 'targetURL';
$source = 'sourceURL';
$token = 'token';
@@ -265,18 +226,18 @@ class RequestSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret',
[
- 'body' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'body' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
+ 'verify' => true,
]
)->willThrowException($this->createMock(ConnectException::class));
- $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
- $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ self::invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob'));
}
}