diff --git a/lacre/core.py b/lacre/core.py index 0b1d01e..f5eb3ce 100644 --- a/lacre/core.py +++ b/lacre/core.py @@ -506,6 +506,7 @@ def _is_encrypted(raw_message: email.message.Message): def delivery_plan(recipients, message: email.message.Message, key_cache: kcache.KeyCache): """Generate a sequence of delivery strategies.""" if _is_encrypted(message): + LOG.debug(f'Message is already encrypted: {message!r}') return [KeepIntact(recipients)] gpg_to, ungpg_to = _identify_gpg_recipients(recipients, key_cache) diff --git a/lacre/text.py b/lacre/text.py index bdbc3e0..84f8939 100644 --- a/lacre/text.py +++ b/lacre/text.py @@ -8,9 +8,10 @@ from email.message import Message # The standard way to encode line-ending in email: EOL = "\r\n" +EOL_BYTES = b"\r\n" -PGP_INLINE_BEGIN = b"-----BEGIN PGP MESSAGE-----" -PGP_INLINE_END = b"-----END PGP MESSAGE-----" +PGP_INLINE_BEGIN = EOL_BYTES + b"-----BEGIN PGP MESSAGE-----" + EOL_BYTES +PGP_INLINE_END = EOL_BYTES + b"-----END PGP MESSAGE-----" + EOL_BYTES LOG = logging.getLogger(__name__) diff --git a/test/daemon_test.py b/test/daemon_test.py index d529acd..8488eef 100644 --- a/test/daemon_test.py +++ b/test/daemon_test.py @@ -65,9 +65,19 @@ def _load_test_config(): return cp -def _report_result(message_file, expected, test_output): +def _identity(x): + return x + + +def _inversion(x): + return not(x) + + +def _report_result(message_file, expected, test_output, boolean_func=_identity): status = None - if expected in test_output: + expected_line = "\r\n" + expected # + "\r\n" + cond_met = boolean_func(expected_line in test_output) + if cond_met: status = "Success" else: status = "Failure" @@ -91,7 +101,10 @@ def _execute_case(config, case_name): test_out = test_out.decode('utf-8') logging.debug(f"Read {len(test_out)} characters of output: '{test_out}'") - _report_result(config.get(case_name, "in"), config.get(case_name, "out"), test_out) + if 'out' in config[case_name]: + _report_result(config.get(case_name, "in"), config.get(case_name, "out"), test_out) + else: + _report_result(config.get(case_name, "in"), config.get(case_name, "out-not"), test_out, boolean_func=_inversion) def _main(): diff --git a/test/e2e.ini b/test/e2e.ini index 4b9883d..e27eafc 100644 --- a/test/e2e.ini +++ b/test/e2e.ini @@ -89,4 +89,4 @@ out: -----BEGIN PGP MESSAGE----- descr: Clear text message with inline PGP markers to recipient without a key. to: carlos@disposlab in: test/msgin/with-markers2clear.msg -out: This message includes inline PGP markers. +out-not: This message includes inline PGP markers. diff --git a/test/e2e_test.py b/test/e2e_test.py index 5a32053..7d0255d 100644 --- a/test/e2e_test.py +++ b/test/e2e_test.py @@ -81,10 +81,19 @@ def _load_file(name): return bytes(contents, 'utf-8') -def _report_result(message_file, expected, test_output): +def _identity(x): + return x + + +def _inversion(x): + return not(x) + + +def _report_result(message_file, expected, test_output, boolean_func=_identity): status = None expected_line = "\r\n" + expected # + "\r\n" - if expected_line in test_output: + cond_met = boolean_func(expected_line in test_output) + if cond_met: status = "Success" else: status = "Failure" @@ -132,7 +141,10 @@ def _execute_e2e_test(case_name, config, config_path): logging.debug(f"Read {len(testout)} characters of test output: '{testout}'") - _report_result(config.get(case_name, "in"), config.get(case_name, "out"), testout) + if 'out' in config[case_name]: + _report_result(config.get(case_name, "in"), config.get(case_name, "out"), testout) + else: + _report_result(config.get(case_name, "in"), config.get(case_name, "out-not"), testout, boolean_func=_inversion) def _load_test_config():