Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-08-01 12:23:40 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2017-08-01 12:23:40 +0300
commitbc54e6ff7cf6bb587feb5bf93b24b023a07a4123 (patch)
treead5a45004bfc52b59b274f350abd76fd29fe5645 /apps/federation/lib
parent3ffff08819365e6a38e0c7d381343f59bc2fc89c (diff)
Use ITimeFactory
* Inject the timefacotry so we can mock it properly in the tests. * Extended unit tests to cover the new paths Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/federation/lib')
-rw-r--r--apps/federation/lib/AppInfo/Application.php4
-rw-r--r--apps/federation/lib/BackgroundJob/GetSharedSecret.php24
-rw-r--r--apps/federation/lib/BackgroundJob/RequestSharedSecret.php23
-rw-r--r--apps/federation/lib/Controller/OCSAuthAPIController.php16
-rw-r--r--apps/federation/lib/TrustedServers.php15
5 files changed, 50 insertions, 32 deletions
diff --git a/apps/federation/lib/AppInfo/Application.php b/apps/federation/lib/AppInfo/Application.php
index 55647622915..0525245d9c4 100644
--- a/apps/federation/lib/AppInfo/Application.php
+++ b/apps/federation/lib/AppInfo/Application.php
@@ -32,6 +32,7 @@ use OCA\Federation\Middleware\AddServerMiddleware;
use OCA\Federation\SyncFederationAddressBooks;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\IAppContainer;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\SabrePluginEvent;
use OCP\Util;
use Sabre\DAV\Auth\Plugin;
@@ -74,7 +75,8 @@ class Application extends \OCP\AppFramework\App {
$server->getJobList(),
$server->getSecureRandom(),
$server->getConfig(),
- $server->getEventDispatcher()
+ $server->getEventDispatcher(),
+ $server->query(ITimeFactory::class)
);
});
diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
index d679fcb6aa3..bf9f58999db 100644
--- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
@@ -32,6 +32,7 @@ use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
@@ -47,7 +48,7 @@ use OCP\OCS\IDiscoveryService;
*
* @package OCA\Federation\Backgroundjob
*/
-class GetSharedSecret extends Job{
+class GetSharedSecret extends Job {
/** @var IClient */
private $httpClient;
@@ -70,6 +71,9 @@ class GetSharedSecret extends Job{
/** @var ILogger */
private $logger;
+ /** @var ITimeFactory */
+ private $timeFactory;
+
/** @var bool */
protected $retainJob = false;
@@ -90,6 +94,7 @@ class GetSharedSecret extends Job{
* @param ILogger $logger
* @param DbHandler $dbHandler
* @param IDiscoveryService $ocsDiscoveryService
+ * @param ITimeFactory $timeFactory
*/
public function __construct(
IClientService $httpClientService,
@@ -98,7 +103,8 @@ class GetSharedSecret extends Job{
TrustedServers $trustedServers,
ILogger $logger,
DbHandler $dbHandler,
- IDiscoveryService $ocsDiscoveryService
+ IDiscoveryService $ocsDiscoveryService,
+ ITimeFactory $timeFactory
) {
$this->logger = $logger;
$this->httpClient = $httpClientService->newClient();
@@ -107,6 +113,7 @@ class GetSharedSecret extends Job{
$this->dbHandler = $dbHandler;
$this->ocsDiscoveryService = $ocsDiscoveryService;
$this->trustedServers = $trustedServers;
+ $this->timeFactory = $timeFactory;
}
/**
@@ -125,7 +132,7 @@ class GetSharedSecret extends Job{
$jobList->remove($this, $this->argument);
if ($this->retainJob) {
- $this->reAddJob($jobList, $this->argument);
+ $this->reAddJob($this->argument);
}
}
@@ -141,8 +148,8 @@ class GetSharedSecret extends Job{
protected function run($argument) {
$target = $argument['url'];
- $created = isset($argument['created']) ? (int)$argument['created'] : time();
- $currentTime = time();
+ $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime();
+ $currentTime = $this->timeFactory->getTime();
$source = $this->urlGenerator->getAbsoluteURL('/');
$source = rtrim($source, '/');
$token = $argument['token'];
@@ -158,7 +165,7 @@ class GetSharedSecret extends Job{
$endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING');
$endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint;
- // make sure that we have a well formated url
+ // make sure that we have a well formatted url
$url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format;
$result = null;
@@ -223,12 +230,11 @@ class GetSharedSecret extends Job{
/**
* re-add background job
*
- * @param IJobList $jobList
* @param array $argument
*/
- protected function reAddJob(IJobList $jobList, array $argument) {
+ protected function reAddJob(array $argument) {
$url = $argument['url'];
- $created = isset($argument['created']) ? (int)$argument['created'] : time();
+ $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime();
$token = $argument['token'];
$this->jobList->add(
GetSharedSecret::class,
diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
index 0180c0dbf55..7effb838d8b 100644
--- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
@@ -33,6 +33,7 @@ use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
@@ -70,6 +71,9 @@ class RequestSharedSecret extends Job {
/** @var ILogger */
private $logger;
+ /** @var ITimeFactory */
+ private $timeFactory;
+
/** @var bool */
protected $retainJob = false;
@@ -90,6 +94,7 @@ class RequestSharedSecret extends Job {
* @param DbHandler $dbHandler
* @param IDiscoveryService $ocsDiscoveryService
* @param ILogger $logger
+ * @param ITimeFactory $timeFactory
*/
public function __construct(
IClientService $httpClientService,
@@ -98,7 +103,8 @@ class RequestSharedSecret extends Job {
TrustedServers $trustedServers,
DbHandler $dbHandler,
IDiscoveryService $ocsDiscoveryService,
- ILogger $logger
+ ILogger $logger,
+ ITimeFactory $timeFactory
) {
$this->httpClient = $httpClientService->newClient();
$this->jobList = $jobList;
@@ -107,6 +113,7 @@ class RequestSharedSecret extends Job {
$this->logger = $logger;
$this->ocsDiscoveryService = $ocsDiscoveryService;
$this->trustedServers = $trustedServers;
+ $this->timeFactory = $timeFactory;
}
@@ -126,7 +133,7 @@ class RequestSharedSecret extends Job {
$jobList->remove($this, $this->argument);
if ($this->retainJob) {
- $this->reAddJob($jobList, $this->argument);
+ $this->reAddJob($this->argument);
}
}
@@ -143,8 +150,8 @@ class RequestSharedSecret extends Job {
protected function run($argument) {
$target = $argument['url'];
- $created = isset($argument['created']) ? (int)$argument['created'] : time();
- $currentTime = time();
+ $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime();
+ $currentTime = $this->timeFactory->getTime();
$source = $this->urlGenerator->getAbsoluteURL('/');
$source = rtrim($source, '/');
$token = $argument['token'];
@@ -208,16 +215,14 @@ class RequestSharedSecret extends Job {
/**
* re-add background job
*
- * @param IJobList $jobList
* @param array $argument
*/
- protected function reAddJob(IJobList $jobList, array $argument) {
-
+ protected function reAddJob(array $argument) {
$url = $argument['url'];
- $created = isset($argument['created']) ? (int)$argument['created'] : time();
+ $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime();
$token = $argument['token'];
- $jobList->add(
+ $this->jobList->add(
RequestSharedSecret::class,
[
'url' => $url,
diff --git a/apps/federation/lib/Controller/OCSAuthAPIController.php b/apps/federation/lib/Controller/OCSAuthAPIController.php
index f09f0807bd4..b0594877b23 100644
--- a/apps/federation/lib/Controller/OCSAuthAPIController.php
+++ b/apps/federation/lib/Controller/OCSAuthAPIController.php
@@ -32,6 +32,7 @@ use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCSController;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\ILogger;
use OCP\IRequest;
@@ -61,6 +62,9 @@ class OCSAuthAPIController extends OCSController{
/** @var ILogger */
private $logger;
+ /** @var ITimeFactory */
+ private $timeFactory;
+
/**
* OCSAuthAPI constructor.
*
@@ -71,6 +75,7 @@ class OCSAuthAPIController extends OCSController{
* @param TrustedServers $trustedServers
* @param DbHandler $dbHandler
* @param ILogger $logger
+ * @param ITimeFactory $timeFactory
*/
public function __construct(
$appName,
@@ -79,7 +84,8 @@ class OCSAuthAPIController extends OCSController{
IJobList $jobList,
TrustedServers $trustedServers,
DbHandler $dbHandler,
- ILogger $logger
+ ILogger $logger,
+ ITimeFactory $timeFactory
) {
parent::__construct($appName, $request);
@@ -88,6 +94,7 @@ class OCSAuthAPIController extends OCSController{
$this->trustedServers = $trustedServers;
$this->dbHandler = $dbHandler;
$this->logger = $logger;
+ $this->timeFactory = $timeFactory;
}
/**
@@ -154,7 +161,7 @@ class OCSAuthAPIController extends OCSController{
[
'url' => $url,
'token' => $token,
- 'created' => $this->getTimestamp()
+ 'created' => $this->timeFactory->getTime()
]
);
@@ -202,9 +209,4 @@ class OCSAuthAPIController extends OCSController{
$storedToken = $this->dbHandler->getToken($url);
return hash_equals($storedToken, $token);
}
-
- protected function getTimestamp() {
- return time();
- }
-
}
diff --git a/apps/federation/lib/TrustedServers.php b/apps/federation/lib/TrustedServers.php
index de7d2a1df9a..067cf671a96 100644
--- a/apps/federation/lib/TrustedServers.php
+++ b/apps/federation/lib/TrustedServers.php
@@ -28,6 +28,7 @@ namespace OCA\Federation;
use OC\HintException;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
@@ -68,6 +69,9 @@ class TrustedServers {
/** @var EventDispatcherInterface */
private $dispatcher;
+ /** @var ITimeFactory */
+ private $timeFactory;
+
/**
* @param DbHandler $dbHandler
* @param IClientService $httpClientService
@@ -76,6 +80,7 @@ class TrustedServers {
* @param ISecureRandom $secureRandom
* @param IConfig $config
* @param EventDispatcherInterface $dispatcher
+ * @param ITimeFactory $timeFactory
*/
public function __construct(
DbHandler $dbHandler,
@@ -84,7 +89,8 @@ class TrustedServers {
IJobList $jobList,
ISecureRandom $secureRandom,
IConfig $config,
- EventDispatcherInterface $dispatcher
+ EventDispatcherInterface $dispatcher,
+ ITimeFactory $timeFactory
) {
$this->dbHandler = $dbHandler;
$this->httpClientService = $httpClientService;
@@ -93,6 +99,7 @@ class TrustedServers {
$this->secureRandom = $secureRandom;
$this->config = $config;
$this->dispatcher = $dispatcher;
+ $this->timeFactory = $timeFactory;
}
/**
@@ -112,7 +119,7 @@ class TrustedServers {
[
'url' => $url,
'token' => $token,
- 'created' => $this->getTimestamp()
+ 'created' => $this->timeFactory->getTime()
]
);
}
@@ -276,8 +283,4 @@ class TrustedServers {
return 'https://' . $url;
}
-
- protected function getTimestamp() {
- return time();
- }
}