parent
commit
d91bc5ec66
Signed by: diogo <mail@diogo.site> GPG Key ID: 18D2D35001FBFAB0
6 changed files with 96 additions and 67 deletions
  1. +1
    -0
      plugins/ActivityPub/Util/Explorer.php
  2. +1
    -1
      plugins/ActivityPub/Util/Model/Actor.php
  3. +35
    -0
      plugins/ActivityPub/tests/ActivityPubTestCase.php
  4. +3
    -2
      plugins/ActivityPub/tests/Objects/GSGroupTest.php
  5. +56
    -0
      plugins/ActivityPub/tests/Objects/GSPersonTest.php
  6. +0
    -64
      plugins/ActivityPub/tests/Objects/PersonTest.php

+ 1
- 0
plugins/ActivityPub/Util/Explorer.php View File

@@ -185,6 +185,7 @@ class Explorer
// Try standard ActivityPub route
// Is this a known filthy little mudblood?
$aprofile = DB::findOneBy(ActivitypubActor::class, ['uri' => $uri], return_null: true);
//dd($aprofile, DB::sql('select * from activitypub_actor;'));
if (!\is_null($aprofile)) {
Log::debug('ActivityPub Explorer: Found a known ActivityPub Actor for ' . $uri);
$this->discovered_actors[] = $aprofile->getActor();


+ 1
- 1
plugins/ActivityPub/Util/Model/Actor.php View File

@@ -187,7 +187,7 @@ class Actor extends Model
} else {
// Delete existing avatar if any
try {
$avatar = DB::findOneBy('avatar', ['actor_id' => $actor->getId()]);
$avatar = DB::findOneBy(\Component\Avatar\Entity\Avatar::class, ['actor_id' => $actor->getId()]);
$avatar->delete();
Event::handle('AvatarUpdate', [$actor->getId()]);
} catch (Exception) {


+ 35
- 0
plugins/ActivityPub/tests/ActivityPubTestCase.php View File

@@ -0,0 +1,35 @@
<?php

declare(strict_types = 1);

namespace Plugin\ActivityPub\tests;

use App\Core\DB\DB;
use App\Util\GNUsocialTestCase;
use Plugin\ActivityPub\Util\Model\Activity;
use Plugin\ActivityPub\Util\Model\Actor;
use Plugin\ActivityPub\Util\Model\Note;

class ActivityPubTestCase extends GNUsocialTestCase
{
private static string $fixtures_path = INSTALLDIR . '/plugins/ActivityPub/tests/fixtures';

public static function loadFixtures(string $ontology = 'gnusocial'): void
{
static::bootKernel();
// Load Actors
$person = Actor::fromJson(file_get_contents(self::$fixtures_path . "/{$ontology}/objects/person.jsonld"));
$group = Actor::fromJson(file_get_contents(self::$fixtures_path . "/{$ontology}/objects/group.jsonld"));

// Load Activities
$create_note = Activity::fromJson(file_get_contents(self::$fixtures_path . "/{$ontology}/activities/create_note.jsonld"));
$create_page = Activity::fromJson(file_get_contents(self::$fixtures_path . "/{$ontology}/activities/create_page.jsonld"));

// Load Objects
$note = Note::fromJson(file_get_contents(self::$fixtures_path . "/{$ontology}/objects/note.jsonld"));
$page = Note::fromJson(file_get_contents(self::$fixtures_path . "/{$ontology}/objects/page.jsonld"));
$reply = Note::fromJson(file_get_contents(self::$fixtures_path . "/{$ontology}/objects/reply.jsonld"));

DB::flush();
}
}

plugins/ActivityPub/tests/Objects/GroupTest.php → plugins/ActivityPub/tests/Objects/GSGroupTest.php View File

@@ -24,18 +24,19 @@ declare(strict_types = 1);
namespace Plugin\ActivityPub\tests\Objects;

use App\Core\DB\DB;
use App\Util\GNUsocialTestCase;
use Jchook\AssertThrows\AssertThrows;
use Plugin\ActivityPub\Entity\ActivitypubRsa;
use Plugin\ActivityPub\tests\ActivityPubTestCase;
use Plugin\ActivityPub\Util\Model\Actor;

class GroupTest extends GNUsocialTestCase
class GSGroupTest extends ActivityPubTestCase
{
use AssertThrows;

public function testPersonFromJson()
{
static::bootKernel();
static::loadFixtures();

$fixtures_path = INSTALLDIR . '/plugins/ActivityPub/tests/fixtures/gnusocial/';
$person = Actor::fromJson(file_get_contents($fixtures_path . 'objects/group.jsonld'));

+ 56
- 0
plugins/ActivityPub/tests/Objects/GSPersonTest.php View File

@@ -0,0 +1,56 @@
<?php

declare(strict_types = 1);

// {{{ License

// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social 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.
//
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.

// }}}

namespace Plugin\ActivityPub\tests\Objects;

use Plugin\ActivityPub\tests\ActivityPubTestCase;

class GSPersonTest extends ActivityPubTestCase
{
// public function testPersonFromJson()
// {
// static::bootKernel();
// static::loadFixtures();
//
// $person = Explorer::getOneFromUri('https://testv3.gnusocial.rocks/actor/42', false);
// $ap_person = ActivitypubActor::getByPK(['actor_id' => $person->getId()]);
// static::assertSame('https://testv3.gnusocial.rocks/actor/42/inbox.json', $ap_person->getInboxUri());
// static::assertSame('https://testv3.gnusocial.rocks/inbox.json', $ap_person->getInboxSharedUri());
// $person = $ap_person->getActor();
// static::assertSame('https://testv3.gnusocial.rocks/actor/42', $person->getUri());
// static::assertSame(\App\Entity\Actor::PERSON, $person->getType());
// static::assertSame('diogo', $person->getNickname());
// static::assertSame('Diogo Cordeiro', $person->getFullname());
// $public_key = ActivityPubRsa::getByActor($person)->getPublicKey();
// static::assertSame("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArBB+3ldwA2qC1hQTtIho\n9KYhvvMlPdydn8dA6OlyIQ3Jy57ADt2e144jDSY5RQ3esmzWm2QqsI8rAsZsAraO\nl2+855y7Fw35WH4GBc7PJ6MLAEvMk1YWeS/rttXaDzh2i4n/AXkMuxDjS1IBqw2w\nn0qTz2sdGcBJ+mop6AB9Qt2lseBc5IW040jSnfLEDDIaYgoc5m2yRsjGKItOh3BG\njGHDb6JB9FySToSMGIt0/tE5k06wfvAxtkxX5dfGeKtciBpC2MGT169iyMIOM8DN\nFhSl8mowtV1NJQ7nN692USrmNvSJjqe9ugPCDPPvwQ5A6A61Qrgpz5pav/o5Sz69\nzQIDAQAB\n-----END PUBLIC KEY-----\n", $public_key);
// }

public function testPersonToJson()
{
static::loadFixtures();

//$actor = Explorer::getOneFromUri('https://testv3.gnusocial.rocks/actor/42', false);
//$actual = Actor::toJson($actor);
//static::assertSame(file_get_contents($this->fixtures_path . 'objects/person.jsonld'), $actual);
}
}

+ 0
- 64
plugins/ActivityPub/tests/Objects/PersonTest.php View File

@@ -1,64 +0,0 @@
<?php

declare(strict_types = 1);

// {{{ License

// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social 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.
//
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.

// }}}

namespace Plugin\ActivityPub\tests\Objects;

use App\Core\DB\DB;
use App\Util\GNUsocialTestCase;
use Jchook\AssertThrows\AssertThrows;
use Plugin\ActivityPub\Entity\ActivitypubActor;
use Plugin\ActivityPub\Entity\ActivitypubRsa;
use Plugin\ActivityPub\Util\Explorer;
use Plugin\ActivityPub\Util\Model\Actor;

class PersonTest extends GNUsocialTestCase
{
use AssertThrows;
public string $fixtures_path = INSTALLDIR . '/plugins/ActivityPub/tests/fixtures/gnusocial/';

public function testPersonFromJson()
{
static::bootKernel();

$person = Actor::fromJson(file_get_contents($this->fixtures_path . 'objects/person.jsonld'));
static::assertSame('https://testv3.gnusocial.rocks/actor/42/inbox.json', $person->getInboxUri());
static::assertSame('https://testv3.gnusocial.rocks/inbox.json', $person->getInboxSharedUri());
DB::flush();
$person_actor = $person->getActor();
static::assertSame('https://testv3.gnusocial.rocks/actor/42', $person_actor->getUri());
static::assertSame(\App\Entity\Actor::PERSON, $person_actor->getType());
static::assertSame('diogo', $person_actor->getNickname());
static::assertSame('Diogo Cordeiro', $person_actor->getFullname());
$public_key = ActivityPubRsa::getByActor($person_actor)->getPublicKey();
static::assertSame("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArBB+3ldwA2qC1hQTtIho\n9KYhvvMlPdydn8dA6OlyIQ3Jy57ADt2e144jDSY5RQ3esmzWm2QqsI8rAsZsAraO\nl2+855y7Fw35WH4GBc7PJ6MLAEvMk1YWeS/rttXaDzh2i4n/AXkMuxDjS1IBqw2w\nn0qTz2sdGcBJ+mop6AB9Qt2lseBc5IW040jSnfLEDDIaYgoc5m2yRsjGKItOh3BG\njGHDb6JB9FySToSMGIt0/tE5k06wfvAxtkxX5dfGeKtciBpC2MGT169iyMIOM8DN\nFhSl8mowtV1NJQ7nN692USrmNvSJjqe9ugPCDPPvwQ5A6A61Qrgpz5pav/o5Sz69\nzQIDAQAB\n-----END PUBLIC KEY-----\n", $public_key);
dd(ActivitypubActor::getByPK(['uri' => 'https://testv3.gnusocial.rocks/actor/42']));
}

public function testPersonToJson()
{
//static::bootKernel();
//$actor = Explorer::getOneFromUri('https://testv3.gnusocial.rocks/actor/42', false);
//$actual = Actor::toJson($actor);
//static::assertSame(file_get_contents($this->fixtures_path . 'objects/person.jsonld'), $actual);
}
}

Loading…
Cancel
Save