diff options
Diffstat (limited to 'test')
13 files changed, 184 insertions, 11 deletions
| diff --git a/test/mix/tasks/pleroma/openapi_spec_test.exs b/test/mix/tasks/pleroma/openapi_spec_test.exs new file mode 100644 index 000000000..01437187a --- /dev/null +++ b/test/mix/tasks/pleroma/openapi_spec_test.exs @@ -0,0 +1,62 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.OpenapiSpecTest do +  use Pleroma.DataCase, async: true + +  alias Mix.Tasks.Pleroma.OpenapiSpec + +  @spec_base %{ +    "paths" => %{ +      "/cofe" => %{ +        "get" => %{ +          "operationId" => "Some.operation", +          "tags" => [] +        } +      }, +      "/mew" => %{ +        "post" => %{ +          "operationId" => "Another.operation", +          "tags" => ["mew mew"] +        } +      } +    }, +    "x-tagGroups" => [ +      %{ +        "name" => "mew", +        "tags" => ["mew mew", "abc"] +      }, +      %{ +        "name" => "lol", +        "tags" => ["lol lol", "xyz"] +      } +    ] +  } + +  describe "check_specs/1" do +    test "Every operation must have a tag" do +      assert {:error, ["Some.operation (get /cofe): No tags specified"]} == +               OpenapiSpec.check_specs(@spec_base) +    end + +    test "Every tag must be in tag groups" do +      spec = +        @spec_base +        |> put_in(["paths", "/cofe", "get", "tags"], ["abc", "def", "not specified"]) + +      assert {:error, +              [ +                "Some.operation (get /cofe): Tags #{inspect(["def", "not specified"])} not available. Please add it in \"x-tagGroups\" in Pleroma.Web.ApiSpec" +              ]} == OpenapiSpec.check_specs(spec) +    end + +    test "No errors if ok" do +      spec = +        @spec_base +        |> put_in(["paths", "/cofe", "get", "tags"], ["abc", "mew mew"]) + +      assert :ok == OpenapiSpec.check_specs(spec) +    end +  end +end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 255097ed0..e55aa3a08 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -334,6 +334,32 @@ defmodule Pleroma.NotificationTest do        refute Notification.create_notification(activity, followed)      end +    test "it disables notifications from non-followees" do +      follower = insert(:user) + +      followed = +        insert(:user, +          notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true} +        ) + +      CommonAPI.follow(follower, followed) +      {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) +      refute Notification.create_notification(activity, followed) +    end + +    test "it allows notifications from followees" do +      poster = insert(:user) + +      receiver = +        insert(:user, +          notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true} +        ) + +      CommonAPI.follow(receiver, poster) +      {:ok, activity} = CommonAPI.post(poster, %{status: "hey @#{receiver.nickname}"}) +      assert Notification.create_notification(activity, receiver) +    end +      test "it doesn't create a notification for user if he is the activity author" do        activity = insert(:note_activity)        author = User.get_cached_by_ap_id(activity.data["actor"]) @@ -1225,5 +1251,32 @@ defmodule Pleroma.NotificationTest do        assert length(Notification.for_user(user)) == 1      end + +    test "it returns notifications when related object is without content and filters are defined", +         %{user: user} do +      followed_user = insert(:user, is_locked: true) + +      insert(:filter, user: followed_user, phrase: "test", hide: true) + +      {:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) +      refute FollowingRelationship.following?(user, followed_user) +      assert [notification] = Notification.for_user(followed_user) + +      assert %{type: "follow_request"} = +               NotificationView.render("show.json", %{ +                 notification: notification, +                 for: followed_user +               }) + +      assert {:ok, _} = CommonAPI.accept_follow_request(user, followed_user) + +      assert [notification] = Notification.for_user(followed_user) + +      assert %{type: "follow"} = +               NotificationView.render("show.json", %{ +                 notification: notification, +                 for: followed_user +               }) +    end    end  end diff --git a/test/pleroma/upload/filter/exiftool/strip_location_test.exs b/test/pleroma/upload/filter/exiftool/strip_location_test.exs index 7e1541f60..bcb5f3f60 100644 --- a/test/pleroma/upload/filter/exiftool/strip_location_test.exs +++ b/test/pleroma/upload/filter/exiftool/strip_location_test.exs @@ -31,12 +31,19 @@ defmodule Pleroma.Upload.Filter.Exiftool.StripLocationTest do      refute String.match?(exif_filtered, ~r/GPS/)    end -  test "verify webp files are skipped" do -    upload = %Pleroma.Upload{ -      name: "sample.webp", -      content_type: "image/webp" -    } - -    assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :noop} +  test "verify webp, heic, svg  files are skipped" do +    uploads = +      ~w{webp heic svg svg+xml} +      |> Enum.map(fn type -> +        %Pleroma.Upload{ +          name: "sample.#{type}", +          content_type: "image/#{type}" +        } +      end) + +    uploads +    |> Enum.each(fn upload -> +      assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :noop} +    end)    end  end diff --git a/test/pleroma/user/import_test.exs b/test/pleroma/user/import_test.exs index b4efd4bb0..f75305e0e 100644 --- a/test/pleroma/user/import_test.exs +++ b/test/pleroma/user/import_test.exs @@ -3,7 +3,6 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.User.ImportTest do -  alias Pleroma.Repo    alias Pleroma.Tests.ObanHelpers    alias Pleroma.User diff --git a/test/pleroma/user_search_test.exs b/test/pleroma/user_search_test.exs index 1deab6888..1af9a1493 100644 --- a/test/pleroma/user_search_test.exs +++ b/test/pleroma/user_search_test.exs @@ -3,7 +3,6 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.UserSearchTest do -  alias Pleroma.Repo    alias Pleroma.User    use Pleroma.DataCase diff --git a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs index 9d99df27c..83bf59c6f 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs @@ -65,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do      object = Object.get_by_ap_id(data["object"])      assert object.data["reaction_count"] == 1 -    assert match?([[emoji, _]], object.data["reactions"]) +    assert match?([[^emoji, _]], object.data["reactions"])    end    test "it reject invalid emoji reactions" do diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index 7c406fbd0..a9ad3e9c8 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -104,6 +104,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do        end      end +    @tag capture_log: true      test "it does not crash if the object in inReplyTo can't be fetched" do        data =          File.read!("test/fixtures/mastodon-post-activity.json") @@ -723,6 +724,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do      assert modified.data["context"] == object.data["id"]    end +  @tag capture_log: true    test "the reply note uses its parent's ID when context is missing and reply is unreachable" do      insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8") diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index 9ef7c0c46..9fb5fb520 100644 --- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs @@ -316,6 +316,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do        assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}      end +    @tag capture_log: true      test "save configs setting without explicit key", %{conn: conn} do        adapter = Application.get_env(:http, :adapter)        send_user_agent = Application.get_env(:http, :send_user_agent) diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs index aee26d80a..c141cf69d 100644 --- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs @@ -366,6 +366,34 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do                 |> json_response_and_validate_schema(:ok)      end +    test "renders content correctly", %{conn: conn} do +      [reporter, target_user] = insert_pair(:user) +      note = insert(:note, user: target_user, data: %{"content" => "mew 1"}) +      note2 = insert(:note, user: target_user, data: %{"content" => "mew 2"}) +      activity = insert(:note_activity, user: target_user, note: note) +      activity2 = insert(:note_activity, user: target_user, note: note2) + +      {:ok, _report} = +        CommonAPI.report(reporter, %{ +          account_id: target_user.id, +          comment: "I feel offended", +          status_ids: [activity.id, activity2.id] +        }) + +      CommonAPI.delete(activity.id, target_user) +      CommonAPI.delete(activity2.id, target_user) + +      response = +        conn +        |> get(report_path(conn, :index)) +        |> json_response_and_validate_schema(:ok) + +      assert [open_report] = response["reports"] +      assert %{"statuses" => [s1, s2]} = open_report +      assert "mew 1" in [s1["content"], s2["content"]] +      assert "mew 2" in [s1["content"], s2["content"]] +    end +      test "returns 403 when requested by a non-admin" do        user = insert(:user)        token = insert(:oauth_token, user: user) diff --git a/test/pleroma/web/common_api/utils_test.exs b/test/pleroma/web/common_api/utils_test.exs index b538c5979..d309c6ded 100644 --- a/test/pleroma/web/common_api/utils_test.exs +++ b/test/pleroma/web/common_api/utils_test.exs @@ -178,6 +178,10 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do        code = "https://github.com/pragdave/earmark/"        {result, [], []} = Utils.format_input(code, "text/markdown")        assert result == ~s[<p><a href="#{code}">#{code}</a></p>] + +      code = "https://github.com/~foo/bar" +      {result, [], []} = Utils.format_input(code, "text/markdown") +      assert result == ~s[<p><a href="#{code}">#{code}</a></p>]      end      test "link with local mention" do diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index 13e3ffc0a..a556ef6a8 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -92,4 +92,18 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do      assert ["peer1.com", "peer2.com"] == Enum.sort(result)    end + +  test "instance languages", %{conn: conn} do +    assert %{"languages" => ["en"]} = +             conn +             |> get("/api/v1/instance") +             |> json_response_and_validate_schema(200) + +    clear_config([:instance, :languages], ["aa", "bb"]) + +    assert %{"languages" => ["aa", "bb"]} = +             conn +             |> get("/api/v1/instance") +             |> json_response_and_validate_schema(200) +  end  end diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index d5fac7e25..d4004bcb6 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -375,7 +375,9 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do            "pleroma_background_image" => new_background_oversized          }) -      assert user_response = json_response_and_validate_schema(res, 413) +      assert %{"error" => "File is too large"} == json_response_and_validate_schema(res, 413) + +      user = Repo.get(User, user.id)        assert user.background == %{}        clear_config([:instance, :upload_limit], upload_limit) diff --git a/test/test_helper.exs b/test/test_helper.exs index 60a61484f..7727cffbc 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -2,6 +2,8 @@  # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only +Code.put_compiler_option(:warnings_as_errors, true) +  os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: []  ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude) | 
