Commit graph

130 commits

Author SHA1 Message Date
Richard Hansen
912bc6291a group_hosts_by: Treat undef as unset for consistency with opt
The `opt` function falls back to global/default if the value is
undefined, even if it is explicitly set to `undef`.  `group_hosts_by`
should behave the same.
2024-08-18 01:21:40 -04:00
Richard Hansen
270a82dd58 parse_assignments: Support newlines
Allow newlines to be in values, but stop searching for assignments
once an unescaped/unquoted newline is discovered.  This is preparation
to using `parse_assignments` to process the `--options` command-line
argument, which might have embedded newlines.
2024-08-18 00:41:28 -04:00
Richard Hansen
4c7634855b Move *_env processing to parse_assignment
This makes the behavior transparent to the rest of ddclient, which
will make it possible for a future commit to simplify option
processing.
2024-08-18 00:41:28 -04:00
Richard Hansen
ed2afde72d check_value: die if the value is invalid
This makes it possible to convey details about why the value was
deemed invalid.  It also allows `undef` to be treated as a valid
value.
2024-08-18 00:41:28 -04:00
Richard Hansen
0c094f6ee8 tests: Fix verbose option for dnsexit2 protocol tests
The `verbose` option is a global option, not a per-host option.
2024-08-18 00:35:44 -04:00
Richard Hansen
a136ba4cdc tests: Fix ssl option for dnsexit2 protocol tests
The `ssl` option is a global option, not a per-host option.  This
commit could instead do:

    local $ddclient::globals{ssl} = 0;

but it's more straightforward to include `http://` in the `server`
option, and it tests that `server` supports the inclusion of the
scheme.
2024-08-18 00:35:44 -04:00
Jeff Rego
959b5ddc37 Add support for Directnic provider 2024-08-07 00:06:25 -04:00
Jeff Rego
d497422bf9 Add T_URL type for config properties 2024-08-07 00:06:25 -04:00
Richard Hansen
2330543cc8 dyndns2: Add comment explaining why keys are listed in test 2024-08-05 19:57:18 -04:00
Richard Hansen
eb281ea47b dnsexit2: Rename test file for consistency 2024-08-03 03:32:35 -04:00
Richard Hansen
3d345ff08b dyndns2: Add tests 2024-08-03 03:32:35 -04:00
Richard Hansen
15db76f739 Logger: Accept an arrayref of contexts for ctx parameter 2024-08-02 20:42:36 -04:00
Richard Hansen
f36c2f45aa Logger: Always use STDERR as output filehandle
There's no good reason for the caller of the `log` method to control
the output filehandle.
2024-08-02 17:03:56 -04:00
Richard Hansen
439b0fd0e1 Logger: Minimize STDERR override in tests 2024-08-02 17:00:00 -04:00
Richard Hansen
dff4cd4854 Logger: Localize override in test 2024-08-02 16:13:56 -04:00
Richard Hansen
e036fd0cf6 logging: Use Logger contexts to improve log message readability
This also makes it easier to write useful log messages.
2024-07-31 01:01:00 -04:00
Richard Hansen
9e45aecf20 logging: New Logger class to generally handle context prefixes 2024-07-31 00:39:48 -04:00
Richard Hansen
23bc8cdac3 logging: Move colon from the label to logmsg 2024-07-31 00:39:48 -04:00
Richard Hansen
3262dd0952 logging: Rename pfx to label
This is to prepare for a general log prefix mechanism to improve log
readability.
2024-07-31 00:39:48 -04:00
Richard Hansen
e272caa385 use=web, use=<fw>: Strip HTTP headers before searching for IP 2024-07-27 04:40:34 -04:00
Richard Hansen
b563e9c2fd use=web: Add tests 2024-07-27 04:40:34 -04:00
Richard Hansen
b1752c2622 logging: Delete unused msg function 2024-07-27 03:59:29 -04:00
Richard Hansen
6aa68f72a7 logging: Change multi-line log message designation style
Before, the first line of a multi-line log message was prefixed with a
space while all subsequent messages were prefixed with `|`.  Now the
first line is prefixed with `>` and all subsequent lines with a space.
This makes it easier to quickly discern message boundaries.
2024-07-27 03:47:47 -04:00
Richard Hansen
0ea2f06513 get_ip: Don't mutate $arg
This makes log messages easier to understand.
2024-07-26 19:05:47 -04:00
Richard Hansen
8a65264841 group_hosts_by: Return the common group configuration
This should make it easier to detect missing attribute names passed to
`group_hosts_by`.
2024-07-13 04:09:24 -04:00
Richard Hansen
b8df93febe group_hosts_by: Return a list, not a hashref
The hash key value is an implementation detail that should not be
leaked to the caller.
2024-07-13 04:08:35 -04:00
Richard Hansen
08ccc41650 group_hosts_by: Use arg list instead of arrayref
This is more idiomatic.
2024-07-13 04:08:35 -04:00
Richard Hansen
fa0bfde3cb Don't assume the default interface has a globally routable IP 2024-07-11 00:18:27 -04:00
Richard Hansen
6af76afde9 Use skip_all if test precondition is not met
Subtests can't have zero checks.
2024-07-11 00:18:27 -04:00
Richard Hansen
01d2db06c1 Invert conditions for readability 2024-07-11 00:18:27 -04:00
Richard Hansen
6e7a4fb460 Split subtest into two subtests
This makes it easier to debug failures.
2024-07-11 00:18:27 -04:00
Richard Hansen
49f5551764 Add variable default value tests 2024-06-28 15:53:40 -04:00
Richard Hansen
b426b370fd Rename %cache to %recap for readability 2024-06-22 02:48:03 -04:00
Richard Hansen
211d59fccc header_ok: Log all non-2xx HTTP status codes 2024-06-06 19:34:06 -04:00
Richard Hansen
adbac91be7 header_ok: Only keep first line of argument
This allows callers to pass the entire response without generating
overly long error messages.
2024-06-06 19:34:06 -04:00
Richard Hansen
b58a10b3e3 header_ok: Add unit tests 2024-06-06 19:34:06 -04:00
Richard Hansen
31dbd8e4ed geturl: Set raw (binary) mode when reading from curl 2024-06-03 03:13:05 -04:00
jortkoopmans
216741c9ce dnsexit2: Fix when provided with a zone and a non-identical hostname
Trim the zone from the hostname in the request to fix issue.
2024-06-02 16:58:00 -04:00
jortkoopmans
ec2d5f7f69 dnsexit2: Add tests
Needs LWP::UserAgent.
2024-06-02 16:58:00 -04:00
Richard Hansen
e60e6e804b group_hosts_by: Use Data::Dumper to make the group signature
This is a bit more robust than manually making the group signature
because it gracefully handles corner cases such as `undef`.
2024-06-01 03:06:06 -04:00
Richard Hansen
ce0a362fd0 group_hosts_by: Add tests 2024-06-01 03:05:26 -04:00
Richard Hansen
d8a9d9d089 Add support for infinite duration 2024-05-25 00:38:10 -04:00
Richard Hansen
9c6e5fdda4 Output a | character in log message continuation lines
This makes it easier to tell where multi-line log messages begin and
end.
2024-05-23 02:04:29 -04:00
Richard Hansen
ff39ce3874 Don't use sprintf if there is only one argument
This avoids problems when logging a string that might have
metacharacters.
2024-05-23 02:04:19 -04:00
Richard Hansen
065b227711 logmsg: New low-level logging interface 2024-05-23 01:57:12 -04:00
Richard Hansen
d02a9cf6db Add infrastructure for custom logic in a %builtinfw entry 2024-05-14 22:18:59 -04:00
Richard Hansen
dfb2196499 Translate Perl version string to user-friendly version string
Perl version strings are flawed in a few ways.  Convert them to
user-friendly strings when printed so that Git tags and tarball names
are easier for downstream distributions to work with.
2024-05-12 16:43:43 -04:00
Richard Hansen
0806363b57 Tell Autoconf to get the version from ddclient.in
This avoids the need to maintain the same version string in two
different places.
2024-05-12 16:43:43 -04:00
Richard Hansen
58d7be4e83 Distinguish unset --*-skip settings from set to the empty string
This prevents the `%builtinweb` or `%builtinfw` skip defaults from
overriding a user's explicitly empty `--web-skip=` or `--fw-skip=`
setting.

This is technically a backwards-incompatible change: Any config that
explicitly sets `--web-skip` or `--fw-skip` to the empty string but
depends on the built-in skip behavior will fail.  This is unlikely to
affect many (if any) users; compatibility concerns are believed to be
far less significant than the potential need to turn off the built-in
skip.
2024-05-12 15:55:28 -04:00
Richard Hansen
281b7307a8 Fix misspelled *-ssl-validate option names
There is no `ssl-validate` option, and there never has been.
2024-05-10 16:54:40 -04:00
Richard Hansen
fedf0cbf40 Update ddclient::Test::Fake::HTTPD 2024-05-09 22:32:28 -04:00
Richard Hansen
01d1d5e142 Change t/geturl_connectivity.pl to handwritten
Commit a9c1e545fb removed the
`configure.ac` substitution, so the test no longer needs to be
generated.
2024-05-07 22:39:17 -04:00
Reuben Thomas
a9c1e545fb Require curl
Use command-line curl, and remove alternative Perl and Curl-via-Perl
implementations of network code.
2023-07-19 17:11:45 +03:00
Michal Josef Špaček
c4ff6c12bd Remove setting of MultiHomed, which is default in IO::Socket::IP
From doc in IO::Socket::IP in "IO::Socket::INET" INCOMPATIBILITES
section:
-----
The behaviour enabled by "MultiHomed" is in fact implemented by
"IO::Socket::IP" as it is required to correctly support searching for a
useable address from the results of the getaddrinfo(3) call. The
constructor will ignore the value of this argument, except if it is
defined but false. An exception is thrown in this case, because that
would request it disable the getaddrinfo(3) search behaviour in the
first place.
-----
2022-12-08 14:04:33 +01:00
Michal Josef Špaček
c747f2737a Rewrite deprecated use of IO::Socket::INET6 to new solution
Module IO::Socket::INET6 is deprecated.
There is common IO::Socket::IP module, which is working with ipv4 and
ipv6 in same way. There is backward compatibility with IO::Socket::INET6
2022-12-08 13:58:21 +01:00
David Kerr
1b2f45cc59 Add get_default_interface 2020-09-21 15:16:48 -04:00
David Kerr
213cf6ad09 Add get_ip_from_interface function 2020-09-21 15:16:11 -04:00
David Kerr
d24b75960d Add support for curl and option to not validate SSL certificates for getip from web or firewall
Check exists not just length
2020-08-07 11:17:44 -04:00
David Kerr
1ad4d6737a Add is_ipv6_global and extract_ipv6_global functions 2020-08-01 19:11:28 -04:00
Richard Hansen
310810c291 Group tests by IO::Socket class
Also delete some redundant SSL tests.
2020-07-24 15:23:54 -04:00
Richard Hansen
b46d064f55 Don't show -noipv6 when ipv6_opt is false 2020-07-24 15:18:42 -04:00
Richard Hansen
92a7590846 Whitespace fixes 2020-07-24 15:13:03 -04:00
Richard Hansen
5f1dacc3bd Eliminate unnecessary hashref
Pass the key-value pairs directly instead of via a hashref.
2020-07-11 21:39:48 -04:00
David Kerr
29202f5bc1 New is_ipv6 and extract_ipv6 algorithms
Also add unit tests.
2020-07-11 11:04:47 -04:00
David Kerr
92c1294af9 Accept leading zeros in IPv4 addresses
Also add unit tests.
2020-07-11 11:04:33 -04:00
Richard Hansen
a86f40ae9b Skip IPv6 tests if IO::Socket::INET6 isn't available
Fixes #251
2020-07-10 23:10:56 -04:00
Richard Hansen
bba1ecfe27 Switch from redefine to mock 2020-07-10 12:06:45 -04:00
Richard Hansen
173865bd75 Don't test writing to a read-only directory
root can always write to a read-only directory so the test was failing
on the CI runners (which run as root).
2020-07-10 12:06:45 -04:00
Richard Hansen
192a00ad64 Don't match against locale-dependent $! 2020-07-10 12:06:45 -04:00
Richard Hansen
4e1607c8f6 Enable autoflush on STDOUT and STDERR for tests
This prevents STDOUT lines from appearing out of order relative to
STDERR lines in the test log, which makes it much easier to understand
what's happening.

Devel::Autoflush is from https://metacpan.org/pod/Devel::Autoflush and
is licensed under the terms of the Apache 2.0 license.
2020-07-10 12:06:45 -04:00
Richard Hansen
dd8e376784 Add geturl SSL tests
These don't test validation, only that IO::Socket::SSL is used.
2020-07-08 13:40:31 -04:00
Richard Hansen
199e9125a4 Use subtest to group related tests
This reduces the output of `make check`, making it easier to zero in
on results of interest.
2020-07-07 13:01:15 -04:00
Richard Hansen
94aaff67cd Add Test::Simple v1.302175 to t/lib
The version of Test::More available in CentOS/RHEL 6 doesn't include
`subtest`, which we want to use. We can revert this commit once we
drop support for CentOS/RHEL 6.

The code is licensed under the same terms as Perl 5 itself:
https://github.com/Test-More/test-more/blob/v1.302175/LICENSE
2020-07-07 13:01:13 -04:00
Richard Hansen
ee8e1e8844 Don't abort if unable to write the cache file 2020-07-07 00:04:33 -04:00
Richard Hansen
6ae5fe62d7 Create /var/cache/ddclient if it doesn't exist
Fixes #76
2020-07-07 00:04:33 -04:00
Richard Hansen
323208e9cc Add geturl connectivity unit tests
Addresses #232
2020-07-05 18:36:46 -04:00
Richard Hansen
6d7d248f79 Improve parsing of config file assignments
* Ignore empty `key=value` strings in variable assignments. Now the
    following lines are supported with the expected meaning:
      * `a=1 , b=2`
      * `a=1,,b=2`
  * Improve the warning message when there is an unterminated quote.
  * Add a warning if the line ends with a backslash.

Also add unit tests.
2020-07-03 16:56:01 -04:00
Richard Hansen
a8212a397e Add a test for unexpected warnings 2020-06-30 00:40:26 -04:00
Richard Hansen
0cc83cd5ec Simplify runtime imports in test code
Also use `BAIL_OUT` instead of `die` if `require 'ddclient'` fails.
2020-06-29 17:26:46 -04:00
Richard Hansen
c390e75769 Add unit test infrastructure.
Now all that is needed to add a new unit test is to create a `t/*.pl`
file and list it in the `handwritten_tests` variable.

To run the test suite, run:

    ./autogen && ./configure && make check

Fixes #147
2020-06-29 11:08:32 -04:00