diff --git a/test/fixtures/tesla_mock/mobilizon-event-leave.json b/test/fixtures/tesla_mock/mobilizon-event-leave.json new file mode 100644 index 0000000000..04fffb125a --- /dev/null +++ b/test/fixtures/tesla_mock/mobilizon-event-leave.json @@ -0,0 +1,78 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "addressRegion": "sc:addressRegion", + "timezone": { "@id": "mz:timezone", "@type": "sc:Text" }, + "isOnline": { "@id": "mz:isOnline", "@type": "sc:Boolean" }, + "pt": "https://joinpeertube.org/ns#", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "inLanguage": "sc:inLanguage", + "address": { "@id": "sc:address", "@type": "sc:PostalAddress" }, + "status": { "@id": "ical:status", "@type": "ical:status" }, + "discoverable": "toot:discoverable", + "repliesModerationOption": { + "@id": "mz:repliesModerationOption", + "@type": "mz:repliesModerationOptionType" + }, + "sc": "http://schema.org#", + "mz": "https://joinmobilizon.org/ns#", + "category": "sc:category", + "joinModeType": { "@id": "mz:joinModeType", "@type": "rdfs:Class" }, + "Hashtag": "as:Hashtag", + "propertyID": "sc:propertyID", + "PostalAddress": "sc:PostalAddress", + "discussions": { "@id": "mz:discussions", "@type": "@id" }, + "remainingAttendeeCapacity": "sc:remainingAttendeeCapacity", + "streetAddress": "sc:streetAddress", + "anonymousParticipationEnabled": { + "@id": "mz:anonymousParticipationEnabled", + "@type": "sc:Boolean" + }, + "externalParticipationUrl": { + "@id": "mz:externalParticipationUrl", + "@type": "sc:URL" + }, + "addressLocality": "sc:addressLocality", + "joinMode": { "@id": "mz:joinMode", "@type": "mz:joinModeType" }, + "location": { "@id": "sc:location", "@type": "sc:Place" }, + "toot": "http://joinmastodon.org/ns#", + "participantCount": { + "@id": "mz:participantCount", + "@type": "sc:Integer" + }, + "uuid": "sc:identifier", + "maximumAttendeeCapacity": "sc:maximumAttendeeCapacity", + "participationMessage": { + "@id": "mz:participationMessage", + "@type": "sc:Text" + }, + "openness": { "@id": "mz:openness", "@type": "@id" }, + "members": { "@id": "mz:members", "@type": "@id" }, + "events": { "@id": "mz:events", "@type": "@id" }, + "resources": { "@id": "mz:resources", "@type": "@id" }, + "addressCountry": "sc:addressCountry", + "posts": { "@id": "mz:posts", "@type": "@id" }, + "commentsEnabled": { + "@id": "pt:commentsEnabled", + "@type": "sc:Boolean" + }, + "value": "sc:value", + "PropertyValue": "sc:PropertyValue", + "repliesModerationOptionType": { + "@id": "mz:repliesModerationOptionType", + "@type": "rdfs:Class" + }, + "todos": { "@id": "mz:todos", "@type": "@id" }, + "ical": "http://www.w3.org/2002/12/cal/ical#", + "postalCode": "sc:postalCode", + "memberCount": { "@id": "mz:memberCount", "@type": "sc:Integer" }, + "@language": "und" + } + ], + "actor": "https://mobilizon.org/@tcit", + "id": "https://mobilizon.mkljczk.pl/leave/event/d1828aac-b57f-43c9-ac87-17388fab2bc8", + "object": "https://pleroma.mkljczk.pl/objects/b800bdb9-2cbb-40b6-9b29-196cfbd42398", + "type": "Leave" +} diff --git a/test/pleroma/web/activity_pub/transmogrifier/leave_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/leave_handling_test.exs new file mode 100644 index 0000000000..34620a878c --- /dev/null +++ b/test/pleroma/web/activity_pub/transmogrifier/leave_handling_test.exs @@ -0,0 +1,51 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.Transmogrifier.LeaveHandlingTest do + use Pleroma.DataCase + + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.Web.ActivityPub.Builder + alias Pleroma.Web.ActivityPub.Pipeline + alias Pleroma.Web.ActivityPub.SideEffects + alias Pleroma.Web.ActivityPub.Transmogrifier + + import Pleroma.Factory + + setup_all do + Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + + describe "handle_incoming" do + test "it works for incoming Mobilizon leaves" do + user = insert(:user) + + event = insert(:event) + + {:ok, join_activity, _} = Builder.join(user, event) + {:ok, join_activity, _} = Pipeline.common_pipeline(join_activity, local: true) + {:ok, _, _} = SideEffects.handle(join_activity, local: true) + + event = Object.get_by_id(event.id) + + assert length(event.data["participations"]) === 1 + + leave_data = + File.read!("test/fixtures/tesla_mock/mobilizon-event-leave.json") + |> Jason.decode!() + |> Map.put("actor", user.ap_id) + |> Map.put("object", event.data["id"]) + + {:ok, %Activity{local: false} = _activity} = Transmogrifier.handle_incoming(leave_data) + + event = Object.get_by_id(event.id) + + assert length(event.data["participations"]) === 0 + refute Repo.get(Activity, join_activity.id) + end + end +end diff --git a/uploads/.gitignore b/uploads/.gitignore deleted file mode 100644 index 523e584a70..0000000000 --- a/uploads/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Git will ignore everything in this directory except this file. -* -!.gitignore