[#878] Merge remote-tracking branch 'remotes/upstream/develop' into 878-activity-object-decoupling-in-tests
# Conflicts: # lib/pleroma/object.ex # test/web/activity_pub/transmogrifier_test.exs # test/web/ostatus/ostatus_test.exs
This commit is contained in:
commit
829e997223
145 changed files with 1807 additions and 345 deletions
|
|
@ -11,6 +11,16 @@ defmodule Pleroma.ConversationTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it goes through old direct conversations" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
7
test/fixtures/users_mock/masto_closed_followers.json
vendored
Normal file
7
test/fixtures/users_mock/masto_closed_followers.json
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"id": "http://localhost:4001/users/masto_closed/followers",
|
||||
"type": "OrderedCollection",
|
||||
"totalItems": 437,
|
||||
"first": "http://localhost:4001/users/masto_closed/followers?page=1"
|
||||
}
|
||||
7
test/fixtures/users_mock/masto_closed_following.json
vendored
Normal file
7
test/fixtures/users_mock/masto_closed_following.json
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"id": "http://localhost:4001/users/masto_closed/following",
|
||||
"type": "OrderedCollection",
|
||||
"totalItems": 152,
|
||||
"first": "http://localhost:4001/users/masto_closed/following?page=1"
|
||||
}
|
||||
20
test/fixtures/users_mock/pleroma_followers.json
vendored
Normal file
20
test/fixtures/users_mock/pleroma_followers.json
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"type": "OrderedCollection",
|
||||
"totalItems": 527,
|
||||
"id": "http://localhost:4001/users/fuser2/followers",
|
||||
"first": {
|
||||
"type": "OrderedCollectionPage",
|
||||
"totalItems": 527,
|
||||
"partOf": "http://localhost:4001/users/fuser2/followers",
|
||||
"orderedItems": [],
|
||||
"next": "http://localhost:4001/users/fuser2/followers?page=2",
|
||||
"id": "http://localhost:4001/users/fuser2/followers?page=1"
|
||||
},
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"http://localhost:4001/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
test/fixtures/users_mock/pleroma_following.json
vendored
Normal file
20
test/fixtures/users_mock/pleroma_following.json
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"type": "OrderedCollection",
|
||||
"totalItems": 267,
|
||||
"id": "http://localhost:4001/users/fuser2/following",
|
||||
"first": {
|
||||
"type": "OrderedCollectionPage",
|
||||
"totalItems": 267,
|
||||
"partOf": "http://localhost:4001/users/fuser2/following",
|
||||
"orderedItems": [],
|
||||
"next": "http://localhost:4001/users/fuser2/following?page=2",
|
||||
"id": "http://localhost:4001/users/fuser2/following?page=1"
|
||||
},
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"http://localhost:4001/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
]
|
||||
}
|
||||
91
test/http/request_builder_test.exs
Normal file
91
test/http/request_builder_test.exs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
defmodule Pleroma.HTTP.RequestBuilderTest do
|
||||
use ExUnit.Case, async: true
|
||||
alias Pleroma.HTTP.RequestBuilder
|
||||
|
||||
describe "headers/2" do
|
||||
test "don't send pleroma user agent" do
|
||||
assert RequestBuilder.headers(%{}, []) == %{headers: []}
|
||||
end
|
||||
|
||||
test "send pleroma user agent" do
|
||||
send = Pleroma.Config.get([:http, :send_user_agent])
|
||||
Pleroma.Config.put([:http, :send_user_agent], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:http, :send_user_agent], send)
|
||||
end)
|
||||
|
||||
assert RequestBuilder.headers(%{}, []) == %{
|
||||
headers: [{"User-Agent", Pleroma.Application.user_agent()}]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_optional_params/3" do
|
||||
test "don't add if keyword is empty" do
|
||||
assert RequestBuilder.add_optional_params(%{}, %{}, []) == %{}
|
||||
end
|
||||
|
||||
test "add query parameter" do
|
||||
assert RequestBuilder.add_optional_params(
|
||||
%{},
|
||||
%{query: :query, body: :body, another: :val},
|
||||
[
|
||||
{:query, "param1=val1¶m2=val2"},
|
||||
{:body, "some body"}
|
||||
]
|
||||
) == %{query: "param1=val1¶m2=val2", body: "some body"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_param/4" do
|
||||
test "add file parameter" do
|
||||
%{
|
||||
body: %Tesla.Multipart{
|
||||
boundary: _,
|
||||
content_type_params: [],
|
||||
parts: [
|
||||
%Tesla.Multipart.Part{
|
||||
body: %File.Stream{
|
||||
line_or_bytes: 2048,
|
||||
modes: [:raw, :read_ahead, :read, :binary],
|
||||
path: "some-path/filename.png",
|
||||
raw: true
|
||||
},
|
||||
dispositions: [name: "filename.png", filename: "filename.png"],
|
||||
headers: []
|
||||
}
|
||||
]
|
||||
}
|
||||
} = RequestBuilder.add_param(%{}, :file, "filename.png", "some-path/filename.png")
|
||||
end
|
||||
|
||||
test "add key to body" do
|
||||
%{
|
||||
body: %Tesla.Multipart{
|
||||
boundary: _,
|
||||
content_type_params: [],
|
||||
parts: [
|
||||
%Tesla.Multipart.Part{
|
||||
body: "\"someval\"",
|
||||
dispositions: [name: "somekey"],
|
||||
headers: ["Content-Type": "application/json"]
|
||||
}
|
||||
]
|
||||
}
|
||||
} = RequestBuilder.add_param(%{}, :body, "somekey", "someval")
|
||||
end
|
||||
|
||||
test "add form parameter" do
|
||||
assert RequestBuilder.add_param(%{}, :form, "somename", "someval") == %{
|
||||
body: %{"somename" => "someval"}
|
||||
}
|
||||
end
|
||||
|
||||
test "add for location" do
|
||||
assert RequestBuilder.add_param(%{}, :some_location, "somekey", "someval") == %{
|
||||
some_location: [{"somekey", "someval"}]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -107,5 +107,12 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
|
||||
assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification")
|
||||
end
|
||||
|
||||
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
|
||||
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
|
||||
|
||||
assert {:error, {403, "Forbidden"}} =
|
||||
start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -70,14 +70,6 @@ defmodule Pleroma.MediaProxyTest do
|
|||
assert decode_result(encoded) == url
|
||||
end
|
||||
|
||||
test "ensures urls are url-encoded" do
|
||||
assert decode_result(url("https://pleroma.social/Hello world.jpg")) ==
|
||||
"https://pleroma.social/Hello%20world.jpg"
|
||||
|
||||
assert decode_result(url("https://pleroma.social/Hello%20world.jpg")) ==
|
||||
"https://pleroma.social/Hello%20world.jpg"
|
||||
end
|
||||
|
||||
test "validates signature" do
|
||||
secret_key_base = Pleroma.Config.get([Pleroma.Web.Endpoint, :secret_key_base])
|
||||
|
||||
|
|
@ -141,10 +133,31 @@ defmodule Pleroma.MediaProxyTest do
|
|||
assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url]))
|
||||
end
|
||||
|
||||
# https://git.pleroma.social/pleroma/pleroma/issues/580
|
||||
test "encoding S3 links (must preserve `%2F`)" do
|
||||
# Some sites expect ASCII encoded characters in the URL to be preserved even if
|
||||
# unnecessary.
|
||||
# Issues: https://git.pleroma.social/pleroma/pleroma/issues/580
|
||||
# https://git.pleroma.social/pleroma/pleroma/issues/1055
|
||||
test "preserve ASCII encoding" do
|
||||
url =
|
||||
"https://s3.amazonaws.com/example/test.png?X-Amz-Credential=your-access-key-id%2F20130721%2Fus-east-1%2Fs3%2Faws4_request"
|
||||
"https://pleroma.com/%20/%21/%22/%23/%24/%25/%26/%27/%28/%29/%2A/%2B/%2C/%2D/%2E/%2F/%30/%31/%32/%33/%34/%35/%36/%37/%38/%39/%3A/%3B/%3C/%3D/%3E/%3F/%40/%41/%42/%43/%44/%45/%46/%47/%48/%49/%4A/%4B/%4C/%4D/%4E/%4F/%50/%51/%52/%53/%54/%55/%56/%57/%58/%59/%5A/%5B/%5C/%5D/%5E/%5F/%60/%61/%62/%63/%64/%65/%66/%67/%68/%69/%6A/%6B/%6C/%6D/%6E/%6F/%70/%71/%72/%73/%74/%75/%76/%77/%78/%79/%7A/%7B/%7C/%7D/%7E/%7F/%80/%81/%82/%83/%84/%85/%86/%87/%88/%89/%8A/%8B/%8C/%8D/%8E/%8F/%90/%91/%92/%93/%94/%95/%96/%97/%98/%99/%9A/%9B/%9C/%9D/%9E/%9F/%C2%A0/%A1/%A2/%A3/%A4/%A5/%A6/%A7/%A8/%A9/%AA/%AB/%AC/%C2%AD/%AE/%AF/%B0/%B1/%B2/%B3/%B4/%B5/%B6/%B7/%B8/%B9/%BA/%BB/%BC/%BD/%BE/%BF/%C0/%C1/%C2/%C3/%C4/%C5/%C6/%C7/%C8/%C9/%CA/%CB/%CC/%CD/%CE/%CF/%D0/%D1/%D2/%D3/%D4/%D5/%D6/%D7/%D8/%D9/%DA/%DB/%DC/%DD/%DE/%DF/%E0/%E1/%E2/%E3/%E4/%E5/%E6/%E7/%E8/%E9/%EA/%EB/%EC/%ED/%EE/%EF/%F0/%F1/%F2/%F3/%F4/%F5/%F6/%F7/%F8/%F9/%FA/%FB/%FC/%FD/%FE/%FF"
|
||||
|
||||
encoded = url(url)
|
||||
assert decode_result(encoded) == url
|
||||
end
|
||||
|
||||
# This includes unsafe/reserved characters which are not interpreted as part of the URL
|
||||
# and would otherwise have to be ASCII encoded. It is our role to ensure the proxied URL
|
||||
# is unmodified, so we are testing these characters anyway.
|
||||
test "preserve non-unicode characters per RFC3986" do
|
||||
url =
|
||||
"https://pleroma.com/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-._~:/?#[]@!$&'()*+,;=|^`{}"
|
||||
|
||||
encoded = url(url)
|
||||
assert decode_result(encoded) == url
|
||||
end
|
||||
|
||||
test "preserve unicode characters" do
|
||||
url = "https://ko.wikipedia.org/wiki/위키백과:대문"
|
||||
|
||||
encoded = url(url)
|
||||
assert decode_result(encoded) == url
|
||||
|
|
|
|||
297
test/reverse_proxy_test.exs
Normal file
297
test/reverse_proxy_test.exs
Normal file
|
|
@ -0,0 +1,297 @@
|
|||
defmodule Pleroma.ReverseProxyTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
import ExUnit.CaptureLog
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
alias Pleroma.ReverseProxy
|
||||
alias Pleroma.ReverseProxy.ClientMock
|
||||
|
||||
setup_all do
|
||||
{:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.ReverseProxy.ClientMock)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup :verify_on_exit!
|
||||
|
||||
defp user_agent_mock(user_agent, invokes) do
|
||||
json = Jason.encode!(%{"user-agent": user_agent})
|
||||
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, url, _, _, _ ->
|
||||
Registry.register(Pleroma.ReverseProxy.ClientMock, url, 0)
|
||||
|
||||
{:ok, 200,
|
||||
[
|
||||
{"content-type", "application/json"},
|
||||
{"content-length", byte_size(json) |> to_string()}
|
||||
], %{url: url}}
|
||||
end)
|
||||
|> expect(:stream_body, invokes, fn %{url: url} ->
|
||||
case Registry.lookup(Pleroma.ReverseProxy.ClientMock, url) do
|
||||
[{_, 0}] ->
|
||||
Registry.update_value(Pleroma.ReverseProxy.ClientMock, url, &(&1 + 1))
|
||||
{:ok, json}
|
||||
|
||||
[{_, 1}] ->
|
||||
Registry.unregister(Pleroma.ReverseProxy.ClientMock, url)
|
||||
:done
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
describe "user-agent" do
|
||||
test "don't keep", %{conn: conn} do
|
||||
user_agent_mock("hackney/1.15.1", 2)
|
||||
conn = ReverseProxy.call(conn, "/user-agent")
|
||||
assert json_response(conn, 200) == %{"user-agent" => "hackney/1.15.1"}
|
||||
end
|
||||
|
||||
test "keep", %{conn: conn} do
|
||||
user_agent_mock(Pleroma.Application.user_agent(), 2)
|
||||
conn = ReverseProxy.call(conn, "/user-agent-keep", keep_user_agent: true)
|
||||
assert json_response(conn, 200) == %{"user-agent" => Pleroma.Application.user_agent()}
|
||||
end
|
||||
end
|
||||
|
||||
test "closed connection", %{conn: conn} do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/closed", _, _, _ -> {:ok, 200, [], %{}} end)
|
||||
|> expect(:stream_body, fn _ -> {:error, :closed} end)
|
||||
|> expect(:close, fn _ -> :ok end)
|
||||
|
||||
conn = ReverseProxy.call(conn, "/closed")
|
||||
assert conn.halted
|
||||
end
|
||||
|
||||
describe "max_body " do
|
||||
test "length returns error if content-length more than option", %{conn: conn} do
|
||||
user_agent_mock("hackney/1.15.1", 0)
|
||||
|
||||
assert capture_log(fn ->
|
||||
ReverseProxy.call(conn, "/user-agent", max_body_length: 4)
|
||||
end) =~
|
||||
"[error] Elixir.Pleroma.ReverseProxy: request to \"/user-agent\" failed: :body_too_large"
|
||||
end
|
||||
|
||||
defp stream_mock(invokes, with_close? \\ false) do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/stream-bytes/" <> length, _, _, _ ->
|
||||
Registry.register(Pleroma.ReverseProxy.ClientMock, "/stream-bytes/" <> length, 0)
|
||||
|
||||
{:ok, 200, [{"content-type", "application/octet-stream"}],
|
||||
%{url: "/stream-bytes/" <> length}}
|
||||
end)
|
||||
|> expect(:stream_body, invokes, fn %{url: "/stream-bytes/" <> length} ->
|
||||
max = String.to_integer(length)
|
||||
|
||||
case Registry.lookup(Pleroma.ReverseProxy.ClientMock, "/stream-bytes/" <> length) do
|
||||
[{_, current}] when current < max ->
|
||||
Registry.update_value(
|
||||
Pleroma.ReverseProxy.ClientMock,
|
||||
"/stream-bytes/" <> length,
|
||||
&(&1 + 10)
|
||||
)
|
||||
|
||||
{:ok, "0123456789"}
|
||||
|
||||
[{_, ^max}] ->
|
||||
Registry.unregister(Pleroma.ReverseProxy.ClientMock, "/stream-bytes/" <> length)
|
||||
:done
|
||||
end
|
||||
end)
|
||||
|
||||
if with_close? do
|
||||
expect(ClientMock, :close, fn _ -> :ok end)
|
||||
end
|
||||
end
|
||||
|
||||
test "max_body_size returns error if streaming body more than that option", %{conn: conn} do
|
||||
stream_mock(3, true)
|
||||
|
||||
assert capture_log(fn ->
|
||||
ReverseProxy.call(conn, "/stream-bytes/50", max_body_size: 30)
|
||||
end) =~
|
||||
"[warn] Elixir.Pleroma.ReverseProxy request to /stream-bytes/50 failed while reading/chunking: :body_too_large"
|
||||
end
|
||||
end
|
||||
|
||||
describe "HEAD requests" do
|
||||
test "common", %{conn: conn} do
|
||||
ClientMock
|
||||
|> expect(:request, fn :head, "/head", _, _, _ ->
|
||||
{:ok, 200, [{"content-type", "text/html; charset=utf-8"}]}
|
||||
end)
|
||||
|
||||
conn = ReverseProxy.call(Map.put(conn, :method, "HEAD"), "/head")
|
||||
assert html_response(conn, 200) == ""
|
||||
end
|
||||
end
|
||||
|
||||
defp error_mock(status) when is_integer(status) do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/status/" <> _, _, _, _ ->
|
||||
{:error, status}
|
||||
end)
|
||||
end
|
||||
|
||||
describe "returns error on" do
|
||||
test "500", %{conn: conn} do
|
||||
error_mock(500)
|
||||
|
||||
capture_log(fn -> ReverseProxy.call(conn, "/status/500") end) =~
|
||||
"[error] Elixir.Pleroma.ReverseProxy: request to /status/500 failed with HTTP status 500"
|
||||
end
|
||||
|
||||
test "400", %{conn: conn} do
|
||||
error_mock(400)
|
||||
|
||||
capture_log(fn -> ReverseProxy.call(conn, "/status/400") end) =~
|
||||
"[error] Elixir.Pleroma.ReverseProxy: request to /status/400 failed with HTTP status 400"
|
||||
end
|
||||
|
||||
test "204", %{conn: conn} do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/status/204", _, _, _ -> {:ok, 204, [], %{}} end)
|
||||
|
||||
capture_log(fn ->
|
||||
conn = ReverseProxy.call(conn, "/status/204")
|
||||
assert conn.resp_body == "Request failed: No Content"
|
||||
assert conn.halted
|
||||
end) =~
|
||||
"[error] Elixir.Pleroma.ReverseProxy: request to \"/status/204\" failed with HTTP status 204"
|
||||
end
|
||||
end
|
||||
|
||||
test "streaming", %{conn: conn} do
|
||||
stream_mock(21)
|
||||
conn = ReverseProxy.call(conn, "/stream-bytes/200")
|
||||
assert conn.state == :chunked
|
||||
assert byte_size(conn.resp_body) == 200
|
||||
assert Plug.Conn.get_resp_header(conn, "content-type") == ["application/octet-stream"]
|
||||
end
|
||||
|
||||
defp headers_mock(_) do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/headers", headers, _, _ ->
|
||||
Registry.register(Pleroma.ReverseProxy.ClientMock, "/headers", 0)
|
||||
{:ok, 200, [{"content-type", "application/json"}], %{url: "/headers", headers: headers}}
|
||||
end)
|
||||
|> expect(:stream_body, 2, fn %{url: url, headers: headers} ->
|
||||
case Registry.lookup(Pleroma.ReverseProxy.ClientMock, url) do
|
||||
[{_, 0}] ->
|
||||
Registry.update_value(Pleroma.ReverseProxy.ClientMock, url, &(&1 + 1))
|
||||
headers = for {k, v} <- headers, into: %{}, do: {String.capitalize(k), v}
|
||||
{:ok, Jason.encode!(%{headers: headers})}
|
||||
|
||||
[{_, 1}] ->
|
||||
Registry.unregister(Pleroma.ReverseProxy.ClientMock, url)
|
||||
:done
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "keep request headers" do
|
||||
setup [:headers_mock]
|
||||
|
||||
test "header passes", %{conn: conn} do
|
||||
conn =
|
||||
Plug.Conn.put_req_header(
|
||||
conn,
|
||||
"accept",
|
||||
"text/html"
|
||||
)
|
||||
|> ReverseProxy.call("/headers")
|
||||
|
||||
%{"headers" => headers} = json_response(conn, 200)
|
||||
assert headers["Accept"] == "text/html"
|
||||
end
|
||||
|
||||
test "header is filtered", %{conn: conn} do
|
||||
conn =
|
||||
Plug.Conn.put_req_header(
|
||||
conn,
|
||||
"accept-language",
|
||||
"en-US"
|
||||
)
|
||||
|> ReverseProxy.call("/headers")
|
||||
|
||||
%{"headers" => headers} = json_response(conn, 200)
|
||||
refute headers["Accept-Language"]
|
||||
end
|
||||
end
|
||||
|
||||
test "returns 400 on non GET, HEAD requests", %{conn: conn} do
|
||||
conn = ReverseProxy.call(Map.put(conn, :method, "POST"), "/ip")
|
||||
assert conn.status == 400
|
||||
end
|
||||
|
||||
describe "cache resp headers" do
|
||||
test "returns headers", %{conn: conn} do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/cache/" <> ttl, _, _, _ ->
|
||||
{:ok, 200, [{"cache-control", "public, max-age=" <> ttl}], %{}}
|
||||
end)
|
||||
|> expect(:stream_body, fn _ -> :done end)
|
||||
|
||||
conn = ReverseProxy.call(conn, "/cache/10")
|
||||
assert {"cache-control", "public, max-age=10"} in conn.resp_headers
|
||||
end
|
||||
|
||||
test "add cache-control", %{conn: conn} do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/cache", _, _, _ ->
|
||||
{:ok, 200, [{"ETag", "some ETag"}], %{}}
|
||||
end)
|
||||
|> expect(:stream_body, fn _ -> :done end)
|
||||
|
||||
conn = ReverseProxy.call(conn, "/cache")
|
||||
assert {"cache-control", "public"} in conn.resp_headers
|
||||
end
|
||||
end
|
||||
|
||||
defp disposition_headers_mock(headers) do
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/disposition", _, _, _ ->
|
||||
Registry.register(Pleroma.ReverseProxy.ClientMock, "/disposition", 0)
|
||||
|
||||
{:ok, 200, headers, %{url: "/disposition"}}
|
||||
end)
|
||||
|> expect(:stream_body, 2, fn %{url: "/disposition"} ->
|
||||
case Registry.lookup(Pleroma.ReverseProxy.ClientMock, "/disposition") do
|
||||
[{_, 0}] ->
|
||||
Registry.update_value(Pleroma.ReverseProxy.ClientMock, "/disposition", &(&1 + 1))
|
||||
{:ok, ""}
|
||||
|
||||
[{_, 1}] ->
|
||||
Registry.unregister(Pleroma.ReverseProxy.ClientMock, "/disposition")
|
||||
:done
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
describe "response content disposition header" do
|
||||
test "not atachment", %{conn: conn} do
|
||||
disposition_headers_mock([
|
||||
{"content-type", "image/gif"},
|
||||
{"content-length", 0}
|
||||
])
|
||||
|
||||
conn = ReverseProxy.call(conn, "/disposition")
|
||||
|
||||
assert {"content-type", "image/gif"} in conn.resp_headers
|
||||
end
|
||||
|
||||
test "with content-disposition header", %{conn: conn} do
|
||||
disposition_headers_mock([
|
||||
{"content-disposition", "attachment; filename=\"filename.jpg\""},
|
||||
{"content-length", 0}
|
||||
])
|
||||
|
||||
conn = ReverseProxy.call(conn, "/disposition")
|
||||
|
||||
assert {"content-disposition", "attachment; filename=\"filename.jpg\""} in conn.resp_headers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -31,8 +31,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -40,7 +39,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/status.emelie.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -48,7 +47,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/emelie.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/emelie.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -56,7 +55,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/rinpatch.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/rinpatch.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -69,7 +68,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/webfinger_emelie.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -77,7 +76,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/emelie.atom")
|
||||
body: File.read!("test/fixtures/tesla_mock/emelie.atom")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -90,7 +89,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -103,7 +102,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -111,7 +110,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -124,7 +123,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -137,7 +136,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -150,7 +149,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -158,7 +157,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -171,7 +170,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
|
||||
body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -184,7 +183,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -197,7 +196,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -210,7 +209,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -218,7 +217,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___prismo.news__mxb.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -231,7 +230,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -239,7 +238,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/rye.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/rye.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -247,7 +246,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/rye.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/rye.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -257,7 +256,7 @@ defmodule HttpRequestMock do
|
|||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
|
||||
"test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
|
||||
)
|
||||
}}
|
||||
end
|
||||
|
|
@ -266,7 +265,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/puckipedia.com.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -274,7 +273,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/7even.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/7even.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -282,7 +281,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/peertube.moe-vid.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -290,7 +289,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -298,7 +297,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -306,7 +305,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -331,7 +330,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/7369654.html")
|
||||
body: File.read!("test/fixtures/tesla_mock/7369654.html")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -339,7 +338,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/mayumayu.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -352,7 +351,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/mayumayupost.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -362,7 +361,7 @@ defmodule HttpRequestMock do
|
|||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
|
||||
"test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
|
||||
)
|
||||
}}
|
||||
end
|
||||
|
|
@ -375,7 +374,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -385,7 +384,7 @@ defmodule HttpRequestMock do
|
|||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
|
||||
"test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
|
||||
)
|
||||
}}
|
||||
end
|
||||
|
|
@ -399,7 +398,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -407,8 +406,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -418,7 +416,7 @@ defmodule HttpRequestMock do
|
|||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
|
||||
"test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
|
||||
)
|
||||
}}
|
||||
end
|
||||
|
|
@ -431,7 +429,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/spc_5381.atom")
|
||||
body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -444,7 +442,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -452,7 +450,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/shitposter.club_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -460,7 +458,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/7369654.atom")
|
||||
body: File.read!("test/fixtures/tesla_mock/7369654.atom")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -468,7 +466,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/7369654.html")
|
||||
body: File.read!("test/fixtures/tesla_mock/7369654.html")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -476,7 +474,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
|
||||
body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -484,7 +482,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -497,7 +495,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -507,14 +505,14 @@ defmodule HttpRequestMock do
|
|||
_,
|
||||
Accept: "application/atom+xml"
|
||||
) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")}}
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/mastodon.social_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -528,9 +526,7 @@ defmodule HttpRequestMock do
|
|||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml"
|
||||
)
|
||||
File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -538,7 +534,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/gs.example.org_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -552,9 +548,7 @@ defmodule HttpRequestMock do
|
|||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml"
|
||||
)
|
||||
File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -573,7 +567,7 @@ defmodule HttpRequestMock do
|
|||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
|
||||
"test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
|
||||
)
|
||||
}}
|
||||
end
|
||||
|
|
@ -584,14 +578,14 @@ defmodule HttpRequestMock do
|
|||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
|
||||
"test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
|
||||
)
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://squeet.me/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")}}
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
|
||||
end
|
||||
|
||||
def get(
|
||||
|
|
@ -603,7 +597,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -616,7 +610,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -624,7 +618,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/framatube.org_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -638,7 +632,7 @@ defmodule HttpRequestMock do
|
|||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/json"}],
|
||||
body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -646,7 +640,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/gnusocial.de_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -659,7 +653,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -667,7 +661,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/status.alpicola.com_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -675,7 +669,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/macgirvin.com_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -683,7 +677,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/gerzilla.de_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -697,7 +691,7 @@ defmodule HttpRequestMock do
|
|||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/json"}],
|
||||
body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -707,7 +701,7 @@ defmodule HttpRequestMock do
|
|||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
|
||||
"test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
|
||||
)
|
||||
}}
|
||||
end
|
||||
|
|
@ -721,7 +715,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -729,7 +723,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -737,7 +731,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
|
||||
body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -765,6 +759,54 @@ defmodule HttpRequestMock do
|
|||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/fuser2/following", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/pleroma_following.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 504,
|
||||
body: ""
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 504,
|
||||
body: ""
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://example.com/ogp-missing-data", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
|
|||
11
test/tasks/ecto/ecto_test.exs
Normal file
11
test/tasks/ecto/ecto_test.exs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
defmodule Mix.Tasks.Pleroma.EctoTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
test "raise on bad path" do
|
||||
assert_raise RuntimeError, ~r/Could not find migrations directory/, fn ->
|
||||
Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo,
|
||||
migrations_path: "some-path"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
46
test/tasks/pleroma_test.exs
Normal file
46
test/tasks/pleroma_test.exs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
defmodule Mix.PleromaTest do
|
||||
use ExUnit.Case, async: true
|
||||
import Mix.Pleroma
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
on_exit(fn ->
|
||||
Mix.shell(Mix.Shell.IO)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "shell_prompt/1" do
|
||||
test "input" do
|
||||
send(self(), {:mix_shell_input, :prompt, "Yes"})
|
||||
|
||||
answer = shell_prompt("Do you want this?")
|
||||
assert_received {:mix_shell, :prompt, [message]}
|
||||
assert message =~ "Do you want this?"
|
||||
assert answer == "Yes"
|
||||
end
|
||||
|
||||
test "with defval" do
|
||||
send(self(), {:mix_shell_input, :prompt, "\n"})
|
||||
|
||||
answer = shell_prompt("Do you want this?", "defval")
|
||||
|
||||
assert_received {:mix_shell, :prompt, [message]}
|
||||
assert message =~ "Do you want this? [defval]"
|
||||
assert answer == "defval"
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_option/3" do
|
||||
test "get from options" do
|
||||
assert get_option([domain: "some-domain.com"], :domain, "Promt") == "some-domain.com"
|
||||
end
|
||||
|
||||
test "get from prompt" do
|
||||
send(self(), {:mix_shell_input, :prompt, "another-domain.com"})
|
||||
assert get_option([], :domain, "Prompt") == "another-domain.com"
|
||||
end
|
||||
end
|
||||
end
|
||||
43
test/tasks/robots_txt_test.exs
Normal file
43
test/tasks/robots_txt_test.exs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
|
||||
use ExUnit.Case, async: true
|
||||
alias Mix.Tasks.Pleroma.RobotsTxt
|
||||
|
||||
test "creates new dir" do
|
||||
path = "test/fixtures/new_dir/"
|
||||
file_path = path <> "robots.txt"
|
||||
|
||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
||||
Pleroma.Config.put([:instance, :static_dir], path)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
||||
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
|
||||
end)
|
||||
|
||||
RobotsTxt.run(["disallow_all"])
|
||||
|
||||
assert File.exists?(file_path)
|
||||
{:ok, file} = File.read(file_path)
|
||||
|
||||
assert file == "User-Agent: *\nDisallow: /\n"
|
||||
end
|
||||
|
||||
test "to existance folder" do
|
||||
path = "test/fixtures/"
|
||||
file_path = path <> "robots.txt"
|
||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
||||
Pleroma.Config.put([:instance, :static_dir], path)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
||||
:ok = File.rm(file_path)
|
||||
end)
|
||||
|
||||
RobotsTxt.run(["disallow_all"])
|
||||
|
||||
assert File.exists?(file_path)
|
||||
{:ok, file} = File.read(file_path)
|
||||
|
||||
assert file == "User-Agent: *\nDisallow: /\n"
|
||||
end
|
||||
end
|
||||
|
|
@ -3,6 +3,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
ExUnit.start()
|
||||
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
|
||||
Mox.defmock(Pleroma.ReverseProxy.ClientMock, for: Pleroma.ReverseProxy.Client)
|
||||
{:ok, _} = Application.ensure_all_started(:ex_machina)
|
||||
|
|
|
|||
104
test/user/synchronization_test.exs
Normal file
104
test/user/synchronization_test.exs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.SynchronizationTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.User
|
||||
alias Pleroma.User.Synchronization
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "update following/followers counters" do
|
||||
user1 =
|
||||
insert(:user,
|
||||
local: false,
|
||||
ap_id: "http://localhost:4001/users/masto_closed"
|
||||
)
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
{user, %{}} = Synchronization.call(users, %{})
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
|
||||
test "don't check host if errors exist" do
|
||||
user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1")
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
|
||||
{user, %{"domain-with-errors" => 2}} =
|
||||
Synchronization.call(users, %{"domain-with-errors" => 2}, max_retries: 2)
|
||||
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
end
|
||||
|
||||
test "don't check host if errors appeared" do
|
||||
user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1")
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
|
||||
{user, %{"domain-with-errors" => 2}} = Synchronization.call(users, %{}, max_retries: 2)
|
||||
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
end
|
||||
|
||||
test "other users after error appeared" do
|
||||
user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1")
|
||||
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
|
||||
{user, %{"domain-with-errors" => 2}} = Synchronization.call(users, %{}, max_retries: 2)
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
end
|
||||
49
test/user/synchronization_worker_test.exs
Normal file
49
test/user/synchronization_worker_test.exs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.SynchronizationWorkerTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config = Pleroma.Config.get([:instance, :external_user_synchronization])
|
||||
|
||||
for_update = [enabled: true, interval: 1000]
|
||||
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], for_update)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], config)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "sync follow counters" do
|
||||
user1 =
|
||||
insert(:user,
|
||||
local: false,
|
||||
ap_id: "http://localhost:4001/users/masto_closed"
|
||||
)
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
|
||||
|
||||
{:ok, _} = Pleroma.User.SynchronizationWorker.start_link()
|
||||
:timer.sleep(1500)
|
||||
|
||||
%{follower_count: followers, following_count: following} =
|
||||
Pleroma.User.get_cached_user_info(user1)
|
||||
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} =
|
||||
Pleroma.User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
end
|
||||
|
|
@ -217,5 +217,36 @@ defmodule Pleroma.UserSearchTest do
|
|||
refute Enum.member?(account_ids, blocked_user2.id)
|
||||
assert length(account_ids) == 3
|
||||
end
|
||||
|
||||
test "local user has the same search_rank as for users with the same nickname, but another domain" do
|
||||
user = insert(:user)
|
||||
insert(:user, nickname: "lain@mastodon.social")
|
||||
insert(:user, nickname: "lain")
|
||||
insert(:user, nickname: "lain@pleroma.social")
|
||||
|
||||
assert User.search("lain@localhost", resolve: true, for_user: user)
|
||||
|> Enum.each(fn u -> u.search_rank == 0.5 end)
|
||||
end
|
||||
|
||||
test "localhost is the part of the domain" do
|
||||
user = insert(:user)
|
||||
insert(:user, nickname: "another@somedomain")
|
||||
insert(:user, nickname: "lain")
|
||||
insert(:user, nickname: "lain@examplelocalhost")
|
||||
|
||||
result = User.search("lain@examplelocalhost", resolve: true, for_user: user)
|
||||
assert Enum.each(result, fn u -> u.search_rank == 0.5 end)
|
||||
assert length(result) == 2
|
||||
end
|
||||
|
||||
test "local user search with users" do
|
||||
user = insert(:user)
|
||||
local_user = insert(:user, nickname: "lain")
|
||||
insert(:user, nickname: "another@localhost.com")
|
||||
insert(:user, nickname: "localhost@localhost.com")
|
||||
|
||||
[result] = User.search("lain@localhost", resolve: true, for_user: user)
|
||||
assert Map.put(result, :search_rank, nil) |> Map.put(:search_type, nil) == local_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1183,4 +1183,121 @@ defmodule Pleroma.UserTest do
|
|||
assert user_two.ap_id in ap_ids
|
||||
end
|
||||
end
|
||||
|
||||
describe "sync followers count" do
|
||||
setup do
|
||||
user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
|
||||
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
|
||||
insert(:user, local: true)
|
||||
insert(:user, local: false, info: %{deactivated: true})
|
||||
{:ok, user1: user1, user2: user2}
|
||||
end
|
||||
|
||||
test "external_users/1 external active users with limit", %{user1: user1, user2: user2} do
|
||||
[fdb_user1] = User.external_users(limit: 1)
|
||||
|
||||
assert fdb_user1.ap_id
|
||||
assert fdb_user1.ap_id == user1.ap_id
|
||||
assert fdb_user1.id == user1.id
|
||||
|
||||
[fdb_user2] = User.external_users(max_id: fdb_user1.id, limit: 1)
|
||||
|
||||
assert fdb_user2.ap_id
|
||||
assert fdb_user2.ap_id == user2.ap_id
|
||||
assert fdb_user2.id == user2.id
|
||||
|
||||
assert User.external_users(max_id: fdb_user2.id, limit: 1) == []
|
||||
end
|
||||
|
||||
test "sync_follow_counters/1", %{user1: user1, user2: user2} do
|
||||
{:ok, _pid} = Agent.start_link(fn -> %{} end, name: :domain_errors)
|
||||
|
||||
:ok = User.sync_follow_counters()
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
|
||||
Agent.stop(:domain_errors)
|
||||
end
|
||||
|
||||
test "sync_follow_counters/1 in separate batches", %{user1: user1, user2: user2} do
|
||||
{:ok, _pid} = Agent.start_link(fn -> %{} end, name: :domain_errors)
|
||||
|
||||
:ok = User.sync_follow_counters(limit: 1)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
|
||||
Agent.stop(:domain_errors)
|
||||
end
|
||||
|
||||
test "perform/1 with :sync_follow_counters", %{user1: user1, user2: user2} do
|
||||
:ok = User.perform(:sync_follow_counters)
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
end
|
||||
|
||||
describe "set_info_cache/2" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, user: user}
|
||||
end
|
||||
|
||||
test "update from args", %{user: user} do
|
||||
User.set_info_cache(user, %{following_count: 15, follower_count: 18})
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
|
||||
assert followers == 18
|
||||
assert following == 15
|
||||
end
|
||||
|
||||
test "without args", %{user: user} do
|
||||
User.set_info_cache(user, %{})
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "user_info/2" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, user: user}
|
||||
end
|
||||
|
||||
test "update from args", %{user: user} do
|
||||
%{follower_count: followers, following_count: following} =
|
||||
User.user_info(user, %{following_count: 15, follower_count: 18})
|
||||
|
||||
assert followers == 18
|
||||
assert following == 15
|
||||
end
|
||||
|
||||
test "without args", %{user: user} do
|
||||
%{follower_count: followers, following_count: following} = User.user_info(user)
|
||||
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,6 +15,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -46,12 +47,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
data["object"]
|
||||
|> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
returned_object = Object.normalize(returned_activity)
|
||||
returned_object = Object.normalize(returned_activity, false)
|
||||
|
||||
assert activity =
|
||||
Activity.get_create_by_object_ap_id(
|
||||
|
|
@ -61,6 +59,32 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
end
|
||||
|
||||
test "it does not fetch replied-to activities beyond max_replies_depth" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
allowed_incoming_reply_depth?: fn _ -> false end do
|
||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
returned_object = Object.normalize(returned_activity, false)
|
||||
|
||||
refute Activity.get_create_by_object_ap_id(
|
||||
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
)
|
||||
|
||||
assert returned_object.data["inReplyToAtomUri"] ==
|
||||
"https://shitposter.club/notice/2827873"
|
||||
end
|
||||
end
|
||||
|
||||
test "it does not crash if the object in inReplyTo can't be fetched" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|
|
|
|||
|
|
@ -12,6 +12,13 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue