Added test case for Patrick's trust issue - we can add additional apple mails to it if we have problems with detached sigs, but so far, trusted status works as it should from the TCs we have so far.
authorKrista Grothoff <krista@pep-project.org>
Wed, 18 Jan 2017 13:02:00 +0100
changeset 154344866373e733
parent 1540 b0810e1b8b19
child 1544 59ebfba16240
Added test case for Patrick's trust issue - we can add additional apple mails to it if we have problems with detached sigs, but so far, trusted status works as it should from the TCs we have so far.
test/apple_mail_test.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/apple_mail_test.cc	Wed Jan 18 13:02:00 2017 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +#include <iostream>
     1.5 +#include <iostream>
     1.6 +#include <fstream>
     1.7 +#include <string>
     1.8 +#include <cstring> // for strcmp()
     1.9 +#include <assert.h>
    1.10 +#include "blacklist.h"
    1.11 +#include "keymanagement.h"
    1.12 +#include "message_api.h"
    1.13 +#include "mime.h"
    1.14 +
    1.15 +using namespace std;
    1.16 +
    1.17 +int main(int argc, char** argv) {
    1.18 +    
    1.19 +    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
    1.20 +    
    1.21 +    PEP_SESSION session;
    1.22 +    
    1.23 +    cout << "calling init()\n";
    1.24 +    PEP_STATUS status1 = init(&session);   
    1.25 +    assert(status1 == PEP_STATUS_OK);
    1.26 +    assert(session);
    1.27 +    cout << "init() completed.\n";
    1.28 +
    1.29 +        
    1.30 +    ifstream infile(mailfile);
    1.31 +    string mailtext;
    1.32 +    while (!infile.eof()) {
    1.33 +        static string line;
    1.34 +        getline(infile, line);
    1.35 +        mailtext += line + "\n";
    1.36 +    }
    1.37 +    infile.close(); 
    1.38 +
    1.39 +    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", NULL, PEP_OWN_USERID, "pEp Test Recipient");    
    1.40 +    me->me = true;    
    1.41 +    PEP_STATUS status = update_identity(session, me);
    1.42 +
    1.43 +    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "TOFU_pep.test.apple@pep-project.org", "pEp Test Recipient");    
    1.44 +    you->me = false;    
    1.45 +    status = update_identity(session, you);
    1.46 +
    1.47 +    trust_personal_key(session, you);
    1.48 +    
    1.49 +    status = update_identity(session, you);
    1.50 +    
    1.51 +    message* msg_ptr = nullptr;
    1.52 +    message* dest_msg = nullptr;
    1.53 +    message* final_ptr = nullptr;
    1.54 +    stringlist_t* keylist = nullptr;
    1.55 +    PEP_rating rating;
    1.56 +    PEP_decrypt_flags_t flags;
    1.57 +    
    1.58 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    1.59 +    assert(status == PEP_STATUS_OK);
    1.60 +    assert(msg_ptr);
    1.61 +    final_ptr = msg_ptr;
    1.62 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    1.63 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
    1.64 +  
    1.65 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    1.66 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    1.67 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    1.68 +
    1.69 +    assert(color_from_rating(rating) == PEP_color_green);
    1.70 +
    1.71 +    if (final_ptr == dest_msg)
    1.72 +    	free_message(dest_msg);
    1.73 +    free_message(msg_ptr);
    1.74 +    free_stringlist(keylist);
    1.75 +
    1.76 +    msg_ptr = nullptr;
    1.77 +    dest_msg = nullptr;
    1.78 +    final_ptr = nullptr;
    1.79 +    keylist = nullptr;
    1.80 +    rating = PEP_rating_unreliable;
    1.81 +    
    1.82 +    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
    1.83 +    
    1.84 +    ifstream infile2(mailfile2);
    1.85 +    string mailtext2;
    1.86 +    while (!infile2.eof()) {
    1.87 +        static string line;
    1.88 +        getline(infile2, line);
    1.89 +        mailtext2 += line + "\n";
    1.90 +    }
    1.91 +    infile2.close(); 
    1.92 +    
    1.93 +    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
    1.94 +    assert(status == PEP_STATUS_OK);
    1.95 +    assert(msg_ptr);
    1.96 +    final_ptr = msg_ptr;
    1.97 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    1.98 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
    1.99 +  
   1.100 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   1.101 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   1.102 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   1.103 +
   1.104 +    assert(color_from_rating(rating) == PEP_color_green);
   1.105 +
   1.106 +    if (final_ptr == dest_msg)
   1.107 +    	free_message(dest_msg);
   1.108 +    free_message(msg_ptr);
   1.109 +    free_stringlist(keylist);
   1.110 +
   1.111 +    
   1.112 +    cout << "calling release()\n";
   1.113 +    release(session);
   1.114 +    return 0;
   1.115 +}