aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-06-28 12:55:26 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-08-08 17:03:19 +0200
commit48d9c4d2b093e12ec3bf3cd29295da0f2277028f (patch)
treed66f1d2f54e8ae745fc7ce7bf067ce2072eeac6a /apps/federation
parent19a2d6f6e7d54eb9318279809bf6c3f40bf566e2 (diff)
downloadnextcloud-server-48d9c4d2b093e12ec3bf3cd29295da0f2277028f.tar.gz
nextcloud-server-48d9c4d2b093e12ec3bf3cd29295da0f2277028f.zip
Port existing server code to new interface
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/federation')
-rw-r--r--apps/federation/lib/BackgroundJob/GetSharedSecret.php31
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php13
2 files changed, 15 insertions, 29 deletions
diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
index 75faa7ce1d9..3ca3e0a906b 100644
--- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
@@ -39,7 +39,6 @@ use OCP\BackgroundJob\Job;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
-use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;
@@ -60,7 +59,6 @@ class GetSharedSecret extends Job {
private LoggerInterface $logger;
protected bool $retainJob = false;
private string $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret';
-
/** 30 day = 2592000sec */
private int $maxLifespan = 2592000;
@@ -83,16 +81,13 @@ class GetSharedSecret extends Job {
}
/**
- * run the job, then remove it from the joblist
- *
- * @param IJobList $jobList
- * @param ILogger|null $logger
+ * Run the job, then remove it from the joblist
*/
- public function execute(IJobList $jobList, ILogger $logger = null) {
+ public function start(IJobList $jobList): void {
$target = $this->argument['url'];
// only execute if target is still in the list of trusted domains
if ($this->trustedServers->isTrustedServer($target)) {
- $this->parentExecute($jobList, $logger);
+ $this->parentStart($jobList);
}
$jobList->remove($this, $this->argument);
@@ -102,14 +97,8 @@ class GetSharedSecret extends Job {
}
}
- /**
- * Call execute() method of parent
- *
- * @param IJobList $jobList
- * @param ILogger $logger
- */
- protected function parentExecute($jobList, $logger = null) {
- parent::execute($jobList, $logger);
+ protected function parentStart(IJobList $jobList): void {
+ parent::start($jobList);
}
protected function run($argument) {
@@ -162,12 +151,10 @@ class GetSharedSecret extends Job {
$status = -1; // There is no status code if we could not connect
$this->logger->info('Could not connect to ' . $target, [
'exception' => $e,
- 'app' => 'federation',
]);
} catch (\Throwable $e) {
$status = Http::STATUS_INTERNAL_SERVER_ERROR;
$this->logger->error($e->getMessage(), [
- 'app' => 'federation',
'exception' => $e,
]);
}
@@ -190,8 +177,8 @@ class GetSharedSecret extends Job {
);
} else {
$this->logger->error(
- 'remote server "' . $target . '"" does not return a valid shared secret. Received data: ' . $body,
- ['app' => 'federation']
+ 'remote server "' . $target . '"" does not return a valid shared secret. Received data: ' . $body,
+ ['app' => 'federation']
);
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
}
@@ -199,13 +186,13 @@ class GetSharedSecret extends Job {
}
/**
- * re-add background job
+ * Re-add background job
*
* @param array $argument
*/
protected function reAddJob(array $argument): void {
$url = $argument['url'];
- $created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime();
+ $created = $argument['created'] ?? $this->time->getTime();
$token = $argument['token'];
$this->jobList->add(
GetSharedSecret::class,
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index 5344736b7f9..c0316b8247f 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -76,8 +76,7 @@ class GetSharedSecretTest extends TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|ITimeFactory */
private $timeFactory;
- /** @var GetSharedSecret */
- private $getSharedSecret;
+ private GetSharedSecret $getSharedSecret;
protected function setUp(): void {
parent::setUp();
@@ -113,9 +112,9 @@ class GetSharedSecretTest extends TestCase {
* @param bool $isTrustedServer
* @param bool $retainBackgroundJob
*/
- public function testExecute($isTrustedServer, $retainBackgroundJob) {
+ public function testExecute(bool $isTrustedServer, bool $retainBackgroundJob): void {
/** @var GetSharedSecret |\PHPUnit\Framework\MockObject\MockObject $getSharedSecret */
- $getSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\GetSharedSecret')
+ $getSharedSecret = $this->getMockBuilder(GetSharedSecret::class)
->setConstructorArgs(
[
$this->httpClientService,
@@ -126,15 +125,15 @@ class GetSharedSecretTest extends TestCase {
$this->discoverService,
$this->timeFactory
]
- )->setMethods(['parentExecute'])->getMock();
+ )->setMethods(['parentStart'])->getMock();
$this->invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
$this->trustedServers->expects($this->once())->method('isTrustedServer')
->with('url')->willReturn($isTrustedServer);
if ($isTrustedServer) {
- $getSharedSecret->expects($this->once())->method('parentExecute');
+ $getSharedSecret->expects($this->once())->method('parentStart');
} else {
- $getSharedSecret->expects($this->never())->method('parentExecute');
+ $getSharedSecret->expects($this->never())->method('parentStart');
}
$this->invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]);
$this->jobList->expects($this->once())->method('remove');