From b4f30d7e8f59ae7fef043194924ce63cd579a7ea Mon Sep 17 00:00:00 2001 From: "Piotr F. Mieszkowski" Date: Sat, 22 Oct 2022 20:54:08 +0200 Subject: [PATCH] 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. --- test/daemon_test.py | 4 ++-- test/e2e.ini | 8 +++++++- test/e2e_test.py | 15 ++++++++------- test/msgin/with-markers2clear.msg | 11 +++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 test/msgin/with-markers2clear.msg diff --git a/test/daemon_test.py b/test/daemon_test.py index 5edcb4f..d529acd 100644 --- a/test/daemon_test.py +++ b/test/daemon_test.py @@ -72,7 +72,7 @@ def _report_result(message_file, expected, test_output): else: status = "Failure" - print(message_file.ljust(30), status) + print(message_file.ljust(35), status) def _execute_case(config, case_name): @@ -107,7 +107,7 @@ def _main(): server = _spawn([python, "-m", "lacre.daemon"]) - for case_no in range(1, conf.getint("tests", "cases")): + for case_no in range(1, conf.getint("tests", "cases") + 1): _execute_case(conf, case_name=f"case-{case_no}") _interrupt(server) diff --git a/test/e2e.ini b/test/e2e.ini index a704dcc..4b9883d 100644 --- a/test/e2e.ini +++ b/test/e2e.ini @@ -30,7 +30,7 @@ certs: test/certs [tests] # Number of "test-*" sections in this file, describing test cases. -cases: 8 +cases: 9 e2e_log: test/logs/e2e.log e2e_log_format: %(asctime)s %(pathname)s:%(lineno)d %(levelname)s [%(funcName)s] %(message)s e2e_log_datefmt: %Y-%m-%d %H:%M:%S @@ -84,3 +84,9 @@ descr: Clear text message to address with delimiter and a user with an Ed25519 k to: bob@disposlab in: test/msgin/clear2ed-delim.msg out: -----BEGIN PGP MESSAGE----- + +[case-9] +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. diff --git a/test/e2e_test.py b/test/e2e_test.py index 0cd044f..5a32053 100644 --- a/test/e2e_test.py +++ b/test/e2e_test.py @@ -83,12 +83,13 @@ def _load_file(name): def _report_result(message_file, expected, test_output): status = None - if expected in test_output: + expected_line = "\r\n" + expected # + "\r\n" + if expected_line in test_output: status = "Success" else: status = "Failure" - print(message_file.ljust(30), status) + print(message_file.ljust(35), status) def _execute_e2e_test(case_name, config, config_path): @@ -154,12 +155,12 @@ logging.basicConfig(filename = config.get("tests", "e2e_log"), config_path = os.getcwd() + "/" + CONFIG_FILE _write_test_config(config_path, - port = config.get("relay", "port"), - gpg_keyhome = config.get("dirs", "keys"), - smime_certpath = config.get("dirs", "certs"), - log_config = config.get("tests", "log_config")) + port = config.get("relay", "port"), + gpg_keyhome = config.get("dirs", "keys"), + smime_certpath = config.get("dirs", "certs"), + log_config = config.get("tests", "log_config")) -for case_no in range(1, config.getint("tests", "cases")+1): +for case_no in range(1, config.getint("tests", "cases") + 1): case_name = f"case-{case_no}" logging.info(f"Executing {case_name}: {config.get(case_name, 'descr')}") diff --git a/test/msgin/with-markers2clear.msg b/test/msgin/with-markers2clear.msg new file mode 100644 index 0000000..729aa82 --- /dev/null +++ b/test/msgin/with-markers2clear.msg @@ -0,0 +1,11 @@ +From: Dave +To: Carlos +Subject: Test + +This message includes inline PGP markers. +It's enough to include these two lines: + +-----BEGIN PGP MESSAGE----- +-----END PGP MESSAGE----- + +Test logs will give a hint which path this message takes.