test/src/engine_tests/Engine463Tests.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 29 Jan 2019 19:19:30 +0100
branchENGINE-448
changeset 3254 6e7f6bc9460a
parent 3063 33907822c832
child 3276 c0b3430f1f1d
permissions -rw-r--r--
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
     2 // see LICENSE.txt
     3 
     4 #include <stdlib.h>
     5 #include <string>
     6 
     7 #include "pEpEngine.h"
     8 #include "pEp_internal.h"
     9 #include "test_util.h"
    10 #include "message.h"
    11 
    12 #include "EngineTestIndividualSuite.h"
    13 #include "Engine463Tests.h"
    14 
    15 using namespace std;
    16 
    17 Engine463Tests::Engine463Tests(string suitename, string test_home_dir) :
    18     EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    19     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_no_own_key"),
    20                                                                       static_cast<Func>(&Engine463Tests::check_engine_463_no_own_key)));
    21     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_own_key"),
    22                                                                       static_cast<Func>(&Engine463Tests::check_engine_463_own_key)));                                                                  
    23     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_sender_expired_and_renewed"),
    24                                                                       static_cast<Func>(&Engine463Tests::check_engine_463_sender_expired_and_renewed)));                                                                                                                                    
    25     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_reply_recip_expired_and_renewed"),
    26                                                                       static_cast<Func>(&Engine463Tests::check_engine_463_reply_recip_expired_and_renewed)));                                                                                                                                    
    27 }
    28 
    29 void Engine463Tests::check_engine_463_no_own_key() {
    30     const string claudio_keys = slurp("test_keys/priv/notfound-alt-pub_and_private.asc");
    31     const string fake_schleuder_key = slurp("test_keys/pub/fake-schleuder.asc");
    32     
    33     PEP_STATUS status = import_key(session, claudio_keys.c_str(), claudio_keys.length(), NULL);
    34     TEST_ASSERT_MSG((status == PEP_KEY_IMPORTED), tl_status_string(status));    
    35     status = import_key(session, fake_schleuder_key.c_str(), fake_schleuder_key.length(), NULL);
    36     TEST_ASSERT_MSG((status == PEP_KEY_IMPORTED), tl_status_string(status));    
    37 
    38     // Ok, bring in message, decrypt, and see what happens.
    39     const string msg = slurp("test_mails/notfound-alt.msg");
    40 
    41     char* decrypted_msg = NULL;
    42     stringlist_t* keylist_used = nullptr;
    43     char* modified_src = NULL;
    44     
    45     PEP_rating rating;
    46     PEP_decrypt_flags_t flags = 0;
    47      
    48     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
    49     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    50 }
    51 
    52 void Engine463Tests::check_engine_463_own_key() {
    53     const string claudio_keys = slurp("test_keys/priv/notfound-alt-pub_and_private.asc");
    54     const string fake_schleuder_key = slurp("test_keys/pub/fake-schleuder.asc");
    55     
    56     PEP_STATUS status = import_key(session, claudio_keys.c_str(), claudio_keys.length(), NULL);
    57     TEST_ASSERT_MSG((status == PEP_KEY_IMPORTED), tl_status_string(status));    
    58     status = import_key(session, fake_schleuder_key.c_str(), fake_schleuder_key.length(), NULL);
    59     TEST_ASSERT_MSG((status == PEP_KEY_IMPORTED), tl_status_string(status));    
    60 
    61     pEp_identity* own_ident = new_identity("claudio+engine-463@pep.foundation", "A039BC60E43E0DFDDC9DE8663B48C38325210C88", PEP_OWN_USERID, "Not Actually Claudio");
    62     status = set_own_key(session, own_ident, "A039BC60E43E0DFDDC9DE8663B48C38325210C88");
    63     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));    
    64 
    65     // Ok, bring in message, decrypt, and see what happens.
    66     const string msg = slurp("test_mails/notfound-alt.msg");
    67 
    68     char* decrypted_msg = NULL;
    69     stringlist_t* keylist_used = nullptr;
    70     char* modified_src = NULL;
    71     
    72     PEP_rating rating;
    73     PEP_decrypt_flags_t flags = 0;
    74      
    75     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
    76     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    77 }
    78 
    79 void Engine463Tests::check_engine_463_sender_expired_and_renewed() {
    80     bool ok = false;
    81     ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    82     TEST_ASSERT(ok);    
    83     ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
    84     TEST_ASSERT(ok);
    85     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
    86     TEST_ASSERT(ok);
    87 
    88     // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
    89     // the expired key:
    90     const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
    91     
    92     char* decrypted_msg = NULL;
    93     stringlist_t* keylist_used = nullptr;
    94     char* modified_src = NULL;
    95     
    96     PEP_rating rating;
    97     PEP_decrypt_flags_t flags = 0;
    98      
    99     PEP_STATUS status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   100     TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   101 
   102     free(decrypted_msg);
   103     decrypted_msg = NULL;
   104     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   105     TEST_ASSERT(ok);    
   106 
   107     pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   108     
   109     status = identity_rating(session, expired_inquisitor, &rating);
   110     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   111     TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));
   112         
   113     flags = 0;
   114     
   115     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);    
   116     TEST_ASSERT(decrypted_msg);
   117     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   118     TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));
   119 
   120     free_identity(expired_inquisitor);
   121 
   122 }
   123 
   124  void Engine463Tests::check_engine_463_reply_recip_expired_and_renewed() {
   125     bool ok = false;
   126     ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   127     TEST_ASSERT(ok);    
   128     ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   129     TEST_ASSERT(ok);
   130     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   131     TEST_ASSERT(ok);
   132 
   133     const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   134     pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   135 
   136     PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   137     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   138 
   139     // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   140     // the expired key:
   141     const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   142     
   143     char* decrypted_msg = NULL;
   144     stringlist_t* keylist_used = nullptr;
   145     char* modified_src = NULL;
   146     
   147     PEP_rating rating;
   148     PEP_decrypt_flags_t flags = 0;
   149      
   150     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   151     TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   152 
   153     free(decrypted_msg);
   154     decrypted_msg = NULL;
   155     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   156     TEST_ASSERT(ok);    
   157 
   158     pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   159     message* msg2 = new_message(PEP_dir_outgoing);    
   160 
   161     msg2->from = alice_from;
   162     msg2->to = new_identity_list(expired_inquisitor);
   163     msg2->shortmsg = strdup("Blah!");
   164     msg2->longmsg = strdup("Blahblahblah!");
   165     msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   166 
   167     status = outgoing_message_rating(session, msg2, &rating);
   168     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   169     TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
   170 
   171     free_message(msg2);
   172 }