18 Commits

Author SHA1 Message Date
Alberto Bertogli
5eded4edc3 test: Unify (most) SMTP client calls
To send mails, today some tests use msmtp and others our internal smtpc.py.

This works, but msmtp slows down the tests significantly, and smtpc.py
is also not particularly fast, and also has some limitations.

This patch introduces a new SMTP client tool written in Go, and makes
almost all the tests use it.

Some tests still remain on msmtp, mainly for client-check compatibility.
It's likely that this will be moved in later patches to a separate
special-purpose test.

With this patch, integration tests take ~20% less time than before.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
948cee1ce1 Improve bash quoting, and other similar best practices
This patch updates the shell scripts with some of the common best
practices, which should make them more resilient to unusual failures and
unexpected environments (in particular, directories with spaces).

Most of these were identified by shellcheck.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
4d1526e0c8 test: Reduce main sources of overhead in integration tests
The integration tests spend a lot of time on some ancilliary actions,
which slows them down: generating certificates, adding users, and
waiting for things to happen.

To improve the performance of those actions, this patch:

- Makes (most) tests use plain passwords (-20%)
- Adds a certificate cache to reuse certs (-10%)
- Tightens the sleep loops (-5%)

In aggregate, this patch results in a speedup of the integration tests
of ~30-40%.

Note that some of the tests required adjusting the username, because
`chasquid-util user-add` would convert them to lowercase as per PRECIS
mapping.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
ed38945fca courier: Use DNSError.IsNotFound to identify NXDOMAIN
When resolving MX records, we need to distinguish between "no such
domain" and other kinds of errors. Before Go 1.13, this was not
possible, so we had a workaround that assumed any permanent error was a
"no such domain", which is not great, but functional.

Now that our minimum supported version is Go 1.15, we can remove the
workaround.

This patch replaces the workaround with proper logic using
DNSError.IsNotFound to identify NXDOMAIN results when resolving MX
records.

This requires to adjust a few tests, that used to work on environments
where resolving unknown domains (used for testing) returned a permanent
error, and now they no longer do so. Instead of relying on this
environmental property, we make the affected tests use our own DNS
server, which should make them more hermetic and reproducible.
2021-10-08 23:11:29 +01:00
Alberto Bertogli
d78056aff5 test: Skip integration tests if $HOSTALIASES is not functional
Most integration tests depend on the $HOSTALIASES environment variable
being functional. That variable works on most systems, but not all. In
particular, systems with `systemd-resolved` can cause the variable to be
ignored.

This was reported by Alex Ellwein in
https://github.com/albertito/chasquid/issues/20.

This patch makes the affected tests to be skipped if $HOSTALIASES is not
working properly. It also removes unnecessary hosts files from tests
which don't need it, and documents this behaviour.

Thanks to Alex Ellwein and foxcpp@ for reporting and helping investigate
this issue!
2021-07-15 00:20:21 +01:00
Alberto Bertogli
e9c6775418 test: Remove dependency on wget
This patch removes the dependency on wget for fetching content over
http, which was used in one of the tests to do some checking on debug
and metric pages, as well as loop detection.

Instead of wget, we now use a small built-in utility called fexp.
2020-11-12 23:24:21 +00:00
Alberto Bertogli
7fe42a368a monitoring: Add OpenMetrics exporter
This patch makes chasquid's monitoring server expose an OpenMetrics
metrics endpoint.

It adds a new package "expvarom" which implements an HTTP handler that
exports expvar variables in the OpenMetrics text format.

Then, the handler is registered by the monitoring server at /metrics
(where most things expect it to be).

The existing exported variables are also extended with descriptions,
which is optional, but improves the readability of the metrics.
2020-08-21 12:07:33 +01:00
Alberto Bertogli
7e412db19b test: Check debugging pages are not empty
When testing the debugging pages, do a quick check to verify that the
returned pages are not empty.

This covers the case where a template fails to execute at runtime, and
without this change it wouldn't be caught by tests.
2020-08-20 00:08:36 +01:00
Alberto Bertogli
a6a20fb6e0 monitoring: Add a config dump handler
This patch adds a handler to the monitoring HTTP server which dumps
the parsed config, so it can easily be reviewed for troubleshooting.
2020-07-28 02:12:29 +01:00
Alberto Bertogli
35e19dc4a2 protoio: Use new protobuf API for text marshalling
This patch makes protoio use the new protobuf API for
marshalling/unmarshalling text protobufs, as well as extends the tests
to cover marshalling failures.

The protobuf text output is not stable/deterministic and some spaces are
added randomly, so some integration tests have to be adjusted to account
for it.
2020-06-30 11:14:52 +01:00
Alberto Bertogli
661f759c0c test: Allow up to 2 loops in the loop integration test
In the loop integration test, we detect looping via checking the expvars
of chasquid, and waiting for the loop counter to be 1.

However, if chasquid is fast enough, it will go up to 2 before the
detection notices. This is because the DSN that gets generated also
loops (as expected).
2018-11-30 10:03:48 +00:00
Alberto Bertogli
407f7cf79a test: Test monitoring HTTP fetching
This patch adds HTTP fetching to the integration tests.

It checks that the URLs are properly exported and that the server
replies reasonably to them. The contents are saved as they might be
useful as a debugging aid.

They're added to t-09-loop as it already was doing other HTTP fetches,
but the changes are not particularly tied to it.

The content of the pages is not checked yet, that might come in
subsequent patches.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
f7a4fa895c test: Work around wget's logging to files
There's a bug in wget where it logs to files if -q is used:
https://savannah.gnu.org/bugs/?51181

It is harmless to the test, but it clutters the directory and the test
output, so this patch works around the issue by forcing it to log to
/dev/null.
2017-12-08 13:57:25 +00:00
Alberto Bertogli
a016d78515 courier: Fix SMTP outgoing security level check
The outgoing security level checks are not being performed, because of a
bug: the courier thinks the "to"'s domain is always empty.

This patch fixes the bug by simplifying the logic, as there's no need
for the conditional (there is always a domain in the "to" address if it
got to the SMTP courier).
2017-07-14 01:06:09 +01:00
Alberto Bertogli
54cce0c2bf test: Reduce the loop detection threshold from 50 down to 5
The loop test can be quite slow, specially on computers without
cryptography-friendly instructions.

This patch introduces a new flag for testing, so that we can bring the
threshold down to 5. The test is just as useful but now runs in a few
seconds, as opposed to a few minutes.
2016-11-01 23:56:04 +00:00
Alberto Bertogli
60a7932bd3 log: Replace glog with a new logging module
glog works fine and has great features, but it does not play along well
with systemd or standard log rotators (as it does the rotation itself).

So this patch replaces glog with a new logging module "log", which by
default logs to stderr, in a systemd-friendly manner.

Logging to files or syslog is still supported.
2016-11-01 23:56:04 +00:00
Alberto Bertogli
6f048027a7 test: Readability cleanup
This patch makes a few small changes to the tests for readability, such
as changing the arguments to the add_user function.
2016-10-21 22:20:49 +01:00
Alberto Bertogli
40153e352f chasquid: Detect email loops
This patch implements some measures against email loops, such as keeping
a limit on the lenght of an address, and rejecting email that has too
many Received headers.

It's not perfect (a server could be actively removing Received headers),
but it should cover the normal accidents and misconfigurations.
2016-10-10 00:51:05 +01:00