From 0f59265a50c0985d6ab0ce47b12dd135cfd1e8ac Mon Sep 17 00:00:00 2001 From: Alex S Date: Sun, 16 Jun 2019 18:49:24 +0800 Subject: [PATCH 1/2] salmon fix removed some ownership sandbox error --- lib/pleroma/web/salmon/salmon.ex | 2 +- test/object/containment_test.exs | 6 +++++- test/support/http_request_mock.ex | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 9e91a5a40..e96e4e1e4 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -146,7 +146,7 @@ def publish_one(%{recipient: url, feed: feed} = params) when is_binary(url) do do: Instances.set_reachable(url) Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) - :ok + {:ok, code} else e -> unless params[:unreachable_since], do: Instances.set_reachable(url) diff --git a/test/object/containment_test.exs b/test/object/containment_test.exs index a7a046203..a860355b8 100644 --- a/test/object/containment_test.exs +++ b/test/object/containment_test.exs @@ -5,6 +5,7 @@ defmodule Pleroma.Object.ContainmentTest do alias Pleroma.User import Pleroma.Factory + import ExUnit.CaptureLog setup_all do Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) @@ -57,7 +58,10 @@ test "users cannot be collided through fake direction spoofing attempts" do follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"}) }) - {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye") + assert capture_log(fn -> + {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye") + end) =~ + "[error] Could not decode user at fetch https://n1u.moe/users/rye, {:error, :error}" end end end diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 67ef0928a..f7f55a11a 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -802,6 +802,30 @@ def post("http://example.org/needs_refresh", _, _, _) do }} end + def post("http://mastodon.example.org/inbox", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: "" + }} + end + + def post("https://hubzilla.example.org/inbox", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: "" + }} + end + + def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: "" + }} + end + def post("http://200.site" <> _, _, _, _) do {:ok, %Tesla.Env{ From 2e2edcb461d514609848749355db6fab92e2b4f3 Mon Sep 17 00:00:00 2001 From: Alex S Date: Sun, 16 Jun 2019 19:42:29 +0800 Subject: [PATCH 2/2] capturing errors --- test/web/activity_pub/transmogrifier_test.exs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index cc1781403..68ec03c33 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -15,6 +15,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do alias Pleroma.Web.Websub.WebsubClientSubscription import Pleroma.Factory + import ExUnit.CaptureLog alias Pleroma.Web.CommonAPI setup_all do @@ -73,7 +74,9 @@ test "it does not crash if the object in inReplyTo can't be fetched" do data |> Map.put("object", object) - {:ok, _returned_activity} = Transmogrifier.handle_incoming(data) + assert capture_log(fn -> + {:ok, _returned_activity} = Transmogrifier.handle_incoming(data) + end) =~ "[error] Couldn't fetch \"\"https://404.site/whatever\"\", error: nil" end test "it works for incoming notices" do @@ -516,7 +519,10 @@ test "it fails for incoming deletes with spoofed origin" do data |> Map.put("object", object) - :error = Transmogrifier.handle_incoming(data) + assert capture_log(fn -> + :error = Transmogrifier.handle_incoming(data) + end) =~ + "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}" assert Activity.get_by_id(activity.id) end