ENGINE-179 unittested and fixed. ENGINE-179
authorEdouard Tisserant <edouard@pep-project.org>
Tue, 06 Jun 2017 12:41:38 +0200
branchENGINE-179
changeset 1821dc8d47e6a02c
parent 1820 167f2913e770
child 1822 5a77127f3f7e
ENGINE-179 unittested and fixed.
src/message_api.c
test/least_common_denom_color_test.cc
     1.1 --- a/src/message_api.c	Tue Jun 06 09:59:41 2017 +0200
     1.2 +++ b/src/message_api.c	Tue Jun 06 12:41:38 2017 +0200
     1.3 @@ -2730,6 +2730,8 @@
     1.4      if (!(session && msg && rating))
     1.5          return ERROR(PEP_ILLEGAL_VALUE);
     1.6  
     1.7 +    *rating = PEP_rating_undefined;
     1.8 +
     1.9      if (x_enc_status == PEP_rating_undefined){
    1.10          for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    1.11              if (strcasecmp(i->value->key, "X-EncStatus") == 0){
    1.12 @@ -2741,25 +2743,29 @@
    1.13      if (x_enc_status == PEP_rating_undefined)
    1.14          return ERROR(PEP_ILLEGAL_VALUE);
    1.15  
    1.16 -    PEP_rating _rating = x_enc_status;
    1.17 -
    1.18 -    if (x_keylist == NULL){
    1.19 +
    1.20 +    if (_keylist == NULL){
    1.21          for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    1.22              if (strcasecmp(i->value->key, "X-KeyList") == 0){
    1.23                  status = string_to_keylist(i->value->value, &_keylist);
    1.24                  if (status != PEP_STATUS_OK)
    1.25                      GOTO(pep_error);
    1.26 +                must_free_keylist = true;
    1.27 +                break;
    1.28              }
    1.29          }
    1.30      }
    1.31 -    if (x_keylist == NULL)
    1.32 +    if (_keylist == NULL)
    1.33          return ERROR(PEP_ILLEGAL_VALUE);
    1.34  
    1.35 +    PEP_rating _rating = x_enc_status;
    1.36  
    1.37      status = amend_rating_according_to_sender_and_recipients(session,
    1.38                                                               &_rating,
    1.39                                                               msg->from,
    1.40                                                               _keylist);
    1.41 +    if (status == PEP_STATUS_OK)
    1.42 +        *rating = _rating;
    1.43      
    1.44      return ERROR(status);
    1.45  
     2.1 --- a/test/least_common_denom_color_test.cc	Tue Jun 06 09:59:41 2017 +0200
     2.2 +++ b/test/least_common_denom_color_test.cc	Tue Jun 06 12:41:38 2017 +0200
     2.3 @@ -58,7 +58,6 @@
     2.4      
     2.5      message* msg_ptr = nullptr;
     2.6      message* dest_msg = nullptr;
     2.7 -    message* final_ptr = nullptr;
     2.8      stringlist_t* keylist = nullptr;
     2.9      PEP_rating rating;
    2.10      PEP_decrypt_flags_t flags;
    2.11 @@ -66,53 +65,69 @@
    2.12      status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    2.13      assert(status == PEP_STATUS_OK);
    2.14      assert(msg_ptr);
    2.15 -    final_ptr = msg_ptr;
    2.16 +
    2.17      status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    2.18 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
    2.19 -  
    2.20 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    2.21 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    2.22 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    2.23 -
    2.24 +    assert(status == PEP_STATUS_OK);
    2.25 +    assert(dest_msg);
    2.26      /* message is signed and no recip is mistrusted... */
    2.27      assert(color_from_rating(rating) == PEP_color_yellow);
    2.28  
    2.29 -    if (final_ptr == dest_msg)
    2.30 -    	free_message(dest_msg);
    2.31 -    free_message(msg_ptr);
    2.32 -    free_stringlist(keylist);
    2.33 +    cout << "shortmsg: " << dest_msg->shortmsg << endl << endl;
    2.34 +    cout << "longmsg: " << dest_msg->longmsg << endl << endl;
    2.35 +    cout << "longmsg_formatted: " << (dest_msg->longmsg_formatted ? dest_msg->longmsg_formatted : "(empty)") << endl << endl;
    2.36 +
    2.37 +    PEP_rating decrypt_rating = rating;
    2.38 +    
    2.39 +    /* re-evaluate rating, counting on optional fields */
    2.40 +    status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
    2.41 +    assert(status == PEP_STATUS_OK);
    2.42 +    assert(color_from_rating(rating) == PEP_color_yellow);
    2.43 +
    2.44 +    /* re-evaluate rating, without optional fields */
    2.45 +    status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
    2.46 +    assert(status == PEP_STATUS_OK);
    2.47 +    assert(color_from_rating(rating) == PEP_color_yellow);
    2.48  
    2.49      /* Ok, now mistrust one recip */
    2.50      key_mistrusted(session, recip2);
    2.51 +
    2.52 +    /* re-evaluate rating, counting on optional fields */
    2.53 +    status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
    2.54 +    assert(status == PEP_STATUS_OK);
    2.55 +    assert(color_from_rating(rating) == PEP_color_red);
    2.56 +
    2.57 +    /* re-evaluate rating, without optional fields */
    2.58 +    status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
    2.59 +    assert(status == PEP_STATUS_OK);
    2.60 +    assert(color_from_rating(rating) == PEP_color_red);
    2.61 +
    2.62 +    free_message(dest_msg);
    2.63 +    free_message(msg_ptr);
    2.64 +    free_stringlist(keylist);
    2.65      
    2.66      msg_ptr = nullptr;
    2.67      dest_msg = nullptr;
    2.68 -    final_ptr = nullptr;
    2.69      keylist = nullptr;
    2.70      rating = PEP_rating_unreliable;
    2.71  
    2.72      status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    2.73      assert(status == PEP_STATUS_OK);
    2.74      assert(msg_ptr);
    2.75 -    final_ptr = msg_ptr;
    2.76      status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    2.77 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
    2.78    
    2.79 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    2.80 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    2.81 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    2.82 +    cout << "shortmsg: " << dest_msg->shortmsg << endl << endl;
    2.83 +    cout << "longmsg: " << dest_msg->longmsg << endl << endl;
    2.84 +    cout << "longmsg_formatted: " << (dest_msg->longmsg_formatted ? dest_msg->longmsg_formatted : "(empty)") << endl << endl;
    2.85  
    2.86      /* message is signed and no recip is mistrusted... */
    2.87      assert(color_from_rating(rating) == PEP_color_red);
    2.88  
    2.89 -    if (final_ptr == dest_msg)
    2.90 -    	free_message(dest_msg);
    2.91 +    free_message(dest_msg);
    2.92      free_message(msg_ptr);
    2.93      free_stringlist(keylist);
    2.94  
    2.95      msg_ptr = nullptr;
    2.96      dest_msg = nullptr;
    2.97 -    final_ptr = nullptr;
    2.98      keylist = nullptr;
    2.99      rating = PEP_rating_unreliable;
   2.100