ENGINE-448: fixed non-advancement through loop, added more tests ENGINE-448
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 04 Feb 2019 08:11:20 +0100
branchENGINE-448
changeset 3263db7e13686948
parent 3256 467d2e807b29
child 3264 18c17c856f0e
ENGINE-448: fixed non-advancement through loop, added more tests
src/message_api.c
test/src/engine_tests/KeyAttachmentTests.cc
     1.1 --- a/src/message_api.c	Wed Jan 30 17:56:45 2019 +0100
     1.2 +++ b/src/message_api.c	Mon Feb 04 08:11:20 2019 +0100
     1.3 @@ -1483,6 +1483,7 @@
     1.4      for (bloblist_t *bl = msg->attachments; i < MAX_KEYS_TO_IMPORT && bl && bl->value;
     1.5           i++)
     1.6      {
     1.7 +        do_not_advance = false;
     1.8          if (bl && bl->value && bl->size && bl->size < MAX_KEY_SIZE
     1.9                  && is_key(bl))
    1.10          {
     2.1 --- a/test/src/engine_tests/KeyAttachmentTests.cc	Wed Jan 30 17:56:45 2019 +0100
     2.2 +++ b/test/src/engine_tests/KeyAttachmentTests.cc	Mon Feb 04 08:11:20 2019 +0100
     2.3 @@ -72,11 +72,49 @@
     2.4  }
     2.5  
     2.6  void KeyAttachmentTests::check_key_attach_inline() {
     2.7 -    TEST_ASSERT(true);
     2.8 +    string msg = slurp("test_mails/Inline PGP test.eml");
     2.9 +    message* enc_msg = NULL;
    2.10 +    message* dec_msg = NULL;
    2.11 +
    2.12 +    PEP_STATUS status = mime_decode_message(msg.c_str(), msg.size(), &enc_msg);
    2.13 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.14 +    TEST_ASSERT(enc_msg);
    2.15 +    stringlist_t* keylist = NULL;
    2.16 +    PEP_rating rating;
    2.17 +    PEP_decrypt_flags_t flags = 0;
    2.18 +    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
    2.19 +    TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));    
    2.20 +    TEST_ASSERT(dec_msg);
    2.21 +    TEST_ASSERT_MSG(dec_msg->attachments == NULL, "Decryption left attachments it should have deleted.");
    2.22 +    free_message(enc_msg);
    2.23 +    free_message(dec_msg);
    2.24 +    free_stringlist(keylist);
    2.25  }
    2.26  
    2.27  void KeyAttachmentTests::check_key_plus_encr_att_inline() {
    2.28 -    TEST_ASSERT(true);
    2.29 +    string msg = slurp("test_mails/Inline PGP test - key then already encr attach.eml");
    2.30 +    message* enc_msg = NULL;
    2.31 +    message* dec_msg = NULL;
    2.32 +
    2.33 +    PEP_STATUS status = mime_decode_message(msg.c_str(), msg.size(), &enc_msg);
    2.34 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.35 +    TEST_ASSERT(enc_msg);
    2.36 +    stringlist_t* keylist = NULL;
    2.37 +    PEP_rating rating;
    2.38 +    PEP_decrypt_flags_t flags = 0;
    2.39 +    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
    2.40 +    TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));    
    2.41 +    TEST_ASSERT(dec_msg);
    2.42 +    TEST_ASSERT_MSG(dec_msg->attachments, "Encrypted attachment not preserved.");
    2.43 +    TEST_ASSERT_MSG(dec_msg->attachments->next == NULL, "Decryption left attachments it should have deleted.");    
    2.44 +    TEST_ASSERT_MSG(dec_msg->attachments->filename, "Attachment doesn't have a filename");
    2.45 +    // TODO: is there a missing update to resource IDs in decrypt in parts?
    2.46 +    TEST_ASSERT_MSG(strcmp(dec_msg->attachments->filename, "cheese.txt.gpg") == 0, dec_msg->attachments->filename);    
    2.47 +    TEST_ASSERT_MSG(dec_msg->attachments->mime_type, "Attachment doesn't have a mime type");
    2.48 +    TEST_ASSERT_MSG(strcmp(dec_msg->attachments->mime_type, "application/octet-stream") == 0, dec_msg->attachments->mime_type);    
    2.49 +    free_message(enc_msg);
    2.50 +    free_message(dec_msg);
    2.51 +    free_stringlist(keylist);
    2.52  }
    2.53  
    2.54  void KeyAttachmentTests::check_encr_att_plus_key_inline() {
    2.55 @@ -84,7 +122,29 @@
    2.56  }
    2.57  
    2.58  void KeyAttachmentTests::check_key_plus_unencr_att_inline() {
    2.59 -    TEST_ASSERT(true);
    2.60 +    string msg = slurp("test_mails/Inline PGP test - key then not-yet encr attach.eml");
    2.61 +    message* enc_msg = NULL;
    2.62 +    message* dec_msg = NULL;
    2.63 +
    2.64 +    PEP_STATUS status = mime_decode_message(msg.c_str(), msg.size(), &enc_msg);
    2.65 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.66 +    TEST_ASSERT(enc_msg);
    2.67 +    stringlist_t* keylist = NULL;
    2.68 +    PEP_rating rating;
    2.69 +    PEP_decrypt_flags_t flags = 0;
    2.70 +    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
    2.71 +    TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));    
    2.72 +    TEST_ASSERT(dec_msg);
    2.73 +    TEST_ASSERT_MSG(dec_msg->attachments, "Encrypted attachment not preserved.");
    2.74 +    TEST_ASSERT_MSG(dec_msg->attachments->next == NULL, "Decryption left attachments it should have deleted.");    
    2.75 +    TEST_ASSERT_MSG(dec_msg->attachments->filename, "Attachment doesn't have a filename");
    2.76 +    // TODO: is there a missing update to resource IDs in decrypt in parts?
    2.77 +    TEST_ASSERT_MSG(strcmp(dec_msg->attachments->filename, "cheese.txt") == 0, dec_msg->attachments->filename);    
    2.78 +    TEST_ASSERT_MSG(dec_msg->attachments->mime_type, "Attachment doesn't have a mime type");
    2.79 +    TEST_ASSERT_MSG(strcmp(dec_msg->attachments->mime_type, "application/octet-stream") == 0, dec_msg->attachments->mime_type);    
    2.80 +    free_message(enc_msg);
    2.81 +    free_message(dec_msg);
    2.82 +    free_stringlist(keylist);
    2.83  }
    2.84  
    2.85  void KeyAttachmentTests::check_unencr_att_plus_key_inline() {
    2.86 @@ -92,11 +152,49 @@
    2.87  }
    2.88  
    2.89  void KeyAttachmentTests::check_many_keys_inline() {
    2.90 -    TEST_ASSERT(true);
    2.91 +    string msg = slurp("test_mails/Inline PGP test - many keys.eml");
    2.92 +    message* enc_msg = NULL;
    2.93 +    message* dec_msg = NULL;
    2.94 +
    2.95 +    PEP_STATUS status = mime_decode_message(msg.c_str(), msg.size(), &enc_msg);
    2.96 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.97 +    TEST_ASSERT(enc_msg);
    2.98 +    stringlist_t* keylist = NULL;
    2.99 +    PEP_rating rating;
   2.100 +    PEP_decrypt_flags_t flags = 0;
   2.101 +    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
   2.102 +    TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));    
   2.103 +    TEST_ASSERT(dec_msg);
   2.104 +    TEST_ASSERT_MSG(dec_msg->attachments == NULL, "Decryption left attachments it should have deleted.");
   2.105 +    free_message(enc_msg);
   2.106 +    free_message(dec_msg);
   2.107 +    free_stringlist(keylist);
   2.108  }
   2.109          
   2.110  void KeyAttachmentTests::check_many_keys_w_encr_file_inline() {
   2.111 -    TEST_ASSERT(true);
   2.112 +    string msg = slurp("test_mails/Inline PGP test - many keys w_ encr file.eml");
   2.113 +    message* enc_msg = NULL;
   2.114 +    message* dec_msg = NULL;
   2.115 +
   2.116 +    PEP_STATUS status = mime_decode_message(msg.c_str(), msg.size(), &enc_msg);
   2.117 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.118 +    TEST_ASSERT(enc_msg);
   2.119 +    stringlist_t* keylist = NULL;
   2.120 +    PEP_rating rating;
   2.121 +    PEP_decrypt_flags_t flags = 0;
   2.122 +    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
   2.123 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));    
   2.124 +    TEST_ASSERT(dec_msg);
   2.125 +    TEST_ASSERT_MSG(dec_msg->attachments, "Encrypted attachment not preserved.");
   2.126 +    TEST_ASSERT_MSG(dec_msg->attachments->next == NULL, "Decryption left attachments it should have deleted.");    
   2.127 +    TEST_ASSERT_MSG(dec_msg->attachments->filename, "Attachment doesn't have a filename");
   2.128 +    // TODO: is there a missing update to resource IDs in decrypt in parts?
   2.129 +    TEST_ASSERT_MSG(strcmp(dec_msg->attachments->filename, "cheese.txt") == 0, dec_msg->attachments->filename);    
   2.130 +    TEST_ASSERT_MSG(dec_msg->attachments->mime_type, "Attachment doesn't have a mime type");
   2.131 +    TEST_ASSERT_MSG(strcmp(dec_msg->attachments->mime_type, "application/octet-stream") == 0, dec_msg->attachments->mime_type);    
   2.132 +    free_message(enc_msg);
   2.133 +    free_message(dec_msg);
   2.134 +    free_stringlist(keylist);
   2.135  }
   2.136          
   2.137  void KeyAttachmentTests::check_many_keys_w_unencr_file_inline() {