summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2020-08-03 12:52:17 -0100
committerGitHub <noreply@github.com>2020-08-03 12:52:17 -0100
commitcc4ff9c7ec60ef701a29146395530e23a2b51dd8 (patch)
treec7d5f5fd3386027380dd651fa68fed399d34c72e
parent3fb6ed3ef5426c59805137d99152ff3faa0710b7 (diff)
parent29c3a32ee60cb97d9196d91f2bdddd2b3197519f (diff)
Merge pull request #964 from nextcloud/feature/noid/online-test
online test
-rw-r--r--appinfo/routes.php19
-rw-r--r--docs/test_first-run.pngbin0 -> 57729 bytes
-rw-r--r--docs/test_ok.json161
-rw-r--r--lib/AP.php18
-rw-r--r--lib/Controller/ConfigController.php90
-rw-r--r--lib/Controller/NavigationController.php26
-rw-r--r--lib/Db/CacheActorsRequestBuilder.php4
-rw-r--r--lib/Model/ActivityPub/ACore.php4
-rw-r--r--lib/Model/ActivityPub/Actor/Person.php1
-rw-r--r--lib/Model/ActivityPub/Object/Document.php3
-rw-r--r--lib/Model/Test.php152
-rw-r--r--lib/Service/CacheActorService.php2
-rw-r--r--lib/Service/CurlService.php16
-rw-r--r--lib/Service/TestService.php188
-rw-r--r--lib/hostmeta.php2
-rw-r--r--lib/webfinger.php12
16 files changed, 630 insertions, 68 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index e462d5dd..93ea98bf 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -37,11 +37,12 @@ use OCA\Social\Service\CurlService;
return [
'routes' => [
['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'],
- ['name' => 'Navigation#test', 'url' => '/test', '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',
'requirements' => ['path' => '.+'],
- 'defaults' => ['path' => '']
+ 'defaults' => ['path' => '']
],
['name' => 'Navigation#documentGet', 'url' => '/document/get', 'verb' => 'GET'],
['name' => 'Navigation#documentGetPublic', 'url' => '/document/public', 'verb' => 'GET'],
@@ -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/docs/test_first-run.png b/docs/test_first-run.png
new file mode 100644
index 00000000..de3c0505
--- /dev/null
+++ b/docs/test_first-run.png
Binary files 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/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..3009f1d1 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,68 @@ 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 {
+ 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,
+ 'endpoint' => $this->configService->getSystemValue('social.tests')
+ ]
+ );
+ 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 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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..e96daf39
--- /dev/null
+++ b/lib/Service/TestService.php
@@ -0,0 +1,188 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Social\Service;
+
+
+use daita\MySmallPhpTools\Exceptions\ArrayNotFoundException;
+use daita\MySmallPhpTools\Model\Request;
+use