Merge branch 'capture-test-errors' into 'develop'

Capture test error messages where appropriate

See merge request pleroma/pleroma!1665
This commit is contained in:
lain 2019-09-13 17:07:14 +00:00
commit a9b78f55e3
6 changed files with 70 additions and 36 deletions

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Integration.MastodonWebsocketTest do defmodule Pleroma.Integration.MastodonWebsocketTest do
use Pleroma.DataCase use Pleroma.DataCase
import ExUnit.CaptureLog
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Integration.WebsocketClient alias Pleroma.Integration.WebsocketClient
@ -39,13 +40,17 @@ def start_socket(qs \\ nil, headers \\ []) do
end end
test "refuses invalid requests" do test "refuses invalid requests" do
capture_log(fn ->
assert {:error, {400, _}} = start_socket() assert {:error, {400, _}} = start_socket()
assert {:error, {404, _}} = start_socket("?stream=ncjdk") assert {:error, {404, _}} = start_socket("?stream=ncjdk")
end)
end end
test "requires authentication and a valid token for protected streams" do test "requires authentication and a valid token for protected streams" do
capture_log(fn ->
assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa") assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa")
assert {:error, {403, _}} = start_socket("?stream=user") assert {:error, {403, _}} = start_socket("?stream=user")
end)
end end
test "allows public streams without authentication" do test "allows public streams without authentication" do
@ -100,19 +105,27 @@ test "accepts valid tokens", state do
test "accepts the 'user' stream", %{token: token} = _state do test "accepts the 'user' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}") assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
assert capture_log(fn ->
assert {:error, {403, "Forbidden"}} = start_socket("?stream=user") assert {:error, {403, "Forbidden"}} = start_socket("?stream=user")
end) =~ ":badarg"
end end
test "accepts the 'user:notification' stream", %{token: token} = _state do test "accepts the 'user:notification' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}") assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
assert capture_log(fn ->
assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification") assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification")
end) =~ ":badarg"
end end
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}]) assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
assert capture_log(fn ->
assert {:error, {403, "Forbidden"}} = assert {:error, {403, "Forbidden"}} =
start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}]) start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
end) =~ ":badarg"
end end
end end
end end

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Web.ActivityPub.PublisherTest do defmodule Pleroma.Web.ActivityPub.PublisherTest do
use Pleroma.DataCase use Pleroma.DataCase
import ExUnit.CaptureLog
import Pleroma.Factory import Pleroma.Factory
import Tesla.Mock import Tesla.Mock
import Mock import Mock
@ -188,7 +189,10 @@ test "it returns inbox for messages involving single recipients in total" do
actor = insert(:user) actor = insert(:user)
inbox = "http://connrefused.site/users/nick1/inbox" inbox = "http://connrefused.site/users/nick1/inbox"
assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) assert capture_log(fn ->
assert {:error, _} =
Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
end) =~ "connrefused"
assert called(Instances.set_unreachable(inbox)) assert called(Instances.set_unreachable(inbox))
end end
@ -212,6 +216,7 @@ test "it returns inbox for messages involving single recipients in total" do
actor = insert(:user) actor = insert(:user)
inbox = "http://connrefused.site/users/nick1/inbox" inbox = "http://connrefused.site/users/nick1/inbox"
assert capture_log(fn ->
assert {:error, _} = assert {:error, _} =
Publisher.publish_one(%{ Publisher.publish_one(%{
inbox: inbox, inbox: inbox,
@ -220,6 +225,7 @@ test "it returns inbox for messages involving single recipients in total" do
id: 1, id: 1,
unreachable_since: NaiveDateTime.utc_now() unreachable_since: NaiveDateTime.utc_now()
}) })
end) =~ "connrefused"
refute called(Instances.set_unreachable(inbox)) refute called(Instances.set_unreachable(inbox))
end end

View file

@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Relay
import ExUnit.CaptureLog
import Pleroma.Factory import Pleroma.Factory
import Mock import Mock
@ -20,7 +21,9 @@ test "gets an actor for the relay" do
describe "follow/1" do describe "follow/1" do
test "returns errors when user not found" do test "returns errors when user not found" do
assert capture_log(fn ->
assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"} assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
end) =~ "Could not fetch by AP id"
end end
test "returns activity" do test "returns activity" do
@ -37,7 +40,9 @@ test "returns activity" do
describe "unfollow/1" do describe "unfollow/1" do
test "returns errors when user not found" do test "returns errors when user not found" do
assert capture_log(fn ->
assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"} assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
end) =~ "Could not fetch by AP id"
end end
test "returns activity" do test "returns activity" do
@ -78,7 +83,9 @@ test "returns error when object is unknown" do
} }
) )
assert capture_log(fn ->
assert Relay.publish(activity) == {:error, nil} assert Relay.publish(activity) == {:error, nil}
end) =~ "[error] error: nil"
end end
test_with_mock "returns announce activity and publish to federate", test_with_mock "returns announce activity and publish to federate",

View file

@ -3963,6 +3963,7 @@ test "returns error", %{conn: conn, user: user} do
Config.put([:suggestions, :enabled], true) Config.put([:suggestions, :enabled], true)
Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}") Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
assert capture_log(fn ->
res = res =
conn conn
|> assign(:user, user) |> assign(:user, user)
@ -3970,6 +3971,7 @@ test "returns error", %{conn: conn, user: user} do
|> json_response(500) |> json_response(500)
assert res == "Something went wrong" assert res == "Something went wrong"
end) =~ "Could not retrieve suggestions"
end end
test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do

View file

@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
import ExUnit.CaptureLog
import Pleroma.Factory import Pleroma.Factory
import Mock import Mock
@ -338,12 +339,14 @@ test "show follow page if the `acct` is a account link", %{conn: conn} do
test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
user = insert(:user) user = insert(:user)
assert capture_log(fn ->
response = response =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found") |> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found")
assert html_response(response, 200) =~ "Error fetching user" assert html_response(response, 200) =~ "Error fetching user"
end) =~ "Object has been deleted"
end end
end end

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
import ExUnit.CaptureLog
import Pleroma.Factory import Pleroma.Factory
import Tesla.Mock import Tesla.Mock
@ -75,11 +76,13 @@ test "it returns 404 when user isn't found (XML)" do
test "Sends a 404 when invalid format" do test "Sends a 404 when invalid format" do
user = insert(:user) user = insert(:user)
assert capture_log(fn ->
assert_raise Phoenix.NotAcceptableError, fn -> assert_raise Phoenix.NotAcceptableError, fn ->
build_conn() build_conn()
|> put_req_header("accept", "text/html") |> put_req_header("accept", "text/html")
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost") |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
end end
end) =~ "no supported media type in accept header"
end end
test "Sends a 400 when resource param is missing" do test "Sends a 400 when resource param is missing" do