Update AP tests

This commit is contained in:
Daniel Supernault 2020-04-29 20:27:36 -06:00
parent c39be2464e
commit 802dd326ce
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
6 changed files with 143 additions and 31 deletions

View file

@ -16,11 +16,11 @@ class Announce {
'required',
Rule::in(['Announce'])
],
'actor' => 'required|url|active_url',
'actor' => 'required|url',
'published' => 'required|date',
'to' => 'required',
'cc' => 'required',
'object' => 'required|url|active_url'
'object' => 'required|url'
])->passes();
return $valid;

View file

@ -16,8 +16,8 @@ class Follow {
'required',
Rule::in(['Follow'])
],
'actor' => 'required|url|active_url',
'object' => 'required|url|active_url'
'actor' => 'required|url',
'object' => 'required|url'
])->passes();
return $valid;

View file

@ -1,27 +0,0 @@
<?php
namespace Tests\Unit;
use App\Util\ActivityPub\Helpers;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class FollowTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->mastodon = '{"type":"Follow","signature":{"type":"RsaSignature2017","signatureValue":"Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==","creator":"http://mastodon.example.org/users/admin#main-key","created":"2018-02-17T13:29:31Z"},"object":"http://localtesting.pleroma.lol/users/lain","nickname":"lain","id":"http://mastodon.example.org/users/admin#follows/2","actor":"http://mastodon.example.org/users/admin","@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"toot":"http://joinmastodon.org/ns#","sensitive":"as:sensitive","ostatus":"http://ostatus.org#","movedTo":"as:movedTo","manuallyApprovesFollowers":"as:manuallyApprovesFollowers","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","atomUri":"ostatus:atomUri","Hashtag":"as:Hashtag","Emoji":"toot:Emoji"}]}';
}
/** @test */
public function validateMastodonFollowObject()
{
$mastodon = json_decode($this->mastodon, true);
$mastodon = Helpers::validateObject($mastodon);
$this->assertTrue($mastodon);
}
}

View file

@ -39,6 +39,42 @@ class AcceptVerbTest extends TestCase
'object' => 'https://example.org/u/alice'
]
];
$this->mastodonAccept = [
"@context" => [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
[
"toot" => "https://joinmastodon.org/ns#",
"sensitive" => "as:sensitive",
"ostatus" => "https://ostatus.org#",
"movedTo" => "as:movedTo",
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
"inReplyToAtomUri" => "ostatus:inReplyToAtomUri",
"conversation" => "ostatus:conversation",
"atomUri" => "ostatus:atomUri",
"Hashtag" => "as:Hashtag",
"Emoji" => "toot:Emoji",
],
],
"type" => "Accept",
"object" => [
"type" => "Follow",
"object" => "https://mastodon.example.org/users/admin",
"id" => "https://pixelfed.dev/users/dsup#follows/4",
"actor" => "https://pixelfed.dev/users/dsup",
],
"nickname" => "dsup",
"id" => "https://mastodon.example.org/users/admin#accepts/follows/4",
"actor" => "https://mastodon.example.org/users/admin",
"signature" => [
"type" => "RsaSignature2017",
"signatureValue" => "rBzK4Kqhd4g7HDS8WE5oRbWQb2R+HF/6awbUuMWhgru/xCODT0SJWSri0qWqEO4fPcpoUyz2d25cw6o+iy9wiozQb3hQNnu69AR+H5Mytc06+g10KCHexbGhbAEAw/7IzmeXELHUbaqeduaDIbdt1zw4RkwLXdqgQcGXTJ6ND1wM3WMHXQCK1m0flasIXFoBxpliPAGiElV8s0+Ltuh562GvflG3kB3WO+j+NaR0ZfG5G9N88xMj9UQlCKit5gpAE5p6syUsCU2WGBHywTumv73i3OVTIFfq+P9AdMsRuzw1r7zoKEsthW4aOzLQDi01ZjvdBz8zH6JnjDU7SMN/Ig==",
"creator" => "https://mastodon.example.org/users/admin#main-key",
"created" => "2018-02-17T14:36:41Z",
],
];
}
/** @test */
@ -52,4 +88,10 @@ class AcceptVerbTest extends TestCase
{
$this->assertFalse(Accept::validate($this->invalidAccept));
}
/** @test */
public function mastodon_accept()
{
$this->assertTrue(Accept::validate($this->mastodonAccept));
}
}

View file

@ -126,6 +126,44 @@ class AnnounceTest extends TestCase
],
"object" => "https://example.org/p/bob/100000000000000",
];
$this->mastodonAnnounce = [
"type" => "Announce",
"to" => [
"https://www.w3.org/ns/activitystreams#Public",
],
"signature" => [
"type" => "RsaSignature2017",
"signatureValue" => "T95DRE0eAligvMuRMkQA01lsoz2PKi4XXF+cyZ0BqbrO12p751TEWTyyRn5a+HH0e4kc77EUhQVXwMq80WAYDzHKVUTf2XBJPBa68vl0j6RXw3+HK4ef5hR4KWFNBU34yePS7S1fEmc1mTG4Yx926wtmZwDpEMTp1CXOeVEjCYzmdyHpepPPH2ZZettiacmPRSqBLPGWZoot7kH/SioIdnrMGY0I7b+rqkIdnnEcdhu9N1BKPEO9Sr+KmxgAUiidmNZlbBXX6gCxp8BiIdH4ABsIcwoDcGNkM5EmWunGW31LVjsEQXhH5c1Wly0ugYYPCg/0eHLNBOhKkY/teSM8Lg==",
"creator" => "https://mastodon.example.org/users/admin#main-key",
"created" => "2018-02-17T19:39:15Z",
],
"published" => "2018-02-17T19:39:15Z",
"object" => "https://mastodon.example.org/@admin/99541947525187367",
"id" => "https://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
"cc" => [
"https://mastodon.example.org/users/admin",
"https://mastodon.example.org/users/admin/followers",
],
"atomUri" => "https://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
"actor" => "https://mastodon.example.org/users/admin",
"@context" => [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
[
"toot" => "https://joinmastodon.org/ns#",
"sensitive" => "as:sensitive",
"ostatus" => "https://ostatus.org#",
"movedTo" => "as:movedTo",
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
"inReplyToAtomUri" => "ostatus:inReplyToAtomUri",
"conversation" => "ostatus:conversation",
"atomUri" => "ostatus:atomUri",
"Hashtag" => "as:Hashtag",
"Emoji" => "toot:Emoji",
],
],
];
}
/** @test */
@ -165,4 +203,10 @@ class AnnounceTest extends TestCase
$this->assertFalse(Announce::validate($this->invalidActor));
$this->assertFalse(Announce::validate($this->invalidActor2));
}
/** @test */
public function mastodon_announce()
{
$this->assertTrue(Announce::validate($this->mastodonAnnounce));
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace Tests\Unit\ActivityPub\Verb;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\ActivityPub\Validator\Follow;
class FollowTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->basicFollow = [
"type" => "Follow",
"signature" => [
"type" => "RsaSignature2017",
"signatureValue" => "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==",
"creator" => "http://mastodon.example.org/users/admin#main-key",
"created" => "2018-02-17T13:29:31Z",
],
"object" => "http://pixelfed.dev/users/dsup",
"nickname" => "dsup",
"id" => "http://mastodon.example.org/users/admin#follows/2",
"actor" => "http://mastodon.example.org/users/admin",
"@context" => [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
[
"toot" => "http://joinmastodon.org/ns#",
"sensitive" => "as:sensitive",
"ostatus" => "http://ostatus.org#",
"movedTo" => "as:movedTo",
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
"inReplyToAtomUri" => "ostatus:inReplyToAtomUri",
"conversation" => "ostatus:conversation",
"atomUri" => "ostatus:atomUri",
"Hashtag" => "as:Hashtag",
"Emoji" => "toot:Emoji",
],
],
];
}
/** @test */
public function basic_follow()
{
$this->assertTrue(Follow::validate($this->basicFollow));
}
}