Add T_URL type for config properties
This commit is contained in:
parent
2330543cc8
commit
d497422bf9
3 changed files with 52 additions and 0 deletions
|
@ -63,6 +63,7 @@ AM_PL_LOG_FLAGS = -Mstrict -w \
|
||||||
-MDevel::Autoflush
|
-MDevel::Autoflush
|
||||||
handwritten_tests = \
|
handwritten_tests = \
|
||||||
t/builtinfw_query.pl \
|
t/builtinfw_query.pl \
|
||||||
|
t/check_value.pl \
|
||||||
t/get_ip_from_if.pl \
|
t/get_ip_from_if.pl \
|
||||||
t/geturl_connectivity.pl \
|
t/geturl_connectivity.pl \
|
||||||
t/geturl_response.pl \
|
t/geturl_response.pl \
|
||||||
|
|
|
@ -181,6 +181,7 @@ sub T_OFQDN { 'optional fully qualified host name' }
|
||||||
sub T_FILE { 'file name' }
|
sub T_FILE { 'file name' }
|
||||||
sub T_FQDNP { 'fully qualified host name and optional port number' }
|
sub T_FQDNP { 'fully qualified host name and optional port number' }
|
||||||
sub T_PROTO { 'protocol' }
|
sub T_PROTO { 'protocol' }
|
||||||
|
sub T_URL { 'url including fully qualified host name, optional port number, and path' }
|
||||||
sub T_USE { 'ip strategy' }
|
sub T_USE { 'ip strategy' }
|
||||||
sub T_USEV4 { 'ipv4 strategy' }
|
sub T_USEV4 { 'ipv4 strategy' }
|
||||||
sub T_USEV6 { 'ipv6 strategy' }
|
sub T_USEV6 { 'ipv6 strategy' }
|
||||||
|
@ -2524,6 +2525,9 @@ sub check_value {
|
||||||
$value = lc $value;
|
$value = lc $value;
|
||||||
return undef if !exists $protocols{$value};
|
return undef if !exists $protocols{$value};
|
||||||
|
|
||||||
|
} elsif ($type eq T_URL) {
|
||||||
|
return undef if $value !~ qr{^(?i:https?://)?[^./]+(\.[^./]+)+(:\d+)?(/[^/]+)*/?$};
|
||||||
|
|
||||||
} elsif ($type eq T_USE) {
|
} elsif ($type eq T_USE) {
|
||||||
$value = lc $value;
|
$value = lc $value;
|
||||||
return undef if !exists $ip_strategies{$value};
|
return undef if !exists $ip_strategies{$value};
|
||||||
|
|
47
t/check_value.pl
Normal file
47
t/check_value.pl
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
use Test::More;
|
||||||
|
use strict;
|
||||||
|
SKIP: { eval { require Test::Warnings; } or skip($@, 1); }
|
||||||
|
eval { require 'ddclient'; } or BAIL_OUT($@);
|
||||||
|
|
||||||
|
my @test_cases = (
|
||||||
|
{
|
||||||
|
type => ddclient::T_FQDN(),
|
||||||
|
input => 'example.com',
|
||||||
|
want => 'example.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type => ddclient::T_FQDN(),
|
||||||
|
input => 'example',
|
||||||
|
want => undef,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type => ddclient::T_URL(),
|
||||||
|
input => 'https://www.example.com',
|
||||||
|
want => 'https://www.example.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type => ddclient::T_URL(),
|
||||||
|
input => 'https://directnic.com/dns/gateway/ad133/',
|
||||||
|
want => 'https://directnic.com/dns/gateway/ad133/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type => ddclient::T_URL(),
|
||||||
|
input => 'HTTPS://MixedCase.com/',
|
||||||
|
want => 'HTTPS://MixedCase.com/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type => ddclient::T_URL(),
|
||||||
|
input => 'ftp://bad.protocol/',
|
||||||
|
want => undef,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type => ddclient::T_URL(),
|
||||||
|
input => 'bad-url',
|
||||||
|
want => undef,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
for my $tc (@test_cases) {
|
||||||
|
my $got = ddclient::check_value($tc->{input}, ddclient::setv($tc->{type}, 0, 0, undef, undef));
|
||||||
|
is($got, $tc->{want}, "$tc->{type}: $tc->{input}");
|
||||||
|
}
|
||||||
|
done_testing();
|
Loading…
Reference in a new issue