diff options
| author | Maksim Pechnikov <parallel588@gmail.com> | 2020-04-02 14:47:17 +0300 | 
|---|---|---|
| committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-04-02 14:47:17 +0300 | 
| commit | dbcfac11b45b367185a3b18a2db3e3fb07e8f20d (patch) | |
| tree | 039254a94616f04f4ea00e893bf0fb66dc06d9e8 /test/web | |
| parent | dfd2c741849e9afaf35e3ddbecbb50feb47f5d22 (diff) | |
| parent | fd932b14a7e7335a91a2acc2d6dd6fba7e2e90b3 (diff) | |
| download | pleroma-dbcfac11b45b367185a3b18a2db3e3fb07e8f20d.tar.gz pleroma-dbcfac11b45b367185a3b18a2db3e3fb07e8f20d.zip | |
Merge branch 'develop' into issue/1276
Diffstat (limited to 'test/web')
20 files changed, 167 insertions, 233 deletions
| diff --git a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs index 37a7bfcf7..fca0de7c6 100644 --- a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs +++ b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do diff --git a/test/web/activity_pub/mrf/anti_link_spam_policy_test.exs b/test/web/activity_pub/mrf/anti_link_spam_policy_test.exs index b524fdd23..1a13699be 100644 --- a/test/web/activity_pub/mrf/anti_link_spam_policy_test.exs +++ b/test/web/activity_pub/mrf/anti_link_spam_policy_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do @@ -110,6 +110,15 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do    end    describe "with unknown actors" do +    setup do +      Tesla.Mock.mock(fn +        %{method: :get, url: "http://invalid.actor"} -> +          %Tesla.Env{status: 500, body: ""} +      end) + +      :ok +    end +      test "it rejects posts without links" do        message =          @linkless_message diff --git a/test/web/activity_pub/mrf/ensure_re_prepended_test.exs b/test/web/activity_pub/mrf/ensure_re_prepended_test.exs index dbc8b9e80..38ddec5bb 100644 --- a/test/web/activity_pub/mrf/ensure_re_prepended_test.exs +++ b/test/web/activity_pub/mrf/ensure_re_prepended_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do diff --git a/test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs b/test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs index 63ed71129..64ea61dd4 100644 --- a/test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs +++ b/test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do diff --git a/test/web/activity_pub/mrf/normalize_markup_test.exs b/test/web/activity_pub/mrf/normalize_markup_test.exs index 0207be56b..9b39c45bd 100644 --- a/test/web/activity_pub/mrf/normalize_markup_test.exs +++ b/test/web/activity_pub/mrf/normalize_markup_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do diff --git a/test/web/activity_pub/mrf/object_age_policy_test.exs b/test/web/activity_pub/mrf/object_age_policy_test.exs index 0fbc5f57a..7ee195eeb 100644 --- a/test/web/activity_pub/mrf/object_age_policy_test.exs +++ b/test/web/activity_pub/mrf/object_age_policy_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do diff --git a/test/web/activity_pub/mrf/reject_non_public_test.exs b/test/web/activity_pub/mrf/reject_non_public_test.exs index abfd32df8..f36299b86 100644 --- a/test/web/activity_pub/mrf/reject_non_public_test.exs +++ b/test/web/activity_pub/mrf/reject_non_public_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do diff --git a/test/web/activity_pub/mrf/simple_policy_test.exs b/test/web/activity_pub/mrf/simple_policy_test.exs index 5aebbc675..91c24c2d9 100644 --- a/test/web/activity_pub/mrf/simple_policy_test.exs +++ b/test/web/activity_pub/mrf/simple_policy_test.exs @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs index 040625e4d..9e16e39c4 100644 --- a/test/web/activity_pub/relay_test.exs +++ b/test/web/activity_pub/relay_test.exs @@ -89,6 +89,11 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do            }          ) +      Tesla.Mock.mock(fn +        %{method: :get, url: "http://mastodon.example.org/eee/99541947525187367"} -> +          %Tesla.Env{status: 500, body: ""} +      end) +        assert capture_log(fn ->                 assert Relay.publish(activity) == {:error, nil}               end) =~ "[error] error: nil" diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index c9e228cc8..fe8a086d8 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -21,7 +21,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    alias Pleroma.UserInviteToken    alias Pleroma.Web.ActivityPub.Relay    alias Pleroma.Web.CommonAPI -  alias Pleroma.Web.MastodonAPI.StatusView    alias Pleroma.Web.MediaProxy    setup_all do @@ -1586,208 +1585,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end    end -  describe "GET /api/pleroma/admin/grouped_reports" do -    setup do -      [reporter, target_user] = insert_pair(:user) - -      date1 = (DateTime.to_unix(DateTime.utc_now()) + 1000) |> DateTime.from_unix!() -      date2 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!() -      date3 = (DateTime.to_unix(DateTime.utc_now()) + 3000) |> DateTime.from_unix!() - -      first_status = -        insert(:note_activity, user: target_user, data_attrs: %{"published" => date1}) - -      second_status = -        insert(:note_activity, user: target_user, data_attrs: %{"published" => date2}) - -      third_status = -        insert(:note_activity, user: target_user, data_attrs: %{"published" => date3}) - -      {:ok, first_report} = -        CommonAPI.report(reporter, %{ -          "account_id" => target_user.id, -          "status_ids" => [first_status.id, second_status.id, third_status.id] -        }) - -      {:ok, second_report} = -        CommonAPI.report(reporter, %{ -          "account_id" => target_user.id, -          "status_ids" => [first_status.id, second_status.id] -        }) - -      {:ok, third_report} = -        CommonAPI.report(reporter, %{ -          "account_id" => target_user.id, -          "status_ids" => [first_status.id] -        }) - -      %{ -        first_status: Activity.get_by_ap_id_with_object(first_status.data["id"]), -        second_status: Activity.get_by_ap_id_with_object(second_status.data["id"]), -        third_status: Activity.get_by_ap_id_with_object(third_status.data["id"]), -        first_report: first_report, -        first_status_reports: [first_report, second_report, third_report], -        second_status_reports: [first_report, second_report], -        third_status_reports: [first_report], -        target_user: target_user, -        reporter: reporter -      } -    end - -    test "returns reports grouped by status", %{ -      conn: conn, -      first_status: first_status, -      second_status: second_status, -      third_status: third_status, -      first_status_reports: first_status_reports, -      second_status_reports: second_status_reports, -      third_status_reports: third_status_reports, -      target_user: target_user, -      reporter: reporter -    } do -      response = -        conn -        |> get("/api/pleroma/admin/grouped_reports") -        |> json_response(:ok) - -      assert length(response["reports"]) == 3 - -      first_group = Enum.find(response["reports"], &(&1["status"]["id"] == first_status.id)) - -      second_group = Enum.find(response["reports"], &(&1["status"]["id"] == second_status.id)) - -      third_group = Enum.find(response["reports"], &(&1["status"]["id"] == third_status.id)) - -      assert length(first_group["reports"]) == 3 -      assert length(second_group["reports"]) == 2 -      assert length(third_group["reports"]) == 1 - -      assert first_group["date"] == -               Enum.max_by(first_status_reports, fn act -> -                 NaiveDateTime.from_iso8601!(act.data["published"]) -               end).data["published"] - -      assert first_group["status"] == -               Map.put( -                 stringify_keys(StatusView.render("show.json", %{activity: first_status})), -                 "deleted", -                 false -               ) - -      assert(first_group["account"]["id"] == target_user.id) - -      assert length(first_group["actors"]) == 1 -      assert hd(first_group["actors"])["id"] == reporter.id - -      assert Enum.map(first_group["reports"], & &1["id"]) -- -               Enum.map(first_status_reports, & &1.id) == [] - -      assert second_group["date"] == -               Enum.max_by(second_status_reports, fn act -> -                 NaiveDateTime.from_iso8601!(act.data["published"]) -               end).data["published"] - -      assert second_group["status"] == -               Map.put( -                 stringify_keys(StatusView.render("show.json", %{activity: second_status})), -                 "deleted", -                 false -               ) - -      assert second_group["account"]["id"] == target_user.id - -      assert length(second_group["actors"]) == 1 -      assert hd(second_group["actors"])["id"] == reporter.id - -      assert Enum.map(second_group["reports"], & &1["id"]) -- -               Enum.map(second_status_reports, & &1.id) == [] - -      assert third_group["date"] == -               Enum.max_by(third_status_reports, fn act -> -                 NaiveDateTime.from_iso8601!(act.data["published"]) -               end).data["published"] - -      assert third_group["status"] == -               Map.put( -                 stringify_keys(StatusView.render("show.json", %{activity: third_status})), -                 "deleted", -                 false -               ) - -      assert third_group["account"]["id"] == target_user.id - -      assert length(third_group["actors"]) == 1 -      assert hd(third_group["actors"])["id"] == reporter.id - -      assert Enum.map(third_group["reports"], & &1["id"]) -- -               Enum.map(third_status_reports, & &1.id) == [] -    end - -    test "reopened report renders status data", %{ -      conn: conn, -      first_report: first_report, -      first_status: first_status -    } do -      {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved") - -      response = -        conn -        |> get("/api/pleroma/admin/grouped_reports") -        |> json_response(:ok) - -      first_group = Enum.find(response["reports"], &(&1["status"]["id"] == first_status.id)) - -      assert first_group["status"] == -               Map.put( -                 stringify_keys(StatusView.render("show.json", %{activity: first_status})), -                 "deleted", -                 false -               ) -    end - -    test "reopened report does not render status data if status has been deleted", %{ -      conn: conn, -      first_report: first_report, -      first_status: first_status, -      target_user: target_user -    } do -      {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved") -      {:ok, _} = CommonAPI.delete(first_status.id, target_user) - -      refute Activity.get_by_ap_id(first_status.id) - -      response = -        conn -        |> get("/api/pleroma/admin/grouped_reports") -        |> json_response(:ok) - -      assert Enum.find(response["reports"], &(&1["status"]["deleted"] == true))["status"][ -               "deleted" -             ] == true - -      assert length(Enum.filter(response["reports"], &(&1["status"]["deleted"] == false))) == 2 -    end - -    test "account not empty if status was deleted", %{ -      conn: conn, -      first_report: first_report, -      first_status: first_status, -      target_user: target_user -    } do -      {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved") -      {:ok, _} = CommonAPI.delete(first_status.id, target_user) - -      refute Activity.get_by_ap_id(first_status.id) - -      response = -        conn -        |> get("/api/pleroma/admin/grouped_reports") -        |> json_response(:ok) - -      assert Enum.find(response["reports"], &(&1["status"]["deleted"] == true))["account"] -    end -  end -    describe "PUT /api/pleroma/admin/statuses/:id" do      setup do        activity = insert(:note_activity) @@ -2572,9 +2369,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end      test "common config example", %{conn: conn} do -      adapter = Application.get_env(:tesla, :adapter) -      on_exit(fn -> Application.put_env(:tesla, :adapter, adapter) end) -        conn =          post(conn, "/api/pleroma/admin/config", %{            configs: [ @@ -2587,23 +2381,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do                  %{"tuple" => [":seconds_valid", 60]},                  %{"tuple" => [":path", ""]},                  %{"tuple" => [":key1", nil]}, -                %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},                  %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},                  %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},                  %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},                  %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},                  %{"tuple" => [":name", "Pleroma"]}                ] -            }, -            %{ -              "group" => ":tesla", -              "key" => ":adapter", -              "value" => "Tesla.Adapter.Httpc"              }            ]          }) -      assert Application.get_env(:tesla, :adapter) == Tesla.Adapter.Httpc        assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"        assert json_response(conn, 200) == %{ @@ -2617,7 +2404,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do                       %{"tuple" => [":seconds_valid", 60]},                       %{"tuple" => [":path", ""]},                       %{"tuple" => [":key1", nil]}, -                     %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},                       %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},                       %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},                       %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]}, @@ -2630,19 +2416,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do                       ":seconds_valid",                       ":path",                       ":key1", -                     ":partial_chain",                       ":regex1",                       ":regex2",                       ":regex3",                       ":regex4",                       ":name"                     ] -                 }, -                 %{ -                   "group" => ":tesla", -                   "key" => ":adapter", -                   "value" => "Tesla.Adapter.Httpc", -                   "db" => [":adapter"]                   }                 ]               } diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index 45fc94522..d383d1714 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -472,6 +472,13 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do        activity = insert(:note_activity, user: user, note: object)        Pleroma.Repo.delete(object) +      obj_url = activity.data["object"] + +      Tesla.Mock.mock(fn +        %{method: :get, url: ^obj_url} -> +          %Tesla.Env{status: 404, body: ""} +      end) +        assert Utils.maybe_notify_mentioned_recipients(["test-test"], activity) == [                 "test-test"               ] diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs index 7a0011646..23f94e3a6 100644 --- a/test/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -452,11 +452,24 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      assert length(json_response(conn, 200)) == 1    end +  @tag capture_log: true    test "see move notifications" do      old_user = insert(:user)      new_user = insert(:user, also_known_as: [old_user.ap_id])      %{user: follower, conn: conn} = oauth_access(["read:notifications"]) +    old_user_url = old_user.ap_id + +    body = +      File.read!("test/fixtures/users_mock/localhost.json") +      |> String.replace("{{nickname}}", old_user.nickname) +      |> Jason.encode!() + +    Tesla.Mock.mock(fn +      %{method: :get, url: ^old_user_url} -> +        %Tesla.Env{status: 200, body: body} +    end) +      User.follow(follower, old_user)      Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)      Pleroma.Tests.ObanHelpers.perform_all() diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 0d1c3ecb3..8d00e3c21 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -5,13 +5,19 @@  defmodule Pleroma.Web.MastodonAPI.AccountViewTest do    use Pleroma.DataCase -  import Pleroma.Factory -    alias Pleroma.User    alias Pleroma.UserRelationship    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.MastodonAPI.AccountView +  import Pleroma.Factory +  import Tesla.Mock + +  setup do +    mock(fn env -> apply(HttpRequestMock, :request, [env]) end) +    :ok +  end +    test "Represent a user account" do      source_data = %{        "tag" => [ @@ -164,6 +170,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do      assert expected == AccountView.render("show.json", %{user: user})    end +  test "Represent a Funkwhale channel" do +    {:ok, user} = +      User.get_or_fetch_by_ap_id( +        "https://channels.tests.funkwhale.audio/federation/actors/compositions" +      ) + +    assert represented = AccountView.render("show.json", %{user: user}) +    assert represented.acct == "compositions@channels.tests.funkwhale.audio" +    assert represented.url == "https://channels.tests.funkwhale.audio/channels/compositions" +  end +    test "Represent a deactivated user for an admin" do      admin = insert(:user, is_admin: true)      deactivated_user = insert(:user, deactivated: true) diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index 7965af00a..81eefd735 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -112,11 +112,24 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      test_notifications_rendering([notification], followed, [])    end +  @tag capture_log: true    test "Move notification" do      old_user = insert(:user)      new_user = insert(:user, also_known_as: [old_user.ap_id])      follower = insert(:user) +    old_user_url = old_user.ap_id + +    body = +      File.read!("test/fixtures/users_mock/localhost.json") +      |> String.replace("{{nickname}}", old_user.nickname) +      |> Jason.encode!() + +    Tesla.Mock.mock(fn +      %{method: :get, url: ^old_user_url} -> +        %Tesla.Env{status: 200, body: body} +    end) +      User.follow(follower, old_user)      Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)      Pleroma.Tests.ObanHelpers.perform_all() diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index 9191730cd..6791c2fb0 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -94,6 +94,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      Repo.delete(user)      Cachex.clear(:user_cache) +    finger_url = +      "https://localhost/.well-known/webfinger?resource=acct:#{user.nickname}@localhost" + +    Tesla.Mock.mock_global(fn +      %{method: :get, url: "http://localhost/.well-known/host-meta"} -> +        %Tesla.Env{status: 404, body: ""} + +      %{method: :get, url: "https://localhost/.well-known/host-meta"} -> +        %Tesla.Env{status: 404, body: ""} + +      %{ +        method: :get, +        url: ^finger_url +      } -> +        %Tesla.Env{status: 404, body: ""} +    end) +      %{account: ms_user} = StatusView.render("show.json", activity: activity)      assert ms_user.acct == "erroruser@example.com" @@ -431,6 +448,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      assert length(represented[:media_attachments]) == 1    end +  test "funkwhale audio" do +    user = insert(:user) + +    {:ok, object} = +      Pleroma.Object.Fetcher.fetch_object_from_id( +        "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871" +      ) + +    %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"]) + +    represented = StatusView.render("show.json", %{for: user, activity: activity}) + +    assert represented[:id] == to_string(activity.id) +    assert length(represented[:media_attachments]) == 1 +  end +    test "a Mobilizon event" do      user = insert(:user) diff --git a/test/web/metadata/metadata_test.exs b/test/web/metadata/metadata_test.exs new file mode 100644 index 000000000..3f8b29e58 --- /dev/null +++ b/test/web/metadata/metadata_test.exs @@ -0,0 +1,25 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.MetadataTest do +  use Pleroma.DataCase, async: true + +  import Pleroma.Factory + +  describe "restrict indexing remote users" do +    test "for remote user" do +      user = insert(:user, local: false) + +      assert Pleroma.Web.Metadata.build_tags(%{user: user}) =~ +               "<meta content=\"noindex, noarchive\" name=\"robots\">" +    end + +    test "for local user" do +      user = insert(:user) + +      refute Pleroma.Web.Metadata.build_tags(%{user: user}) =~ +               "<meta content=\"noindex, noarchive\" name=\"robots\">" +    end +  end +end diff --git a/test/web/metadata/restrict_indexing_test.exs b/test/web/metadata/restrict_indexing_test.exs new file mode 100644 index 000000000..aad0bac42 --- /dev/null +++ b/test/web/metadata/restrict_indexing_test.exs @@ -0,0 +1,21 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Metadata.Providers.RestrictIndexingTest do +  use ExUnit.Case, async: true + +  describe "build_tags/1" do +    test "for remote user" do +      assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{ +               user: %Pleroma.User{local: false} +             }) == [{:meta, [name: "robots", content: "noindex, noarchive"], []}] +    end + +    test "for local user" do +      assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{ +               user: %Pleroma.User{local: true} +             }) == [] +    end +  end +end diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index 0b0972b17..f2f98d768 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -575,7 +575,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do        # In case scope param is missing, expecting _all_ app-supported scopes to be granted        for user <- [non_admin, admin],            {requested_scopes, expected_scopes} <- -            %{scopes_subset => scopes_subset, nil => app_scopes} do +            %{scopes_subset => scopes_subset, nil: app_scopes} do          conn =            post(              build_conn(), diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs index 089d55577..9f931c941 100644 --- a/test/web/push/impl_test.exs +++ b/test/web/push/impl_test.exs @@ -134,7 +134,7 @@ defmodule Pleroma.Web.Push.ImplTest do      user = insert(:user, nickname: "Bob")      other_user = insert(:user)      {:ok, _, _, activity} = CommonAPI.follow(user, other_user) -    object = Object.normalize(activity) +    object = Object.normalize(activity, false)      assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has followed you" diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index a5d6e8ecf..5b928629b 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -121,6 +121,18 @@ defmodule Pleroma.Web.StreamerTest do      test "it sends follow activities to the 'user:notification' stream", %{        user: user      } do +      user_url = user.ap_id + +      body = +        File.read!("test/fixtures/users_mock/localhost.json") +        |> String.replace("{{nickname}}", user.nickname) +        |> Jason.encode!() + +      Tesla.Mock.mock_global(fn +        %{method: :get, url: ^user_url} -> +          %Tesla.Env{status: 200, body: body} +      end) +        user2 = insert(:user)        task = Task.async(fn -> assert_receive {:text, _}, @streamer_timeout end) | 
