Merge pull request #305 from firezone/fix-peer-config-not-applied

Fix peer loading on boot
This commit is contained in:
Jamil
2021-10-19 12:56:51 -07:00
committed by GitHub
5 changed files with 28 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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,
" "
)

View File

@@ -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