Commit Graph

28 Commits

Author SHA1 Message Date
Piotr F. Mieszkowski a98ff611ee Continue renaming: config files, tests, docs 2024-01-06 14:45:09 +01:00
Piotr F. Mieszkowski b3c0235486 Make case-discovery code cleaner and more flexible 2023-05-08 22:17:02 +02:00
Piotr F. Mieszkowski 0cdbf5ba7d Add emoji test 2023-05-08 22:17:02 +02:00
Piotr F. Mieszkowski 518b823b5c Fix simple filter: pass policy to as_bytes()
Also: adjust expected test output because it's now Base64-encoded.
2023-05-08 22:17:02 +02:00
Piotr F. Mieszkowski 459779bea6 Add more test cases 2023-05-08 22:17:02 +02:00
Piotr F. Mieszkowski da0ffb4a51 Add a test message with Emoji 2023-05-08 22:17:02 +02:00
Piotr F. Mieszkowski 54ee9d9875 Add minor E2E test improvements 2023-05-08 22:17:02 +02:00
Piotr F. Mieszkowski 56101b86c0 Clean up the code after refactor
- Clean up PGP/MIME flow by using API instead of explicit/manual generation of
  headers.
- Fix E2E test configuration for PGP/MIME case.
- Add first lacre.core unit tests.
- Add another Contract Test.
2023-05-08 22:17:01 +02:00
Piotr F. Mieszkowski 94e22caf8e When encryption fails, revert to cleartext delivery
When GnuPG refuses to encrypt a message (e.g. when key has expired), record
information about the failure and send to logs, then deliver cleartext.  This
way we won't bounce email that could be delivered without encryption.

Also: add more E2E tests.
2023-05-08 22:16:41 +02:00
Piotr F. Mieszkowski ffffa6a364 Correct sample message file name 2023-05-08 22:14:24 +02:00
Piotr F. Mieszkowski b242edf098 Add a more sophisticated UTF-8 test case
Add a new test message to verify Lacre's behaviour when processing
UTF-8 messages with text in two different scripts (latin-based and cyrillic).

Also: log Content-Transfer-Encoding when logging headers is enabled.
2023-05-08 22:14:24 +02:00
Piotr F. Mieszkowski b6bd36a460 Use bytes instead of str to hold message bodies
smtplib.SMTP expects ASCII-only message bodies when message body is provided
as a 'str'.  If we pass a 'bytes', we need to choose encoding earlier and we
do this by calling 'as_bytes' on messages with SMTP policy, which takes care
of formatting the body properly.

As a result, ISO-8859-x messages are converted to Quoted Printable and UTF-8
messages are Base64-encoded.

Testing this behaviour is tricky, because we use the same SMTP client to send
test data.  For this reason, test code has become a bit ugly, but it does
exactly what we need.
2023-05-08 22:14:24 +02:00
Piotr F. Mieszkowski 0fac54a29a Add UTF-8 and ISO-8859-2 test cases, make tests more reliable 2023-05-08 22:14:24 +02:00
Piotr F. Mieszkowski 037a527c44 Add a test case with non-ASCII message content 2023-05-08 22:14:24 +02:00
Piotr F. Mieszkowski 53378b516e Add a test for message with PGP inline markers that's not encrypted
If a user mentions PGP markers inside their message, we should not classify it
as already encrypted.
2022-10-22 21:29:59 +02:00
Piotr F. Mieszkowski b4f30d7e8f Add test clear text input message with PGP markers
It's possible to trick Lacre by sending PGP markers in message body, causing
it to classify that message being already encrypted.  This test case is used
to reproduce this scenario.
2022-10-22 20:54:08 +02:00
Piotr F. Mieszkowski a131cd66d3 Move different parts of Lacre tests to subdirectories
In particular, move:

- test utilities to test/utils;
- unit tests to test/modules.

Also: start implementing the Lacre daemon test (just a stub for now).
2022-10-19 18:36:23 +00:00
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 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 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 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 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 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