1.1 --- a/test/include/KeyAttachmentTests.h Tue Feb 05 12:02:53 2019 +0100
1.2 +++ b/test/include/KeyAttachmentTests.h Tue Feb 05 16:22:55 2019 +0100
1.3 @@ -15,7 +15,6 @@
1.4 protected:
1.5 void setup();
1.6 private:
1.7 - void check_key_attachment();
1.8 void check_key_attach_inline();
1.9 void check_key_plus_encr_att_inline();
1.10 void check_encr_att_plus_key_inline();
1.11 @@ -24,6 +23,7 @@
1.12 void check_many_keys_inline();
1.13 void check_many_keys_w_encr_file_inline();
1.14 void check_many_keys_w_unencr_file_inline(); // not really unencrypted; just not encrypted before attachment
1.15 + void check_many_keys_with_many_files_inline();
1.16 void check_key_attach_OpenPGP();
1.17 void check_key_plus_encr_att_OpenPGP();
1.18 void check_encr_att_plus_key_OpenPGP();
2.1 --- a/test/src/engine_tests/KeyAttachmentTests.cc Tue Feb 05 12:02:53 2019 +0100
2.2 +++ b/test/src/engine_tests/KeyAttachmentTests.cc Tue Feb 05 16:22:55 2019 +0100
2.3 @@ -20,10 +20,6 @@
2.4
2.5 KeyAttachmentTests::KeyAttachmentTests(string suitename, string test_home_dir) :
2.6 EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
2.7 - add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_key_attachment"),
2.8 - static_cast<Func>(&KeyAttachmentTests::check_key_attachment)));
2.9 - add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_key_attachment"),
2.10 - static_cast<Func>(&KeyAttachmentTests::check_key_attachment)));
2.11 add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_key_attach_inline"),
2.12 static_cast<Func>(&KeyAttachmentTests::check_key_attach_inline)));
2.13 add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_key_plus_encr_att_inline"),
2.14 @@ -40,6 +36,8 @@
2.15 static_cast<Func>(&KeyAttachmentTests::check_many_keys_w_encr_file_inline)));
2.16 add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_many_keys_w_unencr_file_inline"),
2.17 static_cast<Func>(&KeyAttachmentTests::check_many_keys_w_unencr_file_inline)));
2.18 + add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_many_keys_with_many_files_inline"),
2.19 + static_cast<Func>(&KeyAttachmentTests::check_many_keys_with_many_files_inline)));
2.20 add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_key_attach_OpenPGP"),
2.21 static_cast<Func>(&KeyAttachmentTests::check_key_attach_OpenPGP)));
2.22 add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyAttachmentTests::check_key_plus_encr_att_OpenPGP"),
2.23 @@ -69,10 +67,6 @@
2.24 assert(slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc"));
2.25 }
2.26
2.27 -void KeyAttachmentTests::check_key_attachment() {
2.28 - TEST_ASSERT(true);
2.29 -}
2.30 -
2.31 void KeyAttachmentTests::check_key_attach_inline() {
2.32 string msg = slurp("test_mails/Inline PGP test.eml");
2.33 message* enc_msg = NULL;
2.34 @@ -273,6 +267,61 @@
2.35 free_stringlist(keylist);
2.36 }
2.37
2.38 +void KeyAttachmentTests::check_many_keys_with_many_files_inline() {
2.39 + string msg = slurp("test_mails/Inline PGP - many keys with many files.eml");
2.40 + message* enc_msg = NULL;
2.41 + message* dec_msg = NULL;
2.42 +
2.43 + PEP_STATUS status = mime_decode_message(msg.c_str(), msg.size(), &enc_msg);
2.44 + TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
2.45 + TEST_ASSERT(enc_msg);
2.46 + stringlist_t* keylist = NULL;
2.47 + PEP_rating rating;
2.48 + PEP_decrypt_flags_t flags = 0;
2.49 + status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
2.50 + TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
2.51 + TEST_ASSERT(dec_msg);
2.52 +
2.53 + const char* not_pres = "Encrypted attachment not preserved.";
2.54 + const char* left_att = "Decryption left attachments it should have deleted.";
2.55 + const char* no_fname = "Attachment doesn't have a filename.";
2.56 + const char* no_mime = "Attachment doesn't have a MIME type.";
2.57 +
2.58 + // pair is filename, mime_type
2.59 + vector<pair<string,string>> v =
2.60 + {
2.61 + {"barky.txt","application/octet-stream"},
2.62 + {"this_is_not_a_key_or_encrypted.asc","application/octet-stream"},
2.63 + {"this_is_not_a_key_or_encrypted.gpg","application/octet-stream"},
2.64 + {"CC_BY-SA.txt","application/octet-stream"},
2.65 + {"Makefile","application/octet-stream"},
2.66 + {"LICENSE.txt","application/octet-stream"},
2.67 + {"README.md","application/octet-stream"},
2.68 + };
2.69 +
2.70 + bloblist_t* curr_att = dec_msg->attachments;
2.71 + vector<pair<string,string>>::iterator it = v.begin();
2.72 +
2.73 + while (it != v.end()) {
2.74 + TEST_ASSERT_MSG(curr_att, not_pres);
2.75 + TEST_ASSERT_MSG(curr_att->filename, no_fname);
2.76 + TEST_ASSERT_MSG(curr_att->mime_type, no_fname);
2.77 + cout << (*it).first << endl;
2.78 + TEST_ASSERT_MSG(strcmp(curr_att->filename,
2.79 + (*it).first.c_str()) == 0,
2.80 + curr_att->filename);
2.81 + TEST_ASSERT_MSG(strcmp(curr_att->mime_type,
2.82 + (*it).second.c_str()) == 0,
2.83 + curr_att->mime_type);
2.84 + it++;
2.85 + curr_att = curr_att->next;
2.86 + }
2.87 +
2.88 + free_message(enc_msg);
2.89 + free_message(dec_msg);
2.90 + free_stringlist(keylist);
2.91 +}
2.92 +
2.93 void KeyAttachmentTests::check_key_attach_OpenPGP() {
2.94 string msg = slurp("test_mails/OpenPGP test key attach.eml");
2.95 message* enc_msg = NULL;
2.96 @@ -498,10 +547,7 @@
2.97 bloblist_t* curr_att = dec_msg->attachments;
2.98 vector<pair<string,string>>::iterator it = v.begin();
2.99
2.100 - int i = 0;
2.101 -
2.102 while (it != v.end()) {
2.103 - cout << i++ << endl;
2.104 TEST_ASSERT_MSG(curr_att, not_pres);
2.105 TEST_ASSERT_MSG(curr_att->filename, no_fname);
2.106 TEST_ASSERT_MSG(curr_att->mime_type, no_fname);