diff --git a/composer.lock b/composer.lock index 37c1c411..817d3b72 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/daita/my-small-php-tools.git", - "reference": "36ea85a58ceb57a521c8f5a43effb4a7330e7b4c" + "reference": "523adb71b0e12fd678909aeef45ef2c0f612e02a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/36ea85a58ceb57a521c8f5a43effb4a7330e7b4c", - "reference": "36ea85a58ceb57a521c8f5a43effb4a7330e7b4c", + "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/523adb71b0e12fd678909aeef45ef2c0f612e02a", + "reference": "523adb71b0e12fd678909aeef45ef2c0f612e02a", "shasum": "" }, "require": { @@ -40,7 +40,7 @@ } ], "description": "My small PHP Tools", - "time": "2018-11-29T16:46:38+00:00" + "time": "2018-12-04T09:44:36+00:00" } ], "packages-dev": [], diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index 830fbf09..af377cc3 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -43,6 +43,7 @@ use OCA\Social\Service\ActorService; use OCA\Social\Service\ImportService; use OCA\Social\Service\MiscService; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Response; use OCP\IRequest; @@ -133,7 +134,8 @@ class ActivityPubController extends Controller { return $this->directSuccess($actor); } catch (Exception $e) { - return $this->fail($e); + http_response_code(404); + exit(); } } diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index 66d8e9a6..86c821ff 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -537,13 +537,14 @@ class LocalController extends Controller { $response = new FileDisplayResponse($document); $response->cacheFor(86400); + return $response; } - - return new NotFoundResponse(); } catch (Exception $e) { - return $this->fail($e); } + + http_response_code(404); + exit(); } diff --git a/lib/Service/ActivityPub/PersonService.php b/lib/Service/ActivityPub/PersonService.php index 59613c38..ab4c9f51 100644 --- a/lib/Service/ActivityPub/PersonService.php +++ b/lib/Service/ActivityPub/PersonService.php @@ -31,6 +31,7 @@ declare(strict_types=1); namespace OCA\Social\Service\ActivityPub; +use daita\MySmallPhpTools\Exceptions\MalformedArrayException; use daita\MySmallPhpTools\Traits\TArrayTools; use Exception; use OCA\Social\Db\CacheActorsRequest; @@ -140,6 +141,7 @@ class PersonService implements ICoreService { * @throws SocialAppConfigException * @throws UrlCloudException * @throws Request410Exception + * @throws MalformedArrayException */ public function getFromId(string $id, bool $refresh = false): Person { @@ -182,6 +184,7 @@ class PersonService implements ICoreService { * @throws SocialAppConfigException * @throws UrlCloudException * @throws Request410Exception + * @throws MalformedArrayException */ public function getFromAccount(string $account, bool $retrieve = true): Person { diff --git a/lib/Service/InstanceService.php b/lib/Service/InstanceService.php index 911a86c9..af18dc7f 100644 --- a/lib/Service/InstanceService.php +++ b/lib/Service/InstanceService.php @@ -31,6 +31,7 @@ namespace OCA\Social\Service; use daita\MySmallPhpTools\Exceptions\ArrayNotFoundException; +use daita\MySmallPhpTools\Exceptions\MalformedArrayException; use daita\MySmallPhpTools\Model\Request; use daita\MySmallPhpTools\Traits\TArrayTools; use daita\MySmallPhpTools\Traits\TPathTools; @@ -81,6 +82,7 @@ class InstanceService { * @throws RequestException * @throws InvalidResourceException * @throws Request410Exception + * @throws MalformedArrayException */ public function retrieveAccount(string $account) { $account = $this->withoutBeginAt($account); @@ -115,9 +117,11 @@ class InstanceService { * @return mixed * @throws RequestException * @throws Request410Exception + * @throws MalformedArrayException */ public function retrieveObject($id) { $url = parse_url($id); + $this->mustContains(['path', 'host'], $url); $request = new Request($url['path'], Request::TYPE_GET); $request->setAddress($url['host']); diff --git a/lib/webfinger.php b/lib/webfinger.php index 9b3a67f5..8c195c6f 100644 --- a/lib/webfinger.php +++ b/lib/webfinger.php @@ -28,8 +28,14 @@ declare(strict_types=1); namespace OCA\Social; + +use Exception; +use OCA\Social\Service\ActorService; +use OCP\AppFramework\QueryException; + require_once(__DIR__ . '/../appinfo/autoload.php'); + if (!array_key_exists('resource', $_GET)) { echo 'missing resource'; exit(); @@ -47,6 +53,16 @@ if ($type !== 'acct') { $username = substr($account, 0, strrpos($account, '@')); + +/** @var ActorService $actorService */ +try { + $actorService = \OC::$server->query(ActorService::class); + $actorService->getActor($username); +} catch (Exception $e) { + http_response_code(404); + exit; +} + $finger = [ 'subject' => $subject, 'links' => [ @@ -60,6 +76,7 @@ $finger = [ ] ]; + header('Content-type: application/json'); echo json_encode($finger);