From 2f67a5a25dfd0c618c091ceddd0d45b25aaf357b Mon Sep 17 00:00:00 2001 From: Jamil Bou Kheir Date: Thu, 28 Oct 2021 09:49:40 -0700 Subject: [PATCH] Fix DNS config not changing --- .../fz_http_web/live/device_live/show.html.heex | 2 +- .../fz_http_web/live/device_live/show_test.exs | 17 +++++++++++++++++ apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/fz_http/lib/fz_http_web/live/device_live/show.html.heex b/apps/fz_http/lib/fz_http_web/live/device_live/show.html.heex index 95f53b24d..403264656 100644 --- a/apps/fz_http/lib/fz_http_web/live/device_live/show.html.heex +++ b/apps/fz_http/lib/fz_http_web/live/device_live/show.html.heex @@ -85,7 +85,7 @@ [Interface] PrivateKey = <%= @device.private_key %> Address = <%= FzHttp.Devices.ipv4_address(@device) %>/32, <%= FzHttp.Devices.ipv6_address(@device) %>/128 -DNS = 1.1.1.1, 1.0.0.1 +DNS = <%= @device.dns_servers %> [Peer] PublicKey = <%= @device.server_public_key %> diff --git a/apps/fz_http/test/fz_http_web/live/device_live/show_test.exs b/apps/fz_http/test/fz_http_web/live/device_live/show_test.exs index d290c7baa..045bd17be 100644 --- a/apps/fz_http/test/fz_http_web/live/device_live/show_test.exs +++ b/apps/fz_http/test/fz_http_web/live/device_live/show_test.exs @@ -6,6 +6,8 @@ defmodule FzHttpWeb.DeviceLive.ShowTest do @valid_params %{"device" => %{"name" => "new_name"}} @invalid_params %{"device" => %{"name" => ""}} + @dns_servers "8.8.8.8, 8.8.4.4" + @dns_servers_change %{"device" => %{"dns_servers" => @dns_servers}} test "shows device details", %{authed_conn: conn, device: device} do path = Routes.device_show_path(conn, :show, device) @@ -37,6 +39,21 @@ defmodule FzHttpWeb.DeviceLive.ShowTest do assert flash["info"] == "Device updated successfully." end + test "allows dns_servers changes", %{authed_conn: conn, device: device} do + path = Routes.device_show_path(conn, :edit, device) + {:ok, view, _html} = live(conn, path) + + view + |> form("#edit-device") + |> render_submit(@dns_servers_change) + + flash = assert_redirected(view, Routes.device_show_path(conn, :show, device)) + assert flash["info"] == "Device updated successfully." + + {:ok, _view, html} = live(conn, path) + assert html =~ "DNS = #{@dns_servers}" + end + test "prevents empty names", %{authed_conn: conn, device: device} do path = Routes.device_show_path(conn, :edit, device) {:ok, view, _html} = live(conn, path) diff --git a/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex b/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex index afd5a6e71..947b01df6 100644 --- a/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex +++ b/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex @@ -31,8 +31,8 @@ defmodule FzVpn.CLI.Sandbox do @default_returned end - def set_peer(pubkey, ip) do - Logger.debug("`set_peer` called with #{pubkey}, #{ip}") + def set_peer(pubkey, {ipv4, ipv6}) do + Logger.debug("`set_peer` called with #{pubkey}, {#{ipv4}, #{ipv6}}") @default_returned end