ENGINE-466: header key import works ENGINE-466
authorKrista Bennett <krista@pep-project.org>
Tue, 09 Oct 2018 19:45:26 +0200
branchENGINE-466
changeset 30342d77f2180edb
parent 3033 5a08c1742299
child 3035 ff76c2a76da1
ENGINE-466: header key import works
src/message_api.c
test/include/HeaderKeyImportTests.h
test/src/engine_tests/HeaderKeyImportTests.cc
     1.1 --- a/src/message_api.c	Tue Oct 09 19:11:36 2018 +0200
     1.2 +++ b/src/message_api.c	Tue Oct 09 19:45:26 2018 +0200
     1.3 @@ -3094,7 +3094,6 @@
     1.4          return false;
     1.5      PEP_STATUS status = import_key(session, the_key->value, the_key->size, NULL);
     1.6      free_bloblist(the_key);
     1.7 -    free_stringpair_list(header_keys); // FIXME
     1.8      if (status == PEP_STATUS_OK)
     1.9          return true;
    1.10      return false;
     2.1 --- a/test/include/HeaderKeyImportTests.h	Tue Oct 09 19:11:36 2018 +0200
     2.2 +++ b/test/include/HeaderKeyImportTests.h	Tue Oct 09 19:45:26 2018 +0200
     2.3 @@ -53,6 +53,7 @@
     2.4          void base_64_kitchen_sink_padded_2();
     2.5          void base_64_kitchen_sink_unpadded_1();        
     2.6          void base_64_kitchen_sink_unpadded_2();
     2.7 +        void check_header_key_import();
     2.8          
     2.9          bool verify_base_64_test(const char* input, const char* desired_output);
    2.10  };
     3.1 --- a/test/src/engine_tests/HeaderKeyImportTests.cc	Tue Oct 09 19:11:36 2018 +0200
     3.2 +++ b/test/src/engine_tests/HeaderKeyImportTests.cc	Tue Oct 09 19:45:26 2018 +0200
     3.3 @@ -11,6 +11,7 @@
     3.4  #include "bloblist.h"
     3.5  #include "base64.h"
     3.6  
     3.7 +#include "test_util.h"
     3.8  #include "EngineTestIndividualSuite.h"
     3.9  #include "HeaderKeyImportTests.h"
    3.10  
    3.11 @@ -98,6 +99,8 @@
    3.12                                                                        static_cast<Func>(&HeaderKeyImportTests::base_64_kitchen_sink_unpadded_1)));
    3.13      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("HeaderKeyImportTests::base_64_kitchen_sink_unpadded_2"),
    3.14                                                                        static_cast<Func>(&HeaderKeyImportTests::base_64_kitchen_sink_unpadded_2)));
    3.15 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("HeaderKeyImportTests::check_header_key_import"),
    3.16 +                                                                      static_cast<Func>(&HeaderKeyImportTests::check_header_key_import)));                                                                  
    3.17  }
    3.18  
    3.19  bool HeaderKeyImportTests::verify_base_64_test(const char* input, const char* desired_output) {
    3.20 @@ -728,3 +731,33 @@
    3.21      TEST_ASSERT(verify_base_64_test(input, output));
    3.22  
    3.23  }
    3.24 +
    3.25 +void HeaderKeyImportTests::check_header_key_import() {
    3.26 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    3.27 +    slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
    3.28 +    slurp_and_import_key(session, "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc");
    3.29 +    
    3.30 +    string message = slurp("test_mails/Header_key_import.eml");
    3.31 +    
    3.32 +    char* dec_msg = NULL;
    3.33 +
    3.34 +    stringlist_t* keylist = NULL;
    3.35 +
    3.36 +    PEP_rating rating;
    3.37 +    PEP_decrypt_flags_t flags;
    3.38 +
    3.39 +    flags = 0;
    3.40 +    char* modified_src = NULL;
    3.41 +    PEP_STATUS status = MIME_decrypt_message(session, message.c_str(), message.size(), &dec_msg, &keylist, &rating, &flags, &modified_src);
    3.42 +    TEST_ASSERT_MSG(rating == PEP_rating_reliable, tl_rating_string(rating));
    3.43 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    3.44 +
    3.45 +    pEp_identity* alice_check = new_identity("pep.test.alice@pep-project.org", NULL, NULL, "pEp Test Alice");
    3.46 +    status = update_identity(session, alice_check);
    3.47 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    3.48 +    TEST_ASSERT(alice_check->fpr);
    3.49 +    TEST_ASSERT_MSG(strcmp(alice_check->fpr, alice_fpr) == 0, alice_check->fpr);
    3.50 +    free(dec_msg);
    3.51 +    free(modified_src);
    3.52 +    free_identity(alice_check);
    3.53 +}