From acb555b75adeef50c81631adf81c22b404327744 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 4 Sep 2020 13:10:57 -0600 Subject: [PATCH] tests: add wireguard tests --- tests/fixtures/wireguard.interfaces | 9 ++++++++ tests/ifquery_test | 10 ++++++++- tests/linux/Kyuafile | 1 + tests/linux/wireguard_test | 33 +++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/wireguard.interfaces create mode 100755 tests/linux/wireguard_test diff --git a/tests/fixtures/wireguard.interfaces b/tests/fixtures/wireguard.interfaces new file mode 100644 index 0000000..fed6429 --- /dev/null +++ b/tests/fixtures/wireguard.interfaces @@ -0,0 +1,9 @@ +iface eth0 + address 203.0.113.2/24 + gateway 203.0.113.1 + +auto wg0 +iface wg0 + use wireguard + address 1.2.3.4/24 + requires eth0 diff --git a/tests/ifquery_test b/tests/ifquery_test index 9d86e28..e095255 100755 --- a/tests/ifquery_test +++ b/tests/ifquery_test @@ -33,7 +33,8 @@ tests_init \ gre_dependency \ vlan_explicit_learned_dependency \ vlan_guessed_learned_dependency \ - vlan_complex_learned_dependency + vlan_complex_learned_dependency \ + wireguard noargs_body() { atf_check -s exit:1 -e ignore ifquery -S/dev/null @@ -218,3 +219,10 @@ vlan_complex_learned_dependency_body() { -o match:"vlan-raw-device eth0" \ ifquery -E $EXECUTORS_LINUX -i $FIXTURES/vlan-complex.interfaces servers } + +wireguard_body() { + atf_check -s exit:0 \ + -o match:"requires eth0" \ + -o match:"use wireguard" \ + ifquery -E $EXECUTORS_LINUX -i $FIXTURES/wireguard.interfaces wg0 +} diff --git a/tests/linux/Kyuafile b/tests/linux/Kyuafile index 7d7389c..050c55d 100644 --- a/tests/linux/Kyuafile +++ b/tests/linux/Kyuafile @@ -10,3 +10,4 @@ atf_test_program{name='vrf_test'} atf_test_program{name='ppp_test'} atf_test_program{name='tunnel_test'} atf_test_program{name='gre_test'} +atf_test_program{name='wireguard_test'} diff --git a/tests/linux/wireguard_test b/tests/linux/wireguard_test new file mode 100755 index 0000000..ca6e19e --- /dev/null +++ b/tests/linux/wireguard_test @@ -0,0 +1,33 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/../test_env.sh +EXECUTOR="$(atf_get_srcdir)/../../executor-scripts/linux/wireguard" + +tests_init \ + pre_up \ + pre_up_specified_config \ + post_down + +pre_up_body() { + export IFACE=wg0 PHASE=pre-up MOCK=echo + atf_check -s exit:0 \ + -o match:'ip link add wg0 type wireguard' \ + -o match:'wg setconf wg0 /etc/wireguard/wg0.conf' \ + ${EXECUTOR} +} + +pre_up_specified_config_body() { + export IFACE=wg0 PHASE=pre-up MOCK=echo \ + IF_WIREGUARD_CONFIG_PATH=/etc/wireguard/vpn.conf + atf_check -s exit:0 \ + -o match:'ip link add wg0 type wireguard' \ + -o match:'wg setconf wg0 /etc/wireguard/vpn.conf' \ + ${EXECUTOR} +} + +post_down_body() { + export IFACE=wg0 PHASE=post-down MOCK=echo + atf_check -s exit:0 \ + -o match:'ip link delete dev wg0' \ + ${EXECUTOR} +}