summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-11-28 14:40:45 -0100
committerGitHub <noreply@github.com>2018-11-28 14:40:45 -0100
commitf08865eeedffd8054dbfc93c69f396a346077eee (patch)
treed5ec26280f587879fe83421c471e91e873979eeb
parent107c49d1412fee86bb30d03fd3e65aebc2de38f4 (diff)
parent13d49b6ebe27df5d6a69e9d5940f92946cc93817 (diff)
Merge pull request #69 from nextcloud-gmbh/small-fix
small fixes
-rw-r--r--lib/Controller/ActivityPubController.php13
-rw-r--r--lib/Controller/LocalController.php1
-rw-r--r--lib/Controller/NavigationController.php6
-rw-r--r--lib/Db/ActorsRequest.php34
-rw-r--r--lib/Db/CacheDocumentsRequest.php2
-rw-r--r--lib/Db/CoreRequestBuilder.php5
-rw-r--r--lib/Db/RequestQueueRequest.php8
-rw-r--r--lib/Exceptions/Request410Exception.php8
-rw-r--r--lib/Exceptions/SignatureIsGoneException.php8
-rw-r--r--lib/Service/ActivityPub/PersonService.php2
-rw-r--r--lib/Service/ActivityService.php18
-rw-r--r--lib/Service/ActorService.php2
-rw-r--r--lib/Service/CurlService.php23
-rw-r--r--lib/Service/InstanceService.php6
14 files changed, 97 insertions, 39 deletions
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php
index 90a1369a..acd79fa3 100644
--- a/lib/Controller/ActivityPubController.php
+++ b/lib/Controller/ActivityPubController.php
@@ -32,9 +32,10 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
+use OC\AppFramework\Http;
use OCA\Social\AppInfo\Application;
use OCA\Social\Db\NotesRequest;
-use OCA\Social\Exceptions\SignatureException;
+use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Service\ActivityPub\FollowService;
use OCA\Social\Service\ActivityService;
@@ -124,7 +125,6 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
- * @throws \OC\User\NoUserException
*/
public function actor(string $username): Response {
if (!$this->checkSourceActivityStreams()) {
@@ -184,6 +184,8 @@ class ActivityPubController extends Controller {
}
return $this->success([]);
+ } catch (SignatureIsGoneException $e) {
+ return $this->fail($e, [], Http::STATUS_GONE);
} catch (Exception $e) {
return $this->fail($e);
}
@@ -207,10 +209,13 @@ class ActivityPubController extends Controller {
public function inbox(string $username): Response {
try {
- $actor = $this->actorService->getActor($username);
+
$this->activityService->checkRequest($this->request);
$body = file_get_contents('php://input');
+ // TODO - check the recipient <-> username
+// $actor = $this->actorService->getActor($username);
+
$this->miscService->log('Inbox: ' . $body);
$activity = $this->importService->import($body);
@@ -220,6 +225,8 @@ class ActivityPubController extends Controller {
}
return $this->success([]);
+ } catch (SignatureIsGoneException $e) {
+ return $this->fail($e, [], Http::STATUS_GONE);
} catch (Exception $e) {
return $this->fail($e);
}
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php
index b5216943..f462319c 100644
--- a/lib/Controller/LocalController.php
+++ b/lib/Controller/LocalController.php
@@ -420,7 +420,6 @@ class LocalController extends Controller {
$cached = [];
foreach ($documents as $id) {
try {
-
$document = $this->documentService->cacheRemoteDocument($id);
$cached[] = $document;
} catch (Exception $e) {
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index 864b9eb8..37f7050f 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -125,7 +125,6 @@ class NavigationController extends Controller {
* @NoSubAdminRequired
*
* @return TemplateResponse
- * @throws NoUserException
*/
public function navigate($path = ''): TemplateResponse {
$data = [
@@ -162,6 +161,10 @@ class NavigationController extends Controller {
$data['serverData']['firstrun'] = true;
} catch (AccountAlreadyExistsException $e) {
// we do nothing
+ } catch (NoUserException $e) {
+ // well, should not happens
+ } catch (SocialAppConfigException $e) {
+ // neither.
}
return new TemplateResponse(Application::APP_NAME, 'main', $data);
@@ -231,7 +234,6 @@ class NavigationController extends Controller {
* @param $username
*
* @return RedirectResponse|PublicTemplateResponse
- * @throws NoUserException
*/
public function public($username) {
if (\OC::$server->getUserSession()
diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php
index 09b37e4b..00572296 100644
--- a/lib/Db/ActorsRequest.php
+++ b/lib/Db/ActorsRequest.php
@@ -60,32 +60,28 @@ class ActorsRequest extends ActorsRequestBuilder {
* @param Person $actor
*
* @return string
- * @throws \Exception
+ * @throws SocialAppConfigException
*/
public function create(Person $actor): string {
$id = $this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername();
- try {
- $qb = $this->getActorsInsertSql();
+ $qb = $this->getActorsInsertSql();
- $qb->setValue('id', $qb->createNamedParameter($id))
+ $qb->setValue('id', $qb->createNamedParameter($id))
// ->setValue('type', $qb->createNamedParameter($actor->getType()))
- ->setValue('user_id', $qb->createNamedParameter($actor->getUserId()))
- ->setValue('name', $qb->createNamedParameter($actor->getName()))
- ->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
- ->setValue(
- 'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
- )
- ->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()))
- ->setValue('private_key', $qb->createNamedParameter($actor->getPrivateKey()));
-
- $qb->execute();
-
- return $id;
- } catch (\Exception $e) {
- throw $e;
- }
+ ->setValue('user_id', $qb->createNamedParameter($actor->getUserId()))
+ ->setValue('name', $qb->createNamedParameter($actor->getName()))
+ ->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
+ ->setValue(
+ 'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
+ )
+ ->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()))
+ ->setValue('private_key', $qb->createNamedParameter($actor->getPrivateKey()));
+
+ $qb->execute();
+
+ return $id;
}
diff --git a/lib/Db/CacheDocumentsRequest.php b/lib/Db/CacheDocumentsRequest.php
index d71a113f..dcb153ad 100644
--- a/lib/Db/CacheDocumentsRequest.php
+++ b/lib/Db/CacheDocumentsRequest.php
@@ -151,7 +151,7 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
$this->limitToDBFieldEmpty($qb, 'local_copy');
$this->limitToCaching($qb, self::CACHE_TTL);
$this->limitToDBFieldInt($qb, 'error', 0);
-
+
$documents = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index e62d72fe..efe8b813 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -363,9 +363,10 @@ class CoreRequestBuilder {
/**
* @param IQueryBuilder $qb
+ * @param string $order
*/
- protected function orderByPriority(IQueryBuilder &$qb) {
- $qb->orderBy('priority', 'desc');
+ protected function orderByPriority(IQueryBuilder &$qb, string $order = 'desc') {
+ $qb->orderBy('priority', $order);
}
diff --git a/lib/Db/RequestQueueRequest.php b/lib/Db/RequestQueueRequest.php
index 33ca298c..045e9c16 100644
--- a/lib/Db/RequestQueueRequest.php
+++ b/lib/Db/RequestQueueRequest.php
@@ -180,9 +180,11 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
*/
public function setAsFailure(RequestQueue &$queue) {
$qb = $this->getQueueUpdateSql();
- $qb->set('status', $qb->createNamedParameter(RequestQueue::STATUS_STANDBY));
- // TODO - increment tries++
-// ->set('tries', 'tries+1');
+ $func = $qb->func();
+ $expr = $qb->expr();
+
+ $qb->set('status', $qb->createNamedParameter(RequestQueue::STATUS_STANDBY))
+ ->set('tries', $func->add('tries', $expr->literal(1)));
$this->limitToId($qb, $queue->getId());
$this->limitToStatus($qb, RequestQueue::STATUS_RUNNING);
diff --git a/lib/Exceptions/Request410Exception.php b/lib/Exceptions/Request410Exception.php
new file mode 100644
index 00000000..85bc8405
--- /dev/null
+++ b/lib/Exceptions/Request410Exception.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class Request410Exception extends \Exception {
+
+}
+
diff --git a/lib/Exceptions/SignatureIsGoneException.php b/lib/Exceptions/SignatureIsGoneException.php
new file mode 100644
index 00000000..80e55fcc
--- /dev/null
+++ b/lib/Exceptions/SignatureIsGoneException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class SignatureIsGoneException extends \Exception {
+
+}
+
diff --git a/lib/Service/ActivityPub/PersonService.php b/lib/Service/ActivityPub/PersonService.php
index 31ac4aaa..6d2e8d87 100644
--- a/lib/Service/ActivityPub/PersonService.php
+++ b/lib/Service/ActivityPub/PersonService.php
@@ -38,6 +38,7 @@ use OCA\Social\Db\CacheDocumentsRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\InvalidResourceException;
+use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException;
@@ -124,6 +125,7 @@ class PersonService implements ICoreService {
* @throws RequestException
* @throws SocialAppConfigException
* @throws UrlCloudException
+ * @throws Request410Exception
*/
public function getFromId(string $id, bool $refresh = false): Person {
diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php
index 03cd437f..85b1ea8d 100644
--- a/lib/Service/ActivityService.php
+++ b/lib/Service/ActivityService.php
@@ -43,8 +43,10 @@ use OCA\Social\Exceptions\EmptyQueueException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\NoHighPriorityRequestException;
use OCA\Social\Exceptions\QueueStatusException;
+use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SignatureException;
+use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\ACore;
@@ -385,6 +387,9 @@ class ActivityService {
* @throws MalformedArrayException
* @throws RequestException
* @throws SignatureException
+ * @throws SocialAppConfigException
+ * @throws UrlCloudException
+ * @throws SignatureIsGoneException
*/
public function checkRequest(IRequest $request) {
$dTime = new DateTime($request->getHeader('date'));
@@ -394,7 +399,12 @@ class ActivityService {
throw new SignatureException('object is too old');
}
- $this->checkSignature($request);
+ try {
+ $this->checkSignature($request);
+ } catch (Request410Exception $e) {
+ throw new SignatureIsGoneException();
+ }
+
}
@@ -429,9 +439,12 @@ class ActivityService {
* @param IRequest $request
*
* @throws InvalidResourceException
+ * @throws MalformedArrayException
+ * @throws Request410Exception
* @throws RequestException
* @throws SignatureException
- * @throws MalformedArrayException
+ * @throws SocialAppConfigException
+ * @throws UrlCloudException
* @throws Exception
*/
private function checkSignature(IRequest $request) {
@@ -508,6 +521,7 @@ class ActivityService {
* @throws RequestException
* @throws SocialAppConfigException
* @throws UrlCloudException
+ * @throws Request410Exception
*/
private function retrieveKey($keyId): string {
$actor = $this->personService->getFromId($keyId);
diff --git a/lib/Service/ActorService.php b/lib/Service/ActorService.php
index 348d1a1f..70fb824e 100644
--- a/lib/Service/ActorService.php
+++ b/lib/Service/ActorService.php
@@ -142,7 +142,7 @@ class ActorService {
*
* @throws AccountAlreadyExistsException
* @throws NoUserException
- * @throws Exception
+ * @throws SocialAppConfigException
*/
public function createActor(string $userId, string $username) {
diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php
index 1aa94cc3..2218a52d 100644
--- a/lib/Service/CurlService.php
+++ b/lib/Service/CurlService.php
@@ -33,6 +33,8 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TPathTools;
+use Exception;
+use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
@@ -71,6 +73,7 @@ class CurlService {
*
* @return array
* @throws RequestException
+ * @throws Request410Exception
*/
public function request(Request $request): array {
$curl = $this->initRequest($request);
@@ -85,6 +88,7 @@ class CurlService {
$this->parseRequestResultCode301($code);
// $this->parseRequestResultCode401($code);
$this->parseRequestResultCode404($code, $request);
+ $this->parseRequestResultCode410($code);
// $this->parseRequestResultCode503($code);
// $this->parseRequestResultCode500($code);
// $this->parseRequestResult($result);
@@ -130,7 +134,7 @@ class CurlService {
$request->setAddress($host);
try {
$this->request($request);
- } catch (RequestException $e) {
+ } catch (Exception $e) {
}
}
@@ -234,11 +238,24 @@ class CurlService {
*
* @param Request $request
*
- * @throws RequestException
+ * @throws Request410Exception
*/
private function parseRequestResultCode404(int $code, Request $request) {
if ($code === 404) {
- throw new RequestException('404 Not Found - ' . json_encode($request));
+ throw new Request410Exception('404 Not Found - ' . json_encode($request));
+ }
+ }
+
+ /**
+ * @param int $code
+ *
+ * @param Request $request
+ *
+ * @throws Request410Exception
+ */
+ private function parseRequestResultCode410(int $code) {
+ if ($code === 410) {
+ throw new Request410Exception();
}
}
diff --git a/lib/Service/InstanceService.php b/lib/Service/InstanceService.php
index 1eafcc33..911a86c9 100644
--- a/lib/Service/InstanceService.php
+++ b/lib/Service/InstanceService.php
@@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TPathTools;
use OCA\Social\Exceptions\InvalidResourceException;
+use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\Instance;
@@ -79,12 +80,12 @@ class InstanceService {
* @return mixed
* @throws RequestException
* @throws InvalidResourceException
+ * @throws Request410Exception
*/
public function retrieveAccount(string $account) {
$account = $this->withoutBeginAt($account);
- if (strstr(substr($account, 0, -3), '@') === false)
- {
+ if (strstr(substr($account, 0, -3), '@') === false) {
throw new InvalidResourceException();
}
list($username, $host) = explode('@', $account);
@@ -113,6 +114,7 @@ class InstanceService {
*
* @return mixed
* @throws RequestException
+ * @throws Request410Exception
*/
public function retrieveObject($id) {
$url = parse_url($id);