ENGINE-448: made key removal much less aggressive. NetPGP will still be a problem, but versions built against gpg will now only remove actual keys
1 // This file is under GNU General Public License 3.0
8 #include <cstring> // for strcmp()
9 #include "keymanagement.h"
10 #include "message_api.h"
12 #include "test_util.h"
14 #include "pEpEngine.h"
17 #include "EngineTestSessionSuite.h"
18 #include "LeastColorGroupTests.h"
22 LeastColorGroupTests::LeastColorGroupTests(string suitename, string test_home_dir) :
23 EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
24 add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("LeastColorGroupTests::check_least_color_group"),
25 static_cast<Func>(&LeastColorGroupTests::check_least_color_group)));
28 void LeastColorGroupTests::check_least_color_group() {
30 const char* mailfile = "test_mails/color_test.eml";
32 const std::vector<const char*> keynames = {
33 "test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
34 "test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
35 "test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
36 "test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
37 "test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
40 for (auto name : keynames) {
41 cout << "\t read keyfile \"" << name << "\"..." << std::endl;
42 const string keytextkey = slurp(name);
43 PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
44 TEST_ASSERT_MSG((statuskey == PEP_KEY_IMPORTED), "statuskey == PEP_STATUS_OK");
47 cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
48 const string mailtext = slurp(mailfile);
49 cout << "\t All files read successfully." << std::endl;
51 pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org",
52 "7EE6C60C68851954E1797F81EA59715E3EBE215C",
53 PEP_OWN_USERID, "Pep Color Test P (recip)");
55 PEP_STATUS status = myself(session, me1);
57 pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
58 NULL, "TOFU_pep.color.test.V@kgrothoff.org",
59 "Pep Color Test V (sender)");
60 status = update_identity(session, sender1);
61 trust_personal_key(session, sender1);
62 status = update_identity(session, sender1);
64 message* msg_ptr = nullptr;
65 message* dest_msg = nullptr;
66 message* final_ptr = nullptr;
67 stringlist_t* keylist = nullptr;
69 PEP_decrypt_flags_t flags;
71 status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
72 TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
73 TEST_ASSERT_MSG((msg_ptr), "msg_ptr");
76 status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
77 final_ptr = dest_msg ? dest_msg : msg_ptr;
79 cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
80 cout << "longmsg: " << final_ptr->longmsg << endl << endl;
81 cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
82 cout << "rating: " << rating << endl << endl;
83 cout << "keys used: " << endl;
86 for (stringlist_t* k = keylist; k; k = k->next) {
88 cout << "\t Signer (key 0):\t" << k->value << endl;
90 cout << "\t #" << i << ":\t" << k->value << endl;
94 // free_identity(me1);
95 if (final_ptr == dest_msg)
96 free_message(dest_msg);
97 free_message(msg_ptr);
98 free_stringlist(keylist);