diff options
Diffstat (limited to 'test')
19 files changed, 237 insertions, 103 deletions
| diff --git a/test/fixtures/modules/good_mrf.ex b/test/fixtures/modules/good_mrf.ex new file mode 100644 index 000000000..39d0f14ec --- /dev/null +++ b/test/fixtures/modules/good_mrf.ex @@ -0,0 +1,19 @@ +defmodule Fixtures.Modules.GoodMRF do +  @behaviour Pleroma.Web.ActivityPub.MRF + +  @impl true +  def filter(a), do: {:ok, a} + +  @impl true +  def describe, do: %{} + +  @impl true +  def config_description do +    %{ +      key: :good_mrf, +      related_policy: "Fixtures.Modules.GoodMRF", +      label: "Good MRF", +      description: "Some description" +    } +  end +end diff --git a/test/mix/tasks/pleroma/instance_test.exs b/test/mix/tasks/pleroma/instance_test.exs index fe69a2def..8a02710ee 100644 --- a/test/mix/tasks/pleroma/instance_test.exs +++ b/test/mix/tasks/pleroma/instance_test.exs @@ -5,8 +5,6 @@  defmodule Mix.Tasks.Pleroma.InstanceTest do    use ExUnit.Case -  @release_env_file "./test/pleroma.test.env" -    setup do      File.mkdir_p!(tmp_path()) @@ -18,8 +16,6 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do          File.rm_rf(Path.join(static_dir, "robots.txt"))        end -      if File.exists?(@release_env_file), do: File.rm_rf(@release_env_file) -        Pleroma.Config.put([:instance, :static_dir], static_dir)      end) @@ -73,9 +69,7 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do          "--dedupe-uploads",          "n",          "--anonymize-uploads", -        "n", -        "--release-env-file", -        @release_env_file +        "n"        ])      end @@ -97,9 +91,6 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do      assert generated_config =~ "filters: [Pleroma.Upload.Filter.ExifTool]"      assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()      assert File.exists?(Path.expand("./test/instance/static/robots.txt")) -    assert File.exists?(@release_env_file) - -    assert File.read!(@release_env_file) =~ ~r/^RELEASE_COOKIE=.*/    end    defp generated_setup_psql do diff --git a/test/mix/tasks/pleroma/release_env_test.exs b/test/mix/tasks/pleroma/release_env_test.exs deleted file mode 100644 index 519f1eba9..000000000 --- a/test/mix/tasks/pleroma/release_env_test.exs +++ /dev/null @@ -1,30 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Mix.Tasks.Pleroma.ReleaseEnvTest do -  use ExUnit.Case -  import ExUnit.CaptureIO, only: [capture_io: 1] - -  @path "config/pleroma.test.env" - -  def do_clean do -    if File.exists?(@path) do -      File.rm_rf(@path) -    end -  end - -  setup do -    do_clean() -    on_exit(fn -> do_clean() end) -    :ok -  end - -  test "generate pleroma.env" do -    assert capture_io(fn -> -             Mix.Tasks.Pleroma.ReleaseEnv.run(["gen", "--path", @path, "--force"]) -           end) =~ "The file generated" - -    assert File.read!(@path) =~ "RELEASE_COOKIE=" -  end -end diff --git a/test/pleroma/activity/ir/topics_test.exs b/test/pleroma/activity/ir/topics_test.exs index 4ddcea1ec..5e5c2f8da 100644 --- a/test/pleroma/activity/ir/topics_test.exs +++ b/test/pleroma/activity/ir/topics_test.exs @@ -97,6 +97,20 @@ defmodule Pleroma.Activity.Ir.TopicsTest do        refute Enum.member?(topics, "hashtag:2")      end + +    test "non-local action produces public:remote topic", %{activity: activity} do +      activity = %{activity | local: false, actor: "https://lain.com/users/lain"} +      topics = Topics.get_activity_topics(activity) + +      assert Enum.member?(topics, "public:remote:lain.com") +    end + +    test "local action doesn't produce public:remote topic", %{activity: activity} do +      activity = %{activity | local: true, actor: "https://lain.com/users/lain"} +      topics = Topics.get_activity_topics(activity) + +      refute Enum.member?(topics, "public:remote:lain.com") +    end    end    describe "public visibility create events with attachments" do @@ -128,6 +142,13 @@ defmodule Pleroma.Activity.Ir.TopicsTest do        refute Enum.member?(topics, "public:local:media")      end + +    test "non-local action produces public:remote:media topic", %{activity: activity} do +      activity = %{activity | local: false, actor: "https://lain.com/users/lain"} +      topics = Topics.get_activity_topics(activity) + +      assert Enum.member?(topics, "public:remote:media:lain.com") +    end    end    describe "non-public visibility" do diff --git a/test/pleroma/emails/admin_email_test.exs b/test/pleroma/emails/admin_email_test.exs index 155057f3e..0da0699cc 100644 --- a/test/pleroma/emails/admin_email_test.exs +++ b/test/pleroma/emails/admin_email_test.exs @@ -19,8 +19,8 @@ defmodule Pleroma.Emails.AdminEmailTest do        AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")      status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12") -    reporter_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id) -    account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id) +    reporter_url = reporter.ap_id +    account_url = account.ap_id      assert res.to == [{to_user.name, to_user.email}]      assert res.from == {config[:name], config[:notify_email]} @@ -54,7 +54,7 @@ defmodule Pleroma.Emails.AdminEmailTest do      res = AdminEmail.new_unapproved_registration(to_user, account) -    account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id) +    account_url = account.ap_id      assert res.to == [{to_user.name, to_user.email}]      assert res.from == {config[:name], config[:notify_email]} diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs index 0f2e6cc2b..bb8e795b7 100644 --- a/test/pleroma/integration/mastodon_websocket_test.exs +++ b/test/pleroma/integration/mastodon_websocket_test.exs @@ -49,6 +49,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do    test "allows public streams without authentication" do      assert {:ok, _} = start_socket("?stream=public")      assert {:ok, _} = start_socket("?stream=public:local") +    assert {:ok, _} = start_socket("?stream=public:remote&instance=lain.com")      assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")    end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index a74fb7bc2..92c0bc8b6 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -229,7 +229,7 @@ defmodule Pleroma.NotificationTest do        muter = insert(:user)        muted = insert(:user) -      {:ok, _user_relationships} = User.mute(muter, muted, false) +      {:ok, _user_relationships} = User.mute(muter, muted, %{notifications: false})        {:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"}) @@ -1015,7 +1015,7 @@ defmodule Pleroma.NotificationTest do      test "it returns notifications for muted user without notifications", %{user: user} do        muted = insert(:user) -      {:ok, _user_relationships} = User.mute(user, muted, false) +      {:ok, _user_relationships} = User.mute(user, muted, %{notifications: false})        {:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"}) diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 9ae52d594..c678dadb3 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -1008,6 +1008,27 @@ defmodule Pleroma.UserTest do        assert User.muted_notifications?(user, muted_user)      end +    test "expiring" do +      user = insert(:user) +      muted_user = insert(:user) + +      {:ok, _user_relationships} = User.mute(user, muted_user, %{expires_in: 60}) +      assert User.mutes?(user, muted_user) + +      worker = Pleroma.Workers.MuteExpireWorker +      args = %{"op" => "unmute_user", "muter_id" => user.id, "mutee_id" => muted_user.id} + +      assert_enqueued( +        worker: worker, +        args: args +      ) + +      assert :ok = perform_job(worker, args) + +      refute User.mutes?(user, muted_user) +      refute User.muted_notifications?(user, muted_user) +    end +      test "it unmutes users" do        user = insert(:user)        muted_user = insert(:user) @@ -1019,6 +1040,17 @@ defmodule Pleroma.UserTest do        refute User.muted_notifications?(user, muted_user)      end +    test "it unmutes users by id" do +      user = insert(:user) +      muted_user = insert(:user) + +      {:ok, _user_relationships} = User.mute(user, muted_user) +      {:ok, _user_mute} = User.unmute(user.id, muted_user.id) + +      refute User.mutes?(user, muted_user) +      refute User.muted_notifications?(user, muted_user) +    end +      test "it mutes user without notifications" do        user = insert(:user)        muted_user = insert(:user) @@ -1026,7 +1058,7 @@ defmodule Pleroma.UserTest do        refute User.mutes?(user, muted_user)        refute User.muted_notifications?(user, muted_user) -      {:ok, _user_relationships} = User.mute(user, muted_user, false) +      {:ok, _user_relationships} = User.mute(user, muted_user, %{notifications: false})        assert User.mutes?(user, muted_user)        refute User.muted_notifications?(user, muted_user) diff --git a/test/pleroma/web/activity_pub/mrf_test.exs b/test/pleroma/web/activity_pub/mrf_test.exs index e8cdde2e1..44a9cf086 100644 --- a/test/pleroma/web/activity_pub/mrf_test.exs +++ b/test/pleroma/web/activity_pub/mrf_test.exs @@ -87,4 +87,20 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do        {:ok, ^expected} = MRF.describe()      end    end + +  test "config_descriptions/0" do +    descriptions = MRF.config_descriptions() + +    good_mrf = Enum.find(descriptions, fn %{key: key} -> key == :good_mrf end) + +    assert good_mrf == %{ +             key: :good_mrf, +             related_policy: "Fixtures.Modules.GoodMRF", +             label: "Good MRF", +             description: "Some description", +             group: :pleroma, +             tab: :mrf, +             type: :group +           } +  end  end diff --git a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs index 74140b7bc..c06ae55ca 100644 --- a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs @@ -844,8 +844,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    describe "instances" do      test "GET /instances/:instance/statuses", %{conn: conn} do -      user = insert(:user, local: false, nickname: "archaeme@archae.me") -      user2 = insert(:user, local: false, nickname: "test@test.com") +      user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme") +      user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")        insert_pair(:note_activity, user: user)        activity = insert(:note_activity, user: user2) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index c5b90ad84..8e87e69fe 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -3,8 +3,8 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.CommonAPITest do -  use Pleroma.DataCase    use Oban.Testing, repo: Pleroma.Repo +  use Pleroma.DataCase    alias Pleroma.Activity    alias Pleroma.Chat @@ -922,12 +922,34 @@ defmodule Pleroma.Web.CommonAPITest do        assert CommonAPI.thread_muted?(user, activity)      end +    test "add expiring mute", %{user: user, activity: activity} do +      {:ok, _} = CommonAPI.add_mute(user, activity, %{expires_in: 60}) +      assert CommonAPI.thread_muted?(user, activity) + +      worker = Pleroma.Workers.MuteExpireWorker +      args = %{"op" => "unmute_conversation", "user_id" => user.id, "activity_id" => activity.id} + +      assert_enqueued( +        worker: worker, +        args: args +      ) + +      assert :ok = perform_job(worker, args) +      refute CommonAPI.thread_muted?(user, activity) +    end +      test "remove mute", %{user: user, activity: activity} do        CommonAPI.add_mute(user, activity)        {:ok, _} = CommonAPI.remove_mute(user, activity)        refute CommonAPI.thread_muted?(user, activity)      end +    test "remove mute by ids", %{user: user, activity: activity} do +      CommonAPI.add_mute(user, activity) +      {:ok, _} = CommonAPI.remove_mute(user.id, activity.id) +      refute CommonAPI.thread_muted?(user, activity) +    end +      test "check that mutes can't be duplicate", %{user: user, activity: activity} do        CommonAPI.add_mute(user, activity)        {:error, _} = CommonAPI.add_mute(user, activity) diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs index eabfe3a63..16f002717 100644 --- a/test/pleroma/web/feed/user_controller_test.exs +++ b/test/pleroma/web/feed/user_controller_test.exs @@ -12,16 +12,17 @@ defmodule Pleroma.Web.Feed.UserControllerTest do    alias Pleroma.Object    alias Pleroma.User    alias Pleroma.Web.CommonAPI +  alias Pleroma.Web.Feed.FeedView    setup do: clear_config([:static_fe, :enabled], false)    describe "feed" do      setup do: clear_config([:feed]) -    test "gets an atom feed", %{conn: conn} do +    setup do        Config.put(          [:feed, :post_title], -        %{max_length: 10, omission: "..."} +        %{max_length: 15, omission: "..."}        )        activity = insert(:note_activity) @@ -29,7 +30,8 @@ defmodule Pleroma.Web.Feed.UserControllerTest do        note =          insert(:note,            data: %{ -            "content" => "This is :moominmamma: note ", +            "content" => "This & this is :moominmamma: note ", +            "source" => "This & this is :moominmamma: note ",              "attachment" => [                %{                  "url" => [ @@ -37,7 +39,9 @@ defmodule Pleroma.Web.Feed.UserControllerTest do                  ]                }              ], -            "inReplyTo" => activity.data["id"] +            "inReplyTo" => activity.data["id"], +            "context" => "2hu & as", +            "summary" => "2hu & as"            }          ) @@ -48,7 +52,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do          insert(:note,            user: user,            data: %{ -            "content" => "42 This is :moominmamma: note ", +            "content" => "42 & This is :moominmamma: note ",              "inReplyTo" => activity.data["id"]            }          ) @@ -56,6 +60,10 @@ defmodule Pleroma.Web.Feed.UserControllerTest do        note_activity2 = insert(:note_activity, note: note2)        object = Object.normalize(note_activity) +      [user: user, object: object, max_id: note_activity2.id] +    end + +    test "gets an atom feed", %{conn: conn, user: user, object: object, max_id: max_id} do        resp =          conn          |> put_req_header("accept", "application/atom+xml") @@ -67,13 +75,15 @@ defmodule Pleroma.Web.Feed.UserControllerTest do          |> SweetXml.parse()          |> SweetXml.xpath(~x"//entry/title/text()"l) -      assert activity_titles == ['42 This...', 'This is...'] -      assert resp =~ object.data["content"] +      assert activity_titles == ['42 & Thi...', 'This & t...'] +      assert resp =~ FeedView.escape(object.data["content"]) +      assert resp =~ FeedView.escape(object.data["summary"]) +      assert resp =~ FeedView.escape(object.data["context"])        resp =          conn          |> put_req_header("accept", "application/atom+xml") -        |> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id}) +        |> get("/users/#{user.nickname}/feed", %{"max_id" => max_id})          |> response(200)        activity_titles = @@ -81,47 +91,10 @@ defmodule Pleroma.Web.Feed.UserControllerTest do          |> SweetXml.parse()          |> SweetXml.xpath(~x"//entry/title/text()"l) -      assert activity_titles == ['This is...'] +      assert activity_titles == ['This & t...']      end -    test "gets a rss feed", %{conn: conn} do -      Pleroma.Config.put( -        [:feed, :post_title], -        %{max_length: 10, omission: "..."} -      ) - -      activity = insert(:note_activity) - -      note = -        insert(:note, -          data: %{ -            "content" => "This is :moominmamma: note ", -            "attachment" => [ -              %{ -                "url" => [ -                  %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"} -                ] -              } -            ], -            "inReplyTo" => activity.data["id"] -          } -        ) - -      note_activity = insert(:note_activity, note: note) -      user = User.get_cached_by_ap_id(note_activity.data["actor"]) - -      note2 = -        insert(:note, -          user: user, -          data: %{ -            "content" => "42 This is :moominmamma: note ", -            "inReplyTo" => activity.data["id"] -          } -        ) - -      note_activity2 = insert(:note_activity, note: note2) -      object = Object.normalize(note_activity) - +    test "gets a rss feed", %{conn: conn, user: user, object: object, max_id: max_id} do        resp =          conn          |> put_req_header("accept", "application/rss+xml") @@ -133,13 +106,15 @@ defmodule Pleroma.Web.Feed.UserControllerTest do          |> SweetXml.parse()          |> SweetXml.xpath(~x"//item/title/text()"l) -      assert activity_titles == ['42 This...', 'This is...'] -      assert resp =~ object.data["content"] +      assert activity_titles == ['42 & Thi...', 'This & t...'] +      assert resp =~ FeedView.escape(object.data["content"]) +      assert resp =~ FeedView.escape(object.data["summary"]) +      assert resp =~ FeedView.escape(object.data["context"])        resp =          conn          |> put_req_header("accept", "application/rss+xml") -        |> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id}) +        |> get("/users/#{user.nickname}/feed.rss", %{"max_id" => max_id})          |> response(200)        activity_titles = @@ -147,7 +122,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do          |> SweetXml.parse()          |> SweetXml.xpath(~x"//item/title/text()"l) -      assert activity_titles == ['This is...'] +      assert activity_titles == ['This & t...']      end      test "returns 404 for a missing feed", %{conn: conn} do diff --git a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs index 70ef0e8b5..5fd518c60 100644 --- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs @@ -502,7 +502,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      assert length(json_response_and_validate_schema(ret_conn, 200)) == 1 -    {:ok, _user_relationships} = User.mute(user, user2, false) +    {:ok, _user_relationships} = User.mute(user, user2, %{notifications: false})      conn = get(conn, "/api/v1/notifications") 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 9f1ee0424..4c08ad60a 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -147,6 +147,18 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        activities = json_response_and_validate_schema(res_conn, 200)        [%{"id" => ^activity_id}] = activities      end + +    test "can be filtered by instance", %{conn: conn} do +      user = insert(:user, ap_id: "https://lain.com/users/lain") +      insert(:note_activity, local: false) +      insert(:note_activity, local: false) + +      {:ok, _} = CommonAPI.post(user, %{status: "test"}) + +      conn = get(conn, "/api/v1/timelines/public?instance=lain.com") + +      assert length(json_response_and_validate_schema(conn, :ok)) == 1 +    end    end    defp local_and_remote_activities do diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 203e61c71..139e32362 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -277,7 +277,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        {:ok, user} = User.follow(user, other_user)        {:ok, other_user} = User.follow(other_user, user)        {:ok, _subscription} = User.subscribe(user, other_user) -      {:ok, _user_relationships} = User.mute(user, other_user, true) +      {:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true})        {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)        expected = diff --git a/test/pleroma/web/mastodon_api/views/poll_view_test.exs b/test/pleroma/web/mastodon_api/views/poll_view_test.exs index b7e2f17ef..c655ca438 100644 --- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs @@ -44,7 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do        ],        voted: false,        votes_count: 0, -      voters_count: nil +      voters_count: 0      }      result = PollView.render("show.json", %{object: object}) diff --git a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs index fa6b9db65..c1e6a8cc5 100644 --- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs @@ -343,6 +343,35 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do        assert length(result) == 0      end +    test "it does not return chats with users you muted", %{conn: conn, user: user} do +      recipient = insert(:user) + +      {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id) + +      result = +        conn +        |> get("/api/v1/pleroma/chats") +        |> json_response_and_validate_schema(200) + +      assert length(result) == 1 + +      User.mute(user, recipient) + +      result = +        conn +        |> get("/api/v1/pleroma/chats") +        |> json_response_and_validate_schema(200) + +      assert length(result) == 0 + +      result = +        conn +        |> get("/api/v1/pleroma/chats?with_muted=true") +        |> json_response_and_validate_schema(200) + +      assert length(result) == 1 +    end +      test "it returns all chats", %{conn: conn, user: user} do        Enum.each(1..30, fn _ ->          recipient = insert(:user) diff --git a/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs new file mode 100644 index 000000000..13491ed9c --- /dev/null +++ b/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs @@ -0,0 +1,38 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.PleromaApi.InstancesControllerTest do +  use Pleroma.Web.ConnCase + +  alias Pleroma.Instances + +  setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1) + +  setup do +    constant = "http://consistently-unreachable.name/" +    eventual = "http://eventually-unreachable.com/path" + +    {:ok, %Pleroma.Instances.Instance{unreachable_since: constant_unreachable}} = +      Instances.set_consistently_unreachable(constant) + +    _eventual_unrechable = Instances.set_unreachable(eventual) + +    %{constant_unreachable: constant_unreachable, constant: constant} +  end + +  test "GET /api/v1/pleroma/federation_status", %{ +    conn: conn, +    constant_unreachable: constant_unreachable, +    constant: constant +  } do +    constant_host = URI.parse(constant).host + +    assert conn +           |> put_req_header("content-type", "application/json") +           |> get("/api/v1/pleroma/federation_status") +           |> json_response_and_validate_schema(200) == %{ +             "unreachable" => %{constant_host => to_string(constant_unreachable)} +           } +  end +end diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index 395016da2..0d89e01d0 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -29,6 +29,14 @@ defmodule Pleroma.Web.StreamerTest do        assert {:ok, "public:local:media"} = Streamer.get_topic("public:local:media", nil, nil)      end +    test "allows instance streams" do +      assert {:ok, "public:remote:lain.com"} = +               Streamer.get_topic("public:remote", nil, nil, %{"instance" => "lain.com"}) + +      assert {:ok, "public:remote:media:lain.com"} = +               Streamer.get_topic("public:remote:media", nil, nil, %{"instance" => "lain.com"}) +    end +      test "allows hashtag streams" do        assert {:ok, "hashtag:cofe"} = Streamer.get_topic("hashtag", nil, nil, %{"tag" => "cofe"})      end | 
