Merge pull request #733 from rhansen/config
Option processing improvements
This commit is contained in:
commit
12ff5bfbdc
6 changed files with 351 additions and 385 deletions
|
@ -15,6 +15,9 @@ repository history](https://github.com/ddclient/ddclient/commits/master).
|
||||||
* The default web service for `--webv4` and `--webv6` has changed from Google
|
* The default web service for `--webv4` and `--webv6` has changed from Google
|
||||||
Domains (which has shut down) to ipify.
|
Domains (which has shut down) to ipify.
|
||||||
[5b104ad1](https://github.com/ddclient/ddclient/commit/5b104ad116c023c3760129cab6e141f04f72b406)
|
[5b104ad1](https://github.com/ddclient/ddclient/commit/5b104ad116c023c3760129cab6e141f04f72b406)
|
||||||
|
* Invalid command-line options or values are now fatal errors (instead of
|
||||||
|
discarded with a warning).
|
||||||
|
[#TODO](https://github.com/ddclient/ddclient/pull/TODO)
|
||||||
* All log messages are now written to STDERR, not a mix of STDOUT and STDERR.
|
* All log messages are now written to STDERR, not a mix of STDOUT and STDERR.
|
||||||
[#676](https://github.com/ddclient/ddclient/pull/676)
|
[#676](https://github.com/ddclient/ddclient/pull/676)
|
||||||
* For `--protocol=freedns` and `--protocol=nfsn`, the core module
|
* For `--protocol=freedns` and `--protocol=nfsn`, the core module
|
||||||
|
@ -95,6 +98,8 @@ repository history](https://github.com/ddclient/ddclient/commits/master).
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
||||||
|
* Fixed numerous bugs in command-line option and configuration file
|
||||||
|
processing. [#TODO](https://github.com/ddclient/ddclient/pull/TODO)
|
||||||
* `noip`: Fixed failure to honor IP discovery settings in some circumstances.
|
* `noip`: Fixed failure to honor IP discovery settings in some circumstances.
|
||||||
[#591](https://github.com/ddclient/ddclient/pull/591)
|
[#591](https://github.com/ddclient/ddclient/pull/591)
|
||||||
* Fixed `--usev6` with providers that have not yet been updated to use the new
|
* Fixed `--usev6` with providers that have not yet been updated to use the new
|
||||||
|
|
676
ddclient.in
676
ddclient.in
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,7 @@ my @test_cases = (
|
||||||
{
|
{
|
||||||
type => ddclient::T_FQDN(),
|
type => ddclient::T_FQDN(),
|
||||||
input => 'example',
|
input => 'example',
|
||||||
want => undef,
|
want_invalid => 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type => ddclient::T_URL(),
|
type => ddclient::T_URL(),
|
||||||
|
@ -32,16 +32,22 @@ my @test_cases = (
|
||||||
{
|
{
|
||||||
type => ddclient::T_URL(),
|
type => ddclient::T_URL(),
|
||||||
input => 'ftp://bad.protocol/',
|
input => 'ftp://bad.protocol/',
|
||||||
want => undef,
|
want_invalid => 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type => ddclient::T_URL(),
|
type => ddclient::T_URL(),
|
||||||
input => 'bad-url',
|
input => 'bad-url',
|
||||||
want => undef,
|
want_invalid => 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
for my $tc (@test_cases) {
|
for my $tc (@test_cases) {
|
||||||
my $got = ddclient::check_value($tc->{input}, ddclient::setv($tc->{type}, 0, 0, undef, undef));
|
my $got;
|
||||||
is($got, $tc->{want}, "$tc->{type}: $tc->{input}");
|
my $got_invalid = !(eval {
|
||||||
|
$got = ddclient::check_value($tc->{input},
|
||||||
|
ddclient::setv($tc->{type}, 0, 0, undef, undef));
|
||||||
|
1;
|
||||||
|
});
|
||||||
|
is($got_invalid, !!$tc->{want_invalid}, "$tc->{type}: $tc->{input}: validity");
|
||||||
|
is($got, $tc->{want}, "$tc->{type}: $tc->{input}: normalization") if !$tc->{want_invalid};
|
||||||
}
|
}
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
|
@ -72,7 +72,9 @@ my @test_cases = (
|
||||||
want => [
|
want => [
|
||||||
{cfg => {falsy => 0}, hosts => [$h1]},
|
{cfg => {falsy => 0}, hosts => [$h1]},
|
||||||
{cfg => {falsy => ''}, hosts => [$h2]},
|
{cfg => {falsy => ''}, hosts => [$h2]},
|
||||||
{cfg => {falsy => undef}, hosts => [$h3]},
|
# undef intentionally becomes unset because undef always means "fall back to global or
|
||||||
|
# default".
|
||||||
|
{cfg => {}, hosts => [$h3]},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -80,8 +82,9 @@ my @test_cases = (
|
||||||
groupby => [qw(maybeunset)],
|
groupby => [qw(maybeunset)],
|
||||||
want => [
|
want => [
|
||||||
{cfg => {maybeunset => 'unique'}, hosts => [$h1]},
|
{cfg => {maybeunset => 'unique'}, hosts => [$h1]},
|
||||||
{cfg => {maybeunset => undef}, hosts => [$h2]},
|
# undef intentionally becomes unset because undef always means "fall back to global or
|
||||||
{cfg => {}, hosts => [$h3]},
|
# default".
|
||||||
|
{cfg => {}, hosts => [$h2, $h3]},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,8 +44,20 @@ my @test_cases = (
|
||||||
tc('unquoted escaped backslash', "a=\\\\", { a => "\\" }, ""),
|
tc('unquoted escaped backslash', "a=\\\\", { a => "\\" }, ""),
|
||||||
tc('squoted escaped squote', "a='\\''", { a => "'" }, ""),
|
tc('squoted escaped squote', "a='\\''", { a => "'" }, ""),
|
||||||
tc('dquoted escaped dquote', "a=\"\\\"\"", { a => '"' }, ""),
|
tc('dquoted escaped dquote', "a=\"\\\"\"", { a => '"' }, ""),
|
||||||
|
tc('env: empty', "a_env=", {}, ""),
|
||||||
|
tc('env: unset', "a_env=UNSET", {}, ""),
|
||||||
|
tc('env: set', "a_env=TEST", { a => 'val' }, ""),
|
||||||
|
tc('env: single quoted', "a_env='TEST'", { a => 'val' }, ""),
|
||||||
|
tc('newline: quoted value', "a='1\n2'", { a => "1\n2" }, ""),
|
||||||
|
tc('newline: escaped value', "a=1\\\n2", { a => "1\n2" }, ""),
|
||||||
|
tc('newline: between vars', "a=1 \n b=2", { a => '1' }, "\n b=2"),
|
||||||
|
tc('newline: terminating', "a=1 \n", { a => '1' }, "\n"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
delete($ENV{''});
|
||||||
|
delete($ENV{UNSET});
|
||||||
|
$ENV{TEST} = 'val';
|
||||||
|
|
||||||
for my $tc (@test_cases) {
|
for my $tc (@test_cases) {
|
||||||
my ($got_rest, %got_vars) = ddclient::parse_assignments($tc->{input});
|
my ($got_rest, %got_vars) = ddclient::parse_assignments($tc->{input});
|
||||||
subtest $tc->{name} => sub {
|
subtest $tc->{name} => sub {
|
||||||
|
|
|
@ -34,6 +34,8 @@ $httpd->run(sub {
|
||||||
|
|
||||||
diag(sprintf("started IPv4 server running at %s", $httpd->endpoint()));
|
diag(sprintf("started IPv4 server running at %s", $httpd->endpoint()));
|
||||||
|
|
||||||
|
local $ddclient::globals{verbose} = 1;
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new;
|
my $ua = LWP::UserAgent->new;
|
||||||
|
|
||||||
sub test_nic_dnsexit2_update {
|
sub test_nic_dnsexit2_update {
|
||||||
|
@ -66,8 +68,6 @@ sub get_requests {
|
||||||
subtest 'Testing nic_dnsexit2_update' => sub {
|
subtest 'Testing nic_dnsexit2_update' => sub {
|
||||||
my %config = (
|
my %config = (
|
||||||
'host.my.zone.com' => {
|
'host.my.zone.com' => {
|
||||||
'ssl' => 'no',
|
|
||||||
'verbose' => 'yes',
|
|
||||||
'usev4' => 'ipv4',
|
'usev4' => 'ipv4',
|
||||||
'wantipv4' => '8.8.4.4',
|
'wantipv4' => '8.8.4.4',
|
||||||
'usev6' => 'ipv6',
|
'usev6' => 'ipv6',
|
||||||
|
@ -75,7 +75,7 @@ subtest 'Testing nic_dnsexit2_update' => sub {
|
||||||
'protocol' => 'dnsexit2',
|
'protocol' => 'dnsexit2',
|
||||||
'password' => 'mytestingpassword',
|
'password' => 'mytestingpassword',
|
||||||
'zone' => 'my.zone.com',
|
'zone' => 'my.zone.com',
|
||||||
'server' => $httpd->host_port(),
|
'server' => $httpd->endpoint(),
|
||||||
'path' => '/update',
|
'path' => '/update',
|
||||||
'ttl' => 5
|
'ttl' => 5
|
||||||
});
|
});
|
||||||
|
@ -111,13 +111,11 @@ subtest 'Testing nic_dnsexit2_update' => sub {
|
||||||
subtest 'Testing nic_dnsexit2_update without a zone set' => sub {
|
subtest 'Testing nic_dnsexit2_update without a zone set' => sub {
|
||||||
my %config = (
|
my %config = (
|
||||||
'myhost.zone.com' => {
|
'myhost.zone.com' => {
|
||||||
'ssl' => 'yes',
|
|
||||||
'verbose' => 'yes',
|
|
||||||
'usev4' => 'ipv4',
|
'usev4' => 'ipv4',
|
||||||
'wantipv4' => '8.8.4.4',
|
'wantipv4' => '8.8.4.4',
|
||||||
'protocol' => 'dnsexit2',
|
'protocol' => 'dnsexit2',
|
||||||
'password' => 'anotherpassword',
|
'password' => 'anotherpassword',
|
||||||
'server' => $httpd->host_port(),
|
'server' => $httpd->endpoint(),
|
||||||
'path' => '/update-alt',
|
'path' => '/update-alt',
|
||||||
'ttl' => 10
|
'ttl' => 10
|
||||||
});
|
});
|
||||||
|
@ -143,24 +141,20 @@ subtest 'Testing nic_dnsexit2_update without a zone set' => sub {
|
||||||
subtest 'Testing nic_dnsexit2_update with two hostnames, one with a zone and one without' => sub {
|
subtest 'Testing nic_dnsexit2_update with two hostnames, one with a zone and one without' => sub {
|
||||||
my %config = (
|
my %config = (
|
||||||
'host1.zone.com' => {
|
'host1.zone.com' => {
|
||||||
'ssl' => 'yes',
|
|
||||||
'verbose' => 'yes',
|
|
||||||
'usev4' => 'ipv4',
|
'usev4' => 'ipv4',
|
||||||
'wantipv4' => '8.8.4.4',
|
'wantipv4' => '8.8.4.4',
|
||||||
'protocol' => 'dnsexit2',
|
'protocol' => 'dnsexit2',
|
||||||
'password' => 'testingpassword',
|
'password' => 'testingpassword',
|
||||||
'server' => $httpd->host_port(),
|
'server' => $httpd->endpoint(),
|
||||||
'path' => '/update',
|
'path' => '/update',
|
||||||
'ttl' => 5
|
'ttl' => 5
|
||||||
},
|
},
|
||||||
'host2.zone.com' => {
|
'host2.zone.com' => {
|
||||||
'ssl' => 'yes',
|
|
||||||
'verbose' => 'yes',
|
|
||||||
'usev6' => 'ipv6',
|
'usev6' => 'ipv6',
|
||||||
'wantipv6' => '2001:4860:4860::8888',
|
'wantipv6' => '2001:4860:4860::8888',
|
||||||
'protocol' => 'dnsexit2',
|
'protocol' => 'dnsexit2',
|
||||||
'password' => 'testingpassword',
|
'password' => 'testingpassword',
|
||||||
'server' => $httpd->host_port(),
|
'server' => $httpd->endpoint(),
|
||||||
'path' => '/update',
|
'path' => '/update',
|
||||||
'ttl' => 10,
|
'ttl' => 10,
|
||||||
'zone' => 'zone.com'
|
'zone' => 'zone.com'
|
||||||
|
|
Loading…
Reference in a new issue