diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-01-19 12:48:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-19 12:48:59 +0100 |
commit | 13d61f6507d2a158019789014e8696788e7989c0 (patch) | |
tree | 5455045306ccee17660a1a83bc27ef74da03ced9 /lib/Service | |
parent | 232df4407c6b1223be5f17b59ef427f117cf6aa7 (diff) | |
parent | 5d484977179086dcdb34dec61c6b74176166525b (diff) |
Merge pull request #336 from nextcloud/feature/noid/not-json-exception-on-request
throw RequestResultNotJsonException on unusual result
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/AccountService.php | 8 | ||||
-rw-r--r-- | lib/Service/ActivityService.php | 3 | ||||
-rw-r--r-- | lib/Service/CacheActorService.php | 3 | ||||
-rw-r--r-- | lib/Service/CacheDocumentService.php | 3 | ||||
-rw-r--r-- | lib/Service/CurlService.php | 11 | ||||
-rw-r--r-- | lib/Service/DocumentService.php | 2 | ||||
-rw-r--r-- | lib/Service/FollowService.php | 3 | ||||
-rw-r--r-- | lib/Service/NoteService.php | 3 | ||||
-rw-r--r-- | lib/Service/SignatureService.php | 7 |
9 files changed, 39 insertions, 4 deletions
diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index ff868350..f94bd965 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -38,6 +38,7 @@ use OCA\Social\Db\FollowsRequest; use OCA\Social\Db\NotesRequest; use OCA\Social\Exceptions\AccountAlreadyExistsException; use OCA\Social\Exceptions\ActorDoesNotExistException; +use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\Actor\Person; @@ -245,8 +246,11 @@ class AccountService { return; } - $iconId = $this->documentService->cacheLocalAvatarByUsername($actor); - $actor->setIconId($iconId); + try { + $iconId = $this->documentService->cacheLocalAvatarByUsername($actor); + $actor->setIconId($iconId); + } catch (ItemUnknownException $e) { + } $count = [ 'followers' => $this->followsRequest->countFollowers($actor->getId()), diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php index 1e538cdf..904807cf 100644 --- a/lib/Service/ActivityService.php +++ b/lib/Service/ActivityService.php @@ -43,6 +43,7 @@ use OCA\Social\Exceptions\NoHighPriorityRequestException; use OCA\Social\Exceptions\QueueStatusException; use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestNetworkException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\SocialAppConfigException; @@ -266,6 +267,8 @@ class ActivityService { $this->signatureService->signRequest($request, $queue); $this->curlService->request($request); $this->queueService->endRequest($queue, true); + } catch (RequestResultNotJsonException $e) { + $this->queueService->endRequest($queue, true); } catch (ActorDoesNotExistException $e) { $this->miscService->log( 'Error while managing request: ' . json_encode($request) . ' ' . $e->getMessage(), 1 diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php index 1030f699..6da7772a 100644 --- a/lib/Service/CacheActorService.php +++ b/lib/Service/CacheActorService.php @@ -40,6 +40,7 @@ use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RequestContentException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RetrieveAccountFormatException; use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestResultSizeException; @@ -120,6 +121,7 @@ class CacheActorService { * @throws RequestServerException * @throws SocialAppConfigException * @throws ItemUnknownException + * @throws RequestResultNotJsonException */ public function getFromId(string $id, bool $refresh = false): Person { @@ -191,6 +193,7 @@ class CacheActorService { * @throws RequestServerException * @throws SocialAppConfigException * @throws ItemUnknownException + * @throws RequestResultNotJsonException */ public function getFromAccount(string $account, bool $retrieve = true): Person { diff --git a/lib/Service/CacheDocumentService.php b/lib/Service/CacheDocumentService.php index 15095330..8f5c3fe0 100644 --- a/lib/Service/CacheDocumentService.php +++ b/lib/Service/CacheDocumentService.php @@ -39,6 +39,7 @@ use OCA\Social\Exceptions\CacheContentMimeTypeException; use OCA\Social\Exceptions\CacheDocumentDoesNotExistException; use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestNetworkException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestServerException; use OCP\Files\IAppData; @@ -98,6 +99,7 @@ class CacheDocumentService { * @throws RequestNetworkException * @throws RequestServerException * @throws RequestResultSizeException + * @throws RequestResultNotJsonException */ public function saveRemoteFileToCache(string $url, &$mime = '') { @@ -191,6 +193,7 @@ class CacheDocumentService { * @throws RequestNetworkException * @throws RequestServerException * @throws RequestResultSizeException + * @throws RequestResultNotJsonException */ public function retrieveContent(string $url) { $url = parse_url($url); diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 63ed8487..f9554670 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -41,6 +41,7 @@ use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RequestContentException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RetrieveAccountFormatException; use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestResultSizeException; @@ -101,6 +102,7 @@ class CurlService { * @throws RequestServerException * @throws SocialAppConfigException * @throws ItemUnknownException + * @throws RequestResultNotJsonException */ public function retrieveAccount(string $account): Person { $account = $this->withoutBeginAt($account); @@ -152,6 +154,7 @@ class CurlService { * @throws RequestNetworkException * @throws RequestServerException * @throws RequestResultSizeException + * @throws RequestResultNotJsonException */ public function retrieveObject($id): array { @@ -177,6 +180,7 @@ class CurlService { * @throws RequestNetworkException * @throws RequestResultSizeException * @throws RequestServerException + * @throws RequestResultNotJsonException */ public function request(Request $request) { @@ -204,7 +208,12 @@ class CurlService { '[>>] request: ' . json_encode($request) . ' - result: ' . $result, 1 ); - return json_decode((string)$result, true); + $result = json_decode((string)$result, true); + if (is_array($result)) { + return $result; + } + + throw new RequestResultNotJsonException(); } diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 07b86f6c..c250d0e3 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -42,6 +42,7 @@ use OCA\Social\Exceptions\CacheDocumentDoesNotExistException; use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestNetworkException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\SocialAppConfigException; @@ -114,6 +115,7 @@ class DocumentService { * @return Document * @throws CacheDocumentDoesNotExistException * @throws MalformedArrayException + * @throws RequestResultNotJsonException */ public function cacheRemoteDocument(string $id, bool $public = false) { $document = $this->cacheDocumentsRequest->getById($id, $public); diff --git a/lib/Service/FollowService.php b/lib/Service/FollowService.php index f6a2c45c..7998760c 100644 --- a/lib/Service/FollowService.php +++ b/lib/Service/FollowService.php @@ -41,6 +41,7 @@ use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RequestContentException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RetrieveAccountFormatException; use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestResultSizeException; @@ -133,6 +134,7 @@ class FollowService { * @throws RequestNetworkException * @throws RequestResultSizeException * @throws RequestServerException + * @throws RequestResultNotJsonException */ public function followAccount(Person $actor, string $account) { $remoteActor = $this->cacheActorService->getFromAccount($account); @@ -181,6 +183,7 @@ class FollowService { * @throws SocialAppConfigException * @throws ItemUnknownException * @throws UrlCloudException + * @throws RequestResultNotJsonException */ public function unfollowAccount(Person $actor, string $account) { $remoteActor = $this->cacheActorService->getFromAccount($account); diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index 373dab72..c832659c 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -43,6 +43,7 @@ use OCA\Social\Exceptions\NoteNotFoundException; use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestNetworkException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\SocialAppConfigException; @@ -260,6 +261,7 @@ class NoteService { * @throws RequestServerException * @throws SocialAppConfigException * @throws ItemUnknownException + * @throws RequestResultNotJsonException */ public function replyTo(Note $note, string $replyTo) { if ($replyTo === '') { @@ -401,6 +403,7 @@ class NoteService { * @throws RequestNetworkException * @throws RequestResultSizeException * @throws RequestServerException + * @throws RequestResultNotJsonException */ public function getAuthorFromPostId($noteId) { $note = $this->notesRequest->getNoteById($noteId); diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php index 45da8ad4..bb8b6102 100644 --- a/lib/Service/SignatureService.php +++ b/lib/Service/SignatureService.php @@ -43,6 +43,7 @@ use OCA\Social\Exceptions\LinkedDataSignatureMissingException; use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestNetworkException; +use OCA\Social\Exceptions\RequestResultNotJsonException; use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\SignatureException; @@ -177,6 +178,7 @@ class SignatureService { * @throws SignatureIsGoneException * @throws SocialAppConfigException * @throws ItemUnknownException + * @throws RequestResultNotJsonException */ public function checkRequest(IRequest $request, int &$time = 0): string { $dTime = new DateTime($request->getHeader('date')); @@ -210,6 +212,7 @@ class SignatureService { * @throws RequestServerException * @throws SocialAppConfigException * @throws ItemUnknownException + * @throws RequestResultNotJsonException */ public function checkObject(ACore $object): bool { try { @@ -276,6 +279,7 @@ class SignatureService { * @throws ItemUnknownException * @throws RequestContentException * @throws RequestResultSizeException + * @throws RequestResultNotJsonException */ private function checkRequestSignature(IRequest $request): string { $signatureHeader = $request->getHeader('Signature'); @@ -365,6 +369,7 @@ class SignatureService { * @return string * @throws InvalidOriginException * @throws InvalidResourceException + * @throws ItemUnknownException * @throws MalformedArrayException * @throws RedundancyLimitException * @throws RequestContentException @@ -372,7 +377,7 @@ class SignatureService { * @throws RequestResultSizeException * @throws RequestServerException * @throws SocialAppConfigException - * @throws ItemUnknownException + * @throws RequestResultNotJsonException */ private function retrieveKey(string $keyId, bool $refresh = false): string { $actor = $this->cacheActorService->getFromId($keyId, $refresh); |