From e7d6b835ae908be8e9f6a303a77c87860fb7a377 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 28 Nov 2023 18:54:11 +0000 Subject: [PATCH 01/20] Fix tests by leveraging Keyword.equal?/2 --- test/pleroma/healthcheck_test.exs | 6 ++++-- test/pleroma/repo/migrations/autolinker_to_linkify_test.exs | 6 +++--- .../repo/migrations/fix_malformed_formatter_config_test.exs | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/test/pleroma/healthcheck_test.exs b/test/pleroma/healthcheck_test.exs index 733537f02..a8ab865ac 100644 --- a/test/pleroma/healthcheck_test.exs +++ b/test/pleroma/healthcheck_test.exs @@ -9,14 +9,16 @@ defmodule Pleroma.HealthcheckTest do test "system_info/0" do result = Healthcheck.system_info() |> Map.from_struct() - assert Map.keys(result) == [ + keys = Map.keys(result) + + assert Keyword.equal?(keys, [ :active, :healthy, :idle, :job_queue_stats, :memory_used, :pool_size - ] + ]) end describe "check_health/1" do diff --git a/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs b/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs index 52a606368..9847781f0 100644 --- a/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs +++ b/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs @@ -29,13 +29,13 @@ test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: mi %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter}) - assert new_opts == [ + assert Keyword.equal?(new_opts, class: false, extra: true, new_window: false, rel: "testing", strip_prefix: false - ] + ) clear_config(Pleroma.Formatter, new_opts) assert new_opts == Pleroma.Config.get(Pleroma.Formatter) @@ -67,6 +67,6 @@ test "transform_opts/1 returns a list of compatible opts", %{migration: migratio strip_prefix: false ] - assert migration.transform_opts(old_opts) == expected_opts + assert Keyword.equal?(migration.transform_opts(old_opts), expected_opts) end end diff --git a/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs b/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs index 4c45adb4b..cf3fe5aac 100644 --- a/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs +++ b/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs @@ -26,13 +26,13 @@ test "change/0 converts a map into a list", %{migration: migration} do %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter}) - assert new_opts == [ + assert Keyword.equal?(new_opts, class: false, extra: true, new_window: false, rel: "F", strip_prefix: false - ] + ) clear_config(Pleroma.Formatter, new_opts) assert new_opts == Pleroma.Config.get(Pleroma.Formatter) From e121e0621467ec6ce87b11f146656ba655feda56 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 28 Nov 2023 18:54:50 +0000 Subject: [PATCH 02/20] Implement a custom uri_equal?/2 to fix comparisons of URLs with unordered query parameters --- test/pleroma/mfa/totp_test.exs | 6 +++++- test/support/helpers.ex | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/pleroma/mfa/totp_test.exs b/test/pleroma/mfa/totp_test.exs index 56e4f48ed..f291ed14b 100644 --- a/test/pleroma/mfa/totp_test.exs +++ b/test/pleroma/mfa/totp_test.exs @@ -7,6 +7,8 @@ defmodule Pleroma.MFA.TOTPTest do alias Pleroma.MFA.TOTP + import Pleroma.Tests.Helpers, only: [uri_equal?: 2] + test "create provisioning_uri to generate qrcode" do uri = TOTP.provisioning_uri("test-secrcet", "test@example.com", @@ -15,7 +17,9 @@ test "create provisioning_uri to generate qrcode" do period: 60 ) - assert uri == + assert uri_equal?( + uri, "otpauth://totp/test@example.com?digits=8&issuer=Plerome-42&period=60&secret=test-secrcet" + ) end end diff --git a/test/support/helpers.ex b/test/support/helpers.ex index e3bfa73d2..ee18753ed 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -10,6 +10,22 @@ defmodule Pleroma.Tests.Helpers do require Logger + @doc "Accepts two URLs/URIs and sorts the query parameters before comparing" + def uri_equal?(a, b) do + a_parsed = URI.parse(a) + b_parsed = URI.parse(b) + + query_sort = fn query -> String.split(query, "&") |> Enum.sort() |> Enum.join("&") end + + a_sorted_query = query_sort.(a_parsed.query) + b_sorted_query = query_sort.(b_parsed.query) + + a_sorted = Map.put(a_parsed, :query, a_sorted_query) + b_sorted = Map.put(b_parsed, :query, b_sorted_query) + + match?(^a_sorted, b_sorted) + end + defmacro clear_config(config_path) do quote do clear_config(unquote(config_path)) do From b51ba39dd1310bb525496645df13d956f0fc7b12 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 28 Nov 2023 19:12:15 +0000 Subject: [PATCH 03/20] Update Floki to get the :attributes_as_maps feature to allow us to compare equality of parsed documents without issues of key ordering --- mix.exs | 2 +- mix.lock | 2 +- .../web/web_finger/web_finger_controller_test.exs | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index b4b77b161..f31e37676 100644 --- a/mix.exs +++ b/mix.exs @@ -156,7 +156,7 @@ defp deps do {:phoenix_swoosh, "~> 1.1"}, {:gen_smtp, "~> 0.13"}, {:ex_syslogger, "~> 1.4"}, - {:floki, "~> 0.27"}, + {:floki, "~> 0.35"}, {:timex, "~> 3.6"}, {:ueberauth, "~> 0.4"}, {:linkify, "~> 0.5.3"}, diff --git a/mix.lock b/mix.lock index 81a05687b..4fa42f606 100644 --- a/mix.lock +++ b/mix.lock @@ -50,7 +50,7 @@ "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "finch": {:hex, :finch, "0.16.0", "40733f02c89f94a112518071c0a91fe86069560f5dbdb39f9150042f44dcfb1a", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f660174c4d519e5fec629016054d60edd822cdfe2b7270836739ac2f97735ec5"}, "flake_id": {:hex, :flake_id, "0.1.0", "7716b086d2e405d09b647121a166498a0d93d1a623bead243e1f74216079ccb3", [:mix], [{:base62, "~> 1.2", [hex: :base62, repo: "hexpm", optional: false]}, {:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "31fc8090fde1acd267c07c36ea7365b8604055f897d3a53dd967658c691bd827"}, - "floki": {:hex, :floki, "0.34.3", "5e2dcaec5d7c228ce5b1d3501502e308b2d79eb655e4191751a1fe491c37feac", [:mix], [], "hexpm", "9577440eea5b97924b4bf3c7ea55f7b8b6dce589f9b28b096cc294a8dc342341"}, + "floki": {:hex, :floki, "0.35.2", "87f8c75ed8654b9635b311774308b2760b47e9a579dabf2e4d5f1e1d42c39e0b", [:mix], [], "hexpm", "6b05289a8e9eac475f644f09c2e4ba7e19201fd002b89c28c1293e7bd16773d9"}, "gen_smtp": {:hex, :gen_smtp, "0.15.0", "9f51960c17769b26833b50df0b96123605a8024738b62db747fece14eb2fbfcc", [:rebar3], [], "hexpm", "29bd14a88030980849c7ed2447b8db6d6c9278a28b11a44cafe41b791205440f"}, "gettext": {:hex, :gettext, "0.22.2", "6bfca374de34ecc913a28ba391ca184d88d77810a3e427afa8454a71a51341ac", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "8a2d389673aea82d7eae387e6a2ccc12660610080ae7beb19452cfdc1ec30f60"}, "gun": {:hex, :gun, "2.0.1", "160a9a5394800fcba41bc7e6d421295cf9a7894c2252c0678244948e3336ad73", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "a10bc8d6096b9502205022334f719cc9a08d9adcfbfc0dbee9ef31b56274a20b"}, diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index e01cec5e4..263191619 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -23,8 +23,15 @@ test "GET host-meta" do assert response.status == 200 - assert response.resp_body == - ~s() + response_xml = + response.resp_body + |> Floki.parse_document!(html_parser: Floki.HTMLParser.Mochiweb, attributes_as_maps: true) + + expected_xml = + ~s() + |> Floki.parse_document!(html_parser: Floki.HTMLParser.Mochiweb, attributes_as_maps: true) + + assert match?(^response_xml, expected_xml) end test "Webfinger JRD" do From 36b3867787b3aff206df4a7d5549d9269dcf0457 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 28 Nov 2023 20:19:31 +0000 Subject: [PATCH 04/20] Fix test "transforms config to tuples" This should have never worked. The default empty values for the other MRF Simple options will always be there. --- test/pleroma/config/deprecation_warnings_test.exs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/pleroma/config/deprecation_warnings_test.exs b/test/pleroma/config/deprecation_warnings_test.exs index 9a482e46e..fca2324ff 100644 --- a/test/pleroma/config/deprecation_warnings_test.exs +++ b/test/pleroma/config/deprecation_warnings_test.exs @@ -125,13 +125,12 @@ test "transforms config to tuples" do media_removal: ["some.removal", {"some.other.instance", "Some reason"}] ) - expected_config = [ + expected_config = {:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]} - ] capture_log(fn -> DeprecationWarnings.warn() end) - assert Config.get([:mrf_simple]) == expected_config + assert expected_config in Config.get([:mrf_simple]) end test "doesn't give a warning with correct config" do From d4dd21303a68df88906d11c4f11961718f7efc59 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 28 Nov 2023 21:00:58 +0000 Subject: [PATCH 05/20] Remove call to Pleroma.Web.Endpoint.config_change/2 This is not necessary for the tests to pass and breaks other tests as this change doesn't get cleanly reverted causing the hostname to stay set this way and leak into other test causing failures with "sub.example.com" not matching "localhost" --- .../web/web_finger/web_finger_controller_test.exs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index 263191619..e952ccc60 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -55,12 +55,7 @@ test "Webfinger JRD" do ] end - test "reach user on tld, while pleroma is running on subdomain" do - Pleroma.Web.Endpoint.config_change( - [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}], - [] - ) - + test "reach user on tld, while pleroma is runned on subdomain" do clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com") clear_config([Pleroma.Web.WebFinger, :domain], "example.com") @@ -75,13 +70,6 @@ test "reach user on tld, while pleroma is running on subdomain" do assert response["subject"] == "acct:#{user.nickname}@example.com" assert response["aliases"] == ["https://sub.example.com/users/#{user.nickname}"] - - on_exit(fn -> - Pleroma.Web.Endpoint.config_change( - [{Pleroma.Web.Endpoint, url: [host: "localhost"]}], - [] - ) - end) end test "it returns 404 when user isn't found (JSON)" do From 0820c23988debd0b31e917dea66fb9e122fc3a98 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 21 Dec 2023 01:40:42 +0000 Subject: [PATCH 06/20] Fix Chat controller tests failing due to OTP26 key order change --- .../pleroma_api/controllers/chat_controller_test.exs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 7138a6636..3a30bc7f9 100644 --- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs @@ -216,30 +216,30 @@ test "it paginates", %{conn: conn, user: user} do assert String.match?( next, - ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$) + ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*; rel=\"next\"$) ) assert String.match?( prev, - ~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*; rel=\"prev\"$) + ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&min_id=.*; rel=\"prev\"$) ) assert length(result) == 20 response = - get(conn, "/api/v1/pleroma/chats/#{chat.id}/messages?max_id=#{List.last(result)["id"]}") + get(conn, "#{api_endpoint}#{chat.id}/messages?max_id=#{List.last(result)["id"]}") result = json_response_and_validate_schema(response, 200) [next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ") assert String.match?( next, - ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$) + ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*; rel=\"next\"$) ) assert String.match?( prev, - ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$) + ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$) ) assert length(result) == 10 From 347e5f33c775ae1de8bffe0ba84611b3d7a59d8f Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 21 Dec 2023 01:47:12 +0000 Subject: [PATCH 07/20] Fix regex string match due to OTP26 key order change OTP25: "; rel=\"next\"" OTP26: "; rel=\"next\"" --- .../web/mastodon_api/controllers/status_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index 4e3d34172..69e087f37 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -2191,7 +2191,7 @@ test "favorites paginate correctly" do # Using the header for pagination works correctly [next, _] = get_resp_header(result, "link") |> hd() |> String.split(", ") - [_, max_id] = Regex.run(~r/max_id=([^&]+)/, next) + [_, max_id] = Regex.run(~r/max_id=([^&]+)>.*/, next) assert max_id == third_favorite.id From 1b5168ae021fa9d6b154b25444dd96c812083ce7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 28 Nov 2023 20:46:41 +0000 Subject: [PATCH 08/20] Phoenix detects the webfinger requests with content-type application/jrd+json as "jrd" now --- lib/pleroma/web/router.ex | 2 +- lib/pleroma/web/web_finger/web_finger_controller.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 00268b121..8ba845364 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -182,7 +182,7 @@ defmodule Pleroma.Web.Router do end pipeline :well_known do - plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"]) + plug(:accepts, ["json", "jrd", "jrd+json", "xml", "xrd+xml"]) end pipeline :config do diff --git a/lib/pleroma/web/web_finger/web_finger_controller.ex b/lib/pleroma/web/web_finger/web_finger_controller.ex index 9e5efb77f..021df9bc5 100644 --- a/lib/pleroma/web/web_finger/web_finger_controller.ex +++ b/lib/pleroma/web/web_finger/web_finger_controller.ex @@ -30,7 +30,7 @@ def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource}) end def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource}) - when format in ["json", "jrd+json"] do + when format in ["jrd", "json", "jrd+json"] do with {:ok, response} <- WebFinger.webfinger(resource, "JSON") do json(conn, response) else From 04366492b23105a5a3707d458b553d5c3c0d6b63 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 21 Dec 2023 01:28:51 +0000 Subject: [PATCH 09/20] ConfigDB export to file does not have a consistent order. Just test a few values to prove it was written --- test/mix/tasks/pleroma/config_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/mix/tasks/pleroma/config_test.exs b/test/mix/tasks/pleroma/config_test.exs index cec1a79e4..7b2134129 100644 --- a/test/mix/tasks/pleroma/config_test.exs +++ b/test/mix/tasks/pleroma/config_test.exs @@ -182,8 +182,8 @@ test "load a settings with large values and pass to file", %{temp_file: temp_fil assert File.exists?(temp_file) {:ok, file} = File.read(temp_file) - assert file == - "import Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n" + assert file =~ "import Config\n" + assert file =~ "A Pleroma instance, an alternative fediverse server" end end From 63a74f7b6dcfd8b5498a98d1fd0a08b7f0cfdd26 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 29 Dec 2023 23:22:31 -0500 Subject: [PATCH 10/20] Support for Erlang OTP 26 --- changelog.d/otp26.add | 1 + docs/installation/generic_dependencies.include | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog.d/otp26.add diff --git a/changelog.d/otp26.add b/changelog.d/otp26.add new file mode 100644 index 000000000..b019afdf3 --- /dev/null +++ b/changelog.d/otp26.add @@ -0,0 +1 @@ +Support for Erlang OTP 26 diff --git a/docs/installation/generic_dependencies.include b/docs/installation/generic_dependencies.include index 3365a36a8..56274a3f0 100644 --- a/docs/installation/generic_dependencies.include +++ b/docs/installation/generic_dependencies.include @@ -2,7 +2,7 @@ * PostgreSQL >=9.6 * Elixir >=1.11.0 <1.15 -* Erlang OTP >=22.2.0 <26 +* Erlang OTP >=22.2.0 * git * file / libmagic * gcc or clang From c6acd2abb39927f9194025bbd30c7e0ebccb16fa Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 29 Dec 2023 23:31:48 -0500 Subject: [PATCH 11/20] Revert grammar leak from bad merge --- test/pleroma/web/web_finger/web_finger_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index e952ccc60..80e072163 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -55,7 +55,7 @@ test "Webfinger JRD" do ] end - test "reach user on tld, while pleroma is runned on subdomain" do + test "reach user on tld, while pleroma is running on subdomain" do clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com") clear_config([Pleroma.Web.WebFinger, :domain], "example.com") From 8883fa326a1de11bdf2cf254aa8a1d141d0332ab Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Sat, 30 Dec 2023 11:44:23 +0400 Subject: [PATCH 12/20] Mix: Update http_signatures version --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index f31e37676..2e622d9da 100644 --- a/mix.exs +++ b/mix.exs @@ -160,7 +160,7 @@ defp deps do {:timex, "~> 3.6"}, {:ueberauth, "~> 0.4"}, {:linkify, "~> 0.5.3"}, - {:http_signatures, "~> 0.1.1"}, + {:http_signatures, "~> 0.1.2"}, {:telemetry, "~> 1.0.0", override: true}, {:poolboy, "~> 1.5"}, {:prom_ex, "~> 1.9"}, diff --git a/mix.lock b/mix.lock index 4fa42f606..e5e2c0baa 100644 --- a/mix.lock +++ b/mix.lock @@ -57,7 +57,7 @@ "hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"}, "hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"}, "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, - "http_signatures": {:hex, :http_signatures, "0.1.1", "ca7ebc1b61542b163644c8c3b1f0e0f41037d35f2395940d3c6c7deceab41fd8", [:mix], [], "hexpm", "cc3b8a007322cc7b624c0c15eec49ee58ac977254ff529a3c482f681465942a3"}, + "http_signatures": {:hex, :http_signatures, "0.1.2", "ed1cc7043abcf5bb4f30d68fb7bad9d618ec1a45c4ff6c023664e78b67d9c406", [:mix], [], "hexpm", "f08aa9ac121829dae109d608d83c84b940ef2f183ae50f2dd1e9a8bc619d8be7"}, "httpoison": {:hex, :httpoison, "1.8.2", "9eb9c63ae289296a544842ef816a85d881d4a31f518a0fec089aaa744beae290", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "2bb350d26972e30c96e2ca74a1aaf8293d61d0742ff17f01e0279fef11599921"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "inet_cidr": {:hex, :inet_cidr, "1.0.4", "a05744ab7c221ca8e395c926c3919a821eb512e8f36547c062f62c4ca0cf3d6e", [:mix], [], "hexpm", "64a2d30189704ae41ca7dbdd587f5291db5d1dda1414e0774c29ffc81088c1bc"}, From fc910f9bb94bb3cefb76f2253369e6198d6ee969 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Sat, 30 Dec 2023 11:45:16 +0400 Subject: [PATCH 13/20] Linting --- .../web/pleroma_api/controllers/chat_controller_test.exs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 3a30bc7f9..e17d9d7cb 100644 --- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs @@ -226,8 +226,7 @@ test "it paginates", %{conn: conn, user: user} do assert length(result) == 20 - response = - get(conn, "#{api_endpoint}#{chat.id}/messages?max_id=#{List.last(result)["id"]}") + response = get(conn, "#{api_endpoint}#{chat.id}/messages?max_id=#{List.last(result)["id"]}") result = json_response_and_validate_schema(response, 200) [next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ") From e7c6410192cfb115246acd4f9bf80f0c42aece90 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 15 Jan 2024 17:07:13 -0500 Subject: [PATCH 14/20] Add Pleroma.Support.Helpers.uri_query_sort/1 for easy sorting of a URL's query parameters --- test/support/helpers.ex | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/test/support/helpers.ex b/test/support/helpers.ex index ee18753ed..bcdc49e4f 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -12,20 +12,26 @@ defmodule Pleroma.Tests.Helpers do @doc "Accepts two URLs/URIs and sorts the query parameters before comparing" def uri_equal?(a, b) do - a_parsed = URI.parse(a) - b_parsed = URI.parse(b) - - query_sort = fn query -> String.split(query, "&") |> Enum.sort() |> Enum.join("&") end - - a_sorted_query = query_sort.(a_parsed.query) - b_sorted_query = query_sort.(b_parsed.query) - - a_sorted = Map.put(a_parsed, :query, a_sorted_query) - b_sorted = Map.put(b_parsed, :query, b_sorted_query) + a_sorted = uri_query_sort(a) + b_sorted = uri_query_sort(b) match?(^a_sorted, b_sorted) end + @doc "Accepts a URL/URI and sorts the query parameters" + def uri_query_sort(uri) do + parsed = URI.parse(uri) + + sorted_query = + String.split(parsed.query, "&") + |> Enum.sort() + |> Enum.join("&") + + parsed + |> Map.put(:query, sorted_query) + |> URI.to_string() + end + defmacro clear_config(config_path) do quote do clear_config(unquote(config_path)) do From 4cbf11d32c9c37f3175e4d7bab04be64a9fe27d4 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 15 Jan 2024 17:12:06 -0500 Subject: [PATCH 15/20] Fix ChatController tests validating prev/next URLs by sorting the query parameters before comparison --- .../controllers/chat_controller_test.exs | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) 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 e17d9d7cb..0d3452559 100644 --- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs @@ -7,6 +7,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do alias Pleroma.Chat alias Pleroma.Chat.MessageReference alias Pleroma.Object + alias Pleroma.Tests.Helpers alias Pleroma.UnstubbedConfigMock, as: ConfigMock alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub @@ -212,18 +213,32 @@ test "it paginates", %{conn: conn, user: user} do result = json_response_and_validate_schema(response, 200) [next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ") - api_endpoint = "/api/v1/pleroma/chats/" + api_endpoint = Pleroma.Web.Endpoint.url() <> "/api/v1/pleroma/chats/" + + [next_url, next_rel] = String.split(next, ";") + next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<") + + next_url_sorted = Helpers.uri_query_sort(next_url) assert String.match?( - next, - ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*; rel=\"next\"$) + next_url_sorted, + ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&offset=\d+$) ) + assert next_rel =~ "next" + + [prev_url, prev_rel] = String.split(prev, ";") + prev_url = String.trim_trailing(prev_url, ">") |> String.trim_leading("<") + + prev_url_sorted = Helpers.uri_query_sort(prev_url) + assert String.match?( - prev, - ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&min_id=.*; rel=\"prev\"$) + prev_url_sorted, + ~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*&offset=\d+$) ) + assert prev_rel =~ "prev" + assert length(result) == 20 response = get(conn, "#{api_endpoint}#{chat.id}/messages?max_id=#{List.last(result)["id"]}") @@ -231,16 +246,30 @@ test "it paginates", %{conn: conn, user: user} do result = json_response_and_validate_schema(response, 200) [next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ") - assert String.match?( - next, - ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*; rel=\"next\"$) - ) + [next_url, next_rel] = String.split(next, ";") + next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<") + + next_url_sorted = Helpers.uri_query_sort(next_url) assert String.match?( - prev, - ~r(#{api_endpoint}.*/messages\?offset=\d+&limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$) + next_url_sorted, + ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&offset=\d+$) ) + assert next_rel =~ "next" + + [prev_url, prev_rel] = String.split(prev, ";") + prev_url = String.trim_trailing(prev_url, ">") |> String.trim_leading("<") + + prev_url_sorted = Helpers.uri_query_sort(prev_url) + + assert String.match?( + prev_url_sorted, + ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*&offset=\d+$) + ) + + assert prev_rel =~ "prev" + assert length(result) == 10 end From 8bd8ee03c23bf1d318f67215195a1aca7465e3ae Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 15 Jan 2024 17:32:15 -0500 Subject: [PATCH 16/20] Add Pleroma.Test.Helpers.get_query_parameter/2 to retrieve specific query parameter values --- test/support/helpers.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/support/helpers.ex b/test/support/helpers.ex index bcdc49e4f..7fa6c31a4 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -32,6 +32,17 @@ def uri_query_sort(uri) do |> URI.to_string() end + @doc "Returns the value of the specified query parameter for the provided URL" + def get_query_parameter(url, param) do + url + |> URI.parse() + |> Map.get(:query) + |> URI.query_decoder() + |> Enum.to_list() + |> Enum.into(%{}, fn {x, y} -> {x, y} end) + |> Map.get(param) + end + defmacro clear_config(config_path) do quote do clear_config(unquote(config_path)) do From ad363c62c350bf95e898baed36608d650258cc99 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 15 Jan 2024 17:32:57 -0500 Subject: [PATCH 17/20] Fix StatusController test by using the get_query_parameter/2 helper to reliably retrieve the max_id value --- .../web/mastodon_api/controllers/status_controller_test.exs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index 69e087f37..7bbe46cbe 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -12,6 +12,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do alias Pleroma.Object alias Pleroma.Repo alias Pleroma.ScheduledActivity + alias Pleroma.Tests.Helpers alias Pleroma.Tests.ObanHelpers alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub @@ -2191,7 +2192,10 @@ test "favorites paginate correctly" do # Using the header for pagination works correctly [next, _] = get_resp_header(result, "link") |> hd() |> String.split(", ") - [_, max_id] = Regex.run(~r/max_id=([^&]+)>.*/, next) + [next_url, _next_rel] = String.split(next, ";") + next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<") + + max_id = Helpers.get_query_parameter(next_url, "max_id") assert max_id == third_favorite.id From 012ab876055e8a045952ee50d760926f88800fd7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 16 Jan 2024 00:56:15 +0000 Subject: [PATCH 18/20] Pleroma.Web.MastodonAPI.SubscriptionControllerTest: disable async and use on_exit/1 to ensure web push config gets restored --- .../controllers/subscription_controller_test.exs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs index ce7cfa9c7..837dc0dce 100644 --- a/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do - use Pleroma.Web.ConnCase, async: true + use Pleroma.Web.ConnCase, async: false import Pleroma.Factory @@ -35,17 +35,20 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do defmacro assert_error_when_disable_push(do: yield) do quote do - vapid_details = Application.get_env(:web_push_encryption, :vapid_details, []) - Application.put_env(:web_push_encryption, :vapid_details, []) - assert %{"error" => "Web push subscription is disabled on this Pleroma instance"} == unquote(yield) - - Application.put_env(:web_push_encryption, :vapid_details, vapid_details) end end describe "when disabled" do + setup do + vapid_config = Application.get_env(:web_push_encryption, :vapid_details) + + Application.put_env(:web_push_encryption, :vapid_details, []) + + on_exit(fn -> Application.put_env(:web_push_encryption, :vapid_details, vapid_config) end) + end + test "POST returns error", %{conn: conn} do assert_error_when_disable_push do conn From e44f6a2ab3c798693599044911278d9a34f8eb84 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 15 Jan 2024 20:18:43 -0500 Subject: [PATCH 19/20] Skip tests on MacOS/Darwin that have always failed --- test/pleroma/activity_test.exs | 1 + .../web/mastodon_api/controllers/search_controller_test.exs | 1 + test/test_helper.exs | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs index e38384c9c..67943d879 100644 --- a/test/pleroma/activity_test.exs +++ b/test/pleroma/activity_test.exs @@ -145,6 +145,7 @@ test "when association is not loaded" do setup do: clear_config([:instance, :limit_to_local_content]) + @tag :skip_darwin test "finds utf8 text in statuses", %{ japanese_activity: japanese_activity, user: user diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs index 3654c6b20..b05487abe 100644 --- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs @@ -42,6 +42,7 @@ test "it returns empty result if user or status search return undefined error", end end + @tag :skip_darwin test "search", %{conn: conn} do user = insert(:user) user_two = insert(:user, %{nickname: "shp@shitposter.club"}) diff --git a/test/test_helper.exs b/test/test_helper.exs index 27b777d5f..e65f7c1d1 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -6,6 +6,12 @@ ExUnit.start(exclude: [:federated, :erratic]) +if match?({:unix, :darwin}, :os.type()) do + excluded = ExUnit.configuration() |> Keyword.get(:exclude, []) + excluded = excluded ++ [:skip_darwin] + ExUnit.configure(exclude: excluded) +end + Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual) Mox.defmock(Pleroma.ReverseProxy.ClientMock, for: Pleroma.ReverseProxy.Client) From 355487041a610a2834eebca520660b74a667df06 Mon Sep 17 00:00:00 2001 From: Haelwenn Date: Tue, 16 Jan 2024 16:21:23 +0000 Subject: [PATCH 20/20] We are unsure if OTP27 will bring more breaking changes --- docs/installation/generic_dependencies.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation/generic_dependencies.include b/docs/installation/generic_dependencies.include index 56274a3f0..aebf21e7c 100644 --- a/docs/installation/generic_dependencies.include +++ b/docs/installation/generic_dependencies.include @@ -2,7 +2,7 @@ * PostgreSQL >=9.6 * Elixir >=1.11.0 <1.15 -* Erlang OTP >=22.2.0 +* Erlang OTP >=22.2.0 (supported: <27) * git * file / libmagic * gcc or clang