diff options
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/factory.ex | 26 | ||||
| -rw-r--r-- | test/support/http_request_mock.ex | 73 | ||||
| -rw-r--r-- | test/support/websocket_client.ex | 32 | 
3 files changed, 102 insertions, 29 deletions
| diff --git a/test/support/factory.ex b/test/support/factory.ex index efbf3df2e..09f02458c 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -10,6 +10,15 @@ defmodule Pleroma.Factory do    alias Pleroma.Object    alias Pleroma.User +  @rsa_keys [ +              "test/fixtures/rsa_keys/key_1.pem", +              "test/fixtures/rsa_keys/key_2.pem", +              "test/fixtures/rsa_keys/key_3.pem", +              "test/fixtures/rsa_keys/key_4.pem", +              "test/fixtures/rsa_keys/key_5.pem" +            ] +            |> Enum.map(&File.read!/1) +    def participation_factory do      conversation = insert(:conversation)      user = insert(:user) @@ -28,6 +37,8 @@ defmodule Pleroma.Factory do    end    def user_factory(attrs \\ %{}) do +    pem = Enum.random(@rsa_keys) +      user = %User{        name: sequence(:name, &"Test ใในใ User #{&1}"),        email: sequence(:email, &"user#{&1}@example.com"), @@ -39,7 +50,8 @@ defmodule Pleroma.Factory do        last_refreshed_at: NaiveDateTime.utc_now(),        notification_settings: %Pleroma.User.NotificationSetting{},        multi_factor_authentication_settings: %Pleroma.MFA.Settings{}, -      ap_enabled: true +      ap_enabled: true, +      keys: pem      }      urls = @@ -111,6 +123,18 @@ defmodule Pleroma.Factory do      }    end +  def attachment_factory(attrs \\ %{}) do +    user = attrs[:user] || insert(:user) + +    data = +      attachment_data(user.ap_id, nil) +      |> Map.put("id", Pleroma.Web.ActivityPub.Utils.generate_object_id()) + +    %Pleroma.Object{ +      data: merge_attributes(data, Map.get(attrs, :data, %{})) +    } +  end +    def attachment_note_factory(attrs \\ %{}) do      user = attrs[:user] || insert(:user)      {length, attrs} = Map.pop(attrs, :length, 1) diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index eb844e469..b0cf613ac 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -424,14 +424,6 @@ defmodule HttpRequestMock do      {:error, :nxdomain}    end -  def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 404, -       body: "" -     }} -  end -    def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{ @@ -765,7 +757,7 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 406, body: ""}}    end -  def get("http://squeet.me/.well-known/host-meta", _, _, _) do +  def get("https://squeet.me/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}    end @@ -806,7 +798,7 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}    end -  def get("http://framatube.org/.well-known/host-meta", _, _, _) do +  def get("https://framatube.org/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{         status: 200, @@ -815,7 +807,7 @@ defmodule HttpRequestMock do    end    def get( -        "http://framatube.org/main/xrd?uri=acct:framasoft@framatube.org", +        "https://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",          _,          _,          [{"accept", "application/xrd+xml,application/jrd+json"}] @@ -850,7 +842,7 @@ defmodule HttpRequestMock do       }}    end -  def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do +  def get("https://status.alpicola.com/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{         status: 200, @@ -858,7 +850,7 @@ defmodule HttpRequestMock do       }}    end -  def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do +  def get("https://macgirvin.com/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{         status: 200, @@ -866,7 +858,7 @@ defmodule HttpRequestMock do       }}    end -  def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do +  def get("https://gerzilla.de/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{         status: 200, @@ -1084,6 +1076,14 @@ defmodule HttpRequestMock do       }}    end +  def get("https://404.site" <> _, _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 404, +       body: "" +     }} +  end +    def get(          "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:lain@zetsubou.xn--q9jyb4c",          _, @@ -1401,6 +1401,51 @@ defmodule HttpRequestMock do       }}    end +  def get("https://mk.absturztau.be/users/8ozbzjs3o8", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: File.read!("test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json"), +       headers: activitypub_object_headers() +     }} +  end + +  def get("https://p.helene.moe/users/helene", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: File.read!("test/fixtures/tesla_mock/helene@p.helene.moe.json"), +       headers: activitypub_object_headers() +     }} +  end + +  def get("https://mk.absturztau.be/notes/93e7nm8wqg", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: File.read!("test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json"), +       headers: activitypub_object_headers() +     }} +  end + +  def get("https://mk.absturztau.be/notes/93e7nm8wqg/activity", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: File.read!("test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json"), +       headers: activitypub_object_headers() +     }} +  end + +  def get("https://p.helene.moe/objects/fd5910ac-d9dc-412e-8d1d-914b203296c4", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: File.read!("test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json"), +       headers: activitypub_object_headers() +     }} +  end +    def get(url, query, body, headers) do      {:error,       "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"} diff --git a/test/support/websocket_client.ex b/test/support/websocket_client.ex index d149b324e..7163bbd41 100644 --- a/test/support/websocket_client.ex +++ b/test/support/websocket_client.ex @@ -5,18 +5,17 @@  defmodule Pleroma.Integration.WebsocketClient do    # https://github.com/phoenixframework/phoenix/blob/master/test/support/websocket_client.exs +  use WebSockex +    @doc """    Starts the WebSocket server for given ws URL. Received Socket.Message's    are forwarded to the sender pid    """    def start_link(sender, url, headers \\ []) do -    :crypto.start() -    :ssl.start() - -    :websocket_client.start_link( -      String.to_charlist(url), +    WebSockex.start_link( +      url,        __MODULE__, -      [sender], +      %{sender: sender},        extra_headers: headers      )    end @@ -36,27 +35,32 @@ defmodule Pleroma.Integration.WebsocketClient do    end    @doc false -  def init([sender], _conn_state) do -    {:ok, %{sender: sender}} +  @impl true +  def handle_frame(frame, state) do +    send(state.sender, frame) +    {:ok, state}    end -  @doc false -  def websocket_handle(frame, _conn_state, state) do -    send(state.sender, frame) +  @impl true +  def handle_disconnect(conn_status, state) do +    send(state.sender, {:close, conn_status})      {:ok, state}    end    @doc false -  def websocket_info({:text, msg}, _conn_state, state) do +  @impl true +  def handle_info({:text, msg}, state) do      {:reply, {:text, msg}, state}    end -  def websocket_info(:close, _conn_state, _state) do +  @impl true +  def handle_info(:close, _state) do      {:close, <<>>, "done"}    end    @doc false -  def websocket_terminate(_reason, _conn_state, _state) do +  @impl true +  def terminate(_reason, _state) do      :ok    end  end | 
