From a5cad6741ec0c5d1fff669bc60551845913b13c2 Mon Sep 17 00:00:00 2001 From: Jamil Bou Kheir Date: Tue, 19 Oct 2021 12:18:03 -0700 Subject: [PATCH] Fix peers loaded on boot --- apps/fz_http/lib/fz_http/devices.ex | 2 +- apps/fz_http/test/fz_http/devices_test.exs | 2 +- apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex | 27 ++++++++++++++++++---- apps/fz_vpn/lib/fz_vpn/config.ex | 4 ++-- apps/fz_vpn/test/fz_vpn/config_test.exs | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/fz_http/lib/fz_http/devices.ex b/apps/fz_http/lib/fz_http/devices.ex index c4a47caa8..07cefd8ad 100644 --- a/apps/fz_http/lib/fz_http/devices.ex +++ b/apps/fz_http/lib/fz_http/devices.ex @@ -58,7 +58,7 @@ defmodule FzHttp.Devices do for device <- Repo.all(Device) do %{ public_key: device.public_key, - allowed_ips: "#{ipv4_address(device)}/32, #{ipv6_address(device)}/128" + allowed_ips: "#{ipv4_address(device)}/32,#{ipv6_address(device)}/128" } end end diff --git a/apps/fz_http/test/fz_http/devices_test.exs b/apps/fz_http/test/fz_http/devices_test.exs index 61d9254fb..3fc9014f3 100644 --- a/apps/fz_http/test/fz_http/devices_test.exs +++ b/apps/fz_http/test/fz_http/devices_test.exs @@ -145,7 +145,7 @@ defmodule FzHttp.DevicesTest do assert Devices.to_peer_list() |> List.first() == %{ public_key: device.public_key, allowed_ips: - "#{Devices.ipv4_address(device)}/32, #{Devices.ipv6_address(device)}/128" + "#{Devices.ipv4_address(device)}/32,#{Devices.ipv6_address(device)}/128" } end end diff --git a/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex b/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex index 6cde4780a..afd5a6e71 100644 --- a/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex +++ b/apps/fz_vpn/lib/fz_vpn/cli/sandbox.ex @@ -3,6 +3,8 @@ defmodule FzVpn.CLI.Sandbox do Sandbox CLI environment for WireGuard CLI operations. """ + require Logger + @show_latest_handshakes "4 seconds ago" @show_persistent_keepalives "every 25 seconds" @show_transfer "4.60 MiB received, 59.21 MiB sent" @@ -13,10 +15,27 @@ defmodule FzVpn.CLI.Sandbox do def teardown, do: @default_returned def genkey, do: {rand_key(), rand_key()} def pubkey(_privkey), do: rand_key() - def exec!(_cmd), do: @default_returned - def set(_conf_str), do: @default_returned - def delete_peer(_pubkey), do: @default_returned - def set_peer(_pubkey, _ip), do: @default_returned + + def exec!(cmd) do + Logger.debug("`exec!` called with #{cmd}") + @default_returned + end + + def set(conf_str) do + Logger.debug("`set` called with #{conf_str}") + @default_returned + end + + def delete_peer(pubkey) do + Logger.debug("`delete_peer` called with #{pubkey}") + @default_returned + end + + def set_peer(pubkey, ip) do + Logger.debug("`set_peer` called with #{pubkey}, #{ip}") + @default_returned + end + def show_latest_handshakes, do: @show_latest_handshakes def show_persistent_keepalives, do: @show_persistent_keepalives def show_transfer, do: @show_transfer diff --git a/apps/fz_vpn/lib/fz_vpn/config.ex b/apps/fz_vpn/lib/fz_vpn/config.ex index b6fe1e84f..0b5740918 100644 --- a/apps/fz_vpn/lib/fz_vpn/config.ex +++ b/apps/fz_vpn/lib/fz_vpn/config.ex @@ -6,8 +6,8 @@ defmodule FzVpn.Config do # Render peers list into server config def render(config) do Enum.join( - for {public_key, {ipv4, ipv6}} <- config do - "peer #{public_key} allowed-ips #{ipv4}/32,#{ipv6}/128" + for {public_key, allowed_ips} <- config do + "peer #{public_key} allowed-ips #{allowed_ips}" end, " " ) diff --git a/apps/fz_vpn/test/fz_vpn/config_test.exs b/apps/fz_vpn/test/fz_vpn/config_test.exs index e50de1dd7..f1d7d0c3e 100644 --- a/apps/fz_vpn/test/fz_vpn/config_test.exs +++ b/apps/fz_vpn/test/fz_vpn/config_test.exs @@ -12,7 +12,7 @@ defmodule FzVpn.ConfigTest do end test "renders populated config" do - config = %{"test-pubkey" => {"test-ipv4", "test-ipv6"}} + config = %{"test-pubkey" => "test-ipv4/32,test-ipv6/128"} assert Config.render(config) == @populated_config end