From 58f22f961da9a92604814dd3aa1e1f2529956d10 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sat, 1 Aug 2020 00:12:01 -0100 Subject: remote testing Signed-off-by: Maxence Lange --- appinfo/routes.php | 19 ++- lib/AP.php | 18 +-- lib/Controller/ConfigController.php | 81 ++++++++++++- lib/Controller/NavigationController.php | 26 ----- lib/Db/CacheActorsRequestBuilder.php | 4 +- lib/Model/ActivityPub/ACore.php | 4 +- lib/Model/ActivityPub/Actor/Person.php | 1 + lib/Model/ActivityPub/Object/Document.php | 3 +- lib/Model/Test.php | 152 ++++++++++++++++++++++++ lib/Service/CacheActorService.php | 2 +- lib/Service/CurlService.php | 16 +-- lib/Service/TestService.php | 188 ++++++++++++++++++++++++++++++ lib/hostmeta.php | 2 +- lib/webfinger.php | 12 -- 14 files changed, 460 insertions(+), 68 deletions(-) create mode 100644 lib/Model/Test.php create mode 100644 lib/Service/TestService.php diff --git a/appinfo/routes.php b/appinfo/routes.php index e462d5dd..73e6802d 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -37,9 +37,10 @@ use OCA\Social\Service\CurlService; return [ 'routes' => [ ['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'], - ['name' => 'Navigation#test', 'url' => '/test', 'verb' => 'GET'], + ['name' => 'Config#remote', 'url' => '/test/{account}/', 'verb' => 'GET'], + ['name' => 'Config#local', 'url' => '/local/', 'verb' => 'GET'], [ - 'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET', + 'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+'], 'defaults' => ['path' => ''] ], @@ -92,8 +93,14 @@ return [ ['name' => 'Local#currentFollowing', 'url' => '/api/v1/current/following', 'verb' => 'GET'], ['name' => 'Local#accountInfo', 'url' => '/api/v1/account/{username}/info', 'verb' => 'GET'], - ['name' => 'Local#accountFollowers', 'url' => '/api/v1/account/{username}/followers', 'verb' => 'GET'], - ['name' => 'Local#accountFollowing', 'url' => '/api/v1/account/{username}/following', 'verb' => 'GET'], + [ + 'name' => 'Local#accountFollowers', 'url' => '/api/v1/account/{username}/followers', + 'verb' => 'GET' + ], + [ + 'name' => 'Local#accountFollowing', 'url' => '/api/v1/account/{username}/following', + 'verb' => 'GET' + ], ['name' => 'Local#globalAccountInfo', 'url' => '/api/v1/global/account/info', 'verb' => 'GET'], ['name' => 'Local#globalActorInfo', 'url' => '/api/v1/global/actor/info', 'verb' => 'GET'], @@ -101,9 +108,9 @@ return [ ['name' => 'Local#globalAccountsSearch', 'url' => '/api/v1/global/accounts/search', 'verb' => 'GET'], ['name' => 'Local#globalTagsSearch', 'url' => '/api/v1/global/tags/search', 'verb' => 'GET'], -// ['name' => 'Local#documentsCache', 'url' => '/api/v1/documents/cache', 'verb' => 'POST'], + // ['name' => 'Local#documentsCache', 'url' => '/api/v1/documents/cache', 'verb' => 'POST'], - ['name' => 'Local#search', 'url' => '/api/v1/search', 'verb' => 'GET'], + ['name' => 'Local#search', 'url' => '/api/v1/search', 'verb' => 'GET'], ['name' => 'Queue#asyncForRequest', 'url' => CurlService::ASYNC_REQUEST_TOKEN, 'verb' => 'POST'], diff --git a/lib/AP.php b/lib/AP.php index ec3251a1..7937bb86 100644 --- a/lib/AP.php +++ b/lib/AP.php @@ -41,19 +41,19 @@ use OCA\Social\Interfaces\Activity\AddInterface; use OCA\Social\Interfaces\Activity\BlockInterface; use OCA\Social\Interfaces\Activity\CreateInterface; use OCA\Social\Interfaces\Activity\DeleteInterface; -use OCA\Social\Interfaces\Actor\ServiceInterface; -use OCA\Social\Interfaces\Object\FollowInterface; -use OCA\Social\Interfaces\Object\LikeInterface; use OCA\Social\Interfaces\Activity\RejectInterface; use OCA\Social\Interfaces\Activity\RemoveInterface; use OCA\Social\Interfaces\Activity\UndoInterface; use OCA\Social\Interfaces\Activity\UpdateInterface; use OCA\Social\Interfaces\Actor\PersonInterface; +use OCA\Social\Interfaces\Actor\ServiceInterface; use OCA\Social\Interfaces\IActivityPubInterface; use OCA\Social\Interfaces\Internal\SocialAppNotificationInterface; +use OCA\Social\Interfaces\Object\AnnounceInterface; use OCA\Social\Interfaces\Object\DocumentInterface; +use OCA\Social\Interfaces\Object\FollowInterface; use OCA\Social\Interfaces\Object\ImageInterface; -use OCA\Social\Interfaces\Object\AnnounceInterface; +use OCA\Social\Interfaces\Object\LikeInterface; use OCA\Social\Interfaces\Object\NoteInterface; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Accept; @@ -61,19 +61,19 @@ use OCA\Social\Model\ActivityPub\Activity\Add; use OCA\Social\Model\ActivityPub\Activity\Block; use OCA\Social\Model\ActivityPub\Activity\Create; use OCA\Social\Model\ActivityPub\Activity\Delete; -use OCA\Social\Model\ActivityPub\Actor\Service; -use OCA\Social\Model\ActivityPub\Object\Follow; -use OCA\Social\Model\ActivityPub\Object\Like; use OCA\Social\Model\ActivityPub\Activity\Reject; use OCA\Social\Model\ActivityPub\Activity\Remove; use OCA\Social\Model\ActivityPub\Activity\Undo; use OCA\Social\Model\ActivityPub\Activity\Update; use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Model\ActivityPub\Actor\Service; +use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification; use OCA\Social\Model\ActivityPub\Object\Announce; use OCA\Social\Model\ActivityPub\Object\Document; +use OCA\Social\Model\ActivityPub\Object\Follow; use OCA\Social\Model\ActivityPub\Object\Image; +use OCA\Social\Model\ActivityPub\Object\Like; use OCA\Social\Model\ActivityPub\Object\Note; -use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification; use OCA\Social\Model\ActivityPub\Object\Tombstone; use OCA\Social\Model\ActivityPub\Stream; use OCA\Social\Service\ConfigService; @@ -208,7 +208,7 @@ class AP { * @throws SocialAppConfigException * @throws ItemUnknownException */ - public function getItemFromData(array $data, $parent = null, int $level = 0): ACore { + public function getItemFromData(array $data, ACore $parent = null, int $level = 0): ACore { if (++$level > self::REDUNDANCY_LIMIT) { throw new RedundancyLimitException($level); } diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 7a47d700..319a9344 100644 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -25,20 +25,44 @@ declare(strict_types=1); namespace OCA\Social\Controller; +use daita\MySmallPhpTools\Model\SimpleDataStore; +use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse; +use Exception; +use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Service\ConfigService; +use OCA\Social\Service\MiscService; +use OCA\Social\Service\TestService; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; class ConfigController extends Controller { + + use TNCDataResponse; + + + /** @var TestService */ + private $testService; + + /** @var ConfigService */ private $configService; - public function __construct(string $appName, IRequest $request, ConfigService $configService) { + /** @var MiscService */ + private $miscService; + + + public function __construct( + string $appName, IRequest $request, TestService $testService, + ConfigService $configService, MiscService $miscService + ) { parent::__construct($appName, $request); + $this->testService = $testService; $this->configService = $configService; + $this->miscService = $miscService; } /** @@ -51,4 +75,59 @@ class ConfigController extends Controller { return new DataResponse([]); } + + + /** + * Local Version+Setup Test + * + * @NoCSRFRequired + * @PublicPage + * + * @return DataResponse + */ + public function local(): DataResponse { + $setup = false; + try { + $this->configService->getCloudUrl(); + $setup = true; + } catch (SocialAppConfigException $e) { + } + + return $this->success( + [ + 'version' => $this->configService->getAppValue('installed_version'), + 'setup' => $setup + ] + ); + } + + + /** + * Actor Test + * + * @NoCSRFRequired + * @PublicPage + * + * @param string $account + * + * @return DataResponse + */ + public function remote(string $account): DataResponse { + try { + $this->configService->getCloudUrl(); + } catch (SocialAppConfigException $e) { + return $this->success(['error' => 'error on my side: my own Social App is not configured']); + } + + $tests = new SimpleDataStore(['account' => $account]); + try { + $this->testService->testWebfinger($tests); + } catch (Exception $e) { + return $this->fail($e, ['result' => $tests], Http::STATUS_OK); + } + + return $this->success([$tests]); + } + } + diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index de22a4f1..918684ff 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -46,7 +46,6 @@ use OCA\Social\Service\ConfigService; use OCA\Social\Service\DocumentService; use OCA\Social\Service\MiscService; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; @@ -232,31 +231,6 @@ class NavigationController extends Controller { return $url; } - /** - * Display the navigation page of the Social app. - * - * @NoCSRFRequired - * @PublicPage - * - * @return DataResponse - */ - public function test(): DataResponse { - - $setup = false; - try { - $this->configService->getCloudUrl(); - $setup = true; - } catch (SocialAppConfigException $e) { - } - - return $this->success( - [ - 'version' => $this->configService->getAppValue('installed_version'), - 'setup' => $setup - ] - ); - } - /** * Display the navigation page of the Social app. diff --git a/lib/Db/CacheActorsRequestBuilder.php b/lib/Db/CacheActorsRequestBuilder.php index 0289e204..c4dc0783 100644 --- a/lib/Db/CacheActorsRequestBuilder.php +++ b/lib/Db/CacheActorsRequestBuilder.php @@ -91,7 +91,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder { /** @deprecated */ $this->defaultSelectAlias = 'ca'; $qb->setDefaultSelectAlias('ca'); - + return $qb; } @@ -120,7 +120,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder { try { $result = $qb->getRow([$this, 'parseCacheActorsSelectSql']); } catch (RowNotFoundException $e) { - throw new CacheActorDoesNotExistException($e->getMessage()); + throw new CacheActorDoesNotExistException('Actor is not known'); } return $result; diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index 398a3088..c57d458e 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -308,11 +308,11 @@ class ACore extends Item implements JsonSerializable { /** - * @param $id + * @param string $id * * @throws InvalidOriginException */ - public function checkOrigin($id) { + public function checkOrigin(string $id) { $host = parse_url($id, PHP_URL_HOST); $origin = $this->getRoot() ->getOrigin(); diff --git a/lib/Model/ActivityPub/Actor/Person.php b/lib/Model/ActivityPub/Actor/Person.php index 92e02cf9..bc6c3272 100644 --- a/lib/Model/ActivityPub/Actor/Person.php +++ b/lib/Model/ActivityPub/Actor/Person.php @@ -428,6 +428,7 @@ class Person extends ACore implements IQueryRow, JsonSerializable { /** @var Image $icon */ $icon = AP::$activityPub->getItemFromType(Image::TYPE); + $icon->setParent($this); $icon->import($this->getArray('icon', $data, [])); if ($icon->getType() === Image::TYPE) { diff --git a/lib/Model/ActivityPub/Object/Document.php b/lib/Model/ActivityPub/Object/Document.php index 6685fb62..512cc5b9 100644 --- a/lib/Model/ActivityPub/Object/Document.php +++ b/lib/Model/ActivityPub/Object/Document.php @@ -252,7 +252,8 @@ class Document extends ACore implements JsonSerializable { if ($this->getId() === '') { $this->generateUniqueId('/documents/g'); } else { - $this->checkOrigin($this->getId()); + // TODO: question if we need this, and why during the import ? + // $this->checkOrigin($this->getId()); } } diff --git a/lib/Model/Test.php b/lib/Model/Test.php new file mode 100644 index 00000000..87be284c --- /dev/null +++ b/lib/Model/Test.php @@ -0,0 +1,152 @@ + + * @copyright 2018, Maxence Lange + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Social\Model; + + +use daita\MySmallPhpTools\Model\SimpleDataStore; +use daita\MySmallPhpTools\Traits\TArrayTools; +use JsonSerializable; + + +/** + * Class Test + * + * @package OCA\Social\Model + */ +class Test extends SimpleDataStore implements JsonSerializable { + + + use TArrayTools; + + + const SEVERITY_USELESS = 'useless'; + const SEVERITY_OPTIONAL = 'optional'; + const SEVERITY_MANDATORY = 'mandatory'; + + + /** @var string */ + private $name; + + /** @var string */ + private $severity; + + /** @var bool */ + private $success = false; + + /** @var array */ + private $messages = []; + + + /** + * Test constructor. + * + * @param string $name + * @param string $severity + */ + public function __construct(string $name = '', string $severity = self::SEVERITY_OPTIONAL) { + $this->name = $name; + $this->severity = $severity; + } + + + /** + * @return string + */ + public function getName(): string { + return $this->name; + } + + + /** + * @return string + */ + public function getSeverity(): string { + return $this->severity; + } + + + /** + * @return bool + */ + public function isSuccess(): bool { + return $this->success; + } + + /** + * @param bool $success + * + * @return Test + */ + public function setSuccess(bool $success): self { + $this->success = $success; + + return $this; + } + + + /** + * @return array + */ + public function getMessages(): array { + return $this->messages; + } + + /** + * @param string $message + * + * @return Test + */ + public function addMessage(string $message): self { + $this->messages[] = $message; + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + $result = array_filter( + [ + 'name' => $this->getName(), + 'severity' => $this->getSeverity(), + 'details' => $this->gAll(), + 'message' => $this->getMessages() + ] + ); + + $result['success'] = $this->isSuccess(); + + return $result; + } + +} + diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php index 1b145215..f049c99a 100644 --- a/lib/Service/CacheActorService.php +++ b/lib/Service/CacheActorService.php @@ -176,7 +176,7 @@ class CacheActorService { return $this->cacheActorsRequest->getFromLocalAccount($account); } - throw new CacheActorDoesNotExistException(); + throw new CacheActorDoesNotExistException('Address does is not local'); } /** diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 10af350a..2da6f0cf 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -125,8 +125,9 @@ class CurlService { throw new InvalidResourceException(); } + $protocols = ['https', 'http']; try { - $path = $this->hostMeta($host); + $path = $this->hostMeta($host, $protocols); } catch (HostMetaException $e) { $path = '/.well-known/webfinger'; } @@ -134,7 +135,7 @@ class CurlService { $request = new Request($path); $request->addData('resource', 'acct:' . $account); $request->setAddress($host); - $request->setProtocols(['https', 'http']); + $request->setProtocols($protocols); $result = $this->retrieveJson($request); $subject = $this->get('subject', $result, ''); @@ -149,25 +150,26 @@ class CurlService { /** * @param string $host + * @param array $protocols * * @return string * @throws HostMetaException */ - public function hostMeta(string &$host): string { + public function hostMeta(string &$host, array &$protocols): string { $request = new Request('/.well-known/host-meta'); $request->setAddress($host); + $request->setProtocols($protocols); try { $result = $this->retrieveJson($request); } catch (Exception $e) { - $this->miscService->log( - 'hostMeta Exception - ' . get_class($e) . ' - ' . $e->getMessage(), 0 - ); - throw new HostMetaException($e->getMessage()); + $this->miscService->log('hostMeta Exception - ' . get_class($e) . ' - ' . $e->getMessage(), 0); + throw new HostMetaException(get_class($e) . ' - ' . $e->getMessage()); } $url = $this->get('Link.@attributes.template', $result, ''); $host = parse_url($url, PHP_URL_HOST); + $protocols = [parse_url($url, PHP_URL_SCHEME)]; return parse_url($url, PHP_URL_PATH); } diff --git a/lib/Service/TestService.php b/lib/Service/TestService.php new file mode 100644 index 00000000..758d9377 --- /dev/null +++ b/lib/Service/TestService.php @@ -0,0 +1,188 @@ + + * @copyright 2018, Maxence Lange + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Social\Service; + + +use daita\MySmallPhpTools\Exceptions\ArrayNotFoundException; +use daita\MySmallPhpTools\Model\Request; +use daita\MySmallPhpTools\Model\SimpleDataStore; +use daita\MySmallPhpTools\Traits\TArrayTools; +use Exception; +use OCA\Social\AP; +use OCA\Social\Exceptions\HostMetaException; +use OCA\Social\Exceptions\InvalidOriginException; +use OCA\Social\Exceptions\InvalidResourceException; +use OCA\Social\Exceptions\ItemUnknownException; +use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Model\Test; + + +/** + * Class TestService + * + * @package OCA\Social\Service + */ +class TestService { + + + use TArrayTools; + + + /** @var CurlService */ + private $curlService; + + /** @var ConfigService */ + private $configService; + + /** @var MiscService */ + private $miscService; + + + /** + * PostService constructor. + * + * @param CurlService $curlService + * @param ConfigService $configService + * @param MiscService $miscService + */ + public function __construct( + CurlService $curlService, ConfigService $configService, MiscService $miscService + ) { + $this->curlService = $curlService; + $this->configService = $configService; + $this->miscService = $miscService; + } + + + public function testWebfinger(SimpleDataStore $tests) { + $account = ltrim($tests->g('account'), '@'); + + if (!filter_var($account, FILTER_VALIDATE_EMAIL)) { + throw new InvalidResourceException('account format is not valid'); + } + + list($username, $host) = explode('@', $account); + if ($username === null || $host === null) { + throw new InvalidResourceException('account format should be valid'); + } + + $testHostMeta = new Test('host-meta', Test::SEVERITY_OPTIONAL); + $protocols = ['https', 'http']; + try { + $path = $this->curlService->hostMeta($host, $protocols); + $testHostMeta->s('host', $host); + $testHostMeta->s('path', $path); + $testHostMeta->sArray('protocol', $protocols); + $testHostMeta->setSuccess(true); + } catch (HostMetaException $e) { + $testHostMeta->addMessage($e->getMessage()); + $path = '/.well-known/webfinger'; + } + $tests->aObj('tests', $testHostMeta); + + + $request = new Request($path); + $request->addData('resource', 'acct:' . $account); + $request->setAddress($host); + $request->setProtocols($protocols); + + $testWebfinger = new Test('webfinger', Test::SEVERITY_MANDATORY); + $testWebfinger->sObj('request', $request); + $result = []; + try { + $result = $this->curlService->retrieveJson($request); + $testWebfinger->sArray('result', $result); + $testWebfinger->setSuccess(true); + } catch (Exception $e) { + $testWebfinger->addMessage(get_class($e)); + $testWebfinger->addMessage($e->getMessage()); + } + $tests->aObj('tests', $testWebfinger); + + $testActorLink = new Test('actor-link', Test::SEVERITY_MANDATORY); + try { + $links = $this->getArray('links', $result); + $link = $this->extractArray('rel', 'self', $links); + $testActorLink->aArray('link', $link); + $testActorLink->setSuccess(true); + } catch (ArrayNotFoundException $e) { + $testActorLink->addMessage(get_class($e)); + $testActorLink->addMessage('cannot find actor-link in links'); + $testActorLink->aArray('links', $links); + } + + $tests->aObj('tests', $testActorLink); + + + $id = $this->get('href', $link, ''); + + $testActorData = new Test('actor-data', Test::SEVERITY_MANDATORY); + $testActorData->a('id', $id); + $data = []; + try { + $data = $this->curlService->retrieveObject($id); + $testActorData->setSuccess(true); + $testActorData->sArray('data', $data); + } catch (Exception $e) { + $testActorData->addMessage(get_class($e)); + $testActorData->addMessage($e->getMessage()); + } + + $tests->aObj('tests', $testActorData); + + + $testActor = new Test('actor', Test::SEVERITY_MANDATORY); + try { + /** @var Person $actor */ + $actor = AP::$activityPub->getItemFromData($data); + if (!AP::$activityPub->isActor($actor)) { + throw new ItemUnknownException('Actor is not an Actor'); + } + + if (strtolower($actor->getId()) !== strtolower($id)) { + throw new InvalidOriginException( + 'CurlService::retrieveAccount - id: ' . $id . ' - actorId: ' . $actor->getId() + ); + } + + $testActor->setSuccess(true); + $testActor->sObj('actor', $actor); + } catch (Exception $e) { + echo $e->getTraceAsString(); + $testActor->addMessage(get_class($e)); + $testActor->addMessage($e->getMessage()); + } + + $tests->aObj('tests', $testActor); + + } + +} + diff --git a/lib/hostmeta.php b/lib/hostmeta.php index 4965b37f..4f06424d 100644 --- a/lib/hostmeta.php +++ b/lib/hostmeta.php @@ -49,7 +49,7 @@ try { exit; } -header('Content-type: application/xdr+xml'); +header('Content-type: application/xrd+xml'); try { $url = $configService->getCloudUrl(true) . '/.well-known/webfinger?resource={uri}'; diff --git a/lib/webfinger.php b/lib/webfinger.php index d575dfa3..16690f87 100644 --- a/lib/webfinger.php +++ b/lib/webfinger.php @@ -39,7 +39,6 @@ use OCP\AppFramework\QueryException; require_once(__DIR__ . '/../appinfo/autoload.php'); - if (!array_key_exists('resource', $_GET)) { echo 'missing resource'; exit(); @@ -75,17 +74,6 @@ try { try { $fediverseService->jailed(); - if ($configService->getSocialAddress() !== $instance) { - if ($configService->getCloudHost() === $instance) { - $instance = $configService->getSocialAddress(); - } else { - throw new Exception( - 'instance is ' . $instance . ', expected ' . $configService->getSocialAddress() - . ' or ' . $configService->getCloudHost() - ); - } - } - $cacheActorService->getFromLocalAccount($username); } catch (Exception $e) { if ($type !== '') { -- cgit v1.2.3 From f149363bffbe228456935b39917e024d5fde21c5 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sat, 1 Aug 2020 09:43:41 -0100 Subject: cleaning Signed-off-by: Maxence Lange --- lib/Service/TestService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/TestService.php b/lib/Service/TestService.php index 758d9377..e96daf39 100644 --- a/lib/Service/TestService.php +++ b/lib/Service/TestService.php @@ -127,6 +127,7 @@ class TestService { $tests->aObj('tests', $testWebfinger); $testActorLink = new Test('actor-link', Test::SEVERITY_MANDATORY); + $link = []; try { $links = $this->getArray('links', $result); $link = $this->extractArray('rel', 'self', $links); @@ -175,7 +176,6 @@ class TestService { $testActor->setSuccess(true); $testActor->sObj('actor', $actor); } catch (Exception $e) { - echo $e->getTraceAsString(); $testActor->addMessage(get_class($e)); $testActor->addMessage($e->getMessage()); } -- cgit v1.2.3 From 29c3a32ee60cb97d9196d91f2bdddd2b3197519f Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 3 Aug 2020 12:51:14 -0100 Subject: cleaning Signed-off-by: Maxence Lange --- appinfo/routes.php | 6 +- docs/test_first-run.png | Bin 0 -> 57729 bytes docs/test_ok.json | 161 ++++++++++++++++++++++++++++++++++++ lib/Controller/ConfigController.php | 11 ++- 4 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 docs/test_first-run.png create mode 100644 docs/test_ok.json diff --git a/appinfo/routes.php b/appinfo/routes.php index 73e6802d..93ea98bf 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -37,12 +37,12 @@ use OCA\Social\Service\CurlService; return [ 'routes' => [ ['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'], - ['name' => 'Config#remote', 'url' => '/test/{account}/', 'verb' => 'GET'], ['name' => 'Config#local', 'url' => '/local/', 'verb' => 'GET'], + ['name' => 'Config#remote', 'url' => '/test/{account}/', 'verb' => 'GET'], [ - 'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET', + 'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+'], - 'defaults' => ['path' => ''] + 'defaults' => ['path' => ''] ], ['name' => 'Navigation#documentGet', 'url' => '/document/get', 'verb' => 'GET'], ['name' => 'Navigation#documentGetPublic', 'url' => '/document/public', 'verb' => 'GET'], diff --git a/docs/test_first-run.png b/docs/test_first-run.png new file mode 100644 index 00000000..de3c0505 Binary files /dev/null and b/docs/test_first-run.png differ diff --git a/docs/test_ok.json b/docs/test_ok.json new file mode 100644 index 00000000..933b6e9c --- /dev/null +++ b/docs/test_ok.json @@ -0,0 +1,161 @@ +{ + "result": [ + { + "account": "cult@test.artificial-owl.com", + "endpoint": "test@social.artificial-owl.com", + "tests": [ + { + "name": "host-meta", + "severity": "optional", + "details": { + "host": "test.artificial-owl.com", + "path": "/.well-known/webfinger", + "protocol": [ + "https" + ] + }, + "success": true + }, + { + "name": "webfinger", + "severity": "mandatory", + "details": { + "request": { + "protocols": [ + "https" + ], + "used_protocol": "https", + "host": "test.artificial-owl.com", + "url": "/.well-known/webfinger", + "timeout": 10, + "type": 0, + "data": { + "resource": "acct:cult@test.artificial-owl.com" + } + }, + "result": { + "subject": "acct:cult@test.artificial-owl.com", + "links": [ + { + "rel": "self", + "type": "application/activity+json", + "href": "https://test.artificial-owl.com/index.php/apps/social/@cult" + }, + { + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": "https://test.artificial-owl.com/index.php/apps/social/ostatus/follow/?uri={uri}" + } + ] + } + }, + "success": true + }, + { + "name": "actor-link", + "severity": "mandatory", + "details": { + "link": { + "rel": "self", + "type": "application/activity+json", + "href": "https://test.artificial-owl.com/index.php/apps/social/@cult" + } + }, + "success": true + }, + { + "name": "actor-data", + "severity": "mandatory", + "details": { + "id": [ + "https://test.artificial-owl.com/index.php/apps/social/@cult" + ], + "data": { + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + "id": "https://test.artificial-owl.com/index.php/apps/social/@cult", + "type": "Person", + "url": "https://test.artificial-owl.com/index.php/apps/social/@cult", + "icon": { + "id": "https://test.artificial-owl.com/index.php/documents/avatar/c7ad599c-499a-4680-9f01-e7f57fbea631", + "type": "Image", + "url": "https://test.artificial-owl.com/index.php/avatar/cult/128", + "mediaType": "", + "mimeType": "", + "localCopy": "avatar", + "resizedCopy": "" + }, + "local": true, + "aliases": [ + "@cult", + "users/cult" + ], + "preferredUsername": "cult", + "name": "", + "inbox": "https://test.artificial-owl.com/index.php/apps/social/@cult/inbox", + "outbox": "https://test.artificial-owl.com/index.php/apps/social/@cult/outbox", + "account": "cult@test.artificial-owl.com", + "following": "https://test.artificial-owl.com/index.php/apps/social/@cult/following", + "followers": "https://test.artificial-owl.com/index.php/apps/social/@cult/followers", + "endpoints": { + "sharedInbox": "https://test.artificial-owl.com/index.php/apps/social/inbox" + }, + "publicKey": { + "id": "https://test.artificial-owl.com/index.php/apps/social/@cult#main-key", + "owner": "https://test.artificial-owl.com/index.php/apps/social/@cult", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwz9YTXDH2IJS/zfITuFF\n/tjUbdxK0LzzcvpFKWeaXH3ybQbjw3AjRIn4PPXCtzuBqUK54yI52gxT7DR98r21\nG0q6/ifucoZV6zb2Af5T+BiHKwhV4/HY9XAgQf6GR1bpP0Qxdf1g/ZuCu5tEdjB4\ncu+/WX7rDZ2hf2ahaHAJC4Nw4CxjF6H6t8ng53dbLTzzFMeGU3nyJmW2I31Pe7r4\n2RfOhe1RwI4t24a/ls/ZVucSuaMm9pFTtfSDao111lZH6CXmo1wFYnCalPSnF1kh\ncviKyPpxJXaAYggM24IkYJpwbH8JWoSMk8UebSN9sgM5QfsLK7bMKXazB829RxoM\n/wIDAQAB\n-----END PUBLIC KEY-----\n" + }, + "_host": "test.artificial-owl.com" + } + }, + "success": true + }, + { + "name": "actor", + "severity": "mandatory", + "details": { + "actor": { + "@context": [ + "https://www.w3.org/ns/activitystreams" + ], + "id": "https://test.artificial-owl.com/index.php/apps/social/@cult", + "type": "Person", + "url": "https://test.artificial-owl.com/index.php/apps/social/@cult", + "icon": { + "id": "https://test.artificial-owl.com/index.php/documents/avatar/c7ad599c-499a-4680-9f01-e7f57fbea631", + "type": "Image", + "url": "https://test.artificial-owl.com/index.php/avatar/cult/128", + "mediaType": "", + "mimeType": "", + "localCopy": "", + "resizedCopy": "" + }, + "aliases": [ + "@cult", + "users/cult" + ], + "preferredUsername": "cult", + "name": "", + "inbox": "https://test.artificial-owl.com/index.php/apps/social/@cult/inbox", + "outbox": "https://test.artificial-owl.com/index.php/apps/social/@cult/outbox", + "account": "cult@test.artificial-owl.com", + "following": "https://test.artificial-owl.com/index.php/apps/social/@cult/following", + "followers": "https://test.artificial-owl.com/index.php/apps/social/@cult/followers", + "endpoints": { + "sharedInbox": "https://test.artificial-owl.com/index.php/apps/social/inbox" + }, + "publicKey": { + "id": "https://test.artificial-owl.com/index.php/apps/social/@cult#main-key", + "owner": "https://test.artificial-owl.com/index.php/apps/social/@cult", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwz9YTXDH2IJS/zfITuFF\n/tjUbdxK0LzzcvpFKWeaXH3ybQbjw3AjRIn4PPXCtzuBqUK54yI52gxT7DR98r21\nG0q6/ifucoZV6zb2Af5T+BiHKwhV4/HY9XAgQf6GR1bpP0Qxdf1g/ZuCu5tEdjB4\ncu+/WX7rDZ2hf2ahaHAJC4Nw4CxjF6H6t8ng53dbLTzzFMeGU3nyJmW2I31Pe7r4\n2RfOhe1RwI4t24a/ls/ZVucSuaMm9pFTtfSDao111lZH6CXmo1wFYnCalPSnF1kh\ncviKyPpxJXaAYggM24IkYJpwbH8JWoSMk8UebSN9sgM5QfsLK7bMKXazB829RxoM\n/wIDAQAB\n-----END PUBLIC KEY-----\n" + } + } + }, + "success": true + } + ] + } + ], + "status": 1 +} diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 319a9344..3009f1d1 100644 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -113,13 +113,22 @@ class ConfigController extends Controller { * @return DataResponse */ public function remote(string $account): DataResponse { + if ($account === '' || $this->configService->getSystemValue('social.tests') === '') { + return $this->local(); + } + try { $this->configService->getCloudUrl(); } catch (SocialAppConfigException $e) { return $this->success(['error' => 'error on my side: my own Social App is not configured']); } - $tests = new SimpleDataStore(['account' => $account]); + $tests = new SimpleDataStore( + [ + 'account' => $account, + 'endpoint' => $this->configService->getSystemValue('social.tests') + ] + ); try { $this->testService->testWebfinger($tests); } catch (Exception $e) { -- cgit v1.2.3