From 5d91fb2051038c6b5c315e83dcd27de925ce8b56 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 28 Nov 2018 22:11:07 -0700 Subject: [PATCH 1/5] Update LoginTest --- tests/Feature/LoginTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index c2e54df94..4972c87cd 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -25,7 +25,10 @@ class LoginTest extends TestCase $response->assertSuccessful() ->assertSee('Register a new account'); } else { - $this->assertTrue(true); + $response = $this->get('register'); + + $response->assertSuccessful() + ->assertSee('Registration is closed'); } } } \ No newline at end of file From e0a5eadaeb1a0e077af17e1967f0480ed6c99cff Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 28 Nov 2018 22:20:59 -0700 Subject: [PATCH 2/5] Add AP Note test --- tests/Unit/ActivityPub/NoteAttachmentTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/Unit/ActivityPub/NoteAttachmentTest.php diff --git a/tests/Unit/ActivityPub/NoteAttachmentTest.php b/tests/Unit/ActivityPub/NoteAttachmentTest.php new file mode 100644 index 000000000..7a715a285 --- /dev/null +++ b/tests/Unit/ActivityPub/NoteAttachmentTest.php @@ -0,0 +1,50 @@ +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. #dangerZone","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","like_count":6,"likes":["https://crazynoisybizarre.town/users/jusdepatate","https://social.chinwag.org/users/rolaveric","https://norden.social/users/ReneHenrich","https://mastodon.ketchupma.io/users/KazukyAkayashi","https://chaos.social/users/lutoma","https://playvicious.social/users/jalcine"],"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":"

Good Morning! #coffee

","contentMap":{"en":"

Good Morning! #coffee

"},"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->invalidType = 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":"

Good Morning! #coffee

","contentMap":{"en":"

Good Morning! #coffee

"},"attachment":[{"type":"NotDocument","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->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":"

Good Morning! #coffee

","contentMap":{"en":"

Good Morning! #coffee

"},"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 testPleroma() + { + $valid = Helpers::verifyAttachments($this->pleroma); + $this->assertTrue($valid); + } + + public function testMastodon() + { + $valid = Helpers::verifyAttachments($this->mastodon); + $this->assertTrue($valid); + } + + public function testInvalidAttachmentType() + { + $valid = Helpers::verifyAttachments($this->invalidType); + $this->assertFalse($valid); + } + + public function testInvalidMimeType() + { + $valid = Helpers::verifyAttachments($this->invalidMime); + $this->assertFalse($valid); + } + +} + From 54f996b8538884f481a860e67c530a71d5da563d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 28 Nov 2018 22:46:48 -0700 Subject: [PATCH 3/5] Add testing .env file --- .env.testing | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .env.testing diff --git a/.env.testing b/.env.testing new file mode 100644 index 000000000..f7dcfe55e --- /dev/null +++ b/.env.testing @@ -0,0 +1,55 @@ +APP_NAME="PixelFed Test" +APP_ENV=local +APP_KEY=base64:lwX95GbNWX3XsucdMe0XwtOKECta3h/B+p9NbH2jd0E= +APP_DEBUG=true +APP_URL=https://pixelfed.dev + +ADMIN_DOMAIN="pixelfed.dev" +APP_DOMAIN="pixelfed.dev" + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE= +DB_USERNAME= +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=redis +SESSION_DRIVER=redis +SESSION_LIFETIME=120 +QUEUE_DRIVER=redis + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=log +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS="pixelfed@example.com" +MAIL_FROM_NAME="Pixelfed" + +SESSION_DOMAIN="${APP_DOMAIN}" +SESSION_SECURE_COOKIE=true +API_BASE="/api/1/" +API_SEARCH="/api/search" + +OPEN_REGISTRATION=true +RECAPTCHA_ENABLED=false +ENFORCE_EMAIL_VERIFICATION=true + +MAX_PHOTO_SIZE=15000 +MAX_CAPTION_LENGTH=150 +MAX_ALBUM_LENGTH=4 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" +MIX_APP_URL="${APP_URL}" +MIX_API_BASE="${API_BASE}" +MIX_API_SEARCH="${API_SEARCH}" From 127990e95fd7f048fd108e95b729b2abee7cbe44 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 28 Nov 2018 22:47:39 -0700 Subject: [PATCH 4/5] Add Status Lexer Test --- tests/Unit/Lexer/StatusLexerTest.php | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/Unit/Lexer/StatusLexerTest.php diff --git a/tests/Unit/Lexer/StatusLexerTest.php b/tests/Unit/Lexer/StatusLexerTest.php new file mode 100644 index 000000000..fbfa15cb7 --- /dev/null +++ b/tests/Unit/Lexer/StatusLexerTest.php @@ -0,0 +1,66 @@ +status = "@pixelfed hi, really like the website! #píxelfed"; + $this->entities = Extractor::create()->extract($this->status); + $this->autolink = Autolink::create()->autolink($this->status); + } + + public function testLexerExtractor() + { + $expected = [ + "hashtags" => [ + "píxelfed", + ], + "urls" => [], + "mentions" => [ + "pixelfed", + ], + "replyto" => "pixelfed", + "hashtags_with_indices" => [ + [ + "hashtag" => "píxelfed", + "indices" => [ + 39, + 48, + ], + ], + ], + "urls_with_indices" => [], + "mentions_with_indices" => [ + [ + "screen_name" => "pixelfed", + "indices" => [ + 0, + 9, + ], + ] + ] + ]; + + $this->assertEquals($this->entities, $expected); + } + + public function testAutolink() + { + $expected = '@pixelfed hi, really like the website! #píxelfed'; + + $this->assertEquals($this->autolink, $expected); + } +} From 5b4d76a32e9ae192c8ea7a28343dcc9ebc3ae45a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 28 Nov 2018 22:53:38 -0700 Subject: [PATCH 5/5] Add AudienceScope test --- tests/Unit/ActivityPub/AudienceScopeTest.php | 86 ++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/Unit/ActivityPub/AudienceScopeTest.php diff --git a/tests/Unit/ActivityPub/AudienceScopeTest.php b/tests/Unit/ActivityPub/AudienceScopeTest.php new file mode 100644 index 000000000..c7287fa1d --- /dev/null +++ b/tests/Unit/ActivityPub/AudienceScopeTest.php @@ -0,0 +1,86 @@ +invalid = [ + 'id' => 'test', + 'type' => 'Announce', + 'actor' => null, + 'published' => '', + 'to' => ['test'], + 'cc' => 'test', + 'object' => 'test' + ]; + + $this->mastodon = json_decode('{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":{"@id":"as:movedTo","@type":"@id"},"Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"featured":{"@id":"toot:featured","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}],"id":"https://mastodon.social/users/dansup/statuses/100784657480587830/activity","type":"Announce","actor":"https://mastodon.social/users/dansup","published":"2018-09-25T05:03:49Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://pleroma.site/users/pixeldev","https://mastodon.social/users/dansup/followers"],"object":"https://pleroma.site/objects/68b5c876-f52b-4819-8d81-de6839d73fbc","atomUri":"https://mastodon.social/users/dansup/statuses/100784657480587830/activity"}', true); + + $this->pleroma = json_decode('{"@context":"https://www.w3.org/ns/activitystreams","actor":"https://pleroma.site/users/pixeldev","cc":["https://www.w3.org/ns/activitystreams#Public"],"context":"tag:mastodon.social,2018-10-14:objectId=59146153:objectType=Conversation","context_id":12325955,"id":"https://pleroma.site/activities/db2273eb-d504-4e3a-8f74-c343d069755a","object":"https://mastodon.social/users/dansup/statuses/100891324792793720","published":"2018-10-14T01:22:18.554227Z","to":["https://pleroma.site/users/pixeldev/followers","https://mastodon.social/users/dansup"],"type":"Announce"}', true); + } + + public function testBasicValidation() + { + $this->assertFalse(Helpers::validateObject($this->invalid)); + } + + public function testMastodonValidation() + { + $this->assertTrue(Helpers::validateObject($this->mastodon)); + } + + public function testPleromaValidation() + { + $this->assertTrue(Helpers::validateObject($this->pleroma)); + } + + public function testMastodonAudienceScope() + { + $scope = Helpers::normalizeAudience($this->mastodon, false); + $actual = [ + "to" => [], + "cc" => [ + "https://pleroma.site/users/pixeldev", + "https://mastodon.social/users/dansup/followers", + ], + "scope" => "public", + ]; + + $this->assertEquals($scope, $actual); + } + + public function testPleromaAudienceScope() + { + $scope = Helpers::normalizeAudience($this->pleroma, false); + $actual = [ + "to" => [ + "https://pleroma.site/users/pixeldev/followers", + "https://mastodon.social/users/dansup", + ], + "cc" => [], + "scope" => "unlisted", + ]; + + $this->assertEquals($scope, $actual); + } + + public function testInvalidAudienceScope() + { + $scope = Helpers::normalizeAudience($this->invalid, false); + $actual = [ + 'to' => [], + 'cc' => [], + 'scope' => 'private' + ]; + $this->assertEquals($scope, $actual); + } +}