krista@2661
|
1 |
// This file is under GNU General Public License 3.0
|
krista@2661
|
2 |
// see LICENSE.txt
|
krista@2661
|
3 |
|
krista@2661
|
4 |
#include <stdlib.h>
|
krista@2661
|
5 |
#include <string>
|
krista@1618
|
6 |
#include <iostream>
|
roker@1658
|
7 |
#include <vector>
|
krista@1618
|
8 |
#include <cstring> // for strcmp()
|
krista@1618
|
9 |
#include "keymanagement.h"
|
krista@1618
|
10 |
#include "message_api.h"
|
krista@1618
|
11 |
#include "mime.h"
|
roker@1657
|
12 |
#include "test_util.h"
|
krista@1618
|
13 |
|
krista@2661
|
14 |
#include "pEpEngine.h"
|
krista@2661
|
15 |
|
krista@2661
|
16 |
#include <cpptest.h>
|
krista@2661
|
17 |
#include "EngineTestSessionSuite.h"
|
krista@2661
|
18 |
#include "LeastColorGroupTests.h"
|
krista@2661
|
19 |
|
krista@1618
|
20 |
using namespace std;
|
krista@1618
|
21 |
|
krista@2661
|
22 |
LeastColorGroupTests::LeastColorGroupTests(string suitename, string test_home_dir) :
|
krista@2661
|
23 |
EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
|
krista@2661
|
24 |
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("LeastColorGroupTests::check_least_color_group"),
|
krista@2661
|
25 |
static_cast<Func>(&LeastColorGroupTests::check_least_color_group)));
|
krista@2661
|
26 |
}
|
krista@2661
|
27 |
|
krista@2661
|
28 |
void LeastColorGroupTests::check_least_color_group() {
|
krista@1618
|
29 |
|
krista@1618
|
30 |
const char* mailfile = "test_mails/color_test.eml";
|
krista@1618
|
31 |
|
roker@1658
|
32 |
const std::vector<const char*> keynames = {
|
roker@1658
|
33 |
"test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
|
krista@1618
|
34 |
"test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
|
krista@1618
|
35 |
"test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
|
krista@1618
|
36 |
"test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
|
krista@1618
|
37 |
"test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
|
krista@1618
|
38 |
};
|
krista@2661
|
39 |
|
roker@1658
|
40 |
for (auto name : keynames) {
|
roker@1658
|
41 |
cout << "\t read keyfile \"" << name << "\"..." << std::endl;
|
roker@1658
|
42 |
const string keytextkey = slurp(name);
|
krista@1618
|
43 |
PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
|
krista@2669
|
44 |
TEST_ASSERT_MSG((statuskey == PEP_STATUS_OK), "statuskey == PEP_STATUS_OK");
|
roker@1654
|
45 |
}
|
roker@1654
|
46 |
|
roker@1654
|
47 |
cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
|
roker@1657
|
48 |
const string mailtext = slurp(mailfile);
|
roker@1654
|
49 |
cout << "\t All files read successfully." << std::endl;
|
krista@1618
|
50 |
|
edouard@1847
|
51 |
pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org",
|
edouard@1847
|
52 |
"7EE6C60C68851954E1797F81EA59715E3EBE215C",
|
roker@1654
|
53 |
PEP_OWN_USERID, "Pep Color Test P (recip)");
|
krista@2461
|
54 |
me1->me = true;
|
krista@2461
|
55 |
PEP_STATUS status = myself(session, me1);
|
krista@1618
|
56 |
|
krista@1618
|
57 |
pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
|
krista@1618
|
58 |
NULL, "TOFU_pep.color.test.V@kgrothoff.org",
|
krista@1618
|
59 |
"Pep Color Test V (sender)");
|
krista@1618
|
60 |
status = update_identity(session, sender1);
|
krista@1618
|
61 |
trust_personal_key(session, sender1);
|
roker@1657
|
62 |
status = update_identity(session, sender1);
|
krista@1618
|
63 |
|
krista@1618
|
64 |
message* msg_ptr = nullptr;
|
krista@1618
|
65 |
message* dest_msg = nullptr;
|
krista@1618
|
66 |
message* final_ptr = nullptr;
|
krista@1618
|
67 |
stringlist_t* keylist = nullptr;
|
krista@1618
|
68 |
PEP_rating rating;
|
krista@1618
|
69 |
PEP_decrypt_flags_t flags;
|
krista@1618
|
70 |
|
krista@1618
|
71 |
status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
|
krista@2669
|
72 |
TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
|
krista@2669
|
73 |
TEST_ASSERT_MSG((msg_ptr), "msg_ptr");
|
krista@1618
|
74 |
final_ptr = msg_ptr;
|
krista@2615
|
75 |
flags = 0;
|
krista@1618
|
76 |
status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
|
krista@1618
|
77 |
final_ptr = dest_msg ? dest_msg : msg_ptr;
|
krista@1618
|
78 |
|
krista@1618
|
79 |
cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
|
krista@1618
|
80 |
cout << "longmsg: " << final_ptr->longmsg << endl << endl;
|
krista@1618
|
81 |
cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
|
krista@1618
|
82 |
cout << "rating: " << rating << endl << endl;
|
krista@1618
|
83 |
cout << "keys used: " << endl;
|
roker@1658
|
84 |
|
roker@1658
|
85 |
int i = 0;
|
krista@1618
|
86 |
for (stringlist_t* k = keylist; k; k = k->next) {
|
krista@1618
|
87 |
if (i == 0)
|
roker@1658
|
88 |
cout << "\t Signer (key 0):\t" << k->value << endl;
|
krista@1618
|
89 |
else
|
krista@1618
|
90 |
cout << "\t #" << i << ":\t" << k->value << endl;
|
krista@1618
|
91 |
i++;
|
krista@1618
|
92 |
}
|
krista@1618
|
93 |
|
krista@1618
|
94 |
// free_identity(me1);
|
krista@1618
|
95 |
if (final_ptr == dest_msg)
|
krista@1618
|
96 |
free_message(dest_msg);
|
krista@1618
|
97 |
free_message(msg_ptr);
|
krista@2661
|
98 |
free_stringlist(keylist);
|
krista@1618
|
99 |
}
|