aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation/tests/BackgroundJob/GetSharedSecretTest.php')
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php142
1 files changed, 53 insertions, 89 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'));
}
}