expire requestSharedSecret job after 30 days
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
parent
51d85eb2f8
commit
06b9e58081
|
@ -76,6 +76,9 @@ class RequestSharedSecret extends Job {
|
|||
|
||||
private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret';
|
||||
|
||||
/** @var int 30 day = 2592000sec */
|
||||
private $maxLifespan = 2592000;
|
||||
|
||||
/**
|
||||
* RequestSharedSecret constructor.
|
||||
*
|
||||
|
@ -129,8 +132,10 @@ class RequestSharedSecret extends Job {
|
|||
$this->parentExecute($jobList, $logger);
|
||||
}
|
||||
|
||||
if (!$this->retainJob) {
|
||||
$jobList->remove($this, $this->argument);
|
||||
$jobList->remove($this, $this->argument);
|
||||
|
||||
if ($this->retainJob) {
|
||||
$this->reAddJob($jobList, $this->argument);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,10 +152,20 @@ class RequestSharedSecret extends Job {
|
|||
protected function run($argument) {
|
||||
|
||||
$target = $argument['url'];
|
||||
$created = isset($argument['created']) ? (int)$argument['created'] : time();
|
||||
$currentTime = time();
|
||||
$source = $this->urlGenerator->getAbsoluteURL('/');
|
||||
$source = rtrim($source, '/');
|
||||
$token = $argument['token'];
|
||||
|
||||
// kill job after 30 days of trying
|
||||
$deadline = $currentTime - $this->maxLifespan;
|
||||
if ($created < $deadline) {
|
||||
$this->retainJob = false;
|
||||
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
$endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING');
|
||||
$endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint;
|
||||
|
||||
|
@ -198,4 +213,26 @@ class RequestSharedSecret extends Job {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* re-add background job
|
||||
*
|
||||
* @param IJobList $jobList
|
||||
* @param array $argument
|
||||
*/
|
||||
protected function reAddJob(IJobList $jobList, array $argument) {
|
||||
|
||||
$url = $argument['url'];
|
||||
$created = isset($argument['created']) ? (int)$argument['created'] : time();
|
||||
$token = $argument['token'];
|
||||
|
||||
$jobList->add(
|
||||
RequestSharedSecret::class,
|
||||
[
|
||||
'url' => $url,
|
||||
'token' => $token,
|
||||
'created' => $created
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,8 @@ class TrustedServers {
|
|||
'OCA\Federation\BackgroundJob\RequestSharedSecret',
|
||||
[
|
||||
'url' => $url,
|
||||
'token' => $token
|
||||
'token' => $token,
|
||||
'created' => $this->getTimestamp()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -275,4 +276,8 @@ class TrustedServers {
|
|||
|
||||
return 'https://' . $url;
|
||||
}
|
||||
|
||||
protected function getTimestamp() {
|
||||
return time();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,10 +117,11 @@ class TrustedServersTest extends TestCase {
|
|||
$this->dispatcher
|
||||
]
|
||||
)
|
||||
->setMethods(['normalizeUrl', 'updateProtocol'])
|
||||
->setMethods(['normalizeUrl', 'updateProtocol', 'getTimestamp'])
|
||||
->getMock();
|
||||
$trustedServers->expects($this->once())->method('updateProtocol')
|
||||
->with('url')->willReturn('https://url');
|
||||
$trustedServers->expects($this->any())->method('getTimestamp')->willReturn(1234567);
|
||||
$this->dbHandler->expects($this->once())->method('addServer')->with('https://url')
|
||||
->willReturn($success);
|
||||
|
||||
|
@ -130,7 +131,7 @@ class TrustedServersTest extends TestCase {
|
|||
$this->dbHandler->expects($this->once())->method('addToken')->with('https://url', 'token');
|
||||
$this->jobList->expects($this->once())->method('add')
|
||||
->with('OCA\Federation\BackgroundJob\RequestSharedSecret',
|
||||
['url' => 'https://url', 'token' => 'token']);
|
||||
['url' => 'https://url', 'token' => 'token', 'created' => 1234567]);
|
||||
} else {
|
||||
$this->jobList->expects($this->never())->method('add');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue