From 66cb3294ed942d461cabc32881e2a10ebfd182af Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 2 Nov 2022 22:49:55 -0400 Subject: Switch to PromEx for prometheus metrics Recommending use of the separate HTTP server for exposing the metrics and securing it externally on your firewall or reverse proxy. It will listen on port 4021 by default. --- .../pleroma/web/endpoint/metrics_exporter_test.exs | 69 ---------------------- 1 file changed, 69 deletions(-) delete mode 100644 test/pleroma/web/endpoint/metrics_exporter_test.exs (limited to 'test') diff --git a/test/pleroma/web/endpoint/metrics_exporter_test.exs b/test/pleroma/web/endpoint/metrics_exporter_test.exs deleted file mode 100644 index ad236d4cb..000000000 --- a/test/pleroma/web/endpoint/metrics_exporter_test.exs +++ /dev/null @@ -1,69 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2022 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.Endpoint.MetricsExporterTest do - # Modifies AppEnv, has to stay synchronous - use Pleroma.Web.ConnCase - - alias Pleroma.Web.Endpoint.MetricsExporter - - defp config do - Application.get_env(:prometheus, MetricsExporter) - end - - describe "with default config" do - test "does NOT expose app metrics", %{conn: conn} do - conn - |> get(config()[:path]) - |> json_response(404) - end - end - - describe "when enabled" do - setup do - initial_config = config() - on_exit(fn -> Application.put_env(:prometheus, MetricsExporter, initial_config) end) - - Application.put_env( - :prometheus, - MetricsExporter, - Keyword.put(initial_config, :enabled, true) - ) - end - - test "serves app metrics", %{conn: conn} do - conn = get(conn, config()[:path]) - assert response = response(conn, 200) - - for metric <- [ - "http_requests_total", - "http_request_duration_microseconds", - "phoenix_controller_call_duration", - "telemetry_scrape_duration", - "erlang_vm_memory_atom_bytes_total" - ] do - assert response =~ ~r/#{metric}/ - end - end - - test "when IP whitelist configured, " <> - "serves app metrics only if client IP is whitelisted", - %{conn: conn} do - Application.put_env( - :prometheus, - MetricsExporter, - Keyword.put(config(), :ip_whitelist, ["127.127.127.127", {1, 1, 1, 1}, '255.255.255.255']) - ) - - conn - |> get(config()[:path]) - |> json_response(404) - - conn - |> Map.put(:remote_ip, {127, 127, 127, 127}) - |> get(config()[:path]) - |> response(200) - end - end -end -- cgit v1.2.3 From 66f5ae0c5a0ab57dc6bf3f52bbf976128259800f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 8 Aug 2023 19:08:59 +0200 Subject: router: Make /federation_status publicly available --- test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs index 365d26ab1..02afeda67 100644 --- a/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs @@ -26,6 +26,8 @@ defmodule Pleroma.Web.PleromaApi.InstancesControllerTest do constant_unreachable: constant_unreachable, constant: constant } do + clear_config([:instance, :public], false) + constant_host = URI.parse(constant).host assert conn -- cgit v1.2.3 From 2a58596aef655bb5e347cbb12290700f35ad64e5 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 15 Nov 2023 09:04:41 +0100 Subject: Fix tests for Add support for configuring a favicon and embed PWA manifest in server-generated-meta --- test/pleroma/web/fallback_test.exs | 41 ++++++++++------------ .../web/o_status/o_status_controller_test.exs | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/pleroma/web/fallback_test.exs b/test/pleroma/web/fallback_test.exs index 6d11d4f37..ed34d6490 100644 --- a/test/pleroma/web/fallback_test.exs +++ b/test/pleroma/web/fallback_test.exs @@ -6,20 +6,6 @@ defmodule Pleroma.Web.FallbackTest do use Pleroma.Web.ConnCase import Pleroma.Factory - describe "neither preloaded data nor metadata attached to" do - test "GET /registration/:token", %{conn: conn} do - response = get(conn, "/registration/foo") - - assert html_response(response, 200) =~ "" - end - - test "GET /*path", %{conn: conn} do - assert conn - |> get("/foo") - |> html_response(200) =~ "" - end - end - test "GET /*path adds a title", %{conn: conn} do clear_config([:instance, :name], "a cool title") @@ -29,21 +15,28 @@ defmodule Pleroma.Web.FallbackTest do end describe "preloaded data and metadata attached to" do - test "GET /:maybe_nickname_or_id", %{conn: conn} do + test "GET /:maybe_nickname_or_id with existing user", %{conn: conn} do clear_config([:instance, :name], "a cool title") - user = insert(:user) - user_missing = get(conn, "/foo") - user_present = get(conn, "/#{user.nickname}") - assert html_response(user_missing, 200) =~ "" - refute html_response(user_present, 200) =~ "" - assert html_response(user_present, 200) =~ "initial-results" - assert html_response(user_present, 200) =~ "a cool title" + resp = get(conn, "/#{user.nickname}") + + assert html_response(resp, 200) =~ "a cool title" + refute html_response(resp, 200) =~ "" + assert html_response(resp, 200) =~ "initial-results" + end + + test "GET /:maybe_nickname_or_id with missing user", %{conn: conn} do + clear_config([:instance, :name], "a cool title") + + resp = get(conn, "/foo") + + assert html_response(resp, 200) =~ "a cool title" + refute html_response(resp, 200) =~ "initial-results" end test "GET /*path", %{conn: conn} do - assert conn + refute conn |> get("/foo") |> html_response(200) =~ "" @@ -65,10 +58,12 @@ defmodule Pleroma.Web.FallbackTest do end test "GET /main/all", %{conn: conn} do + clear_config([:instance, :name], "a cool title") public_page = get(conn, "/main/all") refute html_response(public_page, 200) =~ "" assert html_response(public_page, 200) =~ "initial-results" + assert html_response(public_page, 200) =~ "a cool title" end end diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index 36e581f5e..3e8fcd956 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -196,7 +196,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> get("/notice/#{like_activity.id}") |> response(200) - assert resp =~ "" + refute resp =~ ~r( Date: Wed, 15 Nov 2023 00:43:58 -0700 Subject: Add optional URL value for scrobbles --- .../web/pleroma_api/controllers/scrobble_controller_test.exs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs index 908ce962d..df12a05ce 100644 --- a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs @@ -18,7 +18,8 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do "title" => "lain radio episode 1", "artist" => "lain", "album" => "lain radio", - "length" => "180000" + "length" => "180000", + "url" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1" }) assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200) @@ -33,21 +34,24 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do CommonAPI.listen(user, %{ title: "lain radio episode 1", artist: "lain", - album: "lain radio" + album: "lain radio", + url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1" }) {:ok, _activity} = CommonAPI.listen(user, %{ title: "lain radio episode 2", artist: "lain", - album: "lain radio" + album: "lain radio", + url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2" }) {:ok, _activity} = CommonAPI.listen(user, %{ title: "lain radio episode 3", artist: "lain", - album: "lain radio" + album: "lain radio", + url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3" }) conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles") -- cgit v1.2.3 From 5a3b81d92ef532769a11d4374424665f6d97a08f Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Mon, 27 Nov 2023 17:55:16 +0400 Subject: ActivityPub.UtilsTest: Add failing test for strip_report_status_data --- test/pleroma/web/activity_pub/utils_test.exs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test') diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index 3f93c872b..05bff1e1c 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -16,6 +16,37 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do require Pleroma.Constants + describe "strip_report_status_data/1" do + test "does not break on issues with the reported activites" do + reporter = insert(:user) + target_account = insert(:user) + {:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"}) + context = Utils.generate_context_id() + content = "foobar" + + res = + Utils.make_flag_data( + %{ + actor: reporter, + context: context, + account: target_account, + statuses: [%{"id" => activity.data["id"]}], + content: content + }, + %{} + ) + + res = + res + |> Map.put("object", res["object"] ++ [nil, 1, 5, "123"]) + + {:ok, activity} = Pleroma.Web.ActivityPub.ActivityPub.insert(res) + + Utils.strip_report_status_data(activity) + |> IO.inspect() + end + end + describe "fetch the latest Follow" do test "fetches the latest Follow activity" do %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity) -- cgit v1.2.3 From 4ef56c5b65a4d1e7e90a87f1a1a507df523a4b4b Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Mon, 27 Nov 2023 18:44:11 +0400 Subject: ActivityPub.Utils: Only treat object ids as valid while stripping --- test/pleroma/web/activity_pub/utils_test.exs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index 05bff1e1c..9ca21f5d9 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -23,6 +23,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do {:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"}) context = Utils.generate_context_id() content = "foobar" + post_id = activity.data["id"] res = Utils.make_flag_data( @@ -30,7 +31,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do actor: reporter, context: context, account: target_account, - statuses: [%{"id" => activity.data["id"]}], + statuses: [%{"id" => post_id}], content: content }, %{} @@ -42,8 +43,11 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do {:ok, activity} = Pleroma.Web.ActivityPub.ActivityPub.insert(res) - Utils.strip_report_status_data(activity) - |> IO.inspect() + [user_id, object | _] = activity.data["object"] + + {:ok, stripped} = Utils.strip_report_status_data(activity) + + assert stripped.data["object"] == [user_id, object["id"]] end end -- cgit v1.2.3 From 03db495e1d88f34bef8d556b0f88806c3260d403 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Tue, 28 Nov 2023 12:23:41 +0400 Subject: AnalyzeMetadata: Switch to rinpatch_blurhash --- test/fixtures/png_with_transparency.png | Bin 0 -> 84250 bytes test/pleroma/upload/filter/analyze_metadata_test.exs | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/fixtures/png_with_transparency.png (limited to 'test') diff --git a/test/fixtures/png_with_transparency.png b/test/fixtures/png_with_transparency.png new file mode 100644 index 000000000..7963149db Binary files /dev/null and b/test/fixtures/png_with_transparency.png differ diff --git a/test/pleroma/upload/filter/analyze_metadata_test.exs b/test/pleroma/upload/filter/analyze_metadata_test.exs index b800a4a43..e4ac673b2 100644 --- a/test/pleroma/upload/filter/analyze_metadata_test.exs +++ b/test/pleroma/upload/filter/analyze_metadata_test.exs @@ -20,6 +20,20 @@ defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do assert meta.blurhash end + test "it blurhashes images with an alpha component" do + upload = %Pleroma.Upload{ + name: "an… image.jpg", + content_type: "image/jpeg", + path: Path.absname("test/fixtures/png_with_transparency.png"), + tempfile: Path.absname("test/fixtures/png_with_transparency.png") + } + + {:ok, :filtered, meta} = AnalyzeMetadata.filter(upload) + + assert %{width: 320, height: 320} = meta + assert meta.blurhash == "eXJi-E:SwCEm5rCmn$+YWYn+15K#5A$xxCi{SiV]s*W:Efa#s.jE-T" + end + test "adds the dimensions for videos" do upload = %Pleroma.Upload{ name: "coolvideo.mp4", -- cgit v1.2.3 From e216603477e2c393a586f7eb0bc8183e73bf4cd7 Mon Sep 17 00:00:00 2001 From: NEETzsche Date: Wed, 29 Nov 2023 07:55:44 -0700 Subject: Change url to externalLink as requested by hj here: https://shigusegubu.club/notice/AcIjZjackKAt6e522a --- .../web/pleroma_api/controllers/scrobble_controller_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs index df12a05ce..be94a02ad 100644 --- a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs @@ -19,7 +19,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do "artist" => "lain", "album" => "lain radio", "length" => "180000", - "url" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1" + "externalLink" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1" }) assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200) @@ -35,7 +35,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do title: "lain radio episode 1", artist: "lain", album: "lain radio", - url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1" + externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1" }) {:ok, _activity} = @@ -43,7 +43,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do title: "lain radio episode 2", artist: "lain", album: "lain radio", - url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2" + externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2" }) {:ok, _activity} = @@ -51,7 +51,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do title: "lain radio episode 3", artist: "lain", album: "lain radio", - url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3" + externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3" }) conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles") -- cgit v1.2.3 From 1ad0d94d6f1f11c848f277877cc14b3a47a7ae95 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 5 Dec 2023 16:35:41 -0500 Subject: Change set_reachable/1 to an upsert --- test/pleroma/instances/instance_test.exs | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test') diff --git a/test/pleroma/instances/instance_test.exs b/test/pleroma/instances/instance_test.exs index a769f9362..6a718be21 100644 --- a/test/pleroma/instances/instance_test.exs +++ b/test/pleroma/instances/instance_test.exs @@ -31,14 +31,6 @@ defmodule Pleroma.Instances.InstanceTest do assert {:ok, instance} = Instance.set_reachable(instance.host) refute instance.unreachable_since end - - test "does NOT create an Instance record in case of no existing matching record" do - host = "domain.org" - assert nil == Instance.set_reachable(host) - - assert [] = Repo.all(Ecto.Query.from(i in Instance)) - assert Instance.reachable?(host) - end end describe "set_unreachable/1" do -- cgit v1.2.3