Commit Graph

31 Commits

Author SHA1 Message Date
Piotr F. Mieszkowski 881a8d1756 Add GnuPG encryption support for addresses with delimiters
If a user registers their key for address alice@example.com but receives a
message sent to alice+something@example.com, this message should be encrypted
as well.

- Implement delimiter support for GnuPG encryption.

- Add E2E test case for a clear text message delivered to an address with
delimiter.

- Fix minor bug: wrong configuration parameter was retrieved when logging
information about enc_domain_keymap being active.
2022-06-08 21:20:58 +02:00
Piotr F. Mieszkowski c86c620668 Extract delimiter support, add unit tests
Also: fix recursive call to get_cert_for_email.
2022-06-07 22:14:32 +02:00
Piotr F. Mieszkowski 46be24670c Fix charset resolution in Content-Type parser 2022-06-01 23:44:41 +02:00
Piotr F. Mieszkowski 4c6fdc52ec Check mandatory config early, add tests
Also: extend failover logging configuration with file-based handler to make
sure that the user gets _some_ logs even if they do not configure Lacre at
all.
2022-05-31 22:09:10 +02:00
Piotr F. Mieszkowski 3bcc1151e5 Add E2E case: a user with a key and PGP/MIME configured
- Add a new test input message for a new test identity, test scenario
  configuration and a test key.

- While retrieving message payload, determine charset based on the
  Content-Type header.  When missing, default to UTF-8.

- Use more comprehensible variables names.

- Adjust logging levels.
2022-05-30 00:49:40 +02:00
Piotr F. Mieszkowski 707fc96234
Add more contract tests
- Verify that Message.get_payload() returns str, unless passed decode=True,
when it returns bytes.

- Verify that RawConfigParser returns str.
2022-05-25 22:13:40 +02:00
Piotr F. Mieszkowski 558872d9d0 Start documenting dependency contracts with unit tests
Implement some unit tests for 'email' package so we know precisely how this
package behaves.
2022-05-16 20:57:12 +02:00
Piotr F. Mieszkowski 8f0d8f4933 Add newlines to key material 2022-05-06 20:40:16 +02:00
Piotr F. Mieszkowski 75ccfb0850 Use logging module
- Replace custom logging code with calls to logging module.
- Use logging.config to provide configuration parameters.

To make Lacre's logging more flexible, use fileConfig from logging.config to
set up all parameters.  If the configuration file is missing, use dictConfig
with hardcoded reasonable defaults.
2022-05-06 19:39:56 +02:00
Piotr F. Mieszkowski d90b50f7e7 Extract config, separate logging, split into smaller functions
- Move configuration-processing code to a separate module (lacre.config) and
  provide a simple API to access configuration parameters.
- Prepare to use builtin logging module to log diagnostic data.
- Rework the configuration-processing file to make it cleaner.
- Log additional information while processing configuration.
- Reorder functions.
2022-05-06 19:39:56 +02:00
Piotr F. Mieszkowski a82ff9f3f1 Use actual keys (RSA and Ed25519) in cron-test 2022-04-24 10:42:51 +02:00
Piotr F. Mieszkowski ffc53b935a Finish migration to SQLAlchemy and automate testing cron.py 2022-04-23 13:08:40 +02:00
Piotr F. Mieszkowski 9e17726e39 Use f-strings for formatting 2022-02-06 00:27:20 +01:00
Piotr F. Mieszkowski a201265f87 Rework how E2E tests are executed
Tests kept breaking (not failing) randomly with "Broken pipe" errors.  Rework
how processes are spawned to make sure that it doesn't break them again.
2022-01-19 21:57:46 +01:00
Piotr F. Mieszkowski c81c6e6e0d Remove hardcoded python3.8 path
- Let the user overwrite Python binary name while calling make.

- Use environment variable set by make to instruct e2e_test.py which binary it
should call to execute Python code.
2022-01-10 20:22:17 +01:00
Piotr F. Mieszkowski 5a8d2c0108 Add E2E cases: signed cleartext and multipart/encrypted 2022-01-10 19:48:44 +01:00
Piotr F. Mieszkowski 435528de43 Add an E2E test case with an already encrypted message 2022-01-10 19:32:46 +01:00
Piotr F. Mieszkowski 24f0c86d4f Tidy up tests
- Makefile: add 'unittest' to .PHONY targets.
- Remove unnecessary #! line from e2e_test.py.
- Extract Python path to test/e2e.ini file.
2022-01-10 18:39:29 +01:00
Piotr F. Mieszkowski b2a01c15b0 Fix auto-migrated code
- Use b'' (byte strings) where appropriate.

- Fix indentation.

- Replace python2.x references with python3.x.
2022-01-10 18:21:40 +01:00
Piotr F. Mieszkowski 5f02223ec7 Perform automatic migration to Python 3.x
Use lib2to3 automatic migration tool provided by Python 2.x to convert
codebase to new idioms.

Command line:

find . -type f -name '*.py' \
    -exec python2.7 -m lib2to3 \
    -f all -f idioms -f buffer -f set_literal -f ws_comma -w \
    '{}' '+'
2022-01-10 18:21:20 +01:00
Piotr F. Mieszkowski 3b9f714cdb Ignore random_seed
Do not keep test/keyhome/random_seed in repository.
2022-01-10 17:47:23 +01:00
Piotr F. Mieszkowski 1002da78fa Clean up test messages
Remove unused msgout files, fix addresses in msgin files.
2022-01-09 22:00:06 +01:00
Piotr F. Mieszkowski 2cf60dec40 Add unit tests for GnuPG command-line generator
Extract a function to calculate GPG commands to be executed and cover it with
unit tests.
2022-01-09 21:37:14 +01:00
Piotr F. Mieszkowski fc2779ef7d Improve test code structure
- Move things to configuration file where appropriate (logging format, etc.).

- Rework execute_e2e_test signature to simplify it and get rid of keyword
arguments.

- Simplify output.

- Include a header comment in configuration file.
2022-01-08 13:42:23 +01:00
Piotr F. Mieszkowski 01377f4dd2 Keep test/certs directory 2022-01-07 12:03:38 +01:00
Piotr F. Mieszkowski ff3f6aa793 Add a test overview, extract constants
To let the user know that tests produce logs, include a message at the end of
the test output informing about locations of E2E and Mailgate logs.

Also, extract some constants.
2022-01-07 12:00:50 +01:00
Piotr F. Mieszkowski f1a799d864 Adjust E2E tests to work with all scenarios
Since it's not so easy to encrypt a message exactly the same way twice, we
only verify if the message has been encrypted or not.

Introduce minor changes to the library itself, because it doesn't work very
well with modern GnuPG.

Also, include GnuPG directory (pointed at by --homedir option).
2022-01-06 16:34:47 +01:00
Piotr F. Mieszkowski 27d7481078 Set up ground for E2E tests
- Use an environment variable to point at the configuration file while
  strating gpg-mailgate.py.

- Unify paths: store temporary config, logs and anything else under 'test'
  directory.

- Configure more tests (RSA, Ed25519).

- Add test descriptions to be shown before they're started.
2022-01-06 16:33:21 +01:00
Piotr F. Mieszkowski 7a063a91b8 Polish E2E testing script and make it configurable 2021-11-09 21:25:41 +01:00
Piotr F. Mieszkowski f3f56a47bc Implement an E2E testing script 2021-11-08 22:52:22 +01:00
Piotr F. Mieszkowski a9506805fb Write a test mail relay
Provide a simple Python script that would linsten on a given port and print to
standard output any message received via SMTP on that port.

This script will then be used to automatically test gpg-mailgate with different
scenarios (unknown recipient key, RSA key, elliptic curve key).
2021-11-04 22:39:02 +01:00