mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-04-07 02:06:38 +00:00
Add protocol implementation for IPPort struct and tests (#1478)
Closes #1477
This commit is contained in:
@@ -61,10 +61,9 @@ defmodule FzHttp.Config.Resolver do
|
||||
defp fetch_process_value(pid, key) do
|
||||
with {:dictionary, pdict} <- :erlang.process_info(pid, :dictionary),
|
||||
{^key, value} <- List.keyfind(pdict, key, 0) do
|
||||
value
|
||||
{:ok, value}
|
||||
else
|
||||
_other ->
|
||||
:error
|
||||
_other -> :error
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,3 +5,11 @@ end
|
||||
defimpl Phoenix.HTML.Safe, for: Postgrex.INET do
|
||||
def to_iodata(%Postgrex.INET{} = inet), do: FzHttp.Types.INET.to_string(inet)
|
||||
end
|
||||
|
||||
defimpl String.Chars, for: FzHttp.Types.IPPort do
|
||||
def to_string(%FzHttp.Types.IPPort{} = ip_port), do: FzHttp.Types.IPPort.to_string(ip_port)
|
||||
end
|
||||
|
||||
defimpl Phoenix.HTML.Safe, for: FzHttp.Types.IPPort do
|
||||
def to_iodata(%FzHttp.Types.IPPort{} = ip_port), do: FzHttp.Types.IPPort.to_string(ip_port)
|
||||
end
|
||||
|
||||
@@ -325,6 +325,28 @@ defmodule FzHttpWeb.Acceptance.AdminTest do
|
||||
%Postgrex.INET{address: {0, 0, 0, 0, 0, 0, 0, 0}, netmask: 0}
|
||||
]
|
||||
end
|
||||
|
||||
feature "can use IP with a port in default client endpoint and host in DNS", %{
|
||||
session: session
|
||||
} do
|
||||
session
|
||||
|> visit(~p"/settings/client_defaults")
|
||||
|> assert_el(Query.text("Client Defaults", count: 2))
|
||||
|> fill_in(Query.fillable_field("configuration[default_client_dns]"),
|
||||
with: "dns.example.com"
|
||||
)
|
||||
|> fill_in(Query.fillable_field("configuration[default_client_endpoint]"),
|
||||
with: "1.2.3.4:8123"
|
||||
)
|
||||
|> click(Query.button("Save"))
|
||||
# XXX: We need to show a flash that settings are saved
|
||||
|> visit(~p"/settings/client_defaults")
|
||||
|> assert_el(Query.text("Client Defaults", count: 2))
|
||||
|
||||
assert configuration = FzHttp.Config.fetch_db_config!()
|
||||
assert configuration.default_client_endpoint == "1.2.3.4:8123"
|
||||
assert configuration.default_client_dns == ["dns.example.com"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "customization" do
|
||||
|
||||
@@ -31,7 +31,7 @@ defmodule FzHttpWeb.SettingLive.ClientDefaultsTest do
|
||||
path = ~p"/settings/client_defaults"
|
||||
{:ok, view, html} = live(conn, path)
|
||||
|
||||
%{html: html, view: view}
|
||||
%{conn: conn, html: html, view: view}
|
||||
end
|
||||
|
||||
test "renders current configuration", %{html: html} do
|
||||
@@ -92,6 +92,32 @@ defmodule FzHttpWeb.SettingLive.ClientDefaultsTest do
|
||||
"""
|
||||
end
|
||||
|
||||
test "blocks overridden default client endpoint" do
|
||||
FzHttp.Config.put_system_env_override(:default_client_endpoint, "1.2.3.4:1234")
|
||||
|
||||
{_admin_user, conn} = admin_conn(%{})
|
||||
{:ok, view, _html} = live(conn, ~p"/settings/client_defaults")
|
||||
|
||||
test_view =
|
||||
view
|
||||
|> element("#client_defaults_form_component")
|
||||
|> render()
|
||||
|
||||
assert Floki.find(test_view, "#client_defaults_form_component_default_client_endpoint") ==
|
||||
[
|
||||
{"input",
|
||||
[
|
||||
{"class", "input "},
|
||||
{"disabled", "disabled"},
|
||||
{"id", "client_defaults_form_component_default_client_endpoint"},
|
||||
{"name", "configuration[default_client_endpoint]"},
|
||||
{"placeholder", "firezone.example.com"},
|
||||
{"type", "text"},
|
||||
{"value", "Set in environment variable DEFAULT_CLIENT_ENDPOINT: 1.2.3.4:1234"}
|
||||
], []}
|
||||
]
|
||||
end
|
||||
|
||||
test "updates default client persistent_keepalive", %{view: view} do
|
||||
test_view =
|
||||
view
|
||||
|
||||
@@ -27,6 +27,7 @@ defmodule FzHttpWeb.ConnCase do
|
||||
import Phoenix.ConnTest
|
||||
import Phoenix.LiveViewTest
|
||||
import FzHttp.TestHelpers
|
||||
import FzHttpWeb.ConnCase
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint FzHttpWeb.Endpoint
|
||||
|
||||
Reference in New Issue
Block a user