diff options
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 8 | ||||
| -rw-r--r-- | test/web/activity_pub/pipeline_test.exs | 16 | ||||
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 11 | ||||
| -rw-r--r-- | test/web/pleroma_api/controllers/chat_controller_test.exs | 19 | ||||
| -rw-r--r-- | test/web/rich_media/parser_test.exs | 29 | 
5 files changed, 74 insertions, 9 deletions
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 03f968aaf..b579bb0bb 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -1773,6 +1773,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/activity_pub/pipeline_test.exs b/test/web/activity_pub/pipeline_test.exs index f2a231eaf..210a06563 100644 --- a/test/web/activity_pub/pipeline_test.exs +++ b/test/web/activity_pub/pipeline_test.exs @@ -26,7 +26,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do          {            Pleroma.Web.ActivityPub.MRF,            [], -          [filter: fn o -> {:ok, o} end] +          [pipeline_filter: fn o, m -> {:ok, o, m} end]          },          {            Pleroma.Web.ActivityPub.ActivityPub, @@ -51,7 +51,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do                   Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)          assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) -        assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity)) +        assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))          assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))          assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))          refute called(Pleroma.Web.Federator.publish(activity)) @@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do          {            Pleroma.Web.ActivityPub.MRF,            [], -          [filter: fn o -> {:ok, o} end] +          [pipeline_filter: fn o, m -> {:ok, o, m} end]          },          {            Pleroma.Web.ActivityPub.ActivityPub, @@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do                   Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)          assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) -        assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity)) +        assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))          assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))          assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))          assert_called(Pleroma.Web.Federator.publish(activity)) @@ -109,7 +109,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do          {            Pleroma.Web.ActivityPub.MRF,            [], -          [filter: fn o -> {:ok, o} end] +          [pipeline_filter: fn o, m -> {:ok, o, m} end]          },          {            Pleroma.Web.ActivityPub.ActivityPub, @@ -131,7 +131,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do                   Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)          assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) -        assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity)) +        assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))          assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))          assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))        end @@ -148,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do          {            Pleroma.Web.ActivityPub.MRF,            [], -          [filter: fn o -> {:ok, o} end] +          [pipeline_filter: fn o, m -> {:ok, o, m} end]          },          {            Pleroma.Web.ActivityPub.ActivityPub, @@ -170,7 +170,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do                   Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)          assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) -        assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity)) +        assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))          assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))          assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))        end diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 4ba6232dc..28bb6db30 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -213,6 +213,17 @@ defmodule Pleroma.Web.CommonAPITest do        assert message == :content_too_long      end + +    test "it reject messages via MRF" do +      clear_config([:mrf_keyword, :reject], ["GNO"]) +      clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy]) + +      author = insert(:user) +      recipient = insert(:user) + +      assert {:reject, "[KeywordPolicy] Matches with rejected keyword"} == +               CommonAPI.post_chat_message(author, recipient, "GNO/Linux") +    end    end    describe "unblocking" do diff --git a/test/web/pleroma_api/controllers/chat_controller_test.exs b/test/web/pleroma_api/controllers/chat_controller_test.exs index 7be5fe09c..44a78a738 100644 --- a/test/web/pleroma_api/controllers/chat_controller_test.exs +++ b/test/web/pleroma_api/controllers/chat_controller_test.exs @@ -100,7 +100,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do          |> post("/api/v1/pleroma/chats/#{chat.id}/messages")          |> json_response_and_validate_schema(400) -      assert result +      assert %{"error" => "no_content"} == result      end      test "it works with an attachment", %{conn: conn, user: user} do @@ -126,6 +126,23 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do        assert result["attachment"]      end + +    test "gets MRF reason when rejected", %{conn: conn, user: user} do +      clear_config([:mrf_keyword, :reject], ["GNO"]) +      clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy]) + +      other_user = insert(:user) + +      {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id) + +      result = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/pleroma/chats/#{chat.id}/messages", %{"content" => "GNO/Linux"}) +        |> json_response_and_validate_schema(422) + +      assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} == result +    end    end    describe "DELETE /api/v1/pleroma/chats/:id/messages/:message_id" do diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs index 1e09cbf84..b8ef2cccf 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 @@ -146,4 +167,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  | 
