test/apple_mail_test.cc
author Krista Bennett <krista@pep-project.org>
Wed, 24 May 2017 13:16:49 +0200
branchENGINE-209
changeset 1807 795d1b201b6f
parent 1660 e153b77f3e52
child 1808 121361c60644
permissions -rw-r--r--
ENGINE-209: intermittent commit to see if test failures from are from default merge
     1 #include <iostream>
     2 #include <iostream>
     3 #include <fstream>
     4 #include <string>
     5 #include <cstring> // for strcmp()
     6 #include <assert.h>
     7 #include "blacklist.h"
     8 #include "keymanagement.h"
     9 #include "message_api.h"
    10 #include "mime.h"
    11 #include "test_util.h" // for slurp()
    12 
    13 using namespace std;
    14 
    15 int main(int argc, char** argv) {
    16 
    17     const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
    18     
    19     PEP_SESSION session;
    20     
    21     cout << "calling init()\n";
    22     PEP_STATUS status1 = init(&session);   
    23     assert(status1 == PEP_STATUS_OK);
    24     assert(session);
    25     cout << "init() completed.\n";
    26 
    27     const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    28     const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    29     const string keytextkey3 = slurp("test_keys/priv/pep-test-apple-0x1CCBC7D7_priv.asc");
    30     const string keytextkey4 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
    31 
    32     PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    33     PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    34     PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
    35     PEP_STATUS statuskey4 = import_key(session, keytextkey4.c_str(), keytextkey4.length(), NULL);
    36         
    37     const string mailtext = slurp(mailfile);
    38     pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", NULL, PEP_OWN_USERID, "pEp Test Recipient");    
    39     me->me = true;    
    40     PEP_STATUS status = update_identity(session, me);
    41     trust_personal_key(session, me);    
    42     status = update_identity(session, me);
    43     
    44     pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "TOFU_pep.test.apple@pep-project.org", "pEp Test Recipient");    
    45     you->me = false;    
    46     status = update_identity(session, you);
    47 
    48     trust_personal_key(session, you);
    49     
    50     status = update_identity(session, you);
    51     
    52     message* msg_ptr = nullptr;
    53     message* dest_msg = nullptr;
    54     message* final_ptr = nullptr;
    55     stringlist_t* keylist = nullptr;
    56     PEP_rating rating;
    57     PEP_decrypt_flags_t flags;
    58     
    59     status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    60     assert(status == PEP_STATUS_OK);
    61     assert(msg_ptr);
    62     final_ptr = msg_ptr;
    63     status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    64     final_ptr = dest_msg ? dest_msg : msg_ptr;
    65   
    66     cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    67     cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    68     cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    69 
    70     assert(color_from_rating(rating) == PEP_color_green);
    71 
    72     if (final_ptr == dest_msg)
    73     	free_message(dest_msg);
    74     free_message(msg_ptr);
    75     free_stringlist(keylist);
    76 
    77     msg_ptr = nullptr;
    78     dest_msg = nullptr;
    79     final_ptr = nullptr;
    80     keylist = nullptr;
    81     rating = PEP_rating_unreliable;
    82     
    83     const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
    84     const string mailtext2 = slurp(mailfile2);
    85     
    86     status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
    87     assert(status == PEP_STATUS_OK);
    88     assert(msg_ptr);
    89     final_ptr = msg_ptr;
    90     status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    91     final_ptr = dest_msg ? dest_msg : msg_ptr;
    92   
    93     cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    94     cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    95     cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    96 
    97     assert(color_from_rating(rating) == PEP_color_green);
    98 
    99     if (final_ptr == dest_msg)
   100     	free_message(dest_msg);
   101     free_message(msg_ptr);
   102     free_stringlist(keylist);
   103 
   104     msg_ptr = nullptr;
   105     dest_msg = nullptr;
   106     final_ptr = nullptr;
   107     keylist = nullptr;
   108     rating = PEP_rating_unreliable;
   109         
   110     cout << "calling release()\n";
   111     release(session);
   112     return 0;
   113 }