Bring back :send_user_agent for test env only.
Too many tests break as they don't include injected user agent in expected response
This commit is contained in:
parent
fd80b75444
commit
e173bce339
3 changed files with 19 additions and 11 deletions
|
@ -96,6 +96,8 @@
|
|||
|
||||
config :pleroma, :http_security, report_uri: "https://endpoint.com"
|
||||
|
||||
config :pleroma, :http, send_user_agent: false
|
||||
|
||||
rum_enabled = System.get_env("RUM_ENABLED") == "true"
|
||||
config :pleroma, :database, rum_enabled: rum_enabled
|
||||
IO.puts("RUM enabled: #{rum_enabled}")
|
||||
|
|
|
@ -10,6 +10,8 @@ defmodule Pleroma.HTTP.RequestBuilder do
|
|||
alias Pleroma.HTTP.Request
|
||||
alias Tesla.Multipart
|
||||
|
||||
@mix_env Mix.env()
|
||||
|
||||
@doc """
|
||||
Creates new request
|
||||
"""
|
||||
|
@ -33,13 +35,7 @@ def url(request, u), do: %{request | url: u}
|
|||
"""
|
||||
@spec headers(Request.t(), Request.headers()) :: Request.t()
|
||||
def headers(request, headers) do
|
||||
headers_list =
|
||||
with nil <- Enum.find(headers, fn {key, _val} -> String.downcase(key) == "user-agent" end) do
|
||||
[{"user-agent", Pleroma.Application.user_agent()} | headers]
|
||||
else
|
||||
_ ->
|
||||
headers
|
||||
end
|
||||
headers_list = maybe_add_user_agent(headers, @mix_env)
|
||||
|
||||
%{request | headers: headers_list}
|
||||
end
|
||||
|
@ -91,4 +87,16 @@ def convert_to_keyword(request) do
|
|||
|> Map.from_struct()
|
||||
|> Enum.into([])
|
||||
end
|
||||
|
||||
defp maybe_add_user_agent(headers, :test) do
|
||||
with true <- Pleroma.Config.get([:http, :send_user_agent]) do
|
||||
[{"user-agent", Pleroma.Application.user_agent()} | headers]
|
||||
else
|
||||
_ ->
|
||||
headers
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_add_user_agent(headers, _),
|
||||
do: [{"user-agent", Pleroma.Application.user_agent()} | headers]
|
||||
end
|
||||
|
|
|
@ -27,6 +27,7 @@ test "do not track successful request", %{conn: conn} do
|
|||
end
|
||||
|
||||
test "use Pleroma's user agent in the request; don't pass the client's", %{conn: conn} do
|
||||
clear_config([:http, :send_user_agent], true)
|
||||
# Mock will fail if the client's user agent isn't filtered
|
||||
wanted_headers = [{"user-agent", Pleroma.Application.user_agent()}]
|
||||
|
||||
|
@ -164,10 +165,7 @@ test "header passes", %{conn: conn} do
|
|||
|
||||
test "header is filtered", %{conn: conn} do
|
||||
# Mock will fail if the accept-language header isn't filtered
|
||||
wanted_headers = [
|
||||
{"user-agent", Pleroma.Application.user_agent()},
|
||||
{"accept-encoding", "*"}
|
||||
]
|
||||
wanted_headers = [{"accept-encoding", "*"}]
|
||||
|
||||
Tesla.Mock.mock(fn %{url: "/headers", headers: ^wanted_headers} ->
|
||||
%Tesla.Env{
|
||||
|
|
Loading…
Reference in a new issue