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,
Relay,
Transmogrifier,
Visibility,
WebFinger
Visibility
}
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityStream.Converter.Utils, as: ConverterUtils
alias Mobilizon.Federation.HTTPSignatures.Signature
alias Mobilizon.Federation.WebFinger
alias MobilizonWeb.API.Utils, as: APIUtils
alias MobilizonWeb.Email.{Admin, Mailer}
@ -38,7 +38,7 @@ defmodule Mobilizon.Federation.ActivityPub do
@doc """
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
with map <- lazy_put_activity_defaults(map) do
{:ok,

View file

@ -12,7 +12,8 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
alias Mobilizon.Actors.{Actor, Follower}
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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor do
defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
@moduledoc """
Actor converter.
@ -9,12 +9,12 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor do
alias Mobilizon.Actors.Actor, as: ActorModel
alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
@behaviour Converter
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
end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address do
defmodule Mobilizon.Federation.ActivityStream.Converter.Address do
@moduledoc """
Address converter.
@ -8,7 +8,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address do
alias Mobilizon.Addresses.Address, as: AddressModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter
alias Mobilizon.Federation.ActivityStream.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 """
Comment converter.
@ -13,15 +13,15 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Comment do
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.Visibility
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityStream.Converter.Utils, as: ConverterUtils
require Logger
@behaviour Converter
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
end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Event do
defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
@moduledoc """
Event converter.
@ -13,17 +13,17 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Event do
alias Mobilizon.Media.Picture
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address, as: AddressConverter
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture, as: PictureConverter
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityStream.Converter.Address, as: AddressConverter
alias Mobilizon.Federation.ActivityStream.Converter.Picture, as: PictureConverter
alias Mobilizon.Federation.ActivityStream.Converter.Utils, as: ConverterUtils
require Logger
@behaviour Converter
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
end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Flag do
defmodule Mobilizon.Federation.ActivityStream.Converter.Flag do
@moduledoc """
Flag converter.
@ -14,13 +14,13 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Flag do
alias Mobilizon.Events.Event
alias Mobilizon.Reports.Report
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityPub.Relay
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
@behaviour Converter
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
end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower do
defmodule Mobilizon.Federation.ActivityStream.Converter.Follower do
@moduledoc """
Participant converter.
@ -9,10 +9,10 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower do
alias Mobilizon.Actors.Actor
alias Mobilizon.Actors.Follower, as: FollowerModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
alias Mobilizon.Federation.ActivityStream.Convertible
defimpl Convertible, for: FollowerModel do
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower,
alias Mobilizon.Federation.ActivityStream.Converter.Follower,
as: 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 """
Participant converter.
@ -8,10 +8,10 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Participant
alias Mobilizon.Events.Participant, as: ParticipantModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
alias Mobilizon.Federation.ActivityStream.Convertible
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
end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture do
defmodule Mobilizon.Federation.ActivityStream.Converter.Picture do
@moduledoc """
Picture converter.
@ -33,13 +33,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture do
)
when is_bitstring(picture_url) do
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(picture_url),
{:ok,
%{
name: name,
url: url,
content_type: content_type,
size: size
}} <-
{:ok, %{name: name, url: url, content_type: content_type, size: size}} <-
MobilizonWeb.Upload.store(%{body: body, name: name}),
{:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)} do
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 """
Comment converter.
@ -7,14 +7,14 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Tombstone do
alias Mobilizon.Tombstone, as: TombstoneModel
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
require Logger
@behaviour Converter
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
end

View file

@ -1,4 +1,4 @@
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils do
defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
@moduledoc """
Various utils for converters.
"""
@ -29,9 +29,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils do
end
def fetch_address(%{id: id}) do
with {id, ""} <- Integer.parse(id) do
%{id: id}
end
with {id, ""} <- Integer.parse(id), do: %{id: id}
end
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 """
Convertible protocol.
"""

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# 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 """
Performs the WebFinger requests and responses (JSON only).
"""
@ -11,7 +11,7 @@ defmodule Mobilizon.Federation.ActivityPub.WebFinger do
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub.WebFinger.XmlBuilder
alias Mobilizon.Federation.WebFinger.XmlBuilder
require Jason
require Logger

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# 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 """
Builds XRD for WebFinger host_meta.
"""

View file

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

View file

@ -6,7 +6,7 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.{Activity, Utils}
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
alias Mobilizon.Federation.ActivityStream.Convertible
@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.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
actor

View file

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

View file

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

View file

@ -5,7 +5,7 @@ defmodule Mobilizon.Federation.ActivityPub.UtilsTest do
import Mobilizon.Factory
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter
alias Mobilizon.Federation.ActivityStream.Converter
alias MobilizonWeb.Endpoint
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
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
test "valid actor to as" do

View file

@ -3,13 +3,13 @@
# 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
defmodule Mobilizon.Federation.WebFingerTest do
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
use Mobilizon.DataCase
import Mobilizon.Factory
alias Mobilizon.Federation.ActivityPub.WebFinger
alias Mobilizon.Federation.WebFinger
@mastodon_account "tcit@social.tcit.fr"
@mastodon_account_username "tcit"

View file

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