20 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
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
0f487e5fb5 test: Remove dependency on Python 2
Python 2 is approaching end of life, and we only need it to run
the mail_diff test utility.

This patch updates mail_diff to run on Python 3, which only needed minor
changes.
2019-08-30 09:46:46 +01:00
Alberto Bertogli
a5edd9053f queue: Make DSN tidier, especially in handling multi-line errors
This patch contains some changes to generate tidier DSNs, which should
make them slightly more readable.

In particular, it also makes it able to handle multi-line errors much
better than before.
2019-05-04 21:28:07 +01:00
Alberto Bertogli
1ecc957aba queue: Internationalized Delivery Status Notifications (DSN)
Our non-delivery status notifications are quite simple today, but that
makes it much more difficult to support internationalization and
cross-language reporting.

There is a standard for internationalized DSNs, RFC 6533 (which builds
on top of the structured DSNs from RFC 3464).

This patch changes our DSN messages to be based on those standards, so
it is easier for MUAs to display reports according to the users'
languages preferences.

Note we still use message/rfc822 + 8bit to transmit the message, instead
of message/global, for compatibility reasons. This seems to be more
universally compatible, but the decision might be revisited in the
future. See RFC 5335 (section 4.6 in particular).
2019-01-18 23:27:10 +00:00
Alberto Bertogli
29709a0d58 smtpsrv: Improve "Received" header standard compliance
Despite its loose appearance, the "Received" header has a reasonably
standarized format.

We were not following the standard format as closely as we should; this
rarely causes problems in this particular case, but there's no need to
deviate from it.

This patch changes the Received header generation as follows:

 - The "from" section now uses the remote address as canonical (for
   non-authenticated users) which provides more valuable information
   than the user-supplied EHLO address (which is also included).
 - The remote authenticated user is now hidden, for additional privacy.
 - Use the "with" optional clause.
 - Use the standard way of printing TLS cipher suite.
 - Use the standard way of printing address literals.
2018-11-30 10:03:48 +00:00
Alberto Bertogli
a85ba1252b test: Remove nc.py
The nc.py script is only used in a single test, and for waiting for a
TCP port to be opened for listening.

This patch replaces it entirely, by using chamuyero for the test, and
bash for waiting on a TCP port.
2017-07-13 22:05:45 +01:00
Alberto Bertogli
213bc63a95 Support submission (directly) over TLS (submissions/smtps/port 465)
This patch adds support for TLS-wrapped submission connections.

Instead of clients establishing a connection over plain text and then
using STARTTLS to switch over a TLS connection, this new mode allows the
clients to connect directly over TLS, like it's done in HTTPS.

This is not an official standard yet, but it's reasonably common in
practice, and provides some advantages over the traditional submission
port.

The default port is 465, commonly used for this; chasquid defaults to
systemd file descriptor passing as for the other protocols (for now).
2017-04-10 19:59:04 +01:00
Alberto Bertogli
c2ea8a8ef0 test: Use our own netcat implementation :(
Netcat's behaviour after seeing EOF from stdin seems to not be very
portable or consistent, even under the same platform.

This has caused t-05-null_address to break recently under some
conditions, for example depending on the particular Debian version of
netcat-openbsd used, and the current situation is unclear.
See https://bugs.debian.org/854292 and https://bugs.debian.org/849192
for more details.

To stop depending on this brittle behaviour, this patch unfortunately
introduces a simple python3-based netcat for our tests to use.
2017-02-26 01:21:35 +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
d660f88f67 queue: Send DSN for messages that time out in the queue
The queue currently only considers failed recipients when deciding
whether to send a DSN or not. This is a bug, as recipients that time out
are not taken into account.

This patch fixes that issue by including both failed and pending
recipients in the DSN.

It also adds more comprehensive tests for this case, both in the queue
and in the dsn generation code.
2016-10-21 22:20:49 +01: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
febe96697a maillog: Introduce a special-purpose mail logging package
The default INFO logs are more oriented towards debugging and can be
a bit too verbose when looking for high-level information.

This patch introduces a new "maillog" package, used to log messages of
particular relevance to mail transmission at a higher level.
2016-10-21 22:20:47 +01:00
Alberto Bertogli
eadd0ffc89 chasquid: Track and enforce the HELO/EHLO address
HELO and EHLO both take a mandatory parameter, which also should be used
in the Received header.

This patch tracks and enforces that parameter, and also updates the
Received header generation to use it.

https://tools.ietf.org/html/rfc5321#section-4.4
2016-10-21 22:13:39 +01:00
Alberto Bertogli
3eac221a7f chasquid: Make the "Received:" header RFC compliant
The Received header has some predefined structure and valid keywords,
this patch adjust how we create them to be compliant with that
structure.
2016-10-10 00:51:05 +01:00
Alberto Bertogli
bc2b3b40a5 chasquid: Skip SPF if the connection has authenticated
Currently, we do SPF checks for all connections.

However, authenticated users will be sending email from different
locations, applying SPF to them will result in false positives.

So this patch makes chasquid skip SPF checking if the connection is
authenticated.
2016-10-10 00:51:05 +01:00
Alberto Bertogli
2b801a84d1 chasquid: Add SPF checks
This patch makes chasquid perform SPF checks, and add the corresponding
Received-SPF header.
2016-10-10 00:51:05 +01:00
Alberto Bertogli
e138f0dc05 chasquid: De-couple TLS certificates from domains
Having the certificates inside the domain directory may cause some confusion,
as it's possible they're not for the same name (they should be for the MX we
serve as, not the domain itself).

So it's not a problem if we have domains with no certificates (we could be
their MX with another name), and we could have more than one certificate per
"domain" (if we act as MXs with different names).

So this patch moves the certificates out of the domains into a new certs/
directory, where we do a one-level deep lookup for the files.

While at it, change the names of the files to "fullchain.pem" and
"privkey.pem", which match the names generated by the letsencrypt client, to
make it easier to set up.  There's no general convention for these names
anyway.
2016-10-10 00:51:04 +01:00
Alberto Bertogli
469cbd5d76 test: Add a test for DSN and null address deliveries
This patch adds a test for delivery status notifications and null address
deliveries, that check that chasquid can both receive and send DSNs.

To do this, we extend the mail_diff utility to support wildcards in the
comparisons, to skip over variable parts of the messages (like dates).
2016-10-10 00:51:04 +01:00