From bb1af90de478689b4c1c9b20b9fe0de9525dac30 Mon Sep 17 00:00:00 2001 From: Tobias Bossert Date: Fri, 2 Jul 2021 12:19:11 +0200 Subject: [PATCH] version++ --- .debian/DEBIAN/control | 2 +- CHANGES | 9 +++++++++ MANIFEST | 10 ++++++---- MANIFEST.SKIP | 2 ++ VERSION | 2 +- bin/wg-meta | 15 +++++++-------- lib/Wireguard/WGmeta.pm | 2 +- lib/Wireguard/WGmeta/Cli/Commands/Add.pm | 8 ++++---- lib/Wireguard/WGmeta/Cli/Commands/Apply.pm | 6 +++--- lib/Wireguard/WGmeta/Cli/Commands/Set.pm | 3 ++- lib/Wireguard/WGmeta/Cli/Commands/Show.pm | 9 ++++++++- lib/Wireguard/WGmeta/Cli/Human.pm | 13 +++++++++---- lib/Wireguard/WGmeta/Cli/Router.pm | 2 +- lib/Wireguard/WGmeta/Parser/Conf.pm | 2 +- lib/Wireguard/WGmeta/Parser/Middleware.pm | 6 +++--- lib/Wireguard/WGmeta/Parser/Show.pm | 5 ++--- lib/Wireguard/WGmeta/ValidAttributes.pm | 4 ++-- lib/Wireguard/WGmeta/Wrapper/Config.pm | 2 +- lib/Wireguard/WGmeta/Wrapper/ConfigT.pm | 12 +----------- lib/Wireguard/WGmeta/Wrapper/Show.pm | 2 +- t/concurrency_test.t | 21 ++++++++++++--------- t/wrapper_secure_mode.t | 6 +++++- t/wrapper_test.t | 6 +++++- 23 files changed, 87 insertions(+), 62 deletions(-) diff --git a/.debian/DEBIAN/control b/.debian/DEBIAN/control index e7f92c1..38de25f 100644 --- a/.debian/DEBIAN/control +++ b/.debian/DEBIAN/control @@ -1,5 +1,5 @@ Package: wg-meta -Version: 0.0.3 +Version: 0.3.0 Section: base Priority: optional Architecture: all diff --git a/CHANGES b/CHANGES index b661666..615ad24 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +0.3.0 2021-07-03 Tobias Bossert (tobib at cpan.org) +- changed: CLI: Seamless support for custom attributes (set and addpeer) +- added: CLI: Ability to remove peers +- added: CLI: Machine readable output (dump) +- changed: Core: removed any predefined wg-meta attributes (except alias and checksum) +- changed: Core: Rewrote parser architecture to be more general and extendable +- changed: Tests: Are now not dependent on threads any more +- changed: Wrapper: API of set() and add_peer() + 0.2.3 2021-04-15 Tobias Bossert (tobib at cpan.org) - changed: Commit behaviour when set to overwrite = False - changed: Adding custom attributes is now possible in code diff --git a/MANIFEST b/MANIFEST index 07e5476..7d66caf 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2,7 +2,6 @@ AUTHORS bin/wg-meta CHANGES COPYRIGHT -dist.sh lib/Wireguard/WGmeta.pm lib/Wireguard/WGmeta/Cli/Commands/Add.pm lib/Wireguard/WGmeta/Cli/Commands/Apply.pm @@ -10,13 +9,15 @@ lib/Wireguard/WGmeta/Cli/Commands/Command.pm lib/Wireguard/WGmeta/Cli/Commands/Disable.pm lib/Wireguard/WGmeta/Cli/Commands/Enable.pm lib/Wireguard/WGmeta/Cli/Commands/Help.pm +lib/Wireguard/WGmeta/Cli/Commands/Remove.pm lib/Wireguard/WGmeta/Cli/Commands/Set.pm lib/Wireguard/WGmeta/Cli/Commands/Show.pm lib/Wireguard/WGmeta/Cli/Human.pm lib/Wireguard/WGmeta/Cli/Router.pm lib/Wireguard/WGmeta/Cli/TerminalHelpers.pm lib/Wireguard/WGmeta/Index.pod -lib/Wireguard/WGmeta/Parser/Config.pm +lib/Wireguard/WGmeta/Parser/Conf.pm +lib/Wireguard/WGmeta/Parser/Middleware.pm lib/Wireguard/WGmeta/Parser/Show.pm lib/Wireguard/WGmeta/Utils.pm lib/Wireguard/WGmeta/Validator.pm @@ -42,7 +43,8 @@ t/test_data/mini_wg0.conf_skip t/test_data/mini_wg1.conf t/test_data/not_a_wg_config.conf t/test_data/wg_show_dump -t/wrapper_test.t t/wrapper_custom_attrs.t +t/wrapper_secure_mode.t +t/wrapper_test.t VERSION -wg-meta_completions.sh \ No newline at end of file +wg-meta_completions.sh diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index f5e3df6..08f1ee8 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -14,3 +14,5 @@ cpanfile \.perl-version configure\.ac ^_Deparsed_XSubs\.pm +dist.sh +MANIFEST.bak diff --git a/VERSION b/VERSION index 373f8c6..9325c3c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.3 \ No newline at end of file +0.3.0 \ No newline at end of file diff --git a/bin/wg-meta b/bin/wg-meta index 6a1d005..d30e6cb 100755 --- a/bin/wg-meta +++ b/bin/wg-meta @@ -119,7 +119,7 @@ use experimental 'signatures'; use Wireguard::WGmeta::Cli::Router; use Wireguard::WGmeta::Cli::TerminalHelpers; -our $VERSION = "0.0.0"; +our $VERSION = "0.3.0"; local $SIG{__WARN__} = sub($message) { prettify_message($message, 1); @@ -131,12 +131,11 @@ if (@ARGV && $ARGV[0] eq '--version') { } # command line argument parser -route_command(\@ARGV); -# eval { -# route_command(\@ARGV); -# }; -# if ($@) { -# prettify_message($@, 0); -# } +eval { + route_command(\@ARGV); +}; +if ($@) { + prettify_message($@, 0); +} diff --git a/lib/Wireguard/WGmeta.pm b/lib/Wireguard/WGmeta.pm index 644896f..9574e4f 100644 --- a/lib/Wireguard/WGmeta.pm +++ b/lib/Wireguard/WGmeta.pm @@ -66,6 +66,6 @@ use strict; use warnings FATAL => 'all'; package Wireguard::WGmeta; -our $VERSION = "0.0.0"; # Do not change manually +our $VERSION = "0.3.0"; # Do not change manually 1; diff --git a/lib/Wireguard/WGmeta/Cli/Commands/Add.pm b/lib/Wireguard/WGmeta/Cli/Commands/Add.pm index 35c4a26..218d2da 100644 --- a/lib/Wireguard/WGmeta/Cli/Commands/Add.pm +++ b/lib/Wireguard/WGmeta/Cli/Commands/Add.pm @@ -46,7 +46,7 @@ sub _run_command($self) { # lets create a temporary interface $self->wg_meta->add_interface('temp', $self->{ips}, 44544, $self->{priv_key}); $self->wg_meta->add_peer('temp', '0.0.0.0/0, ::/0', $iface_pubkey); - $self->wg_meta->set('temp', $iface_pubkey, 'endpoint', ":$iface_listen"); + $self->wg_meta->set('temp', $iface_pubkey, 'endpoint', "insert.valid.fqdn.not.valid:$iface_listen"); $self->wg_meta->set('temp', $iface_pubkey, 'persistent-keepalive', 25); my $unknown_handler_temp = sub($attribute, $value) { @@ -78,15 +78,15 @@ sub _run_command($self) { print "#Generated by wg-meta\n" . $self->wg_meta->create_config('temp', 0); # remove our temp interface again $self->wg_meta->remove_interface('temp'); - - $self->{wg_meta}->commit(1); + $self->wg_meta->commit(1); } sub cmd_help($self) { print "Usage: wg-meta addpeer [attr1 value1] [attr2 value2] ...\n\n" . "Notes: \nAttributes meant to reside in the [Interface] section are only applied to the peer's interface\n" . "wg-meta attributes are applied to the host's peer config and the client interface config\n" - . "and finally, attributes meant to be in the [Peer] section are only applied to the host's peer entry\n"; + . "and finally, attributes meant to be in the [Peer] section are only applied to the host's peer entry\n\n" + . "Do not forget to reload the configuration afterwards!\n"; exit(); } diff --git a/lib/Wireguard/WGmeta/Cli/Commands/Apply.pm b/lib/Wireguard/WGmeta/Cli/Commands/Apply.pm index 09da678..9eefabd 100644 --- a/lib/Wireguard/WGmeta/Cli/Commands/Apply.pm +++ b/lib/Wireguard/WGmeta/Cli/Commands/Apply.pm @@ -22,11 +22,11 @@ sub _run_command($self) { # please note that there ar potential problems with this commend as mentioned here: https://github.com/WireGuard/wireguard-tools/pull/3 my $cmd_line = "su -c 'wg syncconf $interface <(wg-quick strip $interface)'"; - unless (defined $ENV{WG_META_NO_WG}) { + unless (defined $ENV{WGmeta_NO_WG}) { run_external($cmd_line); + } else { + print "Faked apply \n"; } - print "Faked apply \n"; - } sub cmd_help($self) { diff --git a/lib/Wireguard/WGmeta/Cli/Commands/Set.pm b/lib/Wireguard/WGmeta/Cli/Commands/Set.pm index 98bc86c..34a1d8e 100644 --- a/lib/Wireguard/WGmeta/Cli/Commands/Set.pm +++ b/lib/Wireguard/WGmeta/Cli/Commands/Set.pm @@ -88,7 +88,8 @@ sub _apply_change_set($self, $interface, @change_set) { } sub cmd_help($self) { print "Usage: wg-meta set [attr1 value1] [attr2 value2] [peer {alias|public-key}] [attr1 value1] [attr2 value2] ...\n\n" - . "Notes:\n The interface aims to follow the official `wg set` specification\n"; + . "Notes:\n The interface aims to follow the official `wg set` specification\n" + . "To introduce new attributes prefix them with `+`"; } sub _set_values($self, $interface, $identifier, $ref_hash_values) { diff --git a/lib/Wireguard/WGmeta/Cli/Commands/Show.pm b/lib/Wireguard/WGmeta/Cli/Commands/Show.pm index f3ddb99..12de6dc 100644 --- a/lib/Wireguard/WGmeta/Cli/Commands/Show.pm +++ b/lib/Wireguard/WGmeta/Cli/Commands/Show.pm @@ -125,7 +125,9 @@ sub _run_command($self, $interface, $is_dump, $ref_attr_list) { } else { $identifier = $config_section{'alias'} if exists $config_section{'alias'}; - $state = ($config_section{'disabled'} == 0 and $interface_is_active) ? 1 : 0; + + # we only show a green dot when the peer appears in the show output + $state = ($interface_is_active and keys %wg_show_section > 1) ? 1 : 0; my $state_marker = ($state == 1) ? BOLD . GREEN . '●' . RESET : BOLD . RED . '●' . RESET; $output .= $state_marker . BOLD . lc($type) . ": " . RESET . $identifier . "\n"; $output .= $self->_get_pretty_line(\%config_section, \%wg_show_section, $ref_attr_list) . "\n"; @@ -191,6 +193,11 @@ sub _get_dump_line($self, $ref_config_section, $ref_show_section, $ref_attr_list sub cmd_help($self) { print "Usage: wg-meta show {interface|all} [attribute1, attribute2, ...] [dump] \n" + . "Notes:\n" + . "A green dot indicates an interface/peer's 'real' state which means that its currently possible\n" + . "to connect to this interface/peer.\n" + . "A red dot on the other hand indicates that its not possible to connect. This could mean not applied changes, \n" + . "a disabled peer or the parent interface is down. \n" } 1; diff --git a/lib/Wireguard/WGmeta/Cli/Human.pm b/lib/Wireguard/WGmeta/Cli/Human.pm index ebdb742..d2cb9fc 100644 --- a/lib/Wireguard/WGmeta/Cli/Human.pm +++ b/lib/Wireguard/WGmeta/Cli/Human.pm @@ -11,6 +11,7 @@ package Wireguard::WGmeta::Cli::Human; use strict; use warnings FATAL => 'all'; use experimental 'signatures'; +use Scalar::Util qw(looks_like_number); use base 'Exporter'; our @EXPORT = qw(disabled2human bits2human return_self timestamp2human); @@ -42,8 +43,12 @@ $n_bits * 1_000_000 . "MiB" =cut sub bits2human($n_bits) { - # this calculation is probably not correct, however, I found no reference on what is actually the unit of the wg show dump... - return sprintf("%.2f %s", $n_bits / 1_000_000, "MiB"); + if (looks_like_number($n_bits)){ + # this calculation is probably not correct, however, I found no reference on what is actually the unit of the wg show dump... + return sprintf("%.2f %s", $n_bits / 1_000_000, "MiB"); + } + return "0.0 MiB"; + } =head3 timestamp2human($timestamp) @@ -66,10 +71,10 @@ A string describing how long ago this timestamp was =cut sub timestamp2human($timestamp) { - my $int_timestamp = int($timestamp); - if ($int_timestamp == 0) { + if (not looks_like_number($timestamp) or $timestamp == 0) { return "never" } + my $int_timestamp = int($timestamp); my $delta = time - $int_timestamp; if ($delta > 2592000) { return ">month ago"; diff --git a/lib/Wireguard/WGmeta/Cli/Router.pm b/lib/Wireguard/WGmeta/Cli/Router.pm index 80a10fb..43bf73e 100644 --- a/lib/Wireguard/WGmeta/Cli/Router.pm +++ b/lib/Wireguard/WGmeta/Cli/Router.pm @@ -27,7 +27,7 @@ use Wireguard::WGmeta::Cli::Commands::Remove; use base 'Exporter'; our @EXPORT = qw(route_command); -our $VERSION = "0.0.0"; +our $VERSION = "0.3.0"; =head2 route_command($ref_list_input_args) diff --git a/lib/Wireguard/WGmeta/Parser/Conf.pm b/lib/Wireguard/WGmeta/Parser/Conf.pm index 16afa28..a23a88a 100644 --- a/lib/Wireguard/WGmeta/Parser/Conf.pm +++ b/lib/Wireguard/WGmeta/Parser/Conf.pm @@ -44,7 +44,7 @@ use constant INTERNAL_KEY_PREFIX => 'int_'; use base 'Exporter'; our @EXPORT = qw(parse_raw_wg_config INTERNAL_KEY_PREFIX); -our $VERSION = "0.0.0"; +our $VERSION = "0.3.0"; =head3 parse_raw_wg_config($file_content, $on_every_value, $on_new_section [, $skip, $wg_meta_prefix, $wg_disabled_prefix]) diff --git a/lib/Wireguard/WGmeta/Parser/Middleware.pm b/lib/Wireguard/WGmeta/Parser/Middleware.pm index 1197ef7..1650a22 100644 --- a/lib/Wireguard/WGmeta/Parser/Middleware.pm +++ b/lib/Wireguard/WGmeta/Parser/Middleware.pm @@ -2,7 +2,7 @@ =head1 NAME -WGmeta::Parser::Middleware - Middleware between the parser and wrapper classe(s) +WGmeta::Parser::Middleware - Middleware between the parser and wrapper class(es) =head1 SYNOPSIS @@ -36,7 +36,7 @@ use Wireguard::WGmeta::Utils; use base 'Exporter'; our @EXPORT = qw(parse_wg_config2 create_wg_config2); -our $VERSION = "0.0.0"; +our $VERSION = "0.3.0"; =head3 parse_wg_config2($config_file_content, $interface_name [, $wg_meta_prefix, $disabled_prefix, $use_checksum]) @@ -266,7 +266,7 @@ sub create_wg_config2($ref_interface_config, $wg_meta_prefix = '#+', $disabled_p $new_config .= _write_line($identifier, $ref_interface_config->{$identifier}, '', $wg_meta_prefix); } else { - # First lets check if the following section is active'int_disabled' + # First lets check if the following section is active my $is_disabled = (exists $ref_interface_config->{$identifier}{'disabled'} and $ref_interface_config->{$identifier}{'disabled'} == 1) ? $disabled_prefix : ''; diff --git a/lib/Wireguard/WGmeta/Parser/Show.pm b/lib/Wireguard/WGmeta/Parser/Show.pm index 7ea8d3f..3def996 100644 --- a/lib/Wireguard/WGmeta/Parser/Show.pm +++ b/lib/Wireguard/WGmeta/Parser/Show.pm @@ -28,13 +28,12 @@ use experimental 'signatures'; use base 'Exporter'; our @EXPORT = qw(wg_show_dump_parser); -our $VERSION = "0.0.0"; # do not change manually, this variable is updated when calling make +our $VERSION = "0.3.0"; # do not change manually, this variable is updated when calling make =head3 wg_show_dump_parser($input) -Parser for the output of C. Aims to be produce a similar structure as -L: +Parser for the output of C: { 'interface_name' => { diff --git a/lib/Wireguard/WGmeta/ValidAttributes.pm b/lib/Wireguard/WGmeta/ValidAttributes.pm index b99b3df..7ac5b31 100644 --- a/lib/Wireguard/WGmeta/ValidAttributes.pm +++ b/lib/Wireguard/WGmeta/ValidAttributes.pm @@ -27,7 +27,7 @@ use experimental 'signatures'; use Wireguard::WGmeta::Validator; -our $VERSION = "0.0.0"; +our $VERSION = "0.3.0"; =head1 ATTRIBUTE TYPES @@ -179,7 +179,7 @@ use constant KNOWN_ATTRIBUTES => { 'validator' => \&accept_any }, 'persistent-keepalive' => { - 'in_config_name' => 'PresistentKeepAlive', + 'in_config_name' => 'PresistentKeepalive', 'type' => ATTR_TYPE_IS_WG_ORIG_PEER, 'validator' => \&accept_any }, diff --git a/lib/Wireguard/WGmeta/Wrapper/Config.pm b/lib/Wireguard/WGmeta/Wrapper/Config.pm index 4a54038..17a7c3d 100644 --- a/lib/Wireguard/WGmeta/Wrapper/Config.pm +++ b/lib/Wireguard/WGmeta/Wrapper/Config.pm @@ -50,7 +50,7 @@ use Wireguard::WGmeta::ValidAttributes; use Wireguard::WGmeta::Utils; use Wireguard::WGmeta::Parser::Conf qw(INTERNAL_KEY_PREFIX); -our $VERSION = "0.0.0"; # do not change manually, this variable is updated when calling make +our $VERSION = "0.3.0"; # do not change manually, this variable is updated when calling make use constant FALSE => 0; use constant TRUE => 1; diff --git a/lib/Wireguard/WGmeta/Wrapper/ConfigT.pm b/lib/Wireguard/WGmeta/Wrapper/ConfigT.pm index a5e19c9..2203fa5 100644 --- a/lib/Wireguard/WGmeta/Wrapper/ConfigT.pm +++ b/lib/Wireguard/WGmeta/Wrapper/ConfigT.pm @@ -116,7 +116,7 @@ use constant FALSE => 0; use constant TRUE => 1; use constant INTEGRITY_HASH_SALT => 'wefnwioefh9032ur3'; -our $VERSION = "0.0.0"; # do not change manually, this variable is updated when calling make +our $VERSION = "0.3.0"; # do not change manually, this variable is updated when calling make =head3 is_valid_interface($interface) @@ -190,16 +190,6 @@ sub get_peer_count($self, $interface = undef) { return $self->SUPER::get_peer_count($interface); } -=head3 get_peer_count([$interface]) - -L - -=cut -sub get_interface_fqdn($self, $interface) { - $self->may_reload_from_disk($interface); - return $self->SUPER::get_interface_fqdn($interface); -} - sub _get_all_conf_files($wireguard_home) { my @config_files = read_dir($wireguard_home, qr/.*\.conf$/); if (@config_files == 0) { diff --git a/lib/Wireguard/WGmeta/Wrapper/Show.pm b/lib/Wireguard/WGmeta/Wrapper/Show.pm index ffab9d4..fa7fc1e 100644 --- a/lib/Wireguard/WGmeta/Wrapper/Show.pm +++ b/lib/Wireguard/WGmeta/Wrapper/Show.pm @@ -34,7 +34,7 @@ use warnings FATAL => 'all'; use experimental 'signatures'; -our $VERSION = "0.0.0"; +our $VERSION = "0.3.0"; use constant FALSE => 0; use constant TRUE => 1; diff --git a/t/concurrency_test.t b/t/concurrency_test.t index c70ef6a..871a356 100644 --- a/t/concurrency_test.t +++ b/t/concurrency_test.t @@ -13,6 +13,10 @@ use Time::HiRes qw(usleep); use Wireguard::WGmeta::Wrapper::ConfigT; use Wireguard::WGmeta::Utils; +my $unknown_handler = sub($attribute, $value) { + # Since unknown attribute handling is tested separately, we can safely ignore it + return $attribute, $value; +}; use constant TEST_DIR => $FindBin::Bin . '/test_data/'; my $initial_wg0 = read_file(TEST_DIR . 'mini_wg0.conf'); @@ -22,7 +26,7 @@ my $wg_meta1 = Wireguard::WGmeta::Wrapper::ConfigT->new(TEST_DIR); my $wg_meta2 = Wireguard::WGmeta::Wrapper::ConfigT->new(TEST_DIR); $wg_meta1->add_peer('mini_wg1', '10.0.3.56/32', 'PUBLIC_KEY_PEER_OUTSIDE_THREAD', 'alias_out'); -$wg_meta1->commit(1,1); +$wg_meta1->commit(1, 1); ok $wg_meta2->is_valid_identifier('mini_wg1', 'PUBLIC_KEY_PEER_OUTSIDE_THREAD'), 'added from other instance [Pub-Key]'; ok $wg_meta2->is_valid_alias('mini_wg1', 'alias_out'), 'added from other instance [Alias]'; @@ -32,18 +36,17 @@ ok $wg_meta2->is_valid_alias('mini_wg1', 'alias_out'), 'added from other instanc my %integrity_hashes1 = ( 'PUBLIC_KEY_PEER_OUTSIDE_THREAD' => $wg_meta1->calculate_sha_from_internal('mini_wg1', 'PUBLIC_KEY_PEER_OUTSIDE_THREAD') ); -$wg_meta1->set('mini_wg1', 'PUBLIC_KEY_PEER_OUTSIDE_THREAD', 'name', 'Set by instance 1'); +$wg_meta1->set('mini_wg1', 'PUBLIC_KEY_PEER_OUTSIDE_THREAD', 'name', 'Set by instance 1', $unknown_handler); my %integrity_hashes2 = ( 'WG_1_PEER_A_PUBLIC_KEY' => $wg_meta2->calculate_sha_from_internal('mini_wg1', 'WG_1_PEER_A_PUBLIC_KEY') ); -$wg_meta2->set('mini_wg1', 'WG_1_PEER_A_PUBLIC_KEY', 'name', 'Set by instance 2'); +$wg_meta2->set('mini_wg1', 'WG_1_PEER_A_PUBLIC_KEY', 'name', 'Set by instance 2', $unknown_handler); $wg_meta2->commit(1, 1, \%integrity_hashes2); $wg_meta1->commit(1, 1, \%integrity_hashes1); -ok {$wg_meta2->get_interface_section('mini_wg1', 'PUBLIC_KEY_PEER_OUTSIDE_THREAD')}->{name} eq 'Set by instance 1', 'concurrent edit [1]'; -ok {$wg_meta1->get_interface_section('mini_wg1', 'WG_1_PEER_A_PUBLIC_KEY')}->{name} eq 'Set by instance 2', 'concurrent edit [2]'; - +ok { $wg_meta2->get_interface_section('mini_wg1', 'PUBLIC_KEY_PEER_OUTSIDE_THREAD') }->{name} eq 'Set by instance 1', 'concurrent edit [1]'; +ok { $wg_meta1->get_interface_section('mini_wg1', 'WG_1_PEER_A_PUBLIC_KEY') }->{name} eq 'Set by instance 2', 'concurrent edit [2]'; # concurrent edit (conflict) @@ -68,8 +71,8 @@ $wg_meta2->add_peer('mini_wg0', '10.0.5.57/32', 'PUBLIC_KEY_PEER_ADDED_6', 'alia $wg_meta1->commit(1); $wg_meta2->commit(1); -ok $wg_meta1->is_valid_identifier('mini_wg0','PUBLIC_KEY_PEER_ADDED_6'), 'the (not) lost peer [1]'; -ok $wg_meta2->is_valid_identifier('mini_wg0','PUBLIC_KEY_PEER_ADDED_5'), 'the (not) lost peer [2]'; +ok $wg_meta1->is_valid_identifier('mini_wg0', 'PUBLIC_KEY_PEER_ADDED_6'), 'the (not) lost peer [1]'; +ok $wg_meta2->is_valid_identifier('mini_wg0', 'PUBLIC_KEY_PEER_ADDED_5'), 'the (not) lost peer [2]'; # ping pong @@ -96,7 +99,7 @@ $wg_meta2->remove_interface('thread_iface1'); $wg_meta2->commit(1); @actual = $wg_meta1->get_interface_list(); -ok eq_array(\@actual, [ 'mini_wg0', 'mini_wg1']), 'removed interface'; +ok eq_array(\@actual, [ 'mini_wg0', 'mini_wg1' ]), 'removed interface'; # write back initial configs my ($filename_1, $filename_2) = (TEST_DIR . 'mini_wg1.conf', TEST_DIR . 'mini_wg0.conf'); diff --git a/t/wrapper_secure_mode.t b/t/wrapper_secure_mode.t index ff23f0d..523a9ec 100644 --- a/t/wrapper_secure_mode.t +++ b/t/wrapper_secure_mode.t @@ -15,10 +15,14 @@ use constant TEST_DIR => $FindBin::Bin . '/test_data/'; my $initial_wg0 = read_file(TEST_DIR . 'mini_wg0.conf'); my $initial_wg1 = read_file(TEST_DIR . 'mini_wg1.conf'); +my $unknown_handler = sub($attribute, $value) { + # Since unknown attribute handling is tested separately, we can safely ignore it + return $attribute, $value; +}; my $wg_meta = Wireguard::WGmeta::Wrapper::Config->new(TEST_DIR); -$wg_meta->set('mini_wg0', 'WG_0_PEER_A_PUBLIC_KEY', 'name', 'bli_blu'); +$wg_meta->set('mini_wg0', 'WG_0_PEER_A_PUBLIC_KEY', 'name', 'bli_blu', $unknown_handler); $wg_meta->commit(0,1); $wg_meta->may_reload_from_disk('mini_wg0'); diff --git a/t/wrapper_test.t b/t/wrapper_test.t index 8bb048a..23f9304 100644 --- a/t/wrapper_test.t +++ b/t/wrapper_test.t @@ -18,6 +18,10 @@ my $initial_wg1 = read_file(TEST_DIR . 'mini_wg1.conf'); my $wg_meta = Wireguard::WGmeta::Wrapper::Config->new(TEST_DIR); +my $unknown_handler = sub($attribute, $value) { + # Since unknown attribute handling is tested separately, we can safely ignore it + return $attribute, $value; +}; # parser tests # interfaces @@ -69,7 +73,7 @@ $wg_meta->set('mini_wg0', 'mini_wg0', 'private-key', 'OHLK9lBHFqnu+9olAnyUN11pCe $wg_meta->set('mini_wg0', 'WG_0_PEER_A_PUBLIC_KEY', 'endpoint', '198.51.100.101:60001'); # wg-meta attrs -$wg_meta->set('mini_wg0', 'WG_0_PEER_A_PUBLIC_KEY', 'name', 'Name_by_test1'); +$wg_meta->set('mini_wg0', 'WG_0_PEER_A_PUBLIC_KEY', 'name', 'Name_by_test1', $unknown_handler); $wg_meta->set('mini_wg0', 'WG_0_PEER_A_PUBLIC_KEY', 'alias', 'alias1'); # wg-meta update alias by alias