diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/support/http_request_mock.ex | 17 | ||||
| -rw-r--r-- | test/user_test.exs | 39 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 8 | ||||
| -rw-r--r-- | test/web/rich_media/parser_test.exs | 29 | 
4 files changed, 93 insertions, 0 deletions
| diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 344e27f13..cb022333f 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -1262,4 +1262,21 @@ defmodule HttpRequestMock do         inspect(headers)       }"}    end + +  # Most of the rich media mocks are missing HEAD requests, so we just return 404. +  @rich_media_mocks [ +    "https://example.com/ogp", +    "https://example.com/ogp-missing-data", +    "https://example.com/twitter-card" +  ] +  def head(url, _query, _body, _headers) when url in @rich_media_mocks do +    {:ok, %Tesla.Env{status: 404, body: ""}} +  end + +  def head(url, query, body, headers) do +    {:error, +     "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{ +       inspect(headers) +     }"} +  end  end diff --git a/test/user_test.exs b/test/user_test.exs index 50f72549e..a910226b2 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -440,6 +440,45 @@ defmodule Pleroma.UserTest do        assert activity.actor == welcome_user.ap_id      end +    setup do: +            clear_config(:mrf_simple, +              media_removal: [], +              media_nsfw: [], +              federated_timeline_removal: [], +              report_removal: [], +              reject: [], +              followers_only: [], +              accept: [], +              avatar_removal: [], +              banner_removal: [], +              reject_deletes: [] +            ) + +    setup do: +            clear_config(:mrf, +              policies: [ +                Pleroma.Web.ActivityPub.MRF.SimplePolicy +              ] +            ) + +    test "it sends a welcome chat message when Simple policy applied to local instance" do +      Pleroma.Config.put([:mrf_simple, :media_nsfw], ["localhost"]) + +      welcome_user = insert(:user) +      Pleroma.Config.put([:welcome, :chat_message, :enabled], true) +      Pleroma.Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname) +      Pleroma.Config.put([:welcome, :chat_message, :message], "Hello, this is a chat message") + +      cng = User.register_changeset(%User{}, @full_user_data) +      {:ok, registered_user} = User.register(cng) +      ObanHelpers.perform_all() + +      activity = Repo.one(Pleroma.Activity) +      assert registered_user.ap_id in activity.recipients +      assert Object.normalize(activity).data["content"] =~ "chat message" +      assert activity.actor == welcome_user.ap_id +    end +      test "it sends a welcome email message if it is set" do        welcome_user = insert(:user)        Pleroma.Config.put([:welcome, :email, :enabled], true) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index d8caa0b00..7bdad3810 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -1810,6 +1810,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do          |> Enum.map(& &1.id)        assert activities_ids == [] + +      activities_ids = +        %{} +        |> Map.put(:reply_visibility, "self") +        |> Map.put(:reply_filtering_user, nil) +        |> ActivityPub.fetch_public_activities() + +      assert activities_ids == []      end      test "home timeline", %{users: %{u1: user}} do diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs index 21ae35f8b..6d00c2af5 100644 --- a/test/web/rich_media/parser_test.exs +++ b/test/web/rich_media/parser_test.exs @@ -56,6 +56,27 @@ defmodule Pleroma.Web.RichMedia.ParserTest do        %{method: :get, url: "http://example.com/error"} ->          {:error, :overload} + +      %{ +        method: :head, +        url: "http://example.com/huge-page" +      } -> +        %Tesla.Env{ +          status: 200, +          headers: [{"content-length", "2000001"}, {"content-type", "text/html"}] +        } + +      %{ +        method: :head, +        url: "http://example.com/pdf-file" +      } -> +        %Tesla.Env{ +          status: 200, +          headers: [{"content-length", "1000000"}, {"content-type", "application/pdf"}] +        } + +      %{method: :head} -> +        %Tesla.Env{status: 404, body: "", headers: []}      end)      :ok @@ -144,4 +165,12 @@ defmodule Pleroma.Web.RichMedia.ParserTest do    test "returns error if getting page was not successful" do      assert {:error, :overload} = Parser.parse("http://example.com/error")    end + +  test "does a HEAD request to check if the body is too large" do +    assert {:error, :body_too_large} = Parser.parse("http://example.com/huge-page") +  end + +  test "does a HEAD request to check if the body is html" do +    assert {:error, {:content_type, _}} = Parser.parse("http://example.com/pdf-file") +  end  end | 
