Skip to content

Commit

Permalink
Update dearmoring tests for better coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Dec 6, 2023
1 parent ac36f4e commit 64b3630
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/librepgp/stream-armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,6 @@ armor_str_to_data_type(const char *str, size_t len)
if (str_equals(str, len, "BEGIN PGP SIGNATURE")) {
return PGP_ARMORED_SIGNATURE;
}
if (str_equals(str, len, "BEGIN PGP SIGNED MESSAGE")) {
return PGP_ARMORED_CLEARTEXT;
}
return PGP_ARMORED_UNKNOWN;
}

Expand Down
12 changes: 12 additions & 0 deletions src/tests/cli_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,18 @@ def test_armor(self):
remove_files(dec)
self.assertEqual(ret, 0)
self.assertRegex(err, R_CRC)
# 1-byte message
ret, out, _ = run_proc(RNP, ['--enarmor'], '1')
self.assertEqual(ret, 0)
self.assertRegex(out, r'(?s)^.*BEGIN PGP MESSAGE.*MQ==.*=LrpI.*')
ret, out, _ = run_proc(RNP, ['--dearmor'], out)
self.assertEqual(ret, 0)
self.assertRegex(out, r'(?s)^.*1.*')
# Charset and other headers
ret, _, err = run_proc(RNP, ['--dearmor', data_path('test_stream_armor/misc_headers.asc'), '--output', dec], out)
self.assertEqual(ret, 0)
self.assertRegex(err, r'(?s)^.*unknown header \'Unknown: Unknown\'.*')
remove_files(dec)

def test_rnpkeys_lists(self):
KEYRING_1 = data_path(KEYRING_DIR_1)
Expand Down
19 changes: 19 additions & 0 deletions src/tests/data/test_stream_armor/misc_headers.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN PGP MESSAGE-----
Charset: UTF-8
Charset: UTF-16
Version: Unknown
Version: Known
Comment:
Comment: Large comment
Unknown: Unknown
Hash: SHA1, SHA256
Charset: Something
Version: 1.0


yLIBAAMA/P/IsgEADQDy/wADAPz/yLIBAA0A8v+CcKAcAAAFAPr/gnCgHAAABQD6/wAFAPr/ABQA
6/+CcKAcAAAFAPr/AAUA+v8AFADr/0KIIcQAABQA6/9CiCHEAAAUAOv/QoghxAAAFADr/0KIIcQA
ABQA6/9CiCHEAAAAAP//AAAA//8ACgD1/0KIIcQAAAAA//8AAAD//wAKAPX/ArPALEAAAAD//wKz
wCxAAAAA//8A
=ZXuW
-----END PGP MESSAGE-----
14 changes: 14 additions & 0 deletions src/tests/ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3393,6 +3393,20 @@ TEST_F(rnp_tests, test_ffi_rnp_guess_contents)
assert_string_equal(msgt, "unknown");
rnp_buffer_destroy(msgt);
rnp_input_destroy(input);

const char *msg1 = "-----BEGIN PGP PGP";
assert_rnp_success(rnp_input_from_memory(&input, (uint8_t *) msg1, strlen(msg1), false));
assert_rnp_success(rnp_guess_contents(input, &msgt));
assert_string_equal(msgt, "unknown");
rnp_buffer_destroy(msgt);
rnp_input_destroy(input);

const char *msg2 = "-----BEGIN PGP PGP PGP PGP PGP PGP PGP";
assert_rnp_success(rnp_input_from_memory(&input, (uint8_t *) msg2, strlen(msg2), false));
assert_rnp_success(rnp_guess_contents(input, &msgt));
assert_string_equal(msgt, "unknown");
rnp_buffer_destroy(msgt);
rnp_input_destroy(input);
}

TEST_F(rnp_tests, test_ffi_literal_filename)
Expand Down

0 comments on commit 64b3630

Please sign in to comment.