From c7dc5ce85c5b143df45031d5c87eee0689da3713 Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 29 Dec 2022 01:12:32 +0000 Subject: [PATCH 1/3] TagValidator: Allow unrecognized Tag types --- .../web/activity_pub/object_validators/tag_validator.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex b/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex index 9f15f1981..ad968994e 100644 --- a/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex @@ -68,6 +68,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidator do |> validate_required([:type, :name, :icon]) end + # Fallback + def changeset(struct, data), do: cast(struct, data, [:type, :name]) + def icon_changeset(struct, data) do struct |> cast(data, [:type, :url]) From 45646ff52cd045485c6be92713edcd0b37225bc3 Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 29 Dec 2022 23:57:19 +0000 Subject: [PATCH 2/3] TagValidator: Add test for Link tag --- test/fixtures/fep-e232.json | 26 +++++++++++++++++++ .../web/activity_pub/transmogrifier_test.exs | 16 ++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/fixtures/fep-e232.json diff --git a/test/fixtures/fep-e232.json b/test/fixtures/fep-e232.json new file mode 100644 index 000000000..98f339589 --- /dev/null +++ b/test/fixtures/fep-e232.json @@ -0,0 +1,26 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "type": "Create", + "actor": "https://example.org/users/alice", + "object": { + "id": "https://example.org/objects/10", + "type": "Note", + "attributedTo": "https://example.org/users/alice", + "content": "

test https://example.org/objects/9

", + "published": "2022-10-01T21:30:05.211215Z", + "tag": [ + { + "name": "https://example.org/objects/9", + "type": "Link", + "href": "https://example.org/objects/9", + "mediaType": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" + } + ], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://example.org/users/alice/followers" + ] + } +} diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 6b4636d22..c0425f30c 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -123,6 +123,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert activity.data["context"] == object.data["context"] end + + # https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md + test "it accepts FEP-e232 link tags" do + insert(:user, ap_id: "https://example.org/users/alice") + + message = File.read!("test/fixtures/fep-e232.json") |> Jason.decode!() + + assert {:ok, activity} = Transmogrifier.handle_incoming(message) + + object = Object.normalize(activity) + assert length(object.data["tag"]) == 1 + + tag = object.data["tag"] |> List.first() + assert tag["type"] == "Link" + assert tag["name"] == "https://example.org/objects/9" + end end describe "prepare outgoing" do From 5cfb0578a6845db377b5679ac05aa25ee5656211 Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 30 Dec 2022 17:26:43 +0000 Subject: [PATCH 3/3] TagValidator: Drop unrecognized tags --- .../web/activity_pub/object_validators/tag_validator.ex | 7 +++++-- test/fixtures/fep-e232.json | 5 +++++ test/pleroma/web/activity_pub/transmogrifier_test.exs | 6 ++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex b/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex index ad968994e..cfd510c19 100644 --- a/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/tag_validator.ex @@ -68,8 +68,11 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidator do |> validate_required([:type, :name, :icon]) end - # Fallback - def changeset(struct, data), do: cast(struct, data, [:type, :name]) + def changeset(struct, %{"type" => _} = data) do + struct + |> cast(data, []) + |> Map.put(:action, :ignore) + end def icon_changeset(struct, data) do struct diff --git a/test/fixtures/fep-e232.json b/test/fixtures/fep-e232.json index 98f339589..e9d12ae35 100644 --- a/test/fixtures/fep-e232.json +++ b/test/fixtures/fep-e232.json @@ -9,6 +9,11 @@ "content": "

test https://example.org/objects/9

", "published": "2022-10-01T21:30:05.211215Z", "tag": [ + { + "name": "@bob@example.net", + "type": "Mention", + "href": "https://example.net/users/bob" + }, { "name": "https://example.org/objects/9", "type": "Link", diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index c0425f30c..f76606479 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -124,8 +124,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert activity.data["context"] == object.data["context"] end - # https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md - test "it accepts FEP-e232 link tags" do + test "it drops link tags" do insert(:user, ap_id: "https://example.org/users/alice") message = File.read!("test/fixtures/fep-e232.json") |> Jason.decode!() @@ -136,8 +135,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert length(object.data["tag"]) == 1 tag = object.data["tag"] |> List.first() - assert tag["type"] == "Link" - assert tag["name"] == "https://example.org/objects/9" + assert tag["type"] == "Mention" end end