Improve group refreshment and fixed date signature generation
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -47,10 +47,17 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
File.read!("test/fixtures/mastodon-status-2.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: ^url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: data}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/Framasoft"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
||||
@@ -72,13 +79,20 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
File.read!("test/fixtures/mastodon-status-4.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
|> expect(:call, 3, fn
|
||||
%{method: :get, url: ^url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: data}}
|
||||
|
||||
%{method: :get, url: ^reply_to_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: reply_to_data}}
|
||||
|
||||
%{method: :get, url: "https://pirateradio.social/users/captain"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
||||
@@ -98,13 +112,26 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
File.read!("test/fixtures/peertube-video.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
|> expect(:call, 5, fn
|
||||
%{method: :get, url: ^url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: data}}
|
||||
|
||||
%{method: :get, url: ^origin_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: origin_data}}
|
||||
|
||||
%{method: :get, url: "https://diaspodon.fr/users/dada"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
|
||||
%{method: :get, url: "https://framatube.org/accounts/framasoft"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/Pouhiou"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
||||
|
||||
@@ -1,39 +1,72 @@
|
||||
defmodule Mobilizon.Federation.ActivityPub.ActorTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mox
|
||||
import Mock
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
||||
alias Mobilizon.Federation.ActivityPub.{Fetcher, Relay}
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
alias Mobilizon.Service.HTTP.ActivityPub.Mock
|
||||
|
||||
describe "fetching actor from its url" do
|
||||
@actor_url "https://framapiaf.org/users/tcit"
|
||||
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", visibility: :public} =
|
||||
_actor} = ActivityPubActor.make_actor_from_nickname("tcit@framapiaf.org")
|
||||
end
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("id", @actor_url)
|
||||
|> Map.put("preferredUsername", "tcit")
|
||||
|> Map.put("discoverable", true)
|
||||
|
||||
use_cassette "activity_pub/fetch_tcit@framapiaf.org_not_discoverable" do
|
||||
assert {:ok,
|
||||
%Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :unlisted} =
|
||||
_actor} = ActivityPubActor.make_actor_from_nickname("tcit@framapiaf.org")
|
||||
end
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: @actor_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
assert {:ok,
|
||||
%Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :public} =
|
||||
_actor} = ActivityPubActor.make_actor_from_nickname("tcit@framapiaf.org")
|
||||
end
|
||||
|
||||
test "returns an actor from nickname when not discoverable" do
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("id", @actor_url)
|
||||
|> Map.put("preferredUsername", "tcit")
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: @actor_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
assert {:ok,
|
||||
%Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :unlisted} =
|
||||
_actor} = ActivityPubActor.make_actor_from_nickname("tcit@framapiaf.org")
|
||||
end
|
||||
|
||||
@actor_url "https://framapiaf.org/users/tcit"
|
||||
test "returns an actor from url" do
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("id", @actor_url)
|
||||
|> Map.put("preferredUsername", "tcit")
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: @actor_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
# Initial fetch
|
||||
use_cassette "activity_pub/fetch_framapiaf.org_users_tcit" do
|
||||
# Unlisted because discoverable is not present in the JSON payload
|
||||
assert {:ok,
|
||||
%Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :unlisted}} =
|
||||
ActivityPubActor.get_or_fetch_actor_by_url(@actor_url)
|
||||
end
|
||||
# Unlisted because discoverable is not present in the JSON payload
|
||||
assert {:ok,
|
||||
%Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :unlisted}} =
|
||||
ActivityPubActor.get_or_fetch_actor_by_url(@actor_url)
|
||||
|
||||
# Fetch uses cache if Actors.needs_update? returns false
|
||||
with_mocks([
|
||||
@@ -49,7 +82,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
|
||||
needs_update?: fn _ -> false end
|
||||
]},
|
||||
{ActivityPubActor, [:passthrough],
|
||||
make_actor_from_url: fn @actor_url, false ->
|
||||
make_actor_from_url: fn @actor_url, preload: false ->
|
||||
{:ok,
|
||||
%Actor{
|
||||
preferred_username: "tcit",
|
||||
@@ -61,7 +94,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
|
||||
ActivityPubActor.get_or_fetch_actor_by_url(@actor_url)
|
||||
|
||||
assert_called(Actors.needs_update?(:_))
|
||||
refute called(ActivityPubActor.make_actor_from_url(@actor_url, false))
|
||||
refute called(ActivityPubActor.make_actor_from_url(@actor_url, preload: false))
|
||||
end
|
||||
|
||||
# Fetch doesn't use cache if Actors.needs_update? returns true
|
||||
@@ -78,7 +111,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
|
||||
needs_update?: fn _ -> true end
|
||||
]},
|
||||
{ActivityPubActor, [:passthrough],
|
||||
make_actor_from_url: fn @actor_url, false ->
|
||||
make_actor_from_url: fn @actor_url, preload: false ->
|
||||
{:ok,
|
||||
%Actor{
|
||||
preferred_username: "tcit",
|
||||
@@ -92,24 +125,21 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
|
||||
assert_called(ActivityPubActor.get_or_fetch_actor_by_url(@actor_url))
|
||||
assert_called(Actors.get_actor_by_url(@actor_url, false))
|
||||
assert_called(Actors.needs_update?(:_))
|
||||
assert_called(ActivityPubActor.make_actor_from_url(@actor_url, false))
|
||||
assert_called(ActivityPubActor.make_actor_from_url(@actor_url, preload: false))
|
||||
end
|
||||
end
|
||||
|
||||
test "handles remote actor being deleted" do
|
||||
with_mocks([
|
||||
{Fetcher, [:passthrough],
|
||||
fetch_and_prepare_actor_from_url: fn @actor_url ->
|
||||
{:error, :actor_deleted}
|
||||
end}
|
||||
]) do
|
||||
assert match?(
|
||||
{:error, :actor_deleted},
|
||||
ActivityPubActor.make_actor_from_url(@actor_url, false)
|
||||
)
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: @actor_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 410, body: ""}}
|
||||
end)
|
||||
|
||||
assert_called(Fetcher.fetch_and_prepare_actor_from_url(@actor_url))
|
||||
end
|
||||
assert match?(
|
||||
{:error, :actor_deleted},
|
||||
ActivityPubActor.make_actor_from_url(@actor_url, preload: false)
|
||||
)
|
||||
end
|
||||
|
||||
@public_url "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
@@ -36,12 +36,79 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
|
||||
end
|
||||
|
||||
test "it fetches replied-to activities if we don't have them" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
status_data = File.read!("test/fixtures/mastodon-status-2.json") |> Jason.decode!()
|
||||
|
||||
reply_to_data =
|
||||
File.read!("test/fixtures/pleroma-comment-object.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
reply_to_url = "https://fedi.absturztau.be/objects/1726cdc7-4f2a-4ddb-9c68-03d27c98c3d9"
|
||||
|
||||
Mock
|
||||
|> expect(:call, 5, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/admin")
|
||||
|> Map.put("preferredUsername", "admin")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/tcit")
|
||||
|> Map.put("preferredUsername", "tcit")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/Framasoft"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/Framasoft")
|
||||
|> Map.put("preferredUsername", "Framasoft")
|
||||
}}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://fedi.absturztau.be/objects/1726cdc7-4f2a-4ddb-9c68-03d27c98c3d9"
|
||||
},
|
||||
_opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
status_data
|
||||
|> Map.put(
|
||||
"id",
|
||||
"https://fedi.absturztau.be/objects/1726cdc7-4f2a-4ddb-9c68-03d27c98c3d9"
|
||||
)
|
||||
|> Map.put("actor", "https://fedi.absturztau.be/users/dqn")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://fedi.absturztau.be/users/dqn"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: Map.put(actor_data, "id", "https://fedi.absturztau.be/users/dqn")
|
||||
}}
|
||||
|
||||
%{method: :get, url: ^reply_to_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: reply_to_data}}
|
||||
end)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("inReplyTo", reply_to_url)
|
||||
@@ -50,16 +117,6 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
reply_to_data =
|
||||
File.read!("test/fixtures/pleroma-comment-object.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: ^reply_to_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: reply_to_data}}
|
||||
end)
|
||||
|
||||
{:ok, returned_activity, _} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
%Comment{} =
|
||||
@@ -75,6 +132,25 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
|
||||
end
|
||||
|
||||
test "it doesn't saves replies to an event if the event doesn't accept comments" do
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: Map.put(actor_data, "id", "https://framapiaf.org/users/admin")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: Map.put(actor_data, "id", "https://framapiaf.org/users/tcit")
|
||||
}}
|
||||
end)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Jason.decode!()
|
||||
@@ -94,6 +170,31 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
|
||||
|
||||
@url_404 "https://404.site/whatever"
|
||||
test "it does not crash if the object in inReplyTo can't be fetched" do
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/admin")
|
||||
|> Map.put("preferredUsername", "admin")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/tcit")
|
||||
|> Map.put("preferredUsername", "tcit")
|
||||
}}
|
||||
end)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Jason.decode!()
|
||||
@@ -118,6 +219,31 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
|
||||
end
|
||||
|
||||
test "it ignores incoming private notes" do
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/admin")
|
||||
|> Map.put("preferredUsername", "admin")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/tcit")
|
||||
|> Map.put("preferredUsername", "tcit")
|
||||
}}
|
||||
end)
|
||||
|
||||
data = File.read!("test/fixtures/mastodon-post-activity-private.json") |> Jason.decode!()
|
||||
event = insert(:event)
|
||||
object = data["object"]
|
||||
@@ -128,16 +254,33 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
|
||||
end
|
||||
|
||||
test "it works for incoming notices" do
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: Map.put(actor_data, "id", "https://framapiaf.org/users/admin")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: Map.put(actor_data, "id", "https://framapiaf.org/users/tcit")
|
||||
}}
|
||||
end)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["id"] ==
|
||||
"https://framapiaf.org/users/admin/statuses/99512778738411822/activity"
|
||||
|
||||
assert data["to"] == [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"https://framapiaf.org/users/tcit"
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
]
|
||||
|
||||
# assert data["cc"] == [
|
||||
@@ -164,6 +307,31 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
|
||||
end
|
||||
|
||||
test "it works for incoming notices with hashtags" do
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/admin")
|
||||
|> Map.put("preferredUsername", "admin")
|
||||
}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
actor_data
|
||||
|> Map.put("id", "https://framapiaf.org/users/tcit")
|
||||
|> Map.put("preferredUsername", "tcit")
|
||||
}}
|
||||
end)
|
||||
|
||||
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Jason.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
@@ -56,6 +56,19 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.DeleteTest do
|
||||
end
|
||||
|
||||
test "it fails for incoming deletes with spoofed origin" do
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/peertube"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
|
||||
%{method: :get, url: "http://mastodon.example.org/users/gargron"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
comment = insert(:comment)
|
||||
|
||||
announce_data =
|
||||
@@ -77,7 +90,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.DeleteTest do
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:error, :unknown_actor} = Transmogrifier.handle_incoming(data)
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert Discussions.get_comment_from_url(comment.url)
|
||||
end
|
||||
@@ -132,12 +145,12 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.DeleteTest do
|
||||
|> Map.put("id", deleted_actor_url)
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
|> expect(:call, 2, fn
|
||||
%{url: ^deleted_actor_url}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: deleted_actor_data}}
|
||||
end)
|
||||
|
||||
assert :error == Transmogrifier.handle_incoming(data)
|
||||
assert {:error, "Group object URL remote"} == Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert Actors.get_actor_by_url(url)
|
||||
end
|
||||
|
||||
@@ -1,16 +1,31 @@
|
||||
defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mox
|
||||
import ExUnit.CaptureLog
|
||||
import Mobilizon.Factory
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Follower
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity, Transmogrifier}
|
||||
alias Mobilizon.Service.HTTP.ActivityPub.Mock
|
||||
|
||||
describe "handle incoming follow requests" do
|
||||
test "it works only for groups" do
|
||||
actor = insert(:actor)
|
||||
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://social.tcit.fr/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: Map.put(actor_data, "id", "https://social.tcit.fr/users/tcit")
|
||||
}}
|
||||
end)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Jason.decode!()
|
||||
@@ -27,6 +42,20 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
test "it works for incoming follow requests" do
|
||||
actor = insert(:group)
|
||||
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://social.tcit.fr/users/tcit"}, _opts ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: Map.put(actor_data, "id", "https://social.tcit.fr/users/tcit")
|
||||
}}
|
||||
end)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
@@ -22,9 +22,12 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UndoTest do
|
||||
|> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/Framasoft"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
|
||||
%{method: :get, url: "https://framapiaf.org/users/peertube"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
{:ok, _, %Comment{}} = Transmogrifier.handle_incoming(announce_data)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UpdateTest do
|
||||
use Mobilizon.DataCase
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
||||
import Mobilizon.Factory
|
||||
import Mox
|
||||
|
||||
alias Mobilizon.{Actors, Events, Posts}
|
||||
alias Mobilizon.Actors.{Actor, Member}
|
||||
@@ -10,79 +10,100 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UpdateTest do
|
||||
alias Mobilizon.Posts.Post
|
||||
alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier}
|
||||
alias Mobilizon.Federation.ActivityStream.Convertible
|
||||
alias Mobilizon.Service.HTTP.ActivityPub.Mock
|
||||
|
||||
describe "handle incoming update activities" do
|
||||
test "it works for incoming update activities on actors" do
|
||||
use_cassette "activity_pub/update_actor_activity" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("id", data["actor"])
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
{:ok, %Activity{data: _data, local: false}, _} =
|
||||
Transmogrifier.handle_incoming(update_data)
|
||||
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
|
||||
|
||||
{:ok, %Actor{} = actor} = Actors.get_actor_by_url(update_data["actor"])
|
||||
assert actor.name == "nextsoft"
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("id", data["actor"])
|
||||
|
||||
assert actor.summary == "<p>Some bio</p>"
|
||||
end
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, %Activity{data: _data, local: false}, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
{:ok, %Actor{} = actor} = Actors.get_actor_by_url(update_data["actor"])
|
||||
assert actor.name == "nextsoft"
|
||||
|
||||
assert actor.summary == "<p>Some bio</p>"
|
||||
end
|
||||
|
||||
test "it works for incoming update activities on events" do
|
||||
use_cassette "activity_pub/event_update_activities" do
|
||||
data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!()
|
||||
data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, %Event{id: event_id}} =
|
||||
Transmogrifier.handle_incoming(data)
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
assert_enqueued(
|
||||
worker: Mobilizon.Service.Workers.BuildSearch,
|
||||
args: %{event_id: event_id, op: :insert_search_event}
|
||||
)
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: "https://mobilizon.fr/@metacartes"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
|
||||
assert %{success: 1, snoozed: 0, failure: 0} == Oban.drain_queue(queue: :search)
|
||||
%{method: :get, url: "https://framapiaf.org/users/tcit"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
|
||||
{:ok, %Activity{data: data, local: false}, %Event{id: event_id}} =
|
||||
Transmogrifier.handle_incoming(data)
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("name", "My updated event")
|
||||
|> Map.put("id", data["object"]["id"])
|
||||
|> Map.put("type", "Event")
|
||||
assert_enqueued(
|
||||
worker: Mobilizon.Service.Workers.BuildSearch,
|
||||
args: %{event_id: event_id, op: :insert_search_event}
|
||||
)
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
assert %{success: 1, snoozed: 0, failure: 0} == Oban.drain_queue(queue: :search)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, _} =
|
||||
Transmogrifier.handle_incoming(update_data)
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
|
||||
|
||||
%Event{} = event = Events.get_event_by_url(data["object"]["id"])
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("name", "My updated event")
|
||||
|> Map.put("id", data["object"]["id"])
|
||||
|> Map.put("type", "Event")
|
||||
|
||||
assert_enqueued(
|
||||
worker: Mobilizon.Service.Workers.BuildSearch,
|
||||
args: %{event_id: event_id, op: :update_search_event}
|
||||
)
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
|
||||
assert %{success: 1, snoozed: 0, failure: 0} == Oban.drain_queue(queue: :search)
|
||||
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
assert event.title == "My updated event"
|
||||
%Event{} = event = Events.get_event_by_url(data["object"]["id"])
|
||||
|
||||
assert event.description == data["object"]["content"]
|
||||
end
|
||||
assert_enqueued(
|
||||
worker: Mobilizon.Service.Workers.BuildSearch,
|
||||
args: %{event_id: event_id, op: :update_search_event}
|
||||
)
|
||||
|
||||
assert %{success: 1, snoozed: 0, failure: 0} == Oban.drain_queue(queue: :search)
|
||||
|
||||
assert event.title == "My updated event"
|
||||
|
||||
assert event.description == data["object"]["content"]
|
||||
end
|
||||
|
||||
# test "it works for incoming update activities which lock the account" do
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/transmogrifier_test.exs
|
||||
|
||||
defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase
|
||||
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
||||
|
||||
@@ -33,54 +31,75 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
|
||||
describe "handle incoming events" do
|
||||
test "it works for incoming events" do
|
||||
use_cassette "activity_pub/fetch_mobilizon_post_activity" do
|
||||
data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!()
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, %Event{} = event} =
|
||||
Transmogrifier.handle_incoming(data)
|
||||
Mock
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: url}, _opts ->
|
||||
case url do
|
||||
"https://mobilizon.fr/@metacartes" ->
|
||||
actor_data = Map.put(actor_data, "id", "https://mobilizon.fr/@metacartes")
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
|
||||
assert data["id"] ==
|
||||
"https://mobilizon.fr/events/39a0c4a6-f2b6-41dc-bbe2-fc5bff76cc93/activity"
|
||||
"https://framapiaf.org/users/tcit" ->
|
||||
actor_data = Map.put(actor_data, "id", "https://framapiaf.org/users/tcit")
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end
|
||||
end)
|
||||
|
||||
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!()
|
||||
|
||||
#
|
||||
# assert data["cc"] == [
|
||||
# "https://framapiaf.org/users/admin/followers",
|
||||
# "http://localtesting.pleroma.lol/users/lain"
|
||||
# ]
|
||||
{:ok, %Activity{data: data, local: false}, %Event{} = event} =
|
||||
Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "https://mobilizon.fr/@metacartes"
|
||||
assert data["id"] ==
|
||||
"https://mobilizon.fr/events/39a0c4a6-f2b6-41dc-bbe2-fc5bff76cc93/activity"
|
||||
|
||||
object = data["object"]
|
||||
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert object["id"] ==
|
||||
"https://mobilizon.fr/events/39a0c4a6-f2b6-41dc-bbe2-fc5bff76cc93"
|
||||
#
|
||||
# assert data["cc"] == [
|
||||
# "https://framapiaf.org/users/admin/followers",
|
||||
# "http://localtesting.pleroma.lol/users/lain"
|
||||
# ]
|
||||
|
||||
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
assert data["actor"] == "https://mobilizon.fr/@metacartes"
|
||||
|
||||
# assert object["cc"] == [
|
||||
# "https://framapiaf.org/users/admin/followers",
|
||||
# "http://localtesting.pleroma.lol/users/lain"
|
||||
# ]
|
||||
object = data["object"]
|
||||
|
||||
assert object["actor"] == "https://mobilizon.fr/@metacartes"
|
||||
assert object["location"]["name"] == "Locaux de Framasoft"
|
||||
# assert object["attributedTo"] == "https://mobilizon.fr/@metacartes"
|
||||
assert object["id"] ==
|
||||
"https://mobilizon.fr/events/39a0c4a6-f2b6-41dc-bbe2-fc5bff76cc93"
|
||||
|
||||
assert event.physical_address.street == "10 Rue Jangot"
|
||||
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert event.physical_address.url ==
|
||||
"https://event1.tcit.fr/address/eeecc11d-0030-43e8-a897-6422876372jd"
|
||||
# assert object["cc"] == [
|
||||
# "https://framapiaf.org/users/admin/followers",
|
||||
# "http://localtesting.pleroma.lol/users/lain"
|
||||
# ]
|
||||
|
||||
assert event.online_address == "https://google.com"
|
||||
assert object["actor"] == "https://mobilizon.fr/@metacartes"
|
||||
assert object["location"]["name"] == "Locaux de Framasoft"
|
||||
# assert object["attributedTo"] == "https://mobilizon.fr/@metacartes"
|
||||
|
||||
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
||||
end
|
||||
assert event.physical_address.street == "10 Rue Jangot"
|
||||
|
||||
assert event.physical_address.url ==
|
||||
"https://event1.tcit.fr/address/eeecc11d-0030-43e8-a897-6422876372jd"
|
||||
|
||||
assert event.online_address == "https://google.com"
|
||||
|
||||
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
||||
end
|
||||
|
||||
test "it works for incoming events from Gancio" do
|
||||
data = File.read!("test/fixtures/gancio-event-activity.json") |> Jason.decode!()
|
||||
actor_data = File.read!("test/fixtures/gancio-actor.json") |> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://demo.gancio.org/federation/u/gancio"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, %Event{} = event} =
|
||||
Transmogrifier.handle_incoming(data)
|
||||
@@ -524,6 +543,12 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
end
|
||||
|
||||
test "it accepts incoming resources and handles group being not found" do
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://someurl.com/notfound"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end)
|
||||
|
||||
creator =
|
||||
insert(:actor,
|
||||
domain: "mobilizon.app",
|
||||
@@ -649,12 +674,18 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
test "it works for incoming announces" do
|
||||
data = File.read!("test/fixtures/mastodon-announce.json") |> Jason.decode!()
|
||||
status_data = File.read!("test/fixtures/mastodon-status.json") |> Jason.decode!()
|
||||
actor_data = File.read!("test/fixtures/mastodon-actor.json") |> Jason.decode!()
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/peertube/statuses/104584600044284729"},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: status_data}}
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: url}, _opts ->
|
||||
case url do
|
||||
"https://framapiaf.org/users/peertube/statuses/104584600044284729" ->
|
||||
{:ok, %Tesla.Env{status: 200, body: status_data}}
|
||||
|
||||
"https://framapiaf.org/users/peertube" ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end
|
||||
end)
|
||||
|
||||
{:ok, _, %Comment{actor: %Actor{url: actor_url}, url: comment_url}} =
|
||||
@@ -677,10 +708,12 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
File.read!("test/fixtures/mastodon-announce.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", comment_url)
|
||||
|> Map.put("actor", actor_url)
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: ^actor_url}, _opts ->
|
||||
actor_data = Map.put(actor_data, "id", actor_url)
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end)
|
||||
|
||||
@@ -926,10 +959,21 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
File.read!("test/fixtures/https__info.pleroma.site_activity.json")
|
||||
|> Jason.decode!()
|
||||
|
||||
actor_data =
|
||||
File.read!("test/fixtures/mastodon-actor.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("id", "https://framapiaf.org/users/admin")
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://info.pleroma.site/activity.json"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: data}}
|
||||
|> expect(:call, 2, fn
|
||||
%{method: :get, url: url}, _opts ->
|
||||
case url do
|
||||
"https://info.pleroma.site/activity.json" ->
|
||||
{:ok, %Tesla.Env{status: 200, body: data}}
|
||||
|
||||
"https://framapiaf.org/users/admin" ->
|
||||
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
||||
end
|
||||
end)
|
||||
|
||||
data = %{
|
||||
|
||||
Reference in New Issue
Block a user