Put HTTPSignatures, WebFinger and ActivityStream alongside with ActivityPub

This commit is contained in:
rustra 2020-01-22 22:40:40 +01:00
parent cdb520a95b
commit d1251280c5
28 changed files with 57 additions and 64 deletions

View file

@ -22,13 +22,13 @@ defmodule Mobilizon.Federation.ActivityPub do
Federator, Federator,
Relay, Relay,
Transmogrifier, Transmogrifier,
Visibility, Visibility
WebFinger
} }
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible} alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils alias Mobilizon.Federation.ActivityStream.Converter.Utils, as: ConverterUtils
alias Mobilizon.Federation.HTTPSignatures.Signature alias Mobilizon.Federation.HTTPSignatures.Signature
alias Mobilizon.Federation.WebFinger
alias MobilizonWeb.API.Utils, as: APIUtils alias MobilizonWeb.API.Utils, as: APIUtils
alias MobilizonWeb.Email.{Admin, Mailer} alias MobilizonWeb.Email.{Admin, Mailer}
@ -38,7 +38,7 @@ defmodule Mobilizon.Federation.ActivityPub do
@doc """ @doc """
Wraps an object into an activity Wraps an object into an activity
""" """
@spec create_activity(map(), boolean()) :: {:ok, %Activity{}} @spec create_activity(map, boolean) :: {:ok, Activity.t()}
def create_activity(map, local \\ true) when is_map(map) do def create_activity(map, local \\ true) when is_map(map) do
with map <- lazy_put_activity_defaults(map) do with map <- lazy_put_activity_defaults(map) do
{:ok, {:ok,

View file

@ -12,7 +12,8 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
alias Mobilizon.Actors.{Actor, Follower} alias Mobilizon.Actors.{Actor, Follower}
alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier, WebFinger} alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier}
alias Mobilizon.Federation.WebFinger
alias MobilizonWeb.API.Follows alias MobilizonWeb.API.Follows

View file

@ -15,7 +15,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.{Activity, Utils} alias Mobilizon.Federation.ActivityPub.{Activity, Utils}
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible} alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias MobilizonWeb.Email.Participation alias MobilizonWeb.Email.Participation

View file

@ -13,7 +13,7 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
alias Mobilizon.Media.Picture alias Mobilizon.Media.Picture
alias Mobilizon.Federation.ActivityPub.{Activity, Federator, Relay} alias Mobilizon.Federation.ActivityPub.{Activity, Federator, Relay}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter alias Mobilizon.Federation.ActivityStream.Converter
alias Mobilizon.Federation.HTTPSignatures alias Mobilizon.Federation.HTTPSignatures
require Logger require Logger

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter do defmodule Mobilizon.Federation.ActivityStream.Converter do
@moduledoc """ @moduledoc """
Converter behaviour. Converter behaviour.

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor do defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
@moduledoc """ @moduledoc """
Actor converter. Actor converter.
@ -9,12 +9,12 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor do
alias Mobilizon.Actors.Actor, as: ActorModel alias Mobilizon.Actors.Actor, as: ActorModel
alias Mobilizon.Federation.ActivityPub.Utils alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible} alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
@behaviour Converter @behaviour Converter
defimpl Convertible, for: ActorModel do defimpl Convertible, for: ActorModel do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor, as: ActorConverter alias Mobilizon.Federation.ActivityStream.Converter.Actor, as: ActorConverter
defdelegate model_to_as(actor), to: ActorConverter defdelegate model_to_as(actor), to: ActorConverter
end end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address do defmodule Mobilizon.Federation.ActivityStream.Converter.Address do
@moduledoc """ @moduledoc """
Address converter. Address converter.
@ -8,7 +8,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address do
alias Mobilizon.Addresses.Address, as: AddressModel alias Mobilizon.Addresses.Address, as: AddressModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter alias Mobilizon.Federation.ActivityStream.Converter
@behaviour Converter @behaviour Converter

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Comment do defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do
@moduledoc """ @moduledoc """
Comment converter. Comment converter.
@ -13,15 +13,15 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Comment do
alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.Visibility alias Mobilizon.Federation.ActivityPub.Visibility
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible} alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils alias Mobilizon.Federation.ActivityStream.Converter.Utils, as: ConverterUtils
require Logger require Logger
@behaviour Converter @behaviour Converter
defimpl Convertible, for: CommentModel do defimpl Convertible, for: CommentModel do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Comment, as: CommentConverter alias Mobilizon.Federation.ActivityStream.Converter.Comment, as: CommentConverter
defdelegate model_to_as(comment), to: CommentConverter defdelegate model_to_as(comment), to: CommentConverter
end end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Event do defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
@moduledoc """ @moduledoc """
Event converter. Event converter.
@ -13,17 +13,17 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Event do
alias Mobilizon.Media.Picture alias Mobilizon.Media.Picture
alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible} alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address, as: AddressConverter alias Mobilizon.Federation.ActivityStream.Converter.Address, as: AddressConverter
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture, as: PictureConverter alias Mobilizon.Federation.ActivityStream.Converter.Picture, as: PictureConverter
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils alias Mobilizon.Federation.ActivityStream.Converter.Utils, as: ConverterUtils
require Logger require Logger
@behaviour Converter @behaviour Converter
defimpl Convertible, for: EventModel do defimpl Convertible, for: EventModel do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Event, as: EventConverter alias Mobilizon.Federation.ActivityStream.Converter.Event, as: EventConverter
defdelegate model_to_as(event), to: EventConverter defdelegate model_to_as(event), to: EventConverter
end end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Flag do defmodule Mobilizon.Federation.ActivityStream.Converter.Flag do
@moduledoc """ @moduledoc """
Flag converter. Flag converter.
@ -14,13 +14,13 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Flag do
alias Mobilizon.Events.Event alias Mobilizon.Events.Event
alias Mobilizon.Reports.Report alias Mobilizon.Reports.Report
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.Relay alias Mobilizon.Federation.ActivityPub.Relay
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
@behaviour Converter @behaviour Converter
defimpl Convertible, for: Report do defimpl Convertible, for: Report do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Flag, as: FlagConverter alias Mobilizon.Federation.ActivityStream.Converter.Flag, as: FlagConverter
defdelegate model_to_as(report), to: FlagConverter defdelegate model_to_as(report), to: FlagConverter
end end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower do defmodule Mobilizon.Federation.ActivityStream.Converter.Follower do
@moduledoc """ @moduledoc """
Participant converter. Participant converter.
@ -9,10 +9,10 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower do
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Actors.Follower, as: FollowerModel alias Mobilizon.Actors.Follower, as: FollowerModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible alias Mobilizon.Federation.ActivityStream.Convertible
defimpl Convertible, for: FollowerModel do defimpl Convertible, for: FollowerModel do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower, alias Mobilizon.Federation.ActivityStream.Converter.Follower,
as: FollowerConverter as: FollowerConverter
defdelegate model_to_as(follower), to: FollowerConverter defdelegate model_to_as(follower), to: FollowerConverter

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Participant do defmodule Mobilizon.Federation.ActivityStream.Converter.Participant do
@moduledoc """ @moduledoc """
Participant converter. Participant converter.
@ -8,10 +8,10 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Participant
alias Mobilizon.Events.Participant, as: ParticipantModel alias Mobilizon.Events.Participant, as: ParticipantModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible alias Mobilizon.Federation.ActivityStream.Convertible
defimpl Convertible, for: ParticipantModel do defimpl Convertible, for: ParticipantModel do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Participant, as: ParticipantConverter alias Mobilizon.Federation.ActivityStream.Converter.Participant, as: ParticipantConverter
defdelegate model_to_as(participant), to: ParticipantConverter defdelegate model_to_as(participant), to: ParticipantConverter
end end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture do defmodule Mobilizon.Federation.ActivityStream.Converter.Picture do
@moduledoc """ @moduledoc """
Picture converter. Picture converter.
@ -33,13 +33,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture do
) )
when is_bitstring(picture_url) do when is_bitstring(picture_url) do
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(picture_url), with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(picture_url),
{:ok, {:ok, %{name: name, url: url, content_type: content_type, size: size}} <-
%{
name: name,
url: url,
content_type: content_type,
size: size
}} <-
MobilizonWeb.Upload.store(%{body: body, name: name}), MobilizonWeb.Upload.store(%{body: body, name: name}),
{:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)} do {:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)} do
Mobilizon.Media.create_picture(%{ Mobilizon.Media.create_picture(%{

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Tombstone do defmodule Mobilizon.Federation.ActivityStream.Converter.Tombstone do
@moduledoc """ @moduledoc """
Comment converter. Comment converter.
@ -7,14 +7,14 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Tombstone do
alias Mobilizon.Tombstone, as: TombstoneModel alias Mobilizon.Tombstone, as: TombstoneModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible} alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
require Logger require Logger
@behaviour Converter @behaviour Converter
defimpl Convertible, for: TombstoneModel do defimpl Convertible, for: TombstoneModel do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Tombstone, as: TombstoneConverter alias Mobilizon.Federation.ActivityStream.Converter.Tombstone, as: TombstoneConverter
defdelegate model_to_as(comment), to: TombstoneConverter defdelegate model_to_as(comment), to: TombstoneConverter
end end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils do defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
@moduledoc """ @moduledoc """
Various utils for converters. Various utils for converters.
""" """
@ -29,9 +29,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils do
end end
def fetch_address(%{id: id}) do def fetch_address(%{id: id}) do
with {id, ""} <- Integer.parse(id) do with {id, ""} <- Integer.parse(id), do: %{id: id}
%{id: id}
end
end end
def fetch_address(address) when is_map(address) do def fetch_address(address) when is_map(address) do

View file

@ -1,4 +1,4 @@
defprotocol Mobilizon.Federation.ActivityPub.ActivityStream.Convertible do defprotocol Mobilizon.Federation.ActivityStream.Convertible do
@moduledoc """ @moduledoc """
Convertible protocol. Convertible protocol.
""" """

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/web_finger/web_finger.ex # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/web_finger/web_finger.ex
defmodule Mobilizon.Federation.ActivityPub.WebFinger do defmodule Mobilizon.Federation.WebFinger do
@moduledoc """ @moduledoc """
Performs the WebFinger requests and responses (JSON only). Performs the WebFinger requests and responses (JSON only).
""" """
@ -11,7 +11,7 @@ defmodule Mobilizon.Federation.ActivityPub.WebFinger do
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub.WebFinger.XmlBuilder alias Mobilizon.Federation.WebFinger.XmlBuilder
require Jason require Jason
require Logger require Logger

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/xml_builder.ex # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/xml_builder.ex
defmodule Mobilizon.Federation.ActivityPub.WebFinger.XmlBuilder do defmodule Mobilizon.Federation.WebFinger.XmlBuilder do
@moduledoc """ @moduledoc """
Builds XRD for WebFinger host_meta. Builds XRD for WebFinger host_meta.
""" """

View file

@ -10,7 +10,7 @@ defmodule MobilizonWeb.WebFingerController do
use MobilizonWeb, :controller use MobilizonWeb, :controller
alias Mobilizon.Federation.ActivityPub.WebFinger alias Mobilizon.Federation.WebFinger
plug(MobilizonWeb.Plugs.Federating) plug(MobilizonWeb.Plugs.Federating)

View file

@ -6,7 +6,7 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.{Activity, Utils} alias Mobilizon.Federation.ActivityPub.{Activity, Utils}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible alias Mobilizon.Federation.ActivityStream.Convertible
@private_visibility_empty_collection %{elements: [], total: 0} @private_visibility_empty_collection %{elements: [], total: 0}

View file

@ -14,7 +14,7 @@ defmodule MobilizonWeb.PageView do
alias Mobilizon.Service.Metadata.Utils, as: MetadataUtils alias Mobilizon.Service.Metadata.Utils, as: MetadataUtils
alias Mobilizon.Federation.ActivityPub.Utils alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible alias Mobilizon.Federation.ActivityStream.Convertible
def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do
actor actor

View file

@ -280,9 +280,9 @@ defmodule Mobilizon.Mixfile do
Mobilizon.Federation.ActivityPub.Federator, Mobilizon.Federation.ActivityPub.Federator,
Mobilizon.Federation.ActivityPub.Transmogrifier, Mobilizon.Federation.ActivityPub.Transmogrifier,
Mobilizon.Federation.ActivityPub.Utils, Mobilizon.Federation.ActivityPub.Utils,
Mobilizon.Federation.ActivityPub.WebFinger,
Mobilizon.Federation.ActivityPub.WebFinger.XmlBuilder,
Mobilizon.Federation.HTTPSignatures.Signature, Mobilizon.Federation.HTTPSignatures.Signature,
Mobilizon.Federation.WebFinger,
Mobilizon.Federation.WebFinger.XmlBuilder,
MobilizonWeb.ActivityPub.ActorView, MobilizonWeb.ActivityPub.ActorView,
MobilizonWeb.ActivityPub.ObjectView, MobilizonWeb.ActivityPub.ObjectView,
MobilizonWeb.ActivityPubController, MobilizonWeb.ActivityPubController,

View file

@ -18,7 +18,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.Utils alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityPub.{Activity, Relay, Transmogrifier} alias Mobilizon.Federation.ActivityPub.{Activity, Relay, Transmogrifier}
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Convertible} alias Mobilizon.Federation.ActivityStream.{Convertible}
alias MobilizonWeb.API alias MobilizonWeb.API

View file

@ -5,7 +5,7 @@ defmodule Mobilizon.Federation.ActivityPub.UtilsTest do
import Mobilizon.Factory import Mobilizon.Factory
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter alias Mobilizon.Federation.ActivityStream.Converter
alias MobilizonWeb.Endpoint alias MobilizonWeb.Endpoint
alias MobilizonWeb.Router.Helpers, as: Routes alias MobilizonWeb.Router.Helpers, as: Routes

View file

@ -1,9 +1,9 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.ActorTest do defmodule Mobilizon.Federation.ActivityStream.Converter.ActorTest do
use Mobilizon.DataCase use Mobilizon.DataCase
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor, as: ActorConverter alias Mobilizon.Federation.ActivityStream.Converter.Actor, as: ActorConverter
describe "actor to AS" do describe "actor to AS" do
test "valid actor to as" do test "valid actor to as" do

View file

@ -3,13 +3,13 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs # Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
defmodule Mobilizon.Federation.ActivityPub.WebFingerTest do defmodule Mobilizon.Federation.WebFingerTest do
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
use Mobilizon.DataCase use Mobilizon.DataCase
import Mobilizon.Factory import Mobilizon.Factory
alias Mobilizon.Federation.ActivityPub.WebFinger alias Mobilizon.Federation.WebFinger
@mastodon_account "tcit@social.tcit.fr" @mastodon_account "tcit@social.tcit.fr"
@mastodon_account_username "tcit" @mastodon_account_username "tcit"

View file

@ -9,7 +9,7 @@ defmodule MobilizonWeb.WebFingerControllerTest do
import Mobilizon.Factory import Mobilizon.Factory
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub.WebFinger alias Mobilizon.Federation.WebFinger
setup_all do setup_all do
Mobilizon.Config.put([:instance, :federating], true) Mobilizon.Config.put([:instance, :federating], true)