Split Federation as separate context
This commit is contained in:
193
test/federation/activity_pub/activity_pub_test.exs
Normal file
193
test/federation/activity_pub/activity_pub_test.exs
Normal file
@@ -0,0 +1,193 @@
|
||||
# Portions of this file are derived from Pleroma:
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/activity_pub_test.exs
|
||||
|
||||
defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mock
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||
|
||||
@activity_pub_public_audience "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
end
|
||||
|
||||
describe "setting HTTP signature" do
|
||||
test "set http signature header" do
|
||||
actor = insert(:actor)
|
||||
|
||||
signature =
|
||||
Signature.sign(actor, %{
|
||||
host: "example.com",
|
||||
"content-length": 15,
|
||||
digest: %{id: "my_id"} |> Jason.encode!() |> Signature.build_digest(),
|
||||
"(request-target)": Signature.generate_request_target("POST", "/inbox"),
|
||||
date: Signature.generate_date_header()
|
||||
})
|
||||
|
||||
assert signature =~ "headers=\"(request-target) content-length date digest host\""
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching actor from its url" do
|
||||
test "returns an actor from nickname" do
|
||||
use_cassette "activity_pub/fetch_tcit@framapiaf.org" do
|
||||
assert {:ok, %Actor{preferred_username: "tcit", domain: "framapiaf.org"} = actor} =
|
||||
ActivityPub.make_actor_from_nickname("tcit@framapiaf.org")
|
||||
end
|
||||
end
|
||||
|
||||
test "returns an actor from url" do
|
||||
use_cassette "activity_pub/fetch_framapiaf.org_users_tcit" do
|
||||
assert {:ok, %Actor{preferred_username: "tcit", domain: "framapiaf.org"}} =
|
||||
ActivityPub.get_or_fetch_actor_by_url("https://framapiaf.org/users/tcit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "create activities" do
|
||||
# test "removes doubled 'to' recipients" do
|
||||
# actor = insert(:actor)
|
||||
#
|
||||
# {:ok, activity, _} =
|
||||
# ActivityPub.create(%{
|
||||
# to: ["user1", "user1", "user2"],
|
||||
# actor: actor,
|
||||
# context: "",
|
||||
# object: %{}
|
||||
# })
|
||||
#
|
||||
# assert activity.data["to"] == ["user1", "user2"]
|
||||
# assert activity.actor == actor.url
|
||||
# assert activity.recipients == ["user1", "user2"]
|
||||
# end
|
||||
end
|
||||
|
||||
describe "fetching an" do
|
||||
test "object by url" do
|
||||
use_cassette "activity_pub/fetch_framapiaf_framasoft_status" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://framapiaf.org/users/Framasoft/statuses/102093631881522097"
|
||||
)
|
||||
|
||||
{:ok, object_again} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://framapiaf.org/users/Framasoft/statuses/102093631881522097"
|
||||
)
|
||||
|
||||
assert object.id == object_again.id
|
||||
end
|
||||
end
|
||||
|
||||
test "object reply by url" do
|
||||
use_cassette "activity_pub/fetch_framasoft_framapiaf_reply" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url("https://mamot.fr/@imacrea/102094441327423790")
|
||||
|
||||
assert object.in_reply_to_comment.url ==
|
||||
"https://framapiaf.org/users/Framasoft/statuses/102093632302210150"
|
||||
end
|
||||
end
|
||||
|
||||
test "object reply to a video by url" do
|
||||
use_cassette "activity_pub/fetch_reply_to_framatube" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://diaspodon.fr/users/dada/statuses/100820008426311925"
|
||||
)
|
||||
|
||||
assert object.in_reply_to_comment == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "deletion" do
|
||||
test "it creates a delete activity and deletes the original event" do
|
||||
event = insert(:event)
|
||||
event = Events.get_public_event_by_url_with_preload!(event.url)
|
||||
{:ok, delete, _} = ActivityPub.delete(event)
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
assert delete.data["actor"] == event.organizer_actor.url
|
||||
assert delete.data["object"] == event.url
|
||||
|
||||
assert Events.get_event_by_url(event.url) == nil
|
||||
end
|
||||
|
||||
test "it deletes the original event but only locally if needed" do
|
||||
with_mock ActivityPub.Utils,
|
||||
maybe_federate: fn _ -> :ok end,
|
||||
lazy_put_activity_defaults: fn args -> args end do
|
||||
event = insert(:event)
|
||||
event = Events.get_public_event_by_url_with_preload!(event.url)
|
||||
{:ok, delete, _} = ActivityPub.delete(event, false)
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
assert delete.data["actor"] == event.organizer_actor.url
|
||||
assert delete.data["object"] == event.url
|
||||
assert delete.local == false
|
||||
|
||||
assert Events.get_event_by_url(event.url) == nil
|
||||
|
||||
assert_called(ActivityPub.Utils.maybe_federate(delete))
|
||||
end
|
||||
end
|
||||
|
||||
test "it creates a delete activity and deletes the original comment" do
|
||||
comment = insert(:comment)
|
||||
comment = Events.get_comment_from_url_with_preload!(comment.url)
|
||||
assert is_nil(Events.get_comment_from_url(comment.url).deleted_at)
|
||||
{:ok, delete, _} = ActivityPub.delete(comment)
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
assert delete.data["actor"] == comment.actor.url
|
||||
assert delete.data["object"] == comment.url
|
||||
|
||||
refute is_nil(Events.get_comment_from_url(comment.url).deleted_at)
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
@updated_actor_summary "This is an updated actor"
|
||||
|
||||
test "it creates an update activity with the new actor data" do
|
||||
actor = insert(:actor)
|
||||
actor_data = %{summary: @updated_actor_summary}
|
||||
|
||||
{:ok, update, _} = ActivityPub.update(:actor, actor, actor_data, false)
|
||||
|
||||
assert update.data["actor"] == actor.url
|
||||
assert update.data["to"] == [@activity_pub_public_audience]
|
||||
assert update.data["object"]["id"] == actor.url
|
||||
assert update.data["object"]["type"] == :Person
|
||||
assert update.data["object"]["summary"] == @updated_actor_summary
|
||||
end
|
||||
|
||||
@updated_start_time DateTime.utc_now() |> DateTime.truncate(:second)
|
||||
|
||||
test "it creates an update activity with the new event data" do
|
||||
actor = insert(:actor)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
event_data = %{begins_on: @updated_start_time}
|
||||
|
||||
{:ok, update, _} = ActivityPub.update(:event, event, event_data)
|
||||
|
||||
assert update.data["actor"] == actor.url
|
||||
assert update.data["to"] == [@activity_pub_public_audience]
|
||||
assert update.data["object"]["id"] == event.url
|
||||
assert update.data["object"]["type"] == "Event"
|
||||
assert update.data["object"]["startTime"] == DateTime.to_iso8601(@updated_start_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.ActorTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor, as: ActorConverter
|
||||
|
||||
describe "actor to AS" do
|
||||
test "valid actor to as" do
|
||||
data = ActorConverter.model_to_as(%Actor{type: :Person, preferred_username: "test_account"})
|
||||
assert is_map(data)
|
||||
assert data["type"] == :Person
|
||||
assert data["preferredUsername"] == "test_account"
|
||||
end
|
||||
end
|
||||
|
||||
describe "AS to Actor" do
|
||||
test "valid as data to model" do
|
||||
{:ok, actor} =
|
||||
ActorConverter.as_to_model_data(%{
|
||||
"id" => "https://somedomain.tld/users/someone",
|
||||
"type" => "Person",
|
||||
"preferredUsername" => "test_account"
|
||||
})
|
||||
|
||||
assert actor.type == "Person"
|
||||
assert actor.preferred_username == "test_account"
|
||||
end
|
||||
end
|
||||
end
|
||||
15
test/federation/activity_pub/relay_test.exs
Normal file
15
test/federation/activity_pub/relay_test.exs
Normal file
@@ -0,0 +1,15 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mobilizon.Federation.ActivityPub.RelayTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
|
||||
test "gets an actor for the relay" do
|
||||
actor = Relay.get_actor()
|
||||
|
||||
assert actor.url =~ "/relay"
|
||||
end
|
||||
end
|
||||
1050
test/federation/activity_pub/transmogrifier_test.exs
Normal file
1050
test/federation/activity_pub/transmogrifier_test.exs
Normal file
File diff suppressed because it is too large
Load Diff
56
test/federation/activity_pub/utils_test.exs
Normal file
56
test/federation/activity_pub/utils_test.exs
Normal file
@@ -0,0 +1,56 @@
|
||||
defmodule Mobilizon.Federation.ActivityPub.UtilsTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter
|
||||
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
end
|
||||
|
||||
describe "make" do
|
||||
test "comment data from struct" do
|
||||
comment = insert(:comment)
|
||||
tag = insert(:tag, title: "MyTag")
|
||||
reply = insert(:comment, in_reply_to_comment: comment, tags: [tag])
|
||||
|
||||
assert %{
|
||||
"type" => "Note",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [],
|
||||
"tag" => [
|
||||
%{
|
||||
"href" => "http://mobilizon.test/tags/#{tag.slug}",
|
||||
"name" => "#MyTag",
|
||||
"type" => "Hashtag"
|
||||
}
|
||||
],
|
||||
"content" => "My Comment",
|
||||
"actor" => reply.actor.url,
|
||||
"uuid" => reply.uuid,
|
||||
"id" => Routes.page_url(Endpoint, :comment, reply.uuid),
|
||||
"inReplyTo" => comment.url,
|
||||
"attributedTo" => reply.actor.url,
|
||||
"mediaType" => "text/html"
|
||||
} == Converter.Comment.model_to_as(reply)
|
||||
end
|
||||
|
||||
test "comment data from map" do
|
||||
comment = insert(:comment)
|
||||
reply = insert(:comment, in_reply_to_comment: comment)
|
||||
to = ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
comment_data = Converter.Comment.model_to_as(reply)
|
||||
assert comment_data["type"] == "Note"
|
||||
assert comment_data["to"] == to
|
||||
assert comment_data["content"] == reply.text
|
||||
assert comment_data["actor"] == reply.actor.url
|
||||
assert comment_data["inReplyTo"] == comment.url
|
||||
end
|
||||
end
|
||||
end
|
||||
94
test/federation/activity_pub/web_finger_test.exs
Normal file
94
test/federation/activity_pub/web_finger_test.exs
Normal file
@@ -0,0 +1,94 @@
|
||||
# Portions of this file are derived from Pleroma:
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
|
||||
|
||||
defmodule Mobilizon.Federation.ActivityPub.WebFingerTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.WebFinger
|
||||
|
||||
@mastodon_account "tcit@social.tcit.fr"
|
||||
@mastodon_account_username "tcit"
|
||||
@pleroma_account "lain@pleroma.soykaf.com"
|
||||
@pleroma_account_username "lain"
|
||||
@peertube_account "framasoft@framatube.org"
|
||||
@peertube_account_username "framasoft"
|
||||
@friendica_account "lain@squeet.me"
|
||||
@friendica_account_username "lain"
|
||||
|
||||
describe "host meta" do
|
||||
test "returns a link to the xml lrdd" do
|
||||
host_info = WebFinger.host_meta()
|
||||
|
||||
assert String.contains?(host_info, MobilizonWeb.Endpoint.url())
|
||||
end
|
||||
end
|
||||
|
||||
describe "incoming webfinger request" do
|
||||
test "works for fqns" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, result} =
|
||||
WebFinger.webfinger("#{actor.preferred_username}@#{MobilizonWeb.Endpoint.host()}", "JSON")
|
||||
|
||||
assert is_map(result)
|
||||
end
|
||||
|
||||
test "works for urls" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, result} = WebFinger.webfinger(actor.url, "JSON")
|
||||
assert is_map(result)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fingering" do
|
||||
test "a mastodon actor" do
|
||||
use_cassette "webfinger/mastodon" do
|
||||
res = %{
|
||||
"subject" => "acct:" <> @mastodon_account,
|
||||
"url" => "https://social.tcit.fr/users/#{@mastodon_account_username}"
|
||||
}
|
||||
|
||||
assert {:ok, res} == WebFinger.finger(@mastodon_account)
|
||||
end
|
||||
end
|
||||
|
||||
test "a pleroma actor" do
|
||||
use_cassette "webfinger/pleroma" do
|
||||
res = %{
|
||||
"subject" => "acct:" <> @pleroma_account,
|
||||
"url" => "https://pleroma.soykaf.com/users/#{@pleroma_account_username}"
|
||||
}
|
||||
|
||||
assert {:ok, res} == WebFinger.finger(@pleroma_account)
|
||||
end
|
||||
end
|
||||
|
||||
test "a peertube actor" do
|
||||
use_cassette "webfinger/peertube" do
|
||||
res = %{
|
||||
"subject" => "acct:" <> @peertube_account,
|
||||
"url" => "https://framatube.org/accounts/#{@peertube_account_username}"
|
||||
}
|
||||
|
||||
assert {:ok, res} == WebFinger.finger(@peertube_account)
|
||||
end
|
||||
end
|
||||
|
||||
test "a friendica actor" do
|
||||
use_cassette "webfinger/friendica" do
|
||||
res = %{
|
||||
"subject" => "acct:" <> @friendica_account,
|
||||
"url" => "https://squeet.me/profile/#{@friendica_account_username}"
|
||||
}
|
||||
|
||||
assert {:ok, res} == WebFinger.finger(@friendica_account)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user