From 61dfeca1ccbff9d1fa1f3c1f709df9352573fffd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 2 Feb 2022 10:38:30 -0600 Subject: Test that a Note from Roadhouse validates --- test/fixtures/roadhouse-create-activity.json | 109 +++++++++++++++++++++ .../article_note_page_validator_test.exs | 11 +++ 2 files changed, 120 insertions(+) create mode 100644 test/fixtures/roadhouse-create-activity.json diff --git a/test/fixtures/roadhouse-create-activity.json b/test/fixtures/roadhouse-create-activity.json new file mode 100644 index 000000000..c082f84d7 --- /dev/null +++ b/test/fixtures/roadhouse-create-activity.json @@ -0,0 +1,109 @@ +{ + "@context":[ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "zot":"https://macgirvin.com/apschema#", + "toot":"http://joinmastodon.org/ns#", + "ostatus":"http://ostatus.org#", + "schema":"http://schema.org#", + "litepub":"http://litepub.social/ns#", + "sm":"http://smithereen.software/ns#", + "conversation":"ostatus:conversation", + "manuallyApprovesFollowers":"as:manuallyApprovesFollowers", + "oauthRegistrationEndpoint":"litepub:oauthRegistrationEndpoint", + "sensitive":"as:sensitive", + "movedTo":"as:movedTo", + "copiedTo":"as:copiedTo", + "alsoKnownAs":"as:alsoKnownAs", + "EmojiReact":"as:EmojiReact", + "commentPolicy":"zot:commentPolicy", + "topicalCollection":"zot:topicalCollection", + "eventRepeat":"zot:eventRepeat", + "emojiReaction":"zot:emojiReaction", + "expires":"zot:expires", + "directMessage":"zot:directMessage", + "Category":"zot:Category", + "replyTo":"zot:replyTo", + "PropertyValue":"schema:PropertyValue", + "value":"schema:value", + "discoverable":"toot:discoverable", + "wall":"sm:wall", + "capabilities":"litepub:capabilities", + "acceptsJoins":"litepub:acceptsJoins" + } + ], + "type":"Create", + "id":"https://macgirvin.com/activity/ce9ce740-e1cb-4a75-aa4e-9e923555870d", + "published":"2022-02-02T04:41:46Z", + "context":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", + "conversation":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", + "actor":"https://macgirvin.com/channel/mike", + "replyTo":"https://macgirvin.com/channel/mike", + "url":"https://macgirvin.com/activity/ce9ce740-e1cb-4a75-aa4e-9e923555870d", + "object":{ + "type":"Note", + "id":"https://macgirvin.com/item/ce9ce740-e1cb-4a75-aa4e-9e923555870d", + "published":"2022-02-02T04:41:46Z", + "attributedTo":"https://macgirvin.com/channel/mike", + "inReplyTo":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", + "context":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", + "conversation":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", + "content":"The Accepts should get through now. Now to figure out why the comments are failing.", + "source":{ + "content":"The Accepts should get through now. Now to figure out why the comments are failing.", + "mediaType":"text/x-multicode" + }, + "replyTo":"https://macgirvin.com/channel/mike", + "url":"https://macgirvin.com/item/ce9ce740-e1cb-4a75-aa4e-9e923555870d", + "tag":[ + { + "type":"Mention", + "href":"https://gleasonator.com/users/macgirvin", + "name":"@macgirvin@gleasonator.com" + }, + { + "type":"Mention", + "href":"https://gleasonator.com/users/alex", + "name":"@alex@gleasonator.com" + } + ], + "to":[ + "https://www.w3.org/ns/activitystreams#Public", + "https://gleasonator.com/users/alex", + "https://gleasonator.com/users/macgirvin" + ], + "cc":[ + "https://macgirvin.com/followers/mike", + "https://gleasonator.com/users/macgirvin/followers" + ] + }, + "tag":[ + { + "type":"Mention", + "href":"https://gleasonator.com/users/macgirvin", + "name":"@macgirvin@gleasonator.com" + }, + { + "type":"Mention", + "href":"https://gleasonator.com/users/alex", + "name":"@alex@gleasonator.com" + } + ], + "to":[ + "https://www.w3.org/ns/activitystreams#Public", + "https://gleasonator.com/users/alex", + "https://gleasonator.com/users/macgirvin" + ], + "cc":[ + "https://macgirvin.com/followers/mike", + "https://gleasonator.com/users/macgirvin/followers" + ], + "signature":{ + "type":"RsaSignature2017", + "nonce":"544080164a412f0592f8257094a870a0177276f4a04cc4410974f5e8fa277a14", + "creator":"https://macgirvin.com/channel/mike", + "created":"2022-02-02T04:41:46Z", + "signatureValue":"BkHEdRkki/DGHctiI6BWyQdn0i9ip+7rFiqqlLgotgQzwA8wzcmyvFIRm8Z+3OqrbzkNyQLCmx4qHvkqWyNrR0eSSJPaBryYvTLpLBz5F5PSpHOI5x4kRGVaI2S1Po+pUMWgchyyQ8ylqdLVHe0FnqId7vFVo9uj4jWydU5wPGlbb5nvnRMQGGyPqzCJ69lopMgCRCUNgbOz6hYVU0Mhqgi9BDjs1crbRLoGexz87tu7FeGEmtyfz8/SBGrDy+X+U3ahykwqd7ggcptsYVu5BY7BfREOLNZE8BwapUCg+QSw9PJv7dLJytdh0kUrzpuAPNbugx7y662FALmHZlxcIC1IVwbPOwEiosDm6wXsOiIyTvnNFcvDre/B1corB2yt5wmO3Cu5jINvp4+aBTheGIKMxBvpJXywpWe6C0VBqfNZSreJtDwp9lHd6D1+L4V6hUCOqiCcqmLT/GI5TOR+EhSpJ02TOkuu+/8hyIfO6ec3uK98y8suyidckbfM60jrbvZh2s/kF9WlDsE9K+Jlyd9Xx3mI5jU+4MXo1MDA57zYpsXw0S+v++rvnOw8CkQr/opVdIRSCG+UB3VRinpgjwW1UQcdAI+fiVaAwqr45MgnIEaQdk13skJUfUl06D9IxKxhu7yNW1tR621w/HN+358qVQWWBoj+1ZhCG3Thjug=" + } +} diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index 720c17d8d..150b26bea 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -32,4 +32,15 @@ test "a basic note validates", %{note: note} do %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) end end + + test "a Note from Roadhouse validates" do + insert(:user, ap_id: "https://macgirvin.com/channel/mike") + + %{"object" => note} = + "test/fixtures/roadhouse-create-activity.json" + |> File.read!() + |> Jason.decode!() + + %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) + end end -- cgit v1.2.3 From 5a4e3aa715fdd588b7fefc79dc15535497513218 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 2 Feb 2022 11:02:23 -0600 Subject: Test that a Create/Note from Roadhouse validates --- .../create_generic_validator_test.exs | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs diff --git a/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs new file mode 100644 index 000000000..94c9f6800 --- /dev/null +++ b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs @@ -0,0 +1,27 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2021 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidatorTest do + use Pleroma.DataCase, async: true + + alias Pleroma.Web.ActivityPub.ObjectValidator + alias Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator + + import Pleroma.Factory + + test "a Create/Note from Roadhouse validates" do + insert(:user, ap_id: "https://macgirvin.com/channel/mike") + + note_activity = + "test/fixtures/roadhouse-create-activity.json" + |> File.read!() + |> Jason.decode!() + + # Build metadata + {:ok, object_data} = ObjectValidator.cast_and_apply(note_activity["object"]) + meta = [object_data: ObjectValidator.stringify_keys(object_data)] + + %{valid?: true} = CreateGenericValidator.cast_and_validate(note_activity, meta) + end +end -- cgit v1.2.3 From 2d779763055ebfe02ffb1ffced5c10dbc0baa63b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 2 Feb 2022 12:19:35 -0600 Subject: Add tests for mismatched context in replies --- .../tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json | 35 ++++++++++++++++++ .../tesla_mock/macgirvin@gleasonator.com.json | 41 ++++++++++++++++++++++ .../create_generic_validator_test.exs | 32 +++++++++++++++++ .../web/activity_pub/transmogrifier_test.exs | 11 ++++++ test/support/http_request_mock.ex | 30 ++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json create mode 100644 test/fixtures/tesla_mock/macgirvin@gleasonator.com.json diff --git a/test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json b/test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json new file mode 100644 index 000000000..62d7bb9ae --- /dev/null +++ b/test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json @@ -0,0 +1,35 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://gleasonator.com/schemas/litepub-0.1.jsonld", + { + "@language": "und" + } + ], + "actor": "https://gleasonator.com/users/macgirvin", + "attachment": [], + "attributedTo": "https://gleasonator.com/users/macgirvin", + "cc": [ + "https://gleasonator.com/users/macgirvin/followers" + ], + "content": "@alex Any idea why my posts are failing? I sent an Accept/Follow from macgirvin.com at 2022-02-02T04:06:01Z and it vanished into space. As do all my comments to you.

2022-02-02T04:06:01Z:LOG_INFO:d5c4aa7f6a:Queue.php:435:deliver: deliver: queue post returned 200 from https://gleasonator.com/users/macgirvin/inbox

It's OK if I'm blocked, but if that's the case, I shouldn't be able to send a follow to that address should I?", + "context": "https://gleasonator.com/contexts/b7f01f94-bc92-4d89-a085-0ffc211b0e42", + "conversation": "https://gleasonator.com/contexts/b7f01f94-bc92-4d89-a085-0ffc211b0e42", + "id": "https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", + "published": "2022-02-02T04:14:10.965833Z", + "sensitive": false, + "source": "@alex Any idea why my posts are failing? I sent an Accept/Follow from macgirvin.com at 2022-02-02T04:06:01Z and it vanished into space. As do all my comments to you. \n\n2022-02-02T04:06:01Z:LOG_INFO:d5c4aa7f6a:Queue.php:435:deliver: deliver: queue post returned 200 from https://gleasonator.com/users/macgirvin/inbox\n\nIt's OK if I'm blocked, but if that's the case, I shouldn't be able to send a follow to that address should I?", + "summary": "", + "tag": [ + { + "href": "https://gleasonator.com/users/alex", + "name": "@alex", + "type": "Mention" + } + ], + "to": [ + "https://www.w3.org/ns/activitystreams#Public", + "https://gleasonator.com/users/alex" + ], + "type": "Note" +} diff --git a/test/fixtures/tesla_mock/macgirvin@gleasonator.com.json b/test/fixtures/tesla_mock/macgirvin@gleasonator.com.json new file mode 100644 index 000000000..9d7d47d40 --- /dev/null +++ b/test/fixtures/tesla_mock/macgirvin@gleasonator.com.json @@ -0,0 +1,41 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://gleasonator.com/schemas/litepub-0.1.jsonld", + { + "@language": "und" + } + ], + "alsoKnownAs": [], + "attachment": [], + "capabilities": { + "acceptsChatMessages": true + }, + "discoverable": false, + "endpoints": { + "oauthAuthorizationEndpoint": "https://gleasonator.com/oauth/authorize", + "oauthRegistrationEndpoint": "https://gleasonator.com/api/v1/apps", + "oauthTokenEndpoint": "https://gleasonator.com/oauth/token", + "sharedInbox": "https://gleasonator.com/inbox", + "uploadMedia": "https://gleasonator.com/api/ap/upload_media" + }, + "featured": "https://gleasonator.com/users/macgirvin/collections/featured", + "followers": "https://gleasonator.com/users/macgirvin/followers", + "following": "https://gleasonator.com/users/macgirvin/following", + "id": "https://gleasonator.com/users/macgirvin", + "inbox": "https://gleasonator.com/users/macgirvin/inbox", + "manuallyApprovesFollowers": false, + "name": "macgirvin", + "outbox": "https://gleasonator.com/users/macgirvin/outbox", + "preferredUsername": "macgirvin", + "publicKey": { + "id": "https://gleasonator.com/users/macgirvin#main-key", + "owner": "https://gleasonator.com/users/macgirvin", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0AUMgsQu87tLwoJjZfZu\nsj7NV0qt/THdK8aw4Ha2GZfNkwrep99AZ8gmCI+rr+N5vyETAARzG5/Qzr5bNTUx\nsc1fxFemhhi6sxzAv4qZ5AgvWQ4YPFWizSp5ZY1jpPHLOeF2IftMf8CwVI82PtD0\n7m7T6iUYA4vfvMp9LxVrzQA+CAtpsQxAejTGCt37yM9T2mEWqfmJQQHRIQ4brKBL\nI82sNbzk1cbTwCfH7vRNS/l1ND+vaUGGkDKtpRl56BLmt4picYL0avc+8oO7ebpc\n/zUoS8OOi+mpEzjv7TBrSirYEIGvIh3TKHWSPrpHpQTqj9xBQBy+AxXTWahQEO2M\ndQIDAQAB\n-----END PUBLIC KEY-----\n\n" + }, + "summary": "", + "tag": [], + "type": "Person", + "url": "https://gleasonator.com/users/macgirvin", + "vcard:bday": null +} diff --git a/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs index 94c9f6800..c3e6854e4 100644 --- a/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs @@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidatorTest do alias Pleroma.Web.ActivityPub.ObjectValidator alias Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator + alias Pleroma.Web.ActivityPub.Utils import Pleroma.Factory @@ -24,4 +25,35 @@ test "a Create/Note from Roadhouse validates" do %{valid?: true} = CreateGenericValidator.cast_and_validate(note_activity, meta) end + + test "a Create/Note with mismatched context is invalid" do + user = insert(:user) + + note = %{ + "id" => Utils.generate_object_id(), + "type" => "Note", + "actor" => user.ap_id, + "to" => [user.follower_address], + "cc" => [], + "content" => "Hello world", + "context" => Utils.generate_context_id() + } + + note_activity = %{ + "id" => Utils.generate_activity_id(), + "type" => "Create", + "actor" => note["actor"], + "to" => note["to"], + "cc" => note["cc"], + "object" => note, + "published" => DateTime.utc_now() |> DateTime.to_iso8601(), + "context" => Utils.generate_context_id() + } + + # Build metadata + {:ok, object_data} = ObjectValidator.cast_and_apply(note_activity["object"]) + meta = [object_data: ObjectValidator.stringify_keys(object_data)] + + %{valid?: false} = CreateGenericValidator.cast_and_validate(note_activity, meta) + end end diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 06daf6a9f..41a30be0b 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -107,6 +107,17 @@ test "it accepts Move activities" do assert activity.data["target"] == new_user.ap_id assert activity.data["type"] == "Move" end + + test "a reply with mismatched context is rejected" do + insert(:user, ap_id: "https://macgirvin.com/channel/mike") + + note_activity = + "test/fixtures/roadhouse-create-activity.json" + |> File.read!() + |> Jason.decode!() + + assert {:error, _} = Transmogrifier.handle_incoming(note_activity) + end end describe "prepare outgoing" do diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 94900dc14..b99d70cda 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -1311,6 +1311,36 @@ def get("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f", _, _, _ }} end + def get("https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json"), + headers: activitypub_object_headers() + }} + end + + def get("https://gleasonator.com/users/macgirvin", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/macgirvin@gleasonator.com.json"), + headers: activitypub_object_headers() + }} + end + + def get("https://gleasonator.com/users/macgirvin/collections/featured", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: + File.read!("test/fixtures/users_mock/masto_featured.json") + |> String.replace("{{domain}}", "gleasonator.com") + |> String.replace("{{nickname}}", "macgirvin"), + headers: activitypub_object_headers() + }} + end + def get(url, query, body, headers) do {:error, "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"} -- cgit v1.2.3 From bd81af731eb6c391f647e66847d01afdf374c673 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 2 Feb 2022 12:29:53 -0600 Subject: Tag erratic test --- test/pleroma/web/admin_api/controllers/report_controller_test.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs index 99cc7bbd0..802a8c05f 100644 --- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs @@ -355,6 +355,7 @@ test "it creates report note", %{admin_id: admin_id, report_id: report_id} do } = note end + @tag :erratic test "it returns reports with notes", %{conn: conn, admin: admin} do conn = get(conn, "/api/pleroma/admin/reports") -- cgit v1.2.3