diff options
| author | marcin mikołajczak <git@mkljczk.pl> | 2024-07-28 13:41:58 +0200 | 
|---|---|---|
| committer | marcin mikołajczak <git@mkljczk.pl> | 2024-07-28 13:41:58 +0200 | 
| commit | ad8c26f6c285412be041b7dcaeefa8741d3a6e57 (patch) | |
| tree | 041e9af5f9b64215f12d195d6c98b548b0c1b622 /test/support | |
| parent | 7620b520c13a1c204810cf0cfe6a7b70b9a1c59d (diff) | |
| parent | 6876761837bad399758cd6a93be5bf5cc8a81cef (diff) | |
| download | pleroma-ad8c26f6c285412be041b7dcaeefa8741d3a6e57.tar.gz pleroma-ad8c26f6c285412be041b7dcaeefa8741d3a6e57.zip  | |
Merge remote-tracking branch 'origin/develop' into post-languages
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/data_case.ex | 1 | ||||
| -rw-r--r-- | test/support/factory.ex | 1 | ||||
| -rw-r--r-- | test/support/http_request_mock.ex | 116 | ||||
| -rw-r--r-- | test/support/http_signatures_proxy.ex | 9 | ||||
| -rw-r--r-- | test/support/mocks.ex | 1 | 
5 files changed, 127 insertions, 1 deletions
diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 14403f0b8..52d4bef1a 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -116,6 +116,7 @@ defmodule Pleroma.DataCase do      Mox.stub_with(Pleroma.Web.FederatorMock, Pleroma.Web.Federator)      Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config)      Mox.stub_with(Pleroma.StaticStubbedConfigMock, Pleroma.Test.StaticConfig) +    Mox.stub_with(Pleroma.StubbedHTTPSignaturesMock, Pleroma.Test.HTTPSignaturesProxy)    end    def ensure_local_uploader(context) do diff --git a/test/support/factory.ex b/test/support/factory.ex index 20bc5162e..b248508fa 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -249,6 +249,7 @@ defmodule Pleroma.Factory do        "cc" => [user.follower_address],        "context" => Pleroma.Web.ActivityPub.Utils.generate_context_id(),        "closed" => DateTime.utc_now() |> DateTime.add(86_400) |> DateTime.to_iso8601(), +      "content" => "Which flavor of ice cream do you prefer?",        "oneOf" => [          %{            "type" => "Note", diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index f656c9412..ed044cf98 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -1521,6 +1521,120 @@ defmodule HttpRequestMock do       }}    end +  def get("https://mastodon.example/.well-known/host-meta", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 302, +       headers: [{"location", "https://sub.mastodon.example/.well-known/host-meta"}] +     }} +  end + +  def get("https://sub.mastodon.example/.well-known/host-meta", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: +         "test/fixtures/webfinger/masto-host-meta.xml" +         |> File.read!() +         |> String.replace("{{domain}}", "sub.mastodon.example") +     }} +  end + +  def get( +        "https://sub.mastodon.example/.well-known/webfinger?resource=acct:a@mastodon.example", +        _, +        _, +        _ +      ) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: +         "test/fixtures/webfinger/masto-webfinger.json" +         |> File.read!() +         |> String.replace("{{nickname}}", "a") +         |> String.replace("{{domain}}", "mastodon.example") +         |> String.replace("{{subdomain}}", "sub.mastodon.example"), +       headers: [{"content-type", "application/jrd+json"}] +     }} +  end + +  def get("https://sub.mastodon.example/users/a", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: +         "test/fixtures/webfinger/masto-user.json" +         |> File.read!() +         |> String.replace("{{nickname}}", "a") +         |> String.replace("{{domain}}", "sub.mastodon.example"), +       headers: [{"content-type", "application/activity+json"}] +     }} +  end + +  def get("https://sub.mastodon.example/users/a/collections/featured", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: +         File.read!("test/fixtures/users_mock/masto_featured.json") +         |> String.replace("{{domain}}", "sub.mastodon.example") +         |> String.replace("{{nickname}}", "a"), +       headers: [{"content-type", "application/activity+json"}] +     }} +  end + +  def get("https://pleroma.example/.well-known/host-meta", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 302, +       headers: [{"location", "https://sub.pleroma.example/.well-known/host-meta"}] +     }} +  end + +  def get("https://sub.pleroma.example/.well-known/host-meta", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: +         "test/fixtures/webfinger/pleroma-host-meta.xml" +         |> File.read!() +         |> String.replace("{{domain}}", "sub.pleroma.example") +     }} +  end + +  def get( +        "https://sub.pleroma.example/.well-known/webfinger?resource=acct:a@pleroma.example", +        _, +        _, +        _ +      ) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: +         "test/fixtures/webfinger/pleroma-webfinger.json" +         |> File.read!() +         |> String.replace("{{nickname}}", "a") +         |> String.replace("{{domain}}", "pleroma.example") +         |> String.replace("{{subdomain}}", "sub.pleroma.example"), +       headers: [{"content-type", "application/jrd+json"}] +     }} +  end + +  def get("https://sub.pleroma.example/users/a", _, _, _) do +    {:ok, +     %Tesla.Env{ +       status: 200, +       body: +         "test/fixtures/webfinger/pleroma-user.json" +         |> File.read!() +         |> String.replace("{{nickname}}", "a") +         |> String.replace("{{domain}}", "sub.pleroma.example"), +       headers: [{"content-type", "application/activity+json"}] +     }} +  end +    def get(url, query, body, headers) do      {:error,       "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"} @@ -1610,7 +1724,7 @@ defmodule HttpRequestMock do    ]    def head(url, _query, _body, _headers) when url in @rich_media_mocks do -    {:ok, %Tesla.Env{status: 404, body: ""}} +    {:ok, %Tesla.Env{status: 200, body: ""}}    end    def head("https://example.com/pdf-file", _, _, _) do diff --git a/test/support/http_signatures_proxy.ex b/test/support/http_signatures_proxy.ex new file mode 100644 index 000000000..4c6b39d19 --- /dev/null +++ b/test/support/http_signatures_proxy.ex @@ -0,0 +1,9 @@ +defmodule Pleroma.Test.HTTPSignaturesProxy do +  @behaviour Pleroma.HTTPSignaturesAPI + +  @impl true +  defdelegate validate_conn(conn), to: HTTPSignatures + +  @impl true +  defdelegate signature_for_conn(conn), to: HTTPSignatures +end diff --git a/test/support/mocks.ex b/test/support/mocks.ex index d906f0e1d..63cbc49ab 100644 --- a/test/support/mocks.ex +++ b/test/support/mocks.ex @@ -28,6 +28,7 @@ Mox.defmock(Pleroma.Web.FederatorMock, for: Pleroma.Web.Federator.Publishing)  Mox.defmock(Pleroma.ConfigMock, for: Pleroma.Config.Getting)  Mox.defmock(Pleroma.UnstubbedConfigMock, for: Pleroma.Config.Getting)  Mox.defmock(Pleroma.StaticStubbedConfigMock, for: Pleroma.Config.Getting) +Mox.defmock(Pleroma.StubbedHTTPSignaturesMock, for: Pleroma.HTTPSignaturesAPI)  Mox.defmock(Pleroma.LoggerMock, for: Pleroma.Logging)  | 
