1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pixelfed_ynh.git synced 2024-09-03 20:06:04 +02:00

Merge pull request #4071 from pixelfed/staging

Staging
This commit is contained in:
daniel 2023-01-08 14:18:15 -07:00 committed by GitHub
commit 5676480efc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 1079 additions and 1077 deletions

View file

@ -66,10 +66,13 @@ class CloudMediaMigrate extends Command
try { try {
MediaStorageService::store($media); MediaStorageService::store($media);
} catch (FileNotFoundException $e) { } catch (FileNotFoundException $e) {
$this->error('Error migrating media ' . $media->id . ' to cloud storage: ' . $e->getMessage());
return; return;
} catch (NotFoundHttpException $e) { } catch (NotFoundHttpException $e) {
$this->error('Error migrating media ' . $media->id . ' to cloud storage: ' . $e->getMessage());
return; return;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error('Error migrating media ' . $media->id . ' to cloud storage: ' . $e->getMessage());
return; return;
} }
} }

View file

@ -39,7 +39,11 @@ class UserAdmin extends Command
public function handle() public function handle()
{ {
$id = $this->argument('id'); $id = $this->argument('id');
$user = User::whereUsername($id)->orWhere('id', $id)->first(); if(ctype_digit($id) == true) {
$user = User::find($id);
} else {
$user = User::whereUsername($id)->first();
}
if(!$user) { if(!$user) {
$this->error('Could not find any user with that username or id.'); $this->error('Could not find any user with that username or id.');
exit; exit;

View file

@ -39,7 +39,11 @@ class UserShow extends Command
public function handle() public function handle()
{ {
$id = $this->argument('id'); $id = $this->argument('id');
$user = User::whereUsername($id)->orWhere('id', $id)->first(); if(ctype_digit($id) == true) {
$user = User::find($id);
} else {
$user = User::whereUsername($id)->first();
}
if(!$user) { if(!$user) {
$this->error('Could not find any user with that username or id.'); $this->error('Could not find any user with that username or id.');
exit; exit;

View file

@ -39,7 +39,11 @@ class UserSuspend extends Command
public function handle() public function handle()
{ {
$id = $this->argument('id'); $id = $this->argument('id');
$user = User::whereUsername($id)->orWhere('id', $id)->first(); if(ctype_digit($id) == true) {
$user = User::find($id);
} else {
$user = User::whereUsername($id)->first();
}
if(!$user) { if(!$user) {
$this->error('Could not find any user with that username or id.'); $this->error('Could not find any user with that username or id.');
exit; exit;

View file

@ -39,7 +39,11 @@ class UserUnsuspend extends Command
public function handle() public function handle()
{ {
$id = $this->argument('id'); $id = $this->argument('id');
$user = User::whereUsername($id)->orWhere('id', $id)->first(); if(ctype_digit($id) == true) {
$user = User::find($id);
} else {
$user = User::whereUsername($id)->first();
}
if(!$user) { if(!$user) {
$this->error('Could not find any user with that username or id.'); $this->error('Could not find any user with that username or id.');
exit; exit;

View file

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use Auth; use Auth;
use App\Contact; use App\Contact;
use App\Jobs\ContactPipeline\ContactPipeline; use App\Jobs\ContactPipeline\ContactPipeline;
use App\Rules\MaxMultiLine;
class ContactController extends Controller class ContactController extends Controller
{ {
@ -21,7 +22,7 @@ class ContactController extends Controller
abort_if(!Auth::check(), 403); abort_if(!Auth::check(), 403);
$this->validate($request, [ $this->validate($request, [
'message' => 'required|string|min:5|max:500', 'message' => ['required', 'string', 'min:5', new MaxMultiLine('500')],
'request_response' => 'string|max:3' 'request_response' => 'string|max:3'
]); ]);

View file

@ -0,0 +1,34 @@
<?php
namespace App\Rules;
use Illuminate\Support\Str;
use Illuminate\Contracts\Validation\InvokableRule;
class MaxMultiLine implements InvokableRule
{
private $maxCharacters;
public function __construct($maxCharacters)
{
$this->maxCharacters = $maxCharacters;
}
/**
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function __invoke($attribute, $value, $fail)
{
$realCount = Str::length($value) - Str::substrCount($value, "\r\n");
if($realCount > $this->maxCharacters)
{
$fail('validation.max.string')->translate(['max' => $this->maxCharacters]);
}
}
}

View file

@ -85,9 +85,22 @@ return [
*/ */
'username' => env('MAIL_USERNAME'), 'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'), 'password' => env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
| SMTP EHLO Domain
|--------------------------------------------------------------------------
|
| Some SMTP servers require to present a known domain in order to
| allow sending through its relay. (ie: Google Workspace)
| This will use the MAIL_SMTP_EHLO env variable to avoid the 421 error
| if not present by authenticating the sender domain instead the host.
|
*/
'local_domain' => env('MAIL_EHLO_DOMAIN'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Sendmail System Path | Sendmail System Path

View file

@ -1,32 +1,36 @@
<?= <?=
/* Using an echo tag here so the `<? ... ?>` won't get parsed as short tags */ /* Using an echo tag here so the `<? ... ?>` won't get parsed as short tags */
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL
?> ?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<id>{{$permalink}}</id> <id>{{$permalink}}</id>
<title>{{$profile['username']}} on Pixelfed</title> <title>{{$profile['username']}} on Pixelfed</title>
<subtitle type="html">{{$profile['note']}}</subtitle> <subtitle type="html">{{$profile['note']}}</subtitle>
<updated>{{$profile['created_at']}}</updated> <updated>{{$items[0]['created_at']}}</updated>
<author> <author>
<name>{{$profile['username']}}</name>
<uri>{{$profile['url']}}</uri> <uri>{{$profile['url']}}</uri>
<name>{{$profile['url']}}</name>
</author> </author>
<link rel="alternate" type="text/html" href="{{$profile['url']}}"/> <link rel="alternate" type="text/html" href="{{$profile['url']}}" />
<link rel="self" type="application/atom+xml" href="{{$permalink}}"/> <link rel="self" type="application/atom+xml" href="{{$permalink}}" />
@foreach($items as $item) <entry> @foreach($items as $item)
<title>{{ $item['content'] ? strip_tags($item['content']) : "No caption" }}</title> <entry>
<link rel="alternate" href="{{ $item['url'] }}" />
<id>{{ $item['url'] }}</id> <id>{{ $item['url'] }}</id>
<title>{{ $item['content_text'] ? $item['content_text'] : "No caption" }}</title>
<updated>{{ $item['created_at'] }}</updated>
<author> <author>
<name> <![CDATA[{{ $profile['username'] }}]]></name> <name>{{$profile['username']}}</name>
<uri>{{$profile['url']}}</uri>
</author> </author>
<summary type="html"> <content type="html">
<![CDATA[ <![CDATA[
<img id="rss_item_{{$loop->iteration}}" src="{{ $item['media_attachments'][0]['url'] }}" alt="{{ $item['media_attachments'][0]['description'] }}"> <img id="rss_item_{{$loop->iteration}}" src="{{ $item['media_attachments'][0]['url'] }}" alt="{{ $item['media_attachments'][0]['description'] }}">
<p style="padding:10px;">{{ $item['content'] }}</p> <p style="padding:10px;">{{ $item['content'] }}</p>
]]> ]]>
</summary> </content>
<updated>{{ $item['created_at'] }}</updated> <link rel="alternate" href="{{ $item['url'] }}" />
<summary type="html">{{ $item['content'] }}</summary>
<media:content url="{{ $item['media_attachments'][0]['url'] }}" type="{{ $item['media_attachments'][0]['mime'] }}" medium="image" />
</entry> </entry>
@endforeach @endforeach
</feed> </feed>

View file

@ -24,7 +24,7 @@
@csrf @csrf
<div class="form-group"> <div class="form-group">
<label for="input1" class="font-weight-bold">Message</label> <label for="input1" class="font-weight-bold">Message</label>
<textarea class="form-control" id="input1" name="message" rows="6" placeholder=""></textarea> <textarea class="form-control" id="input1" name="message" rows="6" placeholder="" maxlength="500" required>{{old('message')}}</textarea>
<span class="form-text text-muted text-right msg-counter">0/500</span> <span class="form-text text-muted text-right msg-counter">0/500</span>
</div> </div>
<div class="form-group form-check"> <div class="form-group form-check">

View file

@ -3,6 +3,7 @@
namespace Tests; namespace Tests;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
trait CreatesApplication trait CreatesApplication
@ -10,11 +11,11 @@ trait CreatesApplication
/** /**
* Creates the application. * Creates the application.
* *
* @return \Illuminate\Foundation\Application * @return Application
*/ */
public function createApplication() public function createApplication()
{ {
$app = require __DIR__.'/../bootstrap/app.php'; $app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap(); $app->make(Kernel::class)->bootstrap();

View file

@ -3,19 +3,17 @@
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class InstalledTest extends TestCase class InstalledTest extends TestCase
{ {
/** @test */ /** @test */
public function nodeinfo_api() public function nodeinfo_api(): void
{ {
$response = $this->get('/.well-known/nodeinfo'); $response = $this->get('/.well-known/nodeinfo');
$response->assertJson([ $response->assertJson([
'links' => [ 'links' => [
['rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0'], ['rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0'],
], ]); ],
]);
} }
} }

View file

@ -3,9 +3,6 @@
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use App\User;
class LoginTest extends TestCase class LoginTest extends TestCase
{ {

View file

@ -2,10 +2,8 @@
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Tests\TestCase;
class APAnnounceStrategyTest extends TestCase class APAnnounceStrategyTest extends TestCase
{ {
@ -47,12 +45,12 @@ class APAnnounceStrategyTest extends TestCase
{ {
$scope = Helpers::normalizeAudience($this->mastodon, false); $scope = Helpers::normalizeAudience($this->mastodon, false);
$actual = [ $actual = [
"to" => [], 'to' => [],
"cc" => [ 'cc' => [
"https://pleroma.site/users/pixeldev", 'https://pleroma.site/users/pixeldev',
"https://mastodon.social/users/dansup/followers", 'https://mastodon.social/users/dansup/followers',
], ],
"scope" => "public", 'scope' => 'public',
]; ];
$this->assertEquals($scope, $actual); $this->assertEquals($scope, $actual);
@ -62,12 +60,12 @@ class APAnnounceStrategyTest extends TestCase
{ {
$scope = Helpers::normalizeAudience($this->pleroma, false); $scope = Helpers::normalizeAudience($this->pleroma, false);
$actual = [ $actual = [
"to" => [ 'to' => [
"https://pleroma.site/users/pixeldev/followers", 'https://pleroma.site/users/pixeldev/followers',
"https://mastodon.social/users/dansup", 'https://mastodon.social/users/dansup',
], ],
"cc" => [], 'cc' => [],
"scope" => "unlisted", 'scope' => 'unlisted',
]; ];
$this->assertEquals($scope, $actual); $this->assertEquals($scope, $actual);

View file

@ -2,13 +2,13 @@
namespace Tests\Unit\ActivityPub; namespace Tests\Unit\ActivityPub;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Tests\TestCase;
class AudienceScopeTest extends TestCase class AudienceScopeTest extends TestCase
{ {
protected array $invalid;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -47,12 +47,12 @@ class AudienceScopeTest extends TestCase
{ {
$scope = Helpers::normalizeAudience($this->mastodon, false); $scope = Helpers::normalizeAudience($this->mastodon, false);
$actual = [ $actual = [
"to" => [], 'to' => [],
"cc" => [ 'cc' => [
"https://pleroma.site/users/pixeldev", 'https://pleroma.site/users/pixeldev',
"https://mastodon.social/users/dansup/followers", 'https://mastodon.social/users/dansup/followers',
], ],
"scope" => "public", 'scope' => 'public',
]; ];
$this->assertEquals($scope, $actual); $this->assertEquals($scope, $actual);
@ -62,12 +62,12 @@ class AudienceScopeTest extends TestCase
{ {
$scope = Helpers::normalizeAudience($this->pleroma, false); $scope = Helpers::normalizeAudience($this->pleroma, false);
$actual = [ $actual = [
"to" => [ 'to' => [
"https://pleroma.site/users/pixeldev/followers", 'https://pleroma.site/users/pixeldev/followers',
"https://mastodon.social/users/dansup", 'https://mastodon.social/users/dansup',
], ],
"cc" => [], 'cc' => [],
"scope" => "unlisted", 'scope' => 'unlisted',
]; ];
$this->assertEquals($scope, $actual); $this->assertEquals($scope, $actual);

View file

@ -4,15 +4,21 @@ namespace Tests\Unit\ActivityPub;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class NoteAttachmentTest extends TestCase class NoteAttachmentTest extends TestCase
{ {
protected array $pixelfed;
protected array $pleroma;
protected array $mastodon;
protected array $invalidType;
protected array $invalidMime;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->pixelfed = json_decode('{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"sc":"http://schema.org#","Hashtag":"as:Hashtag","sensitive":"as:sensitive","commentsEnabled":"sc:Boolean","capabilities":{"announce":{"@type":"@id"},"like":{"@type":"@id"},"reply":{"@type":"@id"}},"toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"https://pixelfed.social/p/dansup/2","type":"Note","summary":null,"content":"This was my first IG post too. #mazda #zoomzoom","inReplyTo":null,"published":"2018-06-01T05:16:51+00:00","url":"https://pixelfed.social/p/dansup/2","attributedTo":"https://pixelfed.social/users/dansup","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://pixelfed.social/users/dansup/followers"],"sensitive":false,"attachment":[{"type":"Image","mediaType":"image/jpeg","url":"https://pixelfed.social/storage/m/e64c75f2f4e9a621bb7c43ec9b04a165add6493b/b87fd76cbce4a613a9b9cba20f354709e67caf25/B4SHeEqWsj5t7qCIRzm7nvfCAtm31J8o12Ji1A2x.jpeg","name":null}],"tag":[{"type":"Hashtag","href":"https://pixelfed.social/discover/tags/mazda","name":"#mazda"},{"type":"Hashtag","href":"https://pixelfed.social/discover/tags/zoomzoom","name":"#zoomzoom"}],"commentsEnabled":false,"capabilities":{"announce":"https://www.w3.org/ns/activitystreams#Public","like":"https://www.w3.org/ns/activitystreams#Public","reply":null},"location":null}', true, 9);
$this->pleroma = json_decode('{"@context":"https://www.w3.org/ns/activitystreams","actor":"https://pleroma.site/users/pixeldev","cc":["https://pleroma.site/users/pixeldev/followers"],"context":"https://pleroma.site/contexts/cbe919c6-238e-4e5d-9065-fcb3c312b56a","context_id":8651628,"id":"https://pleroma.site/activities/65b2c43f-f33e-438e-b141-4e2047b43012","object":{"actor":"https://pleroma.site/users/pixeldev","announcement_count":2,"announcements":["https://playvicious.social/users/jalcine","https://mastodon.social/users/dansup"],"attachment":[{"mediaType":"image/png","name":"Screen Shot 2018-09-08 at 10.59.38 PM.png","type":"Document","url":"https://s3.wasabisys.com/pleroma-site/1c49e1f9-1187-404d-a063-1b37ecec44e9/Screen Shot 2018-09-08 at 10.59.38 PM.png"},{"mediaType":"image/jpeg","name":"archer-danger-zone.jpg","type":"Document","url":"https://s3.wasabisys.com/pleroma-site/cd70cdb6-0148-4dcb-bac6-11fd4aa59834/archer-danger-zone.jpg"}],"attributedTo":"https://pleroma.site/users/pixeldev","cc":["https://pleroma.site/users/pixeldev/followers"],"content":"New middleware for specific actions, acts like sudo requiring periodic password verification. <a href=\'https://pleroma.site/tag/dangerzone\' rel=\'tag\'>#dangerZone</a>","context":"https://pleroma.site/contexts/cbe919c6-238e-4e5d-9065-fcb3c312b56a","context_id":8651628,"conversation":"https://pleroma.site/contexts/cbe919c6-238e-4e5d-9065-fcb3c312b56a","emoji":{},"id":"https://pleroma.site/objects/b7576ec9-ae2b-4076-a426-0d8a65b23876","published":"2018-09-09T05:05:53.763752Z","sensitive":false,"summary":"","tag":[{"href":"https://pleroma.site/tags/dangerzone","name":"#dangerzone","type":"Hashtag"}],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Note"},"published":"2018-09-09T05:05:53.749866Z","to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Create"}', true, 9); $this->pleroma = json_decode('{"@context":"https://www.w3.org/ns/activitystreams","actor":"https://pleroma.site/users/pixeldev","cc":["https://pleroma.site/users/pixeldev/followers"],"context":"https://pleroma.site/contexts/cbe919c6-238e-4e5d-9065-fcb3c312b56a","context_id":8651628,"id":"https://pleroma.site/activities/65b2c43f-f33e-438e-b141-4e2047b43012","object":{"actor":"https://pleroma.site/users/pixeldev","announcement_count":2,"announcements":["https://playvicious.social/users/jalcine","https://mastodon.social/users/dansup"],"attachment":[{"mediaType":"image/png","name":"Screen Shot 2018-09-08 at 10.59.38 PM.png","type":"Document","url":"https://s3.wasabisys.com/pleroma-site/1c49e1f9-1187-404d-a063-1b37ecec44e9/Screen Shot 2018-09-08 at 10.59.38 PM.png"},{"mediaType":"image/jpeg","name":"archer-danger-zone.jpg","type":"Document","url":"https://s3.wasabisys.com/pleroma-site/cd70cdb6-0148-4dcb-bac6-11fd4aa59834/archer-danger-zone.jpg"}],"attributedTo":"https://pleroma.site/users/pixeldev","cc":["https://pleroma.site/users/pixeldev/followers"],"content":"New middleware for specific actions, acts like sudo requiring periodic password verification. <a href=\'https://pleroma.site/tag/dangerzone\' rel=\'tag\'>#dangerZone</a>","context":"https://pleroma.site/contexts/cbe919c6-238e-4e5d-9065-fcb3c312b56a","context_id":8651628,"conversation":"https://pleroma.site/contexts/cbe919c6-238e-4e5d-9065-fcb3c312b56a","emoji":{},"id":"https://pleroma.site/objects/b7576ec9-ae2b-4076-a426-0d8a65b23876","published":"2018-09-09T05:05:53.763752Z","sensitive":false,"summary":"","tag":[{"href":"https://pleroma.site/tags/dangerzone","name":"#dangerzone","type":"Hashtag"}],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Note"},"published":"2018-09-09T05:05:53.749866Z","to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Create"}', true, 9);
$this->mastodon = json_decode('{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791/activity","type":"Create","actor":"https://mastodon.social/users/dansup","published":"2018-10-13T18:43:33Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"object":{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791","type":"Note","summary":null,"inReplyTo":null,"published":"2018-10-13T18:43:33Z","url":"https://mastodon.social/@dansup/100889802384218791","attributedTo":"https://mastodon.social/users/dansup","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"sensitive":false,"atomUri":"https://mastodon.social/users/dansup/statuses/100889802384218791","inReplyToAtomUri":null,"conversation":"tag:mastodon.social,2018-10-13:objectId=59103420:objectType=Conversation","content":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>","contentMap":{"en":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>"},"attachment":[{"type":"Document","mediaType":"image/jpeg","url":"https://files.mastodon.social/media_attachments/files/007/110/573/original/96a196885a77c9a4.jpg","name":null}],"tag":[{"type":"Hashtag","href":"https://mastodon.social/tags/coffee","name":"#coffee"}]}}', true, 9); $this->mastodon = json_decode('{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791/activity","type":"Create","actor":"https://mastodon.social/users/dansup","published":"2018-10-13T18:43:33Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"object":{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791","type":"Note","summary":null,"inReplyTo":null,"published":"2018-10-13T18:43:33Z","url":"https://mastodon.social/@dansup/100889802384218791","attributedTo":"https://mastodon.social/users/dansup","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"sensitive":false,"atomUri":"https://mastodon.social/users/dansup/statuses/100889802384218791","inReplyToAtomUri":null,"conversation":"tag:mastodon.social,2018-10-13:objectId=59103420:objectType=Conversation","content":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>","contentMap":{"en":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>"},"attachment":[{"type":"Document","mediaType":"image/jpeg","url":"https://files.mastodon.social/media_attachments/files/007/110/573/original/96a196885a77c9a4.jpg","name":null}],"tag":[{"type":"Hashtag","href":"https://mastodon.social/tags/coffee","name":"#coffee"}]}}', true, 9);
@ -22,6 +28,12 @@ class NoteAttachmentTest extends TestCase
$this->invalidMime = json_decode('{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791/activity","type":"Create","actor":"https://mastodon.social/users/dansup","published":"2018-10-13T18:43:33Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"object":{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791","type":"Note","summary":null,"inReplyTo":null,"published":"2018-10-13T18:43:33Z","url":"https://mastodon.social/@dansup/100889802384218791","attributedTo":"https://mastodon.social/users/dansup","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"sensitive":false,"atomUri":"https://mastodon.social/users/dansup/statuses/100889802384218791","inReplyToAtomUri":null,"conversation":"tag:mastodon.social,2018-10-13:objectId=59103420:objectType=Conversation","content":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>","contentMap":{"en":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>"},"attachment":[{"type":"Document","mediaType":"image/webp","url":"https://files.mastodon.social/media_attachments/files/007/110/573/original/96a196885a77c9a4.jpg","name":null}],"tag":[{"type":"Hashtag","href":"https://mastodon.social/tags/coffee","name":"#coffee"}]}}', true, 9); $this->invalidMime = json_decode('{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791/activity","type":"Create","actor":"https://mastodon.social/users/dansup","published":"2018-10-13T18:43:33Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"object":{"id":"https://mastodon.social/users/dansup/statuses/100889802384218791","type":"Note","summary":null,"inReplyTo":null,"published":"2018-10-13T18:43:33Z","url":"https://mastodon.social/@dansup/100889802384218791","attributedTo":"https://mastodon.social/users/dansup","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mastodon.social/users/dansup/followers"],"sensitive":false,"atomUri":"https://mastodon.social/users/dansup/statuses/100889802384218791","inReplyToAtomUri":null,"conversation":"tag:mastodon.social,2018-10-13:objectId=59103420:objectType=Conversation","content":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>","contentMap":{"en":"<p>Good Morning! <a href=\"https://mastodon.social/tags/coffee\" class=\"mention hashtag\" rel=\"tag\">#<span>coffee</span></a></p>"},"attachment":[{"type":"Document","mediaType":"image/webp","url":"https://files.mastodon.social/media_attachments/files/007/110/573/original/96a196885a77c9a4.jpg","name":null}],"tag":[{"type":"Hashtag","href":"https://mastodon.social/tags/coffee","name":"#coffee"}]}}', true, 9);
} }
public function testPixelfed()
{
$valid = Helpers::verifyAttachments($this->pixelfed);
$this->assertTrue($valid);
}
public function testMastodon() public function testMastodon()
{ {
$valid = Helpers::verifyAttachments($this->mastodon); $valid = Helpers::verifyAttachments($this->mastodon);
@ -39,6 +51,5 @@ class NoteAttachmentTest extends TestCase
$valid = Helpers::verifyAttachments($this->invalidMime); $valid = Helpers::verifyAttachments($this->invalidMime);
$this->assertFalse($valid); $this->assertFalse($valid);
} }
} }

View file

@ -4,11 +4,11 @@ namespace Tests\Unit\ActivityPub;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class RemoteFollowTest extends TestCase class RemoteFollowTest extends TestCase
{ {
protected string $mastodon;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();

View file

@ -2,8 +2,8 @@
namespace Tests\Unit\ActivityPub; namespace Tests\Unit\ActivityPub;
use PHPUnit\Framework\TestCase;
use App\Util\ActivityPub\Validator\StoryValidator; use App\Util\ActivityPub\Validator\StoryValidator;
use PHPUnit\Framework\TestCase;
class StoryValidationTest extends TestCase class StoryValidationTest extends TestCase
{ {
@ -80,5 +80,4 @@ class StoryValidationTest extends TestCase
unset($activity['expiresAt']); unset($activity['expiresAt']);
$this->assertFalse(StoryValidator::validate($activity)); $this->assertFalse(StoryValidator::validate($activity));
} }
} }

View file

@ -2,19 +2,19 @@
namespace Tests\Unit\ActivityPub\Verb; namespace Tests\Unit\ActivityPub\Verb;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\ActivityPub\Validator\Accept; use App\Util\ActivityPub\Validator\Accept;
use Tests\TestCase;
class AcceptVerbTest extends TestCase class AcceptVerbTest extends TestCase
{ {
protected $validAccept; protected array $validAccept;
protected $invalidAccept; protected array $invalidAccept;
protected array $mastodonAccept;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->validAccept = [ $this->validAccept = [
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => 'https://www.w3.org/ns/activitystreams',
'id' => 'https://example.org/og/b3e4a40b-0b26-4c5a-9079-094bd633fab7', 'id' => 'https://example.org/og/b3e4a40b-0b26-4c5a-9079-094bd633fab7',
@ -27,6 +27,7 @@ class AcceptVerbTest extends TestCase
'object' => 'https://example.org/u/alice' 'object' => 'https://example.org/u/alice'
] ]
]; ];
$this->invalidAccept = [ $this->invalidAccept = [
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => 'https://www.w3.org/ns/activitystreams',
'id' => 'https://example.org/og/b3e4a40b-0b26-4c5a-9079-094bd633fab7', 'id' => 'https://example.org/og/b3e4a40b-0b26-4c5a-9079-094bd633fab7',
@ -39,40 +40,39 @@ class AcceptVerbTest extends TestCase
'object' => 'https://example.org/u/alice' 'object' => 'https://example.org/u/alice'
] ]
]; ];
$this->mastodonAccept = [ $this->mastodonAccept = [
"@context" => [ '@context' => [
"https://www.w3.org/ns/activitystreams", 'https://www.w3.org/ns/activitystreams',
"https://w3id.org/security/v1", 'https://w3id.org/security/v1',
[ [
"toot" => "https://joinmastodon.org/ns#", 'toot' => 'https://joinmastodon.org/ns#',
"sensitive" => "as:sensitive", 'sensitive' => 'as:sensitive',
"ostatus" => "https://ostatus.org#", 'ostatus' => 'https://ostatus.org#',
"movedTo" => "as:movedTo", 'movedTo' => 'as:movedTo',
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers", 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
"inReplyToAtomUri" => "ostatus:inReplyToAtomUri", 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
"conversation" => "ostatus:conversation", 'conversation' => 'ostatus:conversation',
"atomUri" => "ostatus:atomUri", 'atomUri' => 'ostatus:atomUri',
"Hashtag" => "as:Hashtag", 'Hashtag' => 'as:Hashtag',
"Emoji" => "toot:Emoji", 'Emoji' => 'toot:Emoji',
], ],
], ],
'type' => 'Accept',
"type" => "Accept", 'object' => [
'type' => 'Follow',
"object" => [ 'object' => 'https://mastodon.example.org/users/admin',
"type" => "Follow", 'id' => 'https://pixelfed.dev/users/dsup#follows/4',
"object" => "https://mastodon.example.org/users/admin", 'actor' => 'https://pixelfed.dev/users/dsup',
"id" => "https://pixelfed.dev/users/dsup#follows/4",
"actor" => "https://pixelfed.dev/users/dsup",
], ],
"nickname" => "dsup", 'nickname' => 'dsup',
"id" => "https://mastodon.example.org/users/admin#accepts/follows/4", 'id' => 'https://mastodon.example.org/users/admin#accepts/follows/4',
"actor" => "https://mastodon.example.org/users/admin", 'actor' => 'https://mastodon.example.org/users/admin',
"signature" => [ 'signature' => [
"type" => "RsaSignature2017", 'type' => 'RsaSignature2017',
"signatureValue" => "rBzK4Kqhd4g7HDS8WE5oRbWQb2R+HF/6awbUuMWhgru/xCODT0SJWSri0qWqEO4fPcpoUyz2d25cw6o+iy9wiozQb3hQNnu69AR+H5Mytc06+g10KCHexbGhbAEAw/7IzmeXELHUbaqeduaDIbdt1zw4RkwLXdqgQcGXTJ6ND1wM3WMHXQCK1m0flasIXFoBxpliPAGiElV8s0+Ltuh562GvflG3kB3WO+j+NaR0ZfG5G9N88xMj9UQlCKit5gpAE5p6syUsCU2WGBHywTumv73i3OVTIFfq+P9AdMsRuzw1r7zoKEsthW4aOzLQDi01ZjvdBz8zH6JnjDU7SMN/Ig==", 'signatureValue' => 'rBzK4Kqhd4g7HDS8WE5oRbWQb2R+HF/6awbUuMWhgru/xCODT0SJWSri0qWqEO4fPcpoUyz2d25cw6o+iy9wiozQb3hQNnu69AR+H5Mytc06+g10KCHexbGhbAEAw/7IzmeXELHUbaqeduaDIbdt1zw4RkwLXdqgQcGXTJ6ND1wM3WMHXQCK1m0flasIXFoBxpliPAGiElV8s0+Ltuh562GvflG3kB3WO+j+NaR0ZfG5G9N88xMj9UQlCKit5gpAE5p6syUsCU2WGBHywTumv73i3OVTIFfq+P9AdMsRuzw1r7zoKEsthW4aOzLQDi01ZjvdBz8zH6JnjDU7SMN/Ig==',
"creator" => "https://mastodon.example.org/users/admin#main-key", 'creator' => 'https://mastodon.example.org/users/admin#main-key',
"created" => "2018-02-17T14:36:41Z", 'created' => '2018-02-17T14:36:41Z',
], ],
]; ];
} }

View file

@ -2,165 +2,172 @@
namespace Tests\Unit\ActivityPub\Verb; namespace Tests\Unit\ActivityPub\Verb;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\ActivityPub\Validator\Announce; use App\Util\ActivityPub\Validator\Announce;
use Tests\TestCase;
class AnnounceTest extends TestCase class AnnounceTest extends TestCase
{ {
protected array $validAnnounce;
protected array $invalidAnnounce;
protected array $invalidDate;
protected array $contextMissing;
protected array $audienceMissing;
protected array $audienceMissing2;
protected array $invalidActor;
protected array $invalidActor2;
protected array $mastodonAnnounce;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->validAnnounce = [ $this->validAnnounce = [
"@context" => "https://www.w3.org/ns/activitystreams", '@context' => 'https://www.w3.org/ns/activitystreams',
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce", 'type' => 'Announce',
"actor" => "https://example.org/users/alice", 'actor' => 'https://example.org/users/alice',
"published" => "2018-12-31T23:59:59Z", 'published' => '2018-12-31T23:59:59Z',
"to" => [ 'to' => [
"https://www.w3.org/ns/activitystreams#Public" 'https://www.w3.org/ns/activitystreams#Public'
], ],
"cc" => [ 'cc' => [
"https://example.org/users/bob", 'https://example.org/users/bob',
"https://example.org/users/alice/followers" 'https://example.org/users/alice/followers'
], ],
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->invalidAnnounce = [ $this->invalidAnnounce = [
"@context" => "https://www.w3.org/ns/activitystreams", '@context' => 'https://www.w3.org/ns/activitystreams',
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce2", 'type' => 'Announce2',
"actor" => "https://example.org/users/alice", 'actor' => 'https://example.org/users/alice',
"published" => "2018-12-31T23:59:59Z", 'published' => '2018-12-31T23:59:59Z',
"to" => [ 'to' => [
"https://www.w3.org/ns/activitystreams#Public" 'https://www.w3.org/ns/activitystreams#Public'
], ],
"cc" => [ 'cc' => [
"https://example.org/users/bob", 'https://example.org/users/bob',
"https://example.org/users/alice/followers" 'https://example.org/users/alice/followers'
], ],
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->invalidDate = [ $this->invalidDate = [
"@context" => "https://www.w3.org/ns/activitystreams", '@context' => 'https://www.w3.org/ns/activitystreams',
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce", 'type' => 'Announce',
"actor" => "https://example.org/users/alice", 'actor' => 'https://example.org/users/alice',
"published" => "2018-12-31T23:59:59ZEZE", 'published' => '2018-12-31T23:59:59ZEZE',
"to" => [ 'to' => [
"https://www.w3.org/ns/activitystreams#Public" 'https://www.w3.org/ns/activitystreams#Public'
], ],
"cc" => [ 'cc' => [
"https://example.org/users/bob", 'https://example.org/users/bob',
"https://example.org/users/alice/followers" 'https://example.org/users/alice/followers'
], ],
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->contextMissing = [ $this->contextMissing = [
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce", 'type' => 'Announce',
"actor" => "https://example.org/users/alice", 'actor' => 'https://example.org/users/alice',
"published" => "2018-12-31T23:59:59Z", 'published' => '2018-12-31T23:59:59Z',
"to" => [ 'to' => [
"https://www.w3.org/ns/activitystreams#Public" 'https://www.w3.org/ns/activitystreams#Public'
], ],
"cc" => [ 'cc' => [
"https://example.org/users/bob", 'https://example.org/users/bob',
"https://example.org/users/alice/followers" 'https://example.org/users/alice/followers'
], ],
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->audienceMissing = [ $this->audienceMissing = [
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce", 'type' => 'Announce',
"actor" => "https://example.org/users/alice", 'actor' => 'https://example.org/users/alice',
"published" => "2018-12-31T23:59:59Z", 'published' => '2018-12-31T23:59:59Z',
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->audienceMissing2 = [ $this->audienceMissing2 = [
"@context" => "https://www.w3.org/ns/activitystreams", '@context' => 'https://www.w3.org/ns/activitystreams',
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce", 'type' => 'Announce',
"actor" => "https://example.org/users/alice", 'actor' => 'https://example.org/users/alice',
"published" => "2018-12-31T23:59:59Z", 'published' => '2018-12-31T23:59:59Z',
"to" => null, 'to' => null,
"cc" => null, 'cc' => null,
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->invalidActor = [ $this->invalidActor = [
"@context" => "https://www.w3.org/ns/activitystreams", '@context' => 'https://www.w3.org/ns/activitystreams',
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce", 'type' => 'Announce',
"actor" => "10000", 'actor' => '10000',
"published" => "2018-12-31T23:59:59Z", 'published' => '2018-12-31T23:59:59Z',
"to" => [ 'to' => [
"https://www.w3.org/ns/activitystreams#Public" 'https://www.w3.org/ns/activitystreams#Public'
], ],
"cc" => [ 'cc' => [
"https://example.org/users/bob", 'https://example.org/users/bob',
"https://example.org/users/alice/followers" 'https://example.org/users/alice/followers'
], ],
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->invalidActor2 = [ $this->invalidActor2 = [
"@context" => "https://www.w3.org/ns/activitystreams", '@context' => 'https://www.w3.org/ns/activitystreams',
"id" => "https://example.org/users/alice/statuses/100000000000001/activity", 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
"type" => "Announce", 'type' => 'Announce',
"published" => "2018-12-31T23:59:59Z", 'published' => '2018-12-31T23:59:59Z',
"to" => [ 'to' => [
"https://www.w3.org/ns/activitystreams#Public" 'https://www.w3.org/ns/activitystreams#Public'
], ],
"cc" => [ 'cc' => [
"https://example.org/users/bob", 'https://example.org/users/bob',
"https://example.org/users/alice/followers" 'https://example.org/users/alice/followers'
], ],
"object" => "https://example.org/p/bob/100000000000000", 'object' => 'https://example.org/p/bob/100000000000000',
]; ];
$this->mastodonAnnounce = [ $this->mastodonAnnounce = [
"type" => "Announce", 'type' => 'Announce',
"to" => [ 'to' => [
"https://www.w3.org/ns/activitystreams#Public", 'https://www.w3.org/ns/activitystreams#Public',
], ],
"signature" => [ 'signature' => [
"type" => "RsaSignature2017", 'type' => 'RsaSignature2017',
"signatureValue" => "T95DRE0eAligvMuRMkQA01lsoz2PKi4XXF+cyZ0BqbrO12p751TEWTyyRn5a+HH0e4kc77EUhQVXwMq80WAYDzHKVUTf2XBJPBa68vl0j6RXw3+HK4ef5hR4KWFNBU34yePS7S1fEmc1mTG4Yx926wtmZwDpEMTp1CXOeVEjCYzmdyHpepPPH2ZZettiacmPRSqBLPGWZoot7kH/SioIdnrMGY0I7b+rqkIdnnEcdhu9N1BKPEO9Sr+KmxgAUiidmNZlbBXX6gCxp8BiIdH4ABsIcwoDcGNkM5EmWunGW31LVjsEQXhH5c1Wly0ugYYPCg/0eHLNBOhKkY/teSM8Lg==", 'signatureValue' => 'T95DRE0eAligvMuRMkQA01lsoz2PKi4XXF+cyZ0BqbrO12p751TEWTyyRn5a+HH0e4kc77EUhQVXwMq80WAYDzHKVUTf2XBJPBa68vl0j6RXw3+HK4ef5hR4KWFNBU34yePS7S1fEmc1mTG4Yx926wtmZwDpEMTp1CXOeVEjCYzmdyHpepPPH2ZZettiacmPRSqBLPGWZoot7kH/SioIdnrMGY0I7b+rqkIdnnEcdhu9N1BKPEO9Sr+KmxgAUiidmNZlbBXX6gCxp8BiIdH4ABsIcwoDcGNkM5EmWunGW31LVjsEQXhH5c1Wly0ugYYPCg/0eHLNBOhKkY/teSM8Lg==',
"creator" => "https://mastodon.example.org/users/admin#main-key", 'creator' => 'https://mastodon.example.org/users/admin#main-key',
"created" => "2018-02-17T19:39:15Z", 'created' => '2018-02-17T19:39:15Z',
], ],
"published" => "2018-02-17T19:39:15Z", 'published' => '2018-02-17T19:39:15Z',
"object" => "https://mastodon.example.org/@admin/99541947525187367", 'object' => 'https://mastodon.example.org/@admin/99541947525187367',
"id" => "https://mastodon.example.org/users/admin/statuses/99542391527669785/activity", 'id' => 'https://mastodon.example.org/users/admin/statuses/99542391527669785/activity',
"cc" => [ 'cc' => [
"https://mastodon.example.org/users/admin", 'https://mastodon.example.org/users/admin',
"https://mastodon.example.org/users/admin/followers", 'https://mastodon.example.org/users/admin/followers',
], ],
"atomUri" => "https://mastodon.example.org/users/admin/statuses/99542391527669785/activity", 'atomUri' => 'https://mastodon.example.org/users/admin/statuses/99542391527669785/activity',
"actor" => "https://mastodon.example.org/users/admin", 'actor' => 'https://mastodon.example.org/users/admin',
"@context" => [ '@context' => [
"https://www.w3.org/ns/activitystreams", 'https://www.w3.org/ns/activitystreams',
"https://w3id.org/security/v1", 'https://w3id.org/security/v1',
[ [
"toot" => "https://joinmastodon.org/ns#", 'toot' => 'https://joinmastodon.org/ns#',
"sensitive" => "as:sensitive", 'sensitive' => 'as:sensitive',
"ostatus" => "https://ostatus.org#", 'ostatus' => 'https://ostatus.org#',
"movedTo" => "as:movedTo", 'movedTo' => 'as:movedTo',
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers", 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
"inReplyToAtomUri" => "ostatus:inReplyToAtomUri", 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
"conversation" => "ostatus:conversation", 'conversation' => 'ostatus:conversation',
"atomUri" => "ostatus:atomUri", 'atomUri' => 'ostatus:atomUri',
"Hashtag" => "as:Hashtag", 'Hashtag' => 'as:Hashtag',
"Emoji" => "toot:Emoji", 'Emoji' => 'toot:Emoji',
], ],
], ],
]; ];

View file

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

View file

@ -2,44 +2,43 @@
namespace Tests\Unit\ActivityPub\Verb; namespace Tests\Unit\ActivityPub\Verb;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\ActivityPub\Validator\Like; use App\Util\ActivityPub\Validator\Like;
use Tests\TestCase;
class LikeTest extends TestCase class LikeTest extends TestCase
{ {
protected array $basicLike;
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->basicLike = [ $this->basicLike = [
"type" => "Like", 'type' => 'Like',
"signature" => [ 'signature' => [
"type" => "RsaSignature2017", 'type' => 'RsaSignature2017',
"signatureValue" => "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==", 'signatureValue' => 'fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==',
"creator" => "http://mastodon.example.org/users/admin#main-key", 'creator' => 'http://mastodon.example.org/users/admin#main-key',
"created" => "2018-02-17T18:57:49Z", 'created' => '2018-02-17T18:57:49Z',
], ],
"object" => "http://pixelfed.dev/p/1", 'object' => 'http://pixelfed.dev/p/1',
"nickname" => "dsup", 'nickname' => 'dsup',
"id" => "http://mastodon.example.org/users/admin#likes/2", 'id' => 'http://mastodon.example.org/users/admin#likes/2',
"actor" => "http://mastodon.example.org/users/admin", 'actor' => 'http://mastodon.example.org/users/admin',
"@context" => [ '@context' => [
"https://www.w3.org/ns/activitystreams", 'https://www.w3.org/ns/activitystreams',
"https://w3id.org/security/v1", 'https://w3id.org/security/v1',
[ [
"toot" => "http://joinmastodon.org/ns#", 'toot' => 'http://joinmastodon.org/ns#',
"sensitive" => "as:sensitive", 'sensitive' => 'as:sensitive',
"ostatus" => "http://ostatus.org#", 'ostatus' => 'http://ostatus.org#',
"movedTo" => "as:movedTo", 'movedTo' => 'as:movedTo',
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers", 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
"inReplyToAtomUri" => "ostatus:inReplyToAtomUri", 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
"conversation" => "ostatus:conversation", 'conversation' => 'ostatus:conversation',
"atomUri" => "ostatus:atomUri", 'atomUri' => 'ostatus:atomUri',
"Hashtag" => "as:Hashtag", 'Hashtag' => 'as:Hashtag',
"Emoji" => "toot:Emoji", 'Emoji' => 'toot:Emoji',
], ],
], ],
]; ];

View file

@ -2,16 +2,13 @@
namespace Tests\Unit\ActivityPub\Verb; namespace Tests\Unit\ActivityPub\Verb;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\ActivityPub\Validator\UndoFollow; use App\Util\ActivityPub\Validator\UndoFollow;
use Tests\TestCase;
class UndoFollowTest extends TestCase class UndoFollowTest extends TestCase
{ {
protected array $validUndo;
protected $validUndo; protected array $invalidUndo;
protected $invalidUndo;
public function setUp(): void public function setUp(): void
{ {
@ -42,5 +39,4 @@ class UndoFollowTest extends TestCase
{ {
$this->assertFalse(UndoFollow::validate($this->invalidUndo)); $this->assertFalse(UndoFollow::validate($this->invalidUndo));
} }
} }

View file

@ -2,8 +2,8 @@
namespace Tests\Unit; namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use App\Util\Lexer\Bearcap; use App\Util\Lexer\Bearcap;
use PHPUnit\Framework\TestCase;
class BearcapTest extends TestCase class BearcapTest extends TestCase
{ {
@ -12,8 +12,8 @@ class BearcapTest extends TestCase
{ {
$str = 'bear:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&u=https://pixelfed.test/stories/admin/337892163734081536'; $str = 'bear:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&u=https://pixelfed.test/stories/admin/337892163734081536';
$expected = [ $expected = [
"token" => "LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2", 'token' => 'LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2',
"url" => "https://pixelfed.test/stories/admin/337892163734081536", 'url' => 'https://pixelfed.test/stories/admin/337892163734081536',
]; ];
$actual = Bearcap::decode($str); $actual = Bearcap::decode($str);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);

View file

@ -2,6 +2,7 @@
namespace Tests\Unit; namespace Tests\Unit;
use phpseclib\Crypt\RSA;
use Tests\TestCase; use Tests\TestCase;
class CryptoTest extends TestCase class CryptoTest extends TestCase
@ -18,7 +19,7 @@ class CryptoTest extends TestCase
public function testRSASigning() public function testRSASigning()
{ {
$rsa = new \phpseclib\Crypt\RSA(); $rsa = new RSA();
extract($rsa->createKey()); extract($rsa->createKey());
$rsa->loadKey($privatekey); $rsa->loadKey($privatekey);
$plaintext = 'pixelfed rsa test'; $plaintext = 'pixelfed rsa test';

View file

@ -1,33 +0,0 @@
<?php
namespace Tests\Unit;
use Carbon\Carbon;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class DateTimeTest extends TestCase
{
/** @test */
public function mastodonTimestamp()
{
$ts = Carbon::createFromFormat(\DateTime::ISO8601, '2019-09-16T02:41:57Z');
$this->assertEquals(9, $ts->month);
$this->assertEquals(16, $ts->day);
$this->assertEquals(2019, $ts->year);
$this->assertEquals(2, $ts->hour);
$this->assertEquals(41, $ts->minute);
}
/** @test */
public function p3kTimestamp()
{
$ts = Carbon::createFromFormat(\DateTime::ISO8601, '2019-09-16T08:40:55+10:00');
$this->assertEquals(9, $ts->month);
$this->assertEquals(16, $ts->day);
$this->assertEquals(2019, $ts->year);
$this->assertEquals(8, $ts->hour);
$this->assertEquals(40, $ts->minute);
}
}

View file

@ -1,18 +0,0 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}

View file

@ -2,10 +2,8 @@
namespace Tests\Unit\Lexer; namespace Tests\Unit\Lexer;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\Lexer\RestrictedNames; use App\Util\Lexer\RestrictedNames;
use Tests\TestCase;
class RestrictedNameTest extends TestCase class RestrictedNameTest extends TestCase
{ {

View file

@ -2,12 +2,10 @@
namespace Tests\Unit\Lexer; namespace Tests\Unit\Lexer;
use Tests\TestCase; use App\Status;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Util\Lexer\Autolink; use App\Util\Lexer\Autolink;
use App\Util\Lexer\Extractor; use App\Util\Lexer\Extractor;
use App\Status; use Tests\TestCase;
class StatusLexerTest extends TestCase class StatusLexerTest extends TestCase
{ {
@ -18,7 +16,7 @@ class StatusLexerTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->status = "@pixelfed hi, really like the website! #píxelfed"; $this->status = '@pixelfed hi, really like the website! #píxelfed';
$this->entities = Extractor::create()->extract($this->status); $this->entities = Extractor::create()->extract($this->status);
$this->autolink = Autolink::create()->autolink($this->status); $this->autolink = Autolink::create()->autolink($this->status);
} }
@ -26,28 +24,28 @@ class StatusLexerTest extends TestCase
public function testLexerExtractor() public function testLexerExtractor()
{ {
$expected = [ $expected = [
"hashtags" => [ 'hashtags' => [
"píxelfed", 'píxelfed',
], ],
"urls" => [], 'urls' => [],
"mentions" => [ 'mentions' => [
"pixelfed", 'pixelfed',
], ],
"replyto" => "pixelfed", 'replyto' => 'pixelfed',
"hashtags_with_indices" => [ 'hashtags_with_indices' => [
[ [
"hashtag" => "píxelfed", 'hashtag' => 'píxelfed',
"indices" => [ 'indices' => [
39, 39,
48, 48,
], ],
], ],
], ],
"urls_with_indices" => [], 'urls_with_indices' => [],
"mentions_with_indices" => [ 'mentions_with_indices' => [
[ [
"screen_name" => "pixelfed", 'screen_name' => 'pixelfed',
"indices" => [ 'indices' => [
0, 0,
9, 9,
], ],
@ -64,40 +62,40 @@ class StatusLexerTest extends TestCase
$this->assertEquals($this->autolink, $expected); $this->assertEquals($this->autolink, $expected);
} }
/** @test **/ /** @test * */
public function remoteMention() public function remoteMention()
{ {
$expected = [ $expected = [
"hashtags" => [ 'hashtags' => [
"dansup", 'dansup',
], ],
"urls" => [], 'urls' => [],
"mentions" => [ 'mentions' => [
"@dansup@mstdn.io", '@dansup@mstdn.io',
"test", 'test',
], ],
"replyto" => null, 'replyto' => null,
"hashtags_with_indices" => [ 'hashtags_with_indices' => [
[ [
"hashtag" => "dansup", 'hashtag' => 'dansup',
"indices" => [ 'indices' => [
0, 0,
7, 7,
], ],
], ],
], ],
"urls_with_indices" => [], 'urls_with_indices' => [],
"mentions_with_indices" => [ 'mentions_with_indices' => [
[ [
"screen_name" => "@dansup@mstdn.io", 'screen_name' => '@dansup@mstdn.io',
"indices" => [ 'indices' => [
8, 8,
24, 24,
], ],
], ],
[ [
"screen_name" => "test", 'screen_name' => 'test',
"indices" => [ 'indices' => [
25, 25,
30, 30,
], ],
@ -108,7 +106,7 @@ class StatusLexerTest extends TestCase
$this->assertEquals($actual, $expected); $this->assertEquals($actual, $expected);
} }
/** @test **/ /** @test * */
public function mentionLimit() public function mentionLimit()
{ {
$text = '@test1 @test @test2 @test3 @test4 @test5 test post'; $text = '@test1 @test @test2 @test3 @test4 @test5 test post';
@ -118,7 +116,7 @@ class StatusLexerTest extends TestCase
$this->assertEquals($count, Status::MAX_MENTIONS); $this->assertEquals($count, Status::MAX_MENTIONS);
} }
/** @test **/ /** @test * */
public function hashtagLimit() public function hashtagLimit()
{ {
$text = '#hashtag0 #hashtag1 #hashtag2 #hashtag3 #hashtag4 #hashtag5 #hashtag6 #hashtag7 #hashtag8 #hashtag9 #hashtag10 #hashtag11 #hashtag12 #hashtag13 #hashtag14 #hashtag15 #hashtag16 #hashtag17 #hashtag18 #hashtag19 #hashtag20 #hashtag21 #hashtag22 #hashtag23 #hashtag24 #hashtag25 #hashtag26 #hashtag27 #hashtag28 #hashtag29 #hashtag30 #hashtag31'; $text = '#hashtag0 #hashtag1 #hashtag2 #hashtag3 #hashtag4 #hashtag5 #hashtag6 #hashtag7 #hashtag8 #hashtag9 #hashtag10 #hashtag11 #hashtag12 #hashtag13 #hashtag14 #hashtag15 #hashtag16 #hashtag17 #hashtag18 #hashtag19 #hashtag20 #hashtag21 #hashtag22 #hashtag23 #hashtag24 #hashtag25 #hashtag26 #hashtag27 #hashtag28 #hashtag29 #hashtag30 #hashtag31';
@ -129,7 +127,7 @@ class StatusLexerTest extends TestCase
} }
/** @test **/ /** @test * */
public function linkLimit() public function linkLimit()
{ {
$text = 'https://example.org https://example.net https://example.com'; $text = 'https://example.org https://example.net https://example.com';

View file

@ -2,14 +2,13 @@
namespace Tests\Unit\Lexer; namespace Tests\Unit\Lexer;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use App\Util\Lexer\Autolink; use App\Util\Lexer\Autolink;
use App\Util\Lexer\Extractor; use App\Util\Lexer\Extractor;
use Tests\TestCase;
class UsernameTest extends TestCase class UsernameTest extends TestCase
{ {
/** @test **/ /** @test * */
public function genericUsername() public function genericUsername()
{ {
$username = '@dansup'; $username = '@dansup';
@ -17,18 +16,18 @@ class UsernameTest extends TestCase
$autolink = Autolink::create()->autolink($username); $autolink = Autolink::create()->autolink($username);
$expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup" rel="external nofollow noopener" target="_blank">@dansup</a>'; $expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup" rel="external nofollow noopener" target="_blank">@dansup</a>';
$expectedEntity = [ $expectedEntity = [
"hashtags" => [], 'hashtags' => [],
"urls" => [], 'urls' => [],
"mentions" => [ 'mentions' => [
"dansup", 'dansup',
], ],
"replyto" => "dansup", 'replyto' => 'dansup',
"hashtags_with_indices" => [], 'hashtags_with_indices' => [],
"urls_with_indices" => [], 'urls_with_indices' => [],
"mentions_with_indices" => [ 'mentions_with_indices' => [
[ [
"screen_name" => "dansup", 'screen_name' => 'dansup',
"indices" => [ 'indices' => [
0, 0,
7, 7,
], ],
@ -39,7 +38,7 @@ class UsernameTest extends TestCase
$this->assertEquals($expectedEntity, $entities); $this->assertEquals($expectedEntity, $entities);
} }
/** @test **/ /** @test * */
public function usernameWithPeriod() public function usernameWithPeriod()
{ {
$username = '@dansup.two'; $username = '@dansup.two';
@ -47,18 +46,18 @@ class UsernameTest extends TestCase
$entities = Extractor::create()->extract($username); $entities = Extractor::create()->extract($username);
$expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup.two" rel="external nofollow noopener" target="_blank">@dansup.two</a>'; $expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup.two" rel="external nofollow noopener" target="_blank">@dansup.two</a>';
$expectedEntity = [ $expectedEntity = [
"hashtags" => [], 'hashtags' => [],
"urls" => [], 'urls' => [],
"mentions" => [ 'mentions' => [
"dansup.two", 'dansup.two',
], ],
"replyto" => "dansup.two", 'replyto' => 'dansup.two',
"hashtags_with_indices" => [], 'hashtags_with_indices' => [],
"urls_with_indices" => [], 'urls_with_indices' => [],
"mentions_with_indices" => [ 'mentions_with_indices' => [
[ [
"screen_name" => "dansup.two", 'screen_name' => 'dansup.two',
"indices" => [ 'indices' => [
0, 0,
11, 11,
], ],
@ -69,7 +68,7 @@ class UsernameTest extends TestCase
$this->assertEquals($expectedEntity, $entities); $this->assertEquals($expectedEntity, $entities);
} }
/** @test **/ /** @test * */
public function usernameWithDash() public function usernameWithDash()
{ {
$username = '@dansup-too'; $username = '@dansup-too';
@ -77,18 +76,18 @@ class UsernameTest extends TestCase
$entities = Extractor::create()->extract($username); $entities = Extractor::create()->extract($username);
$expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup-too" rel="external nofollow noopener" target="_blank">@dansup-too</a>'; $expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup-too" rel="external nofollow noopener" target="_blank">@dansup-too</a>';
$expectedEntity = [ $expectedEntity = [
"hashtags" => [], 'hashtags' => [],
"urls" => [], 'urls' => [],
"mentions" => [ 'mentions' => [
"dansup-too", 'dansup-too',
], ],
"replyto" => "dansup-too", 'replyto' => 'dansup-too',
"hashtags_with_indices" => [], 'hashtags_with_indices' => [],
"urls_with_indices" => [], 'urls_with_indices' => [],
"mentions_with_indices" => [ 'mentions_with_indices' => [
[ [
"screen_name" => "dansup-too", 'screen_name' => 'dansup-too',
"indices" => [ 'indices' => [
0, 0,
11, 11,
], ],
@ -99,7 +98,7 @@ class UsernameTest extends TestCase
$this->assertEquals($expectedEntity, $entities); $this->assertEquals($expectedEntity, $entities);
} }
/** @test **/ /** @test * */
public function usernameWithUnderscore() public function usernameWithUnderscore()
{ {
$username = '@dansup_too'; $username = '@dansup_too';
@ -107,18 +106,18 @@ class UsernameTest extends TestCase
$entities = Extractor::create()->extract($username); $entities = Extractor::create()->extract($username);
$expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup_too" rel="external nofollow noopener" target="_blank">@dansup_too</a>'; $expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/dansup_too" rel="external nofollow noopener" target="_blank">@dansup_too</a>';
$expectedEntity = [ $expectedEntity = [
"hashtags" => [], 'hashtags' => [],
"urls" => [], 'urls' => [],
"mentions" => [ 'mentions' => [
"dansup_too", 'dansup_too',
], ],
"replyto" => "dansup_too", 'replyto' => 'dansup_too',
"hashtags_with_indices" => [], 'hashtags_with_indices' => [],
"urls_with_indices" => [], 'urls_with_indices' => [],
"mentions_with_indices" => [ 'mentions_with_indices' => [
[ [
"screen_name" => "dansup_too", 'screen_name' => 'dansup_too',
"indices" => [ 'indices' => [
0, 0,
11, 11,
], ],
@ -129,7 +128,7 @@ class UsernameTest extends TestCase
$this->assertEquals($expectedEntity, $entities); $this->assertEquals($expectedEntity, $entities);
} }
/** @test **/ /** @test * */
public function multipleMentions() public function multipleMentions()
{ {
$text = 'hello @dansup and @pixelfed.team from @username_underscore'; $text = 'hello @dansup and @pixelfed.team from @username_underscore';
@ -137,34 +136,34 @@ class UsernameTest extends TestCase
$entities = Extractor::create()->extract($text); $entities = Extractor::create()->extract($text);
$expectedAutolink = 'hello <a class="u-url mention" href="https://pixelfed.dev/dansup" rel="external nofollow noopener" target="_blank">@dansup</a> and <a class="u-url mention" href="https://pixelfed.dev/pixelfed.team" rel="external nofollow noopener" target="_blank">@pixelfed.team</a> from <a class="u-url mention" href="https://pixelfed.dev/username_underscore" rel="external nofollow noopener" target="_blank">@username_underscore</a>'; $expectedAutolink = 'hello <a class="u-url mention" href="https://pixelfed.dev/dansup" rel="external nofollow noopener" target="_blank">@dansup</a> and <a class="u-url mention" href="https://pixelfed.dev/pixelfed.team" rel="external nofollow noopener" target="_blank">@pixelfed.team</a> from <a class="u-url mention" href="https://pixelfed.dev/username_underscore" rel="external nofollow noopener" target="_blank">@username_underscore</a>';
$expectedEntity = [ $expectedEntity = [
"hashtags" => [], 'hashtags' => [],
"urls" => [], 'urls' => [],
"mentions" => [ 'mentions' => [
"dansup", 'dansup',
"pixelfed.team", 'pixelfed.team',
"username_underscore", 'username_underscore',
], ],
"replyto" => null, 'replyto' => null,
"hashtags_with_indices" => [], 'hashtags_with_indices' => [],
"urls_with_indices" => [], 'urls_with_indices' => [],
"mentions_with_indices" => [ 'mentions_with_indices' => [
[ [
"screen_name" => "dansup", 'screen_name' => 'dansup',
"indices" => [ 'indices' => [
6, 6,
13, 13,
], ],
], ],
[ [
"screen_name" => "pixelfed.team", 'screen_name' => 'pixelfed.team',
"indices" => [ 'indices' => [
18, 18,
32, 32,
], ],
], ],
[ [
"screen_name" => "username_underscore", 'screen_name' => 'username_underscore',
"indices" => [ 'indices' => [
38, 38,
58, 58,
], ],

View file

@ -4,8 +4,6 @@ namespace Tests\Unit;
use Purify; use Purify;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class PurifierTest extends TestCase class PurifierTest extends TestCase
{ {

View file

@ -1,17 +0,0 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use App\Services\SnowflakeService;
class SnowflakeTest extends TestCase
{
/** @test */
public function snowflakeTest()
{
$expected = 266077397319815168;
$actual = 266077397319815168;
$this->assertEquals($expected, $actual);
}
}

View file

@ -2,8 +2,8 @@
namespace Tests\Unit; namespace Tests\Unit;
use Tests\TestCase;
use App\Util\Lexer\Nickname; use App\Util\Lexer\Nickname;
use Tests\TestCase;
class WebfingerTest extends TestCase class WebfingerTest extends TestCase
{ {
@ -11,36 +11,36 @@ class WebfingerTest extends TestCase
public function webfingerTest() public function webfingerTest()
{ {
$expected = [ $expected = [
"domain" => "pixelfed.org", 'domain' => 'pixelfed.org',
"username" => "dansup", 'username' => 'dansup',
]; ];
$actual = Nickname::normalizeProfileUrl('acct:dansup@pixelfed.org'); $actual = Nickname::normalizeProfileUrl('acct:dansup@pixelfed.org');
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
$expected = [ $expected = [
"domain" => "pixelfed.org", 'domain' => 'pixelfed.org',
"username" => "dansup_", 'username' => 'dansup_',
]; ];
$actual = Nickname::normalizeProfileUrl('acct:dansup@pixelfed.org'); $actual = Nickname::normalizeProfileUrl('acct:dansup@pixelfed.org');
$this->assertNotEquals($expected, $actual); $this->assertNotEquals($expected, $actual);
$expected = [ $expected = [
"domain" => "pixelfed.org", 'domain' => 'pixelfed.org',
"username" => "dansup", 'username' => 'dansup',
]; ];
$actual = Nickname::normalizeProfileUrl('acct:@dansup@pixelfed.org'); $actual = Nickname::normalizeProfileUrl('acct:@dansup@pixelfed.org');
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
$expected = [ $expected = [
"domain" => "pixelfed.org", 'domain' => 'pixelfed.org',
"username" => "dansup", 'username' => 'dansup',
]; ];
$actual = Nickname::normalizeProfileUrl('dansup@pixelfed.org'); $actual = Nickname::normalizeProfileUrl('dansup@pixelfed.org');
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
$expected = [ $expected = [
"domain" => "pixelfed.org", 'domain' => 'pixelfed.org',
"username" => "dansup", 'username' => 'dansup',
]; ];
$actual = Nickname::normalizeProfileUrl('@dansup@pixelfed.org'); $actual = Nickname::normalizeProfileUrl('@dansup@pixelfed.org');
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);