Merge pull request #336 from nextcloud/feature/noid/not-json-exception-on-request

throw RequestResultNotJsonException on unusual result
pull/355/head
Julius Härtl 2019-01-19 12:48:59 +01:00 zatwierdzone przez GitHub
commit 13d61f6507
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
15 zmienionych plików z 57 dodań i 8 usunięć

Wyświetl plik

@ -94,6 +94,12 @@ class SocialPubController extends Controller {
$this->navigationController = $navigationController; $this->navigationController = $navigationController;
} }
/**
* @param $username
*
* @return Response
* @throws UrlCloudException
*/
private function renderPage($username): Response { private function renderPage($username): Response {
if ($this->userId) { if ($this->userId) {
return $this->navigationController->navigate(''); return $this->navigationController->navigate('');

Wyświetl plik

@ -31,11 +31,10 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TArrayTools; use daita\MySmallPhpTools\Traits\TArrayTools;
use DateTime;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\InstancePath; use OCA\Social\Model\InstancePath;
use OCP\DB\QueryBuilder\ICompositeExpression; use OCP\DB\QueryBuilder\ICompositeExpression;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class RequestResultNotJsonException extends \Exception {
}

Wyświetl plik

@ -77,8 +77,8 @@ class DeleteInterface implements IActivityPubInterface {
$interface->delete($object); $interface->delete($object);
return; return;
} catch (UnknownItemException $e) {
} catch (ItemNotFoundException $e) { } catch (ItemNotFoundException $e) {
} catch (ItemUnknownException $e) {
} }
} }
} }

Wyświetl plik

@ -42,6 +42,7 @@ use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
@ -147,6 +148,7 @@ class FollowInterface implements IActivityPubInterface {
* @throws RequestNetworkException * @throws RequestNetworkException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestServerException * @throws RequestServerException
* @throws RequestResultNotJsonException
*/ */
public function processIncomingRequest(ACore $follow) { public function processIncomingRequest(ACore $follow) {
/** @var Follow $follow */ /** @var Follow $follow */

Wyświetl plik

@ -38,7 +38,6 @@ use OCA\Social\Exceptions\NoteNotFoundException;
use OCA\Social\Interfaces\IActivityPubInterface; use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Create; use OCA\Social\Model\ActivityPub\Activity\Create;
use OCA\Social\Model\ActivityPub\Activity\Update;
use OCA\Social\Model\ActivityPub\Object\Note; use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
use OCA\Social\Service\CurlService; use OCA\Social\Service\CurlService;

Wyświetl plik

@ -38,6 +38,7 @@ use OCA\Social\Db\FollowsRequest;
use OCA\Social\Db\NotesRequest; use OCA\Social\Db\NotesRequest;
use OCA\Social\Exceptions\AccountAlreadyExistsException; use OCA\Social\Exceptions\AccountAlreadyExistsException;
use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\ActorDoesNotExistException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
@ -245,8 +246,11 @@ class AccountService {
return; return;
} }
$iconId = $this->documentService->cacheLocalAvatarByUsername($actor); try {
$actor->setIconId($iconId); $iconId = $this->documentService->cacheLocalAvatarByUsername($actor);
$actor->setIconId($iconId);
} catch (ItemUnknownException $e) {
}
$count = [ $count = [
'followers' => $this->followsRequest->countFollowers($actor->getId()), 'followers' => $this->followsRequest->countFollowers($actor->getId()),

Wyświetl plik

@ -43,6 +43,7 @@ use OCA\Social\Exceptions\NoHighPriorityRequestException;
use OCA\Social\Exceptions\QueueStatusException; use OCA\Social\Exceptions\QueueStatusException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
@ -266,6 +267,8 @@ class ActivityService {
$this->signatureService->signRequest($request, $queue); $this->signatureService->signRequest($request, $queue);
$this->curlService->request($request); $this->curlService->request($request);
$this->queueService->endRequest($queue, true); $this->queueService->endRequest($queue, true);
} catch (RequestResultNotJsonException $e) {
$this->queueService->endRequest($queue, true);
} catch (ActorDoesNotExistException $e) { } catch (ActorDoesNotExistException $e) {
$this->miscService->log( $this->miscService->log(
'Error while managing request: ' . json_encode($request) . ' ' . $e->getMessage(), 1 'Error while managing request: ' . json_encode($request) . ' ' . $e->getMessage(), 1

Wyświetl plik

@ -40,6 +40,7 @@ use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RetrieveAccountFormatException; use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
@ -120,6 +121,7 @@ class CacheActorService {
* @throws RequestServerException * @throws RequestServerException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws RequestResultNotJsonException
*/ */
public function getFromId(string $id, bool $refresh = false): Person { public function getFromId(string $id, bool $refresh = false): Person {
@ -191,6 +193,7 @@ class CacheActorService {
* @throws RequestServerException * @throws RequestServerException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws RequestResultNotJsonException
*/ */
public function getFromAccount(string $account, bool $retrieve = true): Person { public function getFromAccount(string $account, bool $retrieve = true): Person {

Wyświetl plik

@ -39,6 +39,7 @@ use OCA\Social\Exceptions\CacheContentMimeTypeException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException; use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\RequestServerException;
use OCP\Files\IAppData; use OCP\Files\IAppData;
@ -98,6 +99,7 @@ class CacheDocumentService {
* @throws RequestNetworkException * @throws RequestNetworkException
* @throws RequestServerException * @throws RequestServerException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestResultNotJsonException
*/ */
public function saveRemoteFileToCache(string $url, &$mime = '') { public function saveRemoteFileToCache(string $url, &$mime = '') {
@ -191,6 +193,7 @@ class CacheDocumentService {
* @throws RequestNetworkException * @throws RequestNetworkException
* @throws RequestServerException * @throws RequestServerException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestResultNotJsonException
*/ */
public function retrieveContent(string $url) { public function retrieveContent(string $url) {
$url = parse_url($url); $url = parse_url($url);

Wyświetl plik

@ -41,6 +41,7 @@ use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RetrieveAccountFormatException; use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
@ -101,6 +102,7 @@ class CurlService {
* @throws RequestServerException * @throws RequestServerException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws RequestResultNotJsonException
*/ */
public function retrieveAccount(string $account): Person { public function retrieveAccount(string $account): Person {
$account = $this->withoutBeginAt($account); $account = $this->withoutBeginAt($account);
@ -152,6 +154,7 @@ class CurlService {
* @throws RequestNetworkException * @throws RequestNetworkException
* @throws RequestServerException * @throws RequestServerException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestResultNotJsonException
*/ */
public function retrieveObject($id): array { public function retrieveObject($id): array {
@ -177,6 +180,7 @@ class CurlService {
* @throws RequestNetworkException * @throws RequestNetworkException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestServerException * @throws RequestServerException
* @throws RequestResultNotJsonException
*/ */
public function request(Request $request) { public function request(Request $request) {
@ -204,7 +208,12 @@ class CurlService {
'[>>] request: ' . json_encode($request) . ' - result: ' . $result, 1 '[>>] 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();
} }

Wyświetl plik

@ -42,6 +42,7 @@ use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
@ -114,6 +115,7 @@ class DocumentService {
* @return Document * @return Document
* @throws CacheDocumentDoesNotExistException * @throws CacheDocumentDoesNotExistException
* @throws MalformedArrayException * @throws MalformedArrayException
* @throws RequestResultNotJsonException
*/ */
public function cacheRemoteDocument(string $id, bool $public = false) { public function cacheRemoteDocument(string $id, bool $public = false) {
$document = $this->cacheDocumentsRequest->getById($id, $public); $document = $this->cacheDocumentsRequest->getById($id, $public);

Wyświetl plik

@ -41,6 +41,7 @@ use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RetrieveAccountFormatException; use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
@ -133,6 +134,7 @@ class FollowService {
* @throws RequestNetworkException * @throws RequestNetworkException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestServerException * @throws RequestServerException
* @throws RequestResultNotJsonException
*/ */
public function followAccount(Person $actor, string $account) { public function followAccount(Person $actor, string $account) {
$remoteActor = $this->cacheActorService->getFromAccount($account); $remoteActor = $this->cacheActorService->getFromAccount($account);
@ -181,6 +183,7 @@ class FollowService {
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws UrlCloudException * @throws UrlCloudException
* @throws RequestResultNotJsonException
*/ */
public function unfollowAccount(Person $actor, string $account) { public function unfollowAccount(Person $actor, string $account) {
$remoteActor = $this->cacheActorService->getFromAccount($account); $remoteActor = $this->cacheActorService->getFromAccount($account);

Wyświetl plik

@ -43,6 +43,7 @@ use OCA\Social\Exceptions\NoteNotFoundException;
use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
@ -260,6 +261,7 @@ class NoteService {
* @throws RequestServerException * @throws RequestServerException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws RequestResultNotJsonException
*/ */
public function replyTo(Note $note, string $replyTo) { public function replyTo(Note $note, string $replyTo) {
if ($replyTo === '') { if ($replyTo === '') {
@ -401,6 +403,7 @@ class NoteService {
* @throws RequestNetworkException * @throws RequestNetworkException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestServerException * @throws RequestServerException
* @throws RequestResultNotJsonException
*/ */
public function getAuthorFromPostId($noteId) { public function getAuthorFromPostId($noteId) {
$note = $this->notesRequest->getNoteById($noteId); $note = $this->notesRequest->getNoteById($noteId);

Wyświetl plik

@ -43,6 +43,7 @@ use OCA\Social\Exceptions\LinkedDataSignatureMissingException;
use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException; use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException; use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException; use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException; use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SignatureException; use OCA\Social\Exceptions\SignatureException;
@ -177,6 +178,7 @@ class SignatureService {
* @throws SignatureIsGoneException * @throws SignatureIsGoneException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws RequestResultNotJsonException
*/ */
public function checkRequest(IRequest $request, int &$time = 0): string { public function checkRequest(IRequest $request, int &$time = 0): string {
$dTime = new DateTime($request->getHeader('date')); $dTime = new DateTime($request->getHeader('date'));
@ -210,6 +212,7 @@ class SignatureService {
* @throws RequestServerException * @throws RequestServerException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws RequestResultNotJsonException
*/ */
public function checkObject(ACore $object): bool { public function checkObject(ACore $object): bool {
try { try {
@ -276,6 +279,7 @@ class SignatureService {
* @throws ItemUnknownException * @throws ItemUnknownException
* @throws RequestContentException * @throws RequestContentException
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestResultNotJsonException
*/ */
private function checkRequestSignature(IRequest $request): string { private function checkRequestSignature(IRequest $request): string {
$signatureHeader = $request->getHeader('Signature'); $signatureHeader = $request->getHeader('Signature');
@ -365,6 +369,7 @@ class SignatureService {
* @return string * @return string
* @throws InvalidOriginException * @throws InvalidOriginException
* @throws InvalidResourceException * @throws InvalidResourceException
* @throws ItemUnknownException
* @throws MalformedArrayException * @throws MalformedArrayException
* @throws RedundancyLimitException * @throws RedundancyLimitException
* @throws RequestContentException * @throws RequestContentException
@ -372,7 +377,7 @@ class SignatureService {
* @throws RequestResultSizeException * @throws RequestResultSizeException
* @throws RequestServerException * @throws RequestServerException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws ItemUnknownException * @throws RequestResultNotJsonException
*/ */
private function retrieveKey(string $keyId, bool $refresh = false): string { private function retrieveKey(string $keyId, bool $refresh = false): string {
$actor = $this->cacheActorService->getFromId($keyId, $refresh); $actor = $this->cacheActorService->getFromId($keyId, $refresh);