Fix external trusted proxies env usage (#1450)

ref https://discourse.firez.one/t/environment-variables-errors/440/4
This commit is contained in:
Andrew Dryga
2023-02-22 17:39:01 -06:00
committed by GitHub
parent 76ef9aaa40
commit ae23fbf61a
2 changed files with 21 additions and 2 deletions

View File

@@ -9,12 +9,12 @@ defmodule FzHttpWeb.HeaderHelpers do
def clients, do: FzHttp.Config.fetch_env!(:fz_http, :private_clients)
def proxied?, do: not (external_trusted_proxies() == false)
def proxied?, do: external_trusted_proxies() != []
def remote_ip_opts do
[
headers: @remote_ip_headers,
proxies: external_trusted_proxies(),
proxies: Enum.join(external_trusted_proxies(), ", "),
clients: clients()
]
end

View File

@@ -0,0 +1,19 @@
defmodule FzHttpWeb.HeaderHelpersTest do
use ExUnit.Case, async: true
import FzHttpWeb.HeaderHelpers
describe "remote_ip_opts/0" do
test "returns a list of options for remote_ip/2" do
FzHttp.Config.put_env_override(:fz_http, :external_trusted_proxies, [
"127.0.0.1",
"10.10.10.0/16"
])
assert remote_ip_opts() == [
headers: ["x-forwarded-for"],
proxies: "127.0.0.1, 10.10.10.0/16",
clients: ["172.28.0.0/16"]
]
end
end
end