diff options
| author | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-11-27 21:24:19 +0000 | 
|---|---|---|
| committer | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-11-27 21:24:19 +0000 | 
| commit | 76bdb01c1835085b25c333e9fc1cc012db571d86 (patch) | |
| tree | 00cfad81ec7d262090b4ae1a2ed378630e5e906a /test | |
| parent | 59b8c920f62649b5b5902cf0e569749abe3d7991 (diff) | |
| parent | 2614f431b903065522e04b6bf1d32a2b79643139 (diff) | |
| download | pleroma-76bdb01c1835085b25c333e9fc1cc012db571d86.tar.gz pleroma-76bdb01c1835085b25c333e9fc1cc012db571d86.zip | |
Merge branch 'release/2.4.5' into 'stable'
Release 2.4.5
See merge request pleroma/pleroma!3793
Diffstat (limited to 'test')
10 files changed, 243 insertions, 16 deletions
| diff --git a/test/pleroma/activity/ir/topics_test.exs b/test/pleroma/activity/ir/topics_test.exs index 9c8e5d932..299fcae9d 100644 --- a/test/pleroma/activity/ir/topics_test.exs +++ b/test/pleroma/activity/ir/topics_test.exs @@ -13,6 +13,29 @@ defmodule Pleroma.Activity.Ir.TopicsTest do    import Mock +  describe "chat message" do +    test "Create produces no topics" do +      activity = %Activity{ +        object: %Object{data: %{"type" => "ChatMessage"}}, +        data: %{"type" => "Create"} +      } + +      assert [] == Topics.get_activity_topics(activity) +    end + +    test "Delete produces user and user:pleroma_chat" do +      activity = %Activity{ +        object: %Object{data: %{"type" => "ChatMessage"}}, +        data: %{"type" => "Delete"} +      } + +      topics = Topics.get_activity_topics(activity) +      assert [_, _] = topics +      assert "user" in topics +      assert "user:pleroma_chat" in topics +    end +  end +    describe "poll answer" do      test "produce no topics" do        activity = %Activity{object: %Object{data: %{"type" => "Answer"}}} @@ -114,6 +137,36 @@ defmodule Pleroma.Activity.Ir.TopicsTest do      end    end +  describe "local-public visibility create events" do +    setup do +      activity = %Activity{ +        object: %Object{data: %{"attachment" => []}}, +        data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]} +      } + +      {:ok, activity: activity} +    end + +    test "doesn't produce public topics", %{activity: activity} do +      topics = Topics.get_activity_topics(activity) + +      refute Enum.member?(topics, "public") +    end + +    test "produces public:local topics", %{activity: activity} do +      topics = Topics.get_activity_topics(activity) + +      assert Enum.member?(topics, "public:local") +    end + +    test "with no attachments doesn't produce public:media topics", %{activity: activity} do +      topics = Topics.get_activity_topics(activity) + +      refute Enum.member?(topics, "public:media") +      refute Enum.member?(topics, "public:local:media") +    end +  end +    describe "public visibility create events with attachments" do      setup do        activity = %Activity{ @@ -152,6 +205,29 @@ defmodule Pleroma.Activity.Ir.TopicsTest do      end    end +  describe "local-public visibility create events with attachments" do +    setup do +      activity = %Activity{ +        object: %Object{data: %{"attachment" => ["foo"]}}, +        data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]} +      } + +      {:ok, activity: activity} +    end + +    test "do not produce public:media topics", %{activity: activity} do +      topics = Topics.get_activity_topics(activity) + +      refute Enum.member?(topics, "public:media") +    end + +    test "produces public:local:media topics", %{activity: activity} do +      topics = Topics.get_activity_topics(activity) + +      assert Enum.member?(topics, "public:local:media") +    end +  end +    describe "non-public visibility" do      test "produces direct topic" do        activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}} diff --git a/test/pleroma/html_test.exs b/test/pleroma/html_test.exs index fe1a1ed57..a1e4bf457 100644 --- a/test/pleroma/html_test.exs +++ b/test/pleroma/html_test.exs @@ -17,6 +17,7 @@ defmodule Pleroma.HTMLTest do      this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>      this is a link with not allowed "rel" attribute: <a href="http://example.com/" rel="tag noallowed">example.com</a>      this is an image: <img src="http://example.com/image.jpg"><br /> +    this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"><br />      <script>alert('hacked')</script>    """ @@ -24,6 +25,10 @@ defmodule Pleroma.HTMLTest do    <img src="http://example.com/image.jpg" onerror="alert('hacked')">    """ +  @html_stillimage_sample """ +  <img class="still-image" src="http://example.com/image.jpg"> +  """ +    @html_span_class_sample """    <span class="animate-spin">hi</span>    """ @@ -45,6 +50,7 @@ defmodule Pleroma.HTMLTest do          this is a link with allowed "rel" attribute: example.com          this is a link with not allowed "rel" attribute: example.com          this is an image:  +        this is an inline emoji:           alert('hacked')        """ @@ -67,6 +73,7 @@ defmodule Pleroma.HTMLTest do          this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>          this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a>          this is an image: <img src="http://example.com/image.jpg"/><br/> +        this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"/><br/>          alert('hacked')        """ @@ -90,6 +97,15 @@ defmodule Pleroma.HTMLTest do                 HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.TwitterText)      end +    test "does not allow images with invalid classes" do +      expected = """ +      <img src="http://example.com/image.jpg"/> +      """ + +      assert expected == +               HTML.filter_tags(@html_stillimage_sample, Pleroma.HTML.Scrubber.TwitterText) +    end +      test "does allow microformats" do        expected = """        <span class="h-card"><a class="u-url mention">@<span>foo</span></a></span> @@ -121,6 +137,7 @@ defmodule Pleroma.HTMLTest do          this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>          this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a>          this is an image: <img src="http://example.com/image.jpg"/><br/> +        this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"/><br/>          alert('hacked')        """ @@ -143,6 +160,15 @@ defmodule Pleroma.HTMLTest do        assert expected == HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.Default)      end +    test "does not allow images with invalid classes" do +      expected = """ +      <img src="http://example.com/image.jpg"/> +      """ + +      assert expected == +               HTML.filter_tags(@html_stillimage_sample, Pleroma.HTML.Scrubber.TwitterText) +    end +      test "does allow microformats" do        expected = """        <span class="h-card"><a class="u-url mention">@<span>foo</span></a></span> diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 85f895f0f..5c2be9b5c 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -507,6 +507,25 @@ defmodule Pleroma.NotificationTest do      end    end +  describe "destroy_multiple_from_types/2" do +    test "clears all notifications of a certain type for a given user" do +      report_activity = insert(:report_activity) +      user1 = insert(:user, is_moderator: true, is_admin: true) +      user2 = insert(:user, is_moderator: true, is_admin: true) +      {:ok, _} = Notification.create_notifications(report_activity) + +      {:ok, _} = +        CommonAPI.post(user2, %{ +          status: "hey @#{user1.nickname} !" +        }) + +      Notification.destroy_multiple_from_types(user1, ["pleroma:report"]) + +      assert [%Pleroma.Notification{type: "mention"}] = Notification.for_user(user1) +      assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user2) +    end +  end +    describe "set_read_up_to()" do      test "it sets all notifications as read up to a specified notification ID" do        user = insert(:user) diff --git a/test/pleroma/signature_test.exs b/test/pleroma/signature_test.exs index 047c537e0..e3ae36b46 100644 --- a/test/pleroma/signature_test.exs +++ b/test/pleroma/signature_test.exs @@ -109,6 +109,11 @@ defmodule Pleroma.SignatureTest do                 {:ok, "https://example.com/users/1234"}      end +    test "it deduces the actor id for gotoSocial" do +      assert Signature.key_id_to_actor_id("https://example.com/users/1234/main-key") == +               {:ok, "https://example.com/users/1234"} +    end +      test "it calls webfinger for 'acct:' accounts" do        with_mock(Pleroma.Web.WebFinger,          finger: fn _ -> %{"ap_id" => "https://gensokyo.2hu/users/raymoo"} end diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 4021a565d..a6421890b 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -5,6 +5,7 @@  defmodule Pleroma.UserTest do    alias Pleroma.Activity    alias Pleroma.Builders.UserBuilder +  alias Pleroma.Notification    alias Pleroma.Object    alias Pleroma.Repo    alias Pleroma.Tests.ObanHelpers @@ -2123,6 +2124,26 @@ defmodule Pleroma.UserTest do        assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")        assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)      end + +    test "removes report notifs when user isn't superuser any more" do +      report_activity = insert(:report_activity) +      user = insert(:user, is_moderator: true, is_admin: true) +      {:ok, _} = Notification.create_notifications(report_activity) + +      assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user) + +      {:ok, user} = user |> User.admin_api_update(%{is_moderator: false}) +      # is still superuser because still admin +      assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user) + +      {:ok, user} = user |> User.admin_api_update(%{is_moderator: true, is_admin: false}) +      # is still superuser because still moderator +      assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user) + +      {:ok, user} = user |> User.admin_api_update(%{is_moderator: false}) +      # is not a superuser any more +      assert [] = Notification.for_user(user) +    end    end    describe "following/followers synchronization" do diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index 720c17d8d..917009912 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -32,4 +32,17 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest        %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)      end    end + +  test "a Note without replies/first/items validates" do +    insert(:user, ap_id: "https://mastodon.social/users/emelie") + +    note = +      "test/fixtures/tesla_mock/status.emelie.json" +      |> File.read!() +      |> Jason.decode!() +      |> pop_in(["replies", "first", "items"]) +      |> elem(1) + +    %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) +  end  end diff --git a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs index 0e49fda99..a72460296 100644 --- a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs @@ -27,6 +27,46 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do        assert attachment.mediaType == "application/octet-stream"      end +    test "works with an unknown but valid mime type" do +      attachment = %{ +        "mediaType" => "x-custom/x-type", +        "type" => "Document", +        "url" => "https://example.org" +      } + +      assert {:ok, attachment} = +               AttachmentValidator.cast_and_validate(attachment) +               |> Ecto.Changeset.apply_action(:insert) + +      assert attachment.mediaType == "x-custom/x-type" +    end + +    test "works with invalid mime types" do +      attachment = %{ +        "mediaType" => "x-customx-type", +        "type" => "Document", +        "url" => "https://example.org" +      } + +      assert {:ok, attachment} = +               AttachmentValidator.cast_and_validate(attachment) +               |> Ecto.Changeset.apply_action(:insert) + +      assert attachment.mediaType == "application/octet-stream" + +      attachment = %{ +        "mediaType" => "https://example.org", +        "type" => "Document", +        "url" => "https://example.org" +      } + +      assert {:ok, attachment} = +               AttachmentValidator.cast_and_validate(attachment) +               |> Ecto.Changeset.apply_action(:insert) + +      assert attachment.mediaType == "application/octet-stream" +    end +      test "it turns mastodon attachments into our attachments" do        attachment = %{          "url" => diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index 3036e25b3..9ffdda5b3 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -1664,21 +1664,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        |> get("/api/v1/mutes")        |> json_response_and_validate_schema(200) -    assert [id1, id2, id3] == Enum.map(result, & &1["id"]) +    assert [id3, id2, id1] == Enum.map(result, & &1["id"])      result =        conn        |> get("/api/v1/mutes?limit=1")        |> json_response_and_validate_schema(200) -    assert [%{"id" => ^id1}] = result +    assert [%{"id" => ^id3}] = result      result =        conn        |> get("/api/v1/mutes?since_id=#{id1}")        |> json_response_and_validate_schema(200) -    assert [%{"id" => ^id2}, %{"id" => ^id3}] = result +    assert [%{"id" => ^id3}, %{"id" => ^id2}] = result      result =        conn @@ -1692,7 +1692,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        |> get("/api/v1/mutes?since_id=#{id1}&limit=1")        |> json_response_and_validate_schema(200) -    assert [%{"id" => ^id2}] = result +    assert [%{"id" => ^id3}] = result    end    test "list of mutes with with_relationships parameter" do @@ -1711,7 +1711,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      assert [               %{ -               "id" => ^id1, +               "id" => ^id3,                 "pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}               },               %{ @@ -1719,7 +1719,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do                 "pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}               },               %{ -               "id" => ^id3, +               "id" => ^id1,                 "pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}               }             ] = @@ -1744,7 +1744,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        |> get("/api/v1/blocks")        |> json_response_and_validate_schema(200) -    assert [id1, id2, id3] == Enum.map(result, & &1["id"]) +    assert [id3, id2, id1] == Enum.map(result, & &1["id"])      result =        conn @@ -1752,7 +1752,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        |> get("/api/v1/blocks?limit=1")        |> json_response_and_validate_schema(200) -    assert [%{"id" => ^id1}] = result +    assert [%{"id" => ^id3}] = result      result =        conn @@ -1760,7 +1760,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        |> get("/api/v1/blocks?since_id=#{id1}")        |> json_response_and_validate_schema(200) -    assert [%{"id" => ^id2}, %{"id" => ^id3}] = result +    assert [%{"id" => ^id3}, %{"id" => ^id2}] = result      result =        conn @@ -1776,6 +1776,30 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        |> get("/api/v1/blocks?since_id=#{id1}&limit=1")        |> json_response_and_validate_schema(200) -    assert [%{"id" => ^id2}] = result +    assert [%{"id" => ^id3}] = result + +    conn_res = +      conn +      |> assign(:user, user) +      |> get("/api/v1/blocks?limit=2") + +    next_url = +      ~r{<.+?(?<link>/api[^>]+)>; rel=\"next\"} +      |> Regex.named_captures(get_resp_header(conn_res, "link") |> Enum.at(0)) +      |> Map.get("link") + +    result = +      conn_res +      |> json_response_and_validate_schema(200) + +    assert [%{"id" => ^id3}, %{"id" => ^id2}] = result + +    result = +      conn +      |> assign(:user, user) +      |> get(next_url) +      |> json_response_and_validate_schema(200) + +    assert [%{"id" => ^id1}] = result    end  end diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs index ed1286675..6abc55ea6 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -885,7 +885,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      end    end -  describe "hashtag timeline handling of :restrict_unauthenticated setting" do +  describe "hashtag timeline handling of restrict_unauthenticated setting" do      setup do        user = insert(:user)        {:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"}) diff --git a/test/pleroma/web/media_proxy/invalidation/script_test.exs b/test/pleroma/web/media_proxy/invalidation/script_test.exs index e9629b72b..a6f88114f 100644 --- a/test/pleroma/web/media_proxy/invalidation/script_test.exs +++ b/test/pleroma/web/media_proxy/invalidation/script_test.exs @@ -10,11 +10,14 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do    test "it logs error when script is not found" do      assert capture_log(fn -> -             assert Invalidation.Script.purge( -                      ["http://example.com/media/example.jpg"], -                      script_path: "./example" -                    ) == {:error, "%ErlangError{original: :enoent}"} -           end) =~ "Error while cache purge: %ErlangError{original: :enoent}" +             assert {:error, msg} = +                      Invalidation.Script.purge( +                        ["http://example.com/media/example.jpg"], +                        script_path: "./example" +                      ) + +             assert msg =~ ~r/%ErlangError{original: :enoent(, reason: nil)?}/ +           end) =~ ~r/Error while cache purge: %ErlangError{original: :enoent(, reason: nil)?}/      capture_log(fn ->        assert Invalidation.Script.purge( | 
