Merged in ENGINE-430, fixed some test bugs related to it. FIXME: make the reencrypt test into individual tests, as that's what started this whole testing nightmare and we're still not testing that directly. local_cpptest
authorKrista Bennett <krista@pep-project.org>
Wed, 09 May 2018 09:46:20 +0200
branchlocal_cpptest
changeset 2664c68f27b7dd22
parent 2662 8179ef5e6b4c
parent 2663 5bcf7e1d9025
child 2667 a8f77b25bed2
Merged in ENGINE-430, fixed some test bugs related to it. FIXME: make the reencrypt test into individual tests, as that's what started this whole testing nightmare and we're still not testing that directly.
test/README.txt
test/src/TestDriver.cc
test/src/engine_tests/ReencryptPlusExtraKeysTests.cc
     1.1 --- a/src/message_api.c	Tue May 08 16:09:02 2018 +0200
     1.2 +++ b/src/message_api.c	Wed May 09 09:46:20 2018 +0200
     1.3 @@ -3002,7 +3002,9 @@
     1.4      PEP_STATUS status = PEP_STATUS_OK;
     1.5      PEP_STATUS decrypt_status = PEP_CANNOT_DECRYPT_UNKNOWN;
     1.6      PEP_STATUS _decrypt_in_pieces_status = PEP_CANNOT_DECRYPT_UNKNOWN;
     1.7 -    message *msg = NULL;
     1.8 +    message* msg = NULL;
     1.9 +    message* calculated_src = src;
    1.10 +    
    1.11      char *ctext;
    1.12      size_t csize;
    1.13      char *ptext = NULL;
    1.14 @@ -3260,7 +3262,8 @@
    1.15                                              reconcile_src_and_inner_messages(src, inner_message);
    1.16                                              
    1.17                                              // FIXME: free msg, but check references
    1.18 -                                            src = msg = inner_message;
    1.19 +                                            //src = msg = inner_message;
    1.20 +                                            calculated_src = msg = inner_message;
    1.21                                              
    1.22                                              if (src->from) {
    1.23                                                  if (!is_me(session, src->from))
    1.24 @@ -3299,13 +3302,13 @@
    1.25          // Ok, so if it was signed and it's all verified, we can update
    1.26          // eligible signer comm_types to PEP_ct_pEp_*
    1.27          if (decrypt_status == PEP_DECRYPTED_AND_VERIFIED && is_pep_msg)
    1.28 -            status = update_sender_to_pep_trust(session, src->from, _keylist);
    1.29 +            status = update_sender_to_pep_trust(session, calculated_src->from, _keylist);
    1.30  
    1.31          /* Ok, now we have a keylist used for decryption/verification.
    1.32             now we need to update the message rating with the 
    1.33             sender and recipients in mind */
    1.34          status = amend_rating_according_to_sender_and_recipients(session,
    1.35 -                 rating, src->from, _keylist);
    1.36 +                 rating, calculated_src->from, _keylist);
    1.37  
    1.38          if (status != PEP_STATUS_OK)
    1.39              goto pep_error;
    1.40 @@ -3352,8 +3355,8 @@
    1.41          if (imported_keys)
    1.42              remove_attached_keys(msg);
    1.43                      
    1.44 -        if (src->id && src != msg) {
    1.45 -            msg->id = strdup(src->id);
    1.46 +        if (calculated_src->id && calculated_src != msg) {
    1.47 +            msg->id = strdup(calculated_src->id);
    1.48              assert(msg->id);
    1.49              if (msg->id == NULL)
    1.50                  goto enomem;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/README.txt	Wed May 09 09:46:20 2018 +0200
     2.3 @@ -0,0 +1,5 @@
     2.4 +Notes:
     2.5 +
     2.6 +- TEST_ASSERT is a macro and does not always behave 100% the way you'd expect. Note the following:
     2.7 +	* 1. If used in if/else blocks, make sure the blocks are guarded, or weird things happen.
     2.8 +        * 2. If performing comparisons, please parenthesise liberally - bitwise operations being compared to 0 should always be parenthesised before comparison  
     3.1 --- a/test/src/TestDriver.cc	Tue May 08 16:09:02 2018 +0200
     3.2 +++ b/test/src/TestDriver.cc	Wed May 09 09:46:20 2018 +0200
     3.3 @@ -81,7 +81,7 @@
     3.4          test_runner->add(suite); 
     3.5      }
     3.6  
     3.7 -    Test::TextOutput output(Test::TextOutput::Terse);
     3.8 -    return test_runner->run(output) ? 1 : 0;
     3.9 +    Test::TextOutput output(Test::TextOutput::Verbose);
    3.10 +    return test_runner->run(output, false) ? 1 : 0;
    3.11      
    3.12  }
     4.1 --- a/test/src/engine_tests/ReencryptPlusExtraKeysTests.cc	Tue May 08 16:09:02 2018 +0200
     4.2 +++ b/test/src/engine_tests/ReencryptPlusExtraKeysTests.cc	Wed May 09 09:46:20 2018 +0200
     4.3 @@ -52,24 +52,24 @@
     4.4      const string pub_extra_key_1 = slurp("test_keys/pub/reencrypt_extra_keys_1-0x8B026AEC_pub.asc");
     4.5  
     4.6      status = import_key(session, own_recip_pub_key.c_str(), own_recip_pub_key.length(), NULL);
     4.7 -    TEST_ASSERT (status == PEP_STATUS_OK);
     4.8 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import own recipient public key.");
     4.9      status = import_key(session, own_recip_priv_key.c_str(), own_recip_priv_key.length(), NULL);
    4.10 -    TEST_ASSERT (status == PEP_STATUS_OK);    
    4.11 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import own recipient private key.");    
    4.12      status = import_key(session, own_recip_2_pub_key.c_str(), own_recip_2_pub_key.length(), NULL);
    4.13 -    TEST_ASSERT (status == PEP_STATUS_OK);
    4.14 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import own second recipient public key.");
    4.15      status = import_key(session, own_recip_2_priv_key.c_str(), own_recip_2_priv_key.length(), NULL);
    4.16 -    TEST_ASSERT (status == PEP_STATUS_OK);
    4.17 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import own second recipient public key.");
    4.18      
    4.19      status = import_key(session, sender_pub_key.c_str(), sender_pub_key.length(), NULL);
    4.20 -    TEST_ASSERT (status == PEP_STATUS_OK);
    4.21 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import own sender public key.");
    4.22      status = import_key(session, recip_2_pub_key.c_str(), recip_2_pub_key.length(), NULL);
    4.23 -    TEST_ASSERT (status == PEP_STATUS_OK);
    4.24 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to second recipient public key.");
    4.25      status = import_key(session, recip_0_pub_key.c_str(), recip_0_pub_key.length(), NULL);
    4.26 -    TEST_ASSERT (status == PEP_STATUS_OK);
    4.27 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import zeroth recipient public key.");
    4.28      status = import_key(session, pub_extra_key_0.c_str(), pub_extra_key_0.length(), NULL);
    4.29 -    TEST_ASSERT (status == PEP_STATUS_OK);
    4.30 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import first extra public key.");
    4.31      status = import_key(session, pub_extra_key_1.c_str(), pub_extra_key_1.length(), NULL);
    4.32 -    TEST_ASSERT (status == PEP_STATUS_OK);
    4.33 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to import second extra public key.");
    4.34  
    4.35      cout << "Keys imported." << endl;
    4.36  
    4.37 @@ -78,7 +78,7 @@
    4.38      
    4.39      cout << "Inserting own identities and keys into database." << endl;
    4.40      status = set_own_key(session, me_recip_2, fpr_own_recip_2_key);
    4.41 -    TEST_ASSERT(status == PEP_STATUS_OK);
    4.42 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Failed to set own second recipient key as own key.");
    4.43      cout << "Done: inserting own identities and keys into database." << endl;
    4.44  
    4.45      const string to_reencrypt_from_enigmail = slurp("test_mails/reencrypt_sent_by_enigmail.eml");
    4.46 @@ -109,12 +109,11 @@
    4.47      cout << decrypted_text << endl;
    4.48  
    4.49      cout << "Status is " << tl_status_string(status) << endl;
    4.50 -    TEST_ASSERT(decrypted_text);
    4.51 -    TEST_ASSERT(rating);
    4.52 -    TEST_ASSERT(!(flags & PEP_decrypt_flag_src_modified));
    4.53 +    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
    4.54 +    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
    4.55 +    TEST_ASSERT_MSG((flags & PEP_decrypt_flag_src_modified) == 0, "Source was modified, but shouldn't have been.");
    4.56      
    4.57 -    TEST_ASSERT(!modified_src);
    4.58 -    TEST_ASSERT(flags & PEP_decrypt_flag_src_modified == 0);
    4.59 +    TEST_ASSERT_MSG(!modified_src, "Modified source was returned, but should not have been generated");
    4.60      //cout << modified_src << endl;
    4.61      
    4.62      free(decrypted_text);
    4.63 @@ -144,8 +143,8 @@
    4.64      cout << "Status is " << tl_status_string(status) << endl;
    4.65  
    4.66  
    4.67 -    TEST_ASSERT(decrypted_text);
    4.68 -    TEST_ASSERT(rating);
    4.69 +    TEST_ASSERT_MSG(decrypted_text, "No decrypted text");
    4.70 +    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
    4.71  
    4.72      free(decrypted_text);
    4.73      decrypted_text = nullptr;
    4.74 @@ -178,7 +177,7 @@
    4.75      {
    4.76          if (i == 0) {
    4.77                cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
    4.78 -              TEST_ASSERT(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
    4.79 +              TEST_ASSERT_MSG(strcasecmp(fpr_own_recip_2_key,kl->value) == 0, "Own recip 2 was not the signer of this message.");
    4.80          }
    4.81          else {
    4.82              if (strcasecmp(fpr_own_recip_2_key, kl->value) == 0) {
    4.83 @@ -195,13 +194,13 @@
    4.84              }
    4.85              else {
    4.86                  cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
    4.87 -                TEST_ASSERT(false);
    4.88 +                TEST_ASSERT_MSG(false, "Encrypted for someone it shouldn't have been.");
    4.89              }
    4.90              cout << "\t " << kl->value << endl;
    4.91          }
    4.92 -        TEST_ASSERT(i < 4);
    4.93 +        TEST_ASSERT_MSG(i < 4, "Encrypted for more extra keys than indicated...");
    4.94      }
    4.95 -    TEST_ASSERT (own_key_found && extra_key_0_found && extra_key_1_found);
    4.96 +    TEST_ASSERT_MSG(own_key_found && extra_key_0_found && extra_key_1_found, "Not encrypted for all desired keys.");
    4.97      cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
    4.98  
    4.99      cout << "Case 1b: PASS" << endl << endl;
   4.100 @@ -228,15 +227,19 @@
   4.101      cout << decrypted_text << endl;
   4.102      cout << "Status is " << tl_status_string(status) << endl;
   4.103  
   4.104 -
   4.105 -    TEST_ASSERT(decrypted_text);
   4.106 -    TEST_ASSERT(rating);
   4.107 +    cout << "1";
   4.108 +    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
   4.109 +    cout << "2";
   4.110 +    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
   4.111 +    cout << "3";
   4.112 +    TEST_ASSERT_MSG((flags & PEP_decrypt_flag_src_modified) == 0, "Source was modified, but shouldn't have been.");
   4.113 +    cout << "4";    
   4.114 +    TEST_ASSERT_MSG(!modified_src, "Modified source was returned, but should not have been generated");
   4.115 +    cout << "5";
   4.116  
   4.117      free(decrypted_text);
   4.118      decrypted_text = nullptr;
   4.119  
   4.120 -    TEST_ASSERT(!modified_src);
   4.121 -    TEST_ASSERT(flags & PEP_decrypt_flag_src_modified == 0);
   4.122  
   4.123      cout << "Case 2a: PASS" << endl << endl;
   4.124  
   4.125 @@ -260,9 +263,8 @@
   4.126      cout << decrypted_text << endl;
   4.127      cout << "Status is " << tl_status_string(status) << endl;
   4.128  
   4.129 -
   4.130 -    TEST_ASSERT(decrypted_text);
   4.131 -    TEST_ASSERT(rating);
   4.132 +    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
   4.133 +    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
   4.134  
   4.135      free(decrypted_text);
   4.136      decrypted_text = nullptr;
   4.137 @@ -295,7 +297,7 @@
   4.138      {
   4.139          if (i == 0) {
   4.140                cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
   4.141 -//              TEST_ASSERT(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
   4.142 +              // TEST_ASSERT_MSG(strcasecmp(fpr_own_recip_2_key,kl->value) == 0, "Own recip 2 was not the signer of this message.");
   4.143          }
   4.144          else {
   4.145              if (strcasecmp(fpr_own_recip_2_key, kl->value) == 0) {
   4.146 @@ -312,13 +314,14 @@
   4.147              }
   4.148              else {
   4.149                  cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
   4.150 -//                TEST_ASSERT(false);
   4.151 +                // TEST_ASSERT_MSG(false, "Encrypted for someone it shouldn't have been.");
   4.152              }
   4.153              cout << "\t " << kl->value << endl;
   4.154          }
   4.155 -        TEST_ASSERT(i < 4);
   4.156 +        TEST_ASSERT_MSG(i < 4, "Encrypted for too many keys.");
   4.157      }
   4.158 -//    TEST_ASSERT (own_key_found && extra_key_0_found && extra_key_1_found);
   4.159 +//        TEST_ASSERT_MSG(own_key_found && extra_key_0_found && extra_key_1_found, "Not encrypted for all desired keys.");
   4.160 +
   4.161      cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
   4.162  
   4.163      cout << "Case 2b: PASS" << endl << endl;
   4.164 @@ -331,7 +334,7 @@
   4.165      keys = NULL;
   4.166  
   4.167      status = set_own_key(session, me_recip_1, fpr_own_recip_key);
   4.168 -    TEST_ASSERT(status == PEP_STATUS_OK);
   4.169 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, "Unable to set own key.");
   4.170  
   4.171      flags = PEP_decrypt_flag_untrusted_server;
   4.172      
   4.173 @@ -347,11 +350,10 @@
   4.174      cout << decrypted_text << endl;
   4.175      cout << "Status is " << tl_status_string(status) << endl;
   4.176  
   4.177 -
   4.178 -    TEST_ASSERT(decrypted_text);
   4.179 -    TEST_ASSERT(rating);
   4.180 -    TEST_ASSERT(!modified_src);
   4.181 -    TEST_ASSERT(flags & PEP_decrypt_flag_src_modified == 0);
   4.182 +    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
   4.183 +    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
   4.184 +    TEST_ASSERT_MSG((flags & PEP_decrypt_flag_src_modified) == 0, "Source was modified, but shouldn't have been.");    
   4.185 +    TEST_ASSERT_MSG(!modified_src, "Modified source was returned, but should not have been generated");
   4.186  
   4.187      free(decrypted_text);
   4.188      decrypted_text = nullptr;
   4.189 @@ -379,8 +381,8 @@
   4.190      cout << decrypted_text << endl;
   4.191      cout << "Status is " << tl_status_string(status) << endl;
   4.192  
   4.193 -    TEST_ASSERT(decrypted_text);
   4.194 -    TEST_ASSERT(rating);
   4.195 +    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
   4.196 +    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
   4.197  
   4.198      free(decrypted_text);
   4.199      decrypted_text = nullptr;
   4.200 @@ -413,7 +415,7 @@
   4.201      {
   4.202          if (i == 0) {
   4.203                cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
   4.204 -//              TEST_ASSERT(strcasecmp(fpr_own_recip_key,kl->value) == 0);
   4.205 +//              TEST_ASSERT_MSG(strcasecmp(fpr_own_recip_key,kl->value) == 0);
   4.206          }
   4.207          else {
   4.208              if (strcasecmp(fpr_own_recip_key, kl->value) == 0) {
   4.209 @@ -430,13 +432,13 @@
   4.210              }
   4.211              else {
   4.212                  cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
   4.213 -//                TEST_ASSERT(false);
   4.214 +//                TEST_ASSERT_MSG(false);
   4.215              }
   4.216              cout << "\t " << kl->value << endl;
   4.217          }
   4.218 -        TEST_ASSERT(i < 4);
   4.219 +        TEST_ASSERT_MSG(i < 4, "Encrypted for too many keys.");
   4.220      }
   4.221 -//    TEST_ASSERT (own_key_found && extra_key_0_found && extra_key_1_found);
   4.222 +//    TEST_ASSERT_MSG(own_key_found && extra_key_0_found && extra_key_1_found);
   4.223      cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
   4.224  
   4.225      cout << "Case 3b: PASS" << endl << endl;