Fix er up. Now works with explicitly-set versions on identities. Now to check the imports... ENGINE-559
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Thu, 27 Jun 2019 12:40:43 +0200
branchENGINE-559
changeset 388449d25cfc873c
parent 3883 0ed6f15cf383
child 3915 c3fa76972af5
Fix er up. Now works with explicitly-set versions on identities. Now to check the imports...
src/keymanagement.c
src/message.c
src/pEpEngine.c
test/src/engine_tests/Message2_1Tests.cc
test/src/util/test_util.cc
     1.1 --- a/src/keymanagement.c	Wed Jun 26 17:37:18 2019 +0200
     1.2 +++ b/src/keymanagement.c	Thu Jun 27 12:40:43 2019 +0200
     1.3 @@ -525,6 +525,9 @@
     1.4      
     1.5      return_id->me = stored_ident->me;
     1.6      
     1.7 +    return_id->major_ver = stored_ident->major_ver;
     1.8 +    return_id->minor_ver = stored_ident->minor_ver;
     1.9 +
    1.10      // FIXME: Do we ALWAYS do this? We probably should...
    1.11      if (EMPTYSTR(return_id->user_id)) {
    1.12          free(return_id->user_id);
    1.13 @@ -557,7 +560,7 @@
    1.14      }
    1.15      
    1.16      transfer_ident_lang_and_flags(return_id, stored_ident);
    1.17 -    
    1.18 +        
    1.19      if (return_id->comm_type == PEP_ct_unknown)
    1.20          return_id->comm_type = PEP_ct_key_not_found;
    1.21      
     2.1 --- a/src/message.c	Wed Jun 26 17:37:18 2019 +0200
     2.2 +++ b/src/message.c	Thu Jun 27 12:40:43 2019 +0200
     2.3 @@ -44,6 +44,7 @@
     2.4          free_stringlist(msg->keywords);
     2.5          free(msg->comments);
     2.6          free_stringpair_list(msg->opt_fields);
     2.7 +        free(msg->_sender_fpr);
     2.8          free(msg);
     2.9      }
    2.10  }
    2.11 @@ -185,6 +186,12 @@
    2.12              goto enomem;
    2.13      }
    2.14  
    2.15 +    if (src->_sender_fpr) {
    2.16 +        msg->_sender_fpr = strdup(src->_sender_fpr);
    2.17 +        if (msg->_sender_fpr == NULL)
    2.18 +            goto enomem;
    2.19 +    }
    2.20 +    
    2.21      msg->enc_format = src->enc_format;
    2.22  
    2.23      return msg;
    2.24 @@ -218,13 +225,15 @@
    2.25      free(dst->longmsg);
    2.26      free(dst->longmsg_formatted);
    2.27      free(dst->comments);
    2.28 +    free(dst->_sender_fpr);
    2.29      dst->id = src->id;
    2.30      dst->shortmsg = src->shortmsg;
    2.31      dst->longmsg = src->longmsg;
    2.32      dst->longmsg_formatted = src->longmsg_formatted;
    2.33      dst->comments = src->comments;    
    2.34 +    dst->_sender_fpr = src->_sender_fpr;
    2.35      src->id = src->shortmsg = src->longmsg = src->longmsg_formatted = NULL;
    2.36 -    src->comments = NULL;
    2.37 +    src->comments = src->_sender_fpr = NULL;
    2.38      
    2.39      /* bloblists */
    2.40      free_bloblist(dst->attachments);
     3.1 --- a/src/pEpEngine.c	Wed Jun 26 17:37:18 2019 +0200
     3.2 +++ b/src/pEpEngine.c	Thu Jun 27 12:40:43 2019 +0200
     3.3 @@ -2379,6 +2379,8 @@
     3.4      dup->lang[2] = 0;
     3.5      dup->flags = src->flags;
     3.6      dup->me = src->me;
     3.7 +    dup->major_ver = src->major_ver;
     3.8 +    dup->minor_ver = src->minor_ver;
     3.9      
    3.10      return dup;
    3.11  }
    3.12 @@ -2651,9 +2653,9 @@
    3.13          ident->me = (unsigned int)
    3.14              sqlite3_column_int(session->get_identities_by_userid, 6);
    3.15          ident->major_ver =
    3.16 -            sqlite3_column_int(session->get_identities_by_userid, 6);
    3.17 +            sqlite3_column_int(session->get_identities_by_userid, 7);
    3.18          ident->minor_ver =
    3.19 -            sqlite3_column_int(session->get_identities_by_userid, 7);
    3.20 +            sqlite3_column_int(session->get_identities_by_userid, 8);
    3.21      
    3.22          identity_list_add(*identities, ident);
    3.23          ident = NULL;
    3.24 @@ -2795,9 +2797,9 @@
    3.25          _identity->me = (unsigned int)
    3.26              sqlite3_column_int(session->get_identity_without_trust_check, 4);
    3.27          _identity->major_ver =
    3.28 +            sqlite3_column_int(session->get_identity_without_trust_check, 5);
    3.29 +        _identity->minor_ver =
    3.30              sqlite3_column_int(session->get_identity_without_trust_check, 6);
    3.31 -        _identity->minor_ver =
    3.32 -            sqlite3_column_int(session->get_identity_without_trust_check, 7);
    3.33      
    3.34          *identity = _identity;
    3.35          break;
    3.36 @@ -3206,6 +3208,12 @@
    3.37          }
    3.38      }
    3.39      
    3.40 +    status = set_pEp_version(session, ident_copy, ident_copy->major_ver, ident_copy->minor_ver);
    3.41 +    if (status != PEP_STATUS_OK) {
    3.42 +        sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
    3.43 +        goto pEp_free;            
    3.44 +    }
    3.45 +    
    3.46      result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
    3.47      if (result == SQLITE_OK)
    3.48          status = PEP_STATUS_OK;
    3.49 @@ -4450,8 +4458,8 @@
    3.50              identity->username))
    3.51          return PEP_ILLEGAL_VALUE;
    3.52  
    3.53 -    const char* saved_username = NULL;
    3.54 -    const char* at = NULL;
    3.55 +    char* saved_username = NULL;
    3.56 +    char* at = NULL;
    3.57      size_t uname_len = strlen(identity->username);
    3.58      
    3.59      if (uname_len > 0)
     4.1 --- a/test/src/engine_tests/Message2_1Tests.cc	Wed Jun 26 17:37:18 2019 +0200
     4.2 +++ b/test/src/engine_tests/Message2_1Tests.cc	Thu Jun 27 12:40:43 2019 +0200
     4.3 @@ -57,7 +57,7 @@
     4.4          *maj_inout = 2;
     4.5          *min_inout = 0;
     4.6      }
     4.7 -    else if (strstr(ptext, "X-pEp-Wrapped-Message-Info: INNER") != NULL && strstr(ptext, "forwarded=no") != NULL) {
     4.8 +    else if (strstr(ptext, "X-pEp-Wrapped-Message-Info: INNER") != NULL && strstr(ptext, "forwarded=\"no\"") != NULL) {
     4.9          *maj_inout = 2;
    4.10          *min_inout = 1;
    4.11      }
    4.12 @@ -84,15 +84,6 @@
    4.13      }
    4.14  }
    4.15  
    4.16 -/* PEP_STATUS set_up_preset(PEP_SESSION session,
    4.17 -                         pEp_test_ident_preset preset_name,
    4.18 -                         bool set_ident, 
    4.19 -                         bool set_pep,
    4.20 -                         bool trust,
    4.21 -                         bool set_own, 
    4.22 -                         bool setup_private, 
    4.23 -                         pEp_identity** ident) {
    4.24 -*/
    4.25  void Message2_1Tests::check_message2_1_recip_2_0() {
    4.26  
    4.27      pEp_identity* alice = NULL;
    4.28 @@ -142,8 +133,63 @@
    4.29      TEST_ASSERT(true);
    4.30  }
    4.31  
    4.32 +/* PEP_STATUS set_up_preset(PEP_SESSION session,
    4.33 +                         pEp_test_ident_preset preset_name,
    4.34 +                         bool set_ident, 
    4.35 +                         bool set_pep,
    4.36 +                         bool trust,
    4.37 +                         bool set_own, 
    4.38 +                         bool setup_private, 
    4.39 +                         pEp_identity** ident) {
    4.40 +*/
    4.41 +
    4.42  void Message2_1Tests::check_message2_1_recip_OpenPGP() {
    4.43      // set recip to 1.0
    4.44 +    pEp_identity* alice = NULL;
    4.45 +    pEp_identity* carol = NULL;
    4.46 +    
    4.47 +    PEP_STATUS status = set_up_preset(session, ALICE, 
    4.48 +                                      true, true, true, true, true, &alice);
    4.49 +
    4.50 +    TEST_ASSERT(status == PEP_STATUS_OK);
    4.51 +    TEST_ASSERT(alice);
    4.52 +    
    4.53 +    status = set_up_preset(session, CAROL, 
    4.54 +                           false, false, false, false, false, &carol);
    4.55 +
    4.56 +    TEST_ASSERT(status == PEP_STATUS_OK);
    4.57 +    TEST_ASSERT(carol);
    4.58 +
    4.59 +    status = update_identity(session, carol);
    4.60 +    TEST_ASSERT(status == PEP_STATUS_OK);
    4.61 +    TEST_ASSERT(carol->major_ver < 2);
    4.62 +    TEST_ASSERT(carol->minor_ver == 0);
    4.63 +
    4.64 +    // generate message
    4.65 +    pEp_identity* carol_to = new_identity(carol->address, NULL, NULL, NULL);
    4.66 +    
    4.67 +    message* msg = new_message(PEP_dir_outgoing);
    4.68 +    
    4.69 +    msg->from = alice;
    4.70 +    msg->to = new_identity_list(carol_to);
    4.71 +    msg->shortmsg = strdup("Boom shaka laka");
    4.72 +    msg->longmsg = strdup("Don't you get sick of these?");
    4.73 +    
    4.74 +    message* enc_msg = NULL;
    4.75 +
    4.76 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    4.77 +    TEST_ASSERT(status == PEP_STATUS_OK);
    4.78 +    
    4.79 +    // ensure sent message is in 1.0 format
    4.80 +    unsigned int major = 1;
    4.81 +    unsigned int minor = 0;
    4.82 +    TEST_ASSERT_MSG(verify_message_version_produced(enc_msg, &major, &minor),
    4.83 +                                                    (to_string(major) + "." + to_string(minor)).c_str());
    4.84 +    
    4.85 +    free_identity(carol);
    4.86 +    free_message(msg);
    4.87 +    free_message(enc_msg);
    4.88 +    TEST_ASSERT(true);
    4.89      
    4.90      // generate message
    4.91      
    4.92 @@ -155,11 +201,52 @@
    4.93  void Message2_1Tests::check_message2_1_recip_2_1() {
    4.94      // set recip to 2.1
    4.95      
    4.96 +    pEp_identity* alice = NULL;
    4.97 +    pEp_identity* carol = NULL;
    4.98 +    
    4.99 +    PEP_STATUS status = set_up_preset(session, ALICE, 
   4.100 +                                      true, true, true, true, true, &alice);
   4.101 +
   4.102 +    TEST_ASSERT(status == PEP_STATUS_OK);
   4.103 +    TEST_ASSERT(alice);
   4.104 +    
   4.105 +    status = set_up_preset(session, CAROL, 
   4.106 +                           true, true, false, false, false, &carol);
   4.107 +
   4.108 +    TEST_ASSERT(status == PEP_STATUS_OK);
   4.109 +    TEST_ASSERT(carol);
   4.110 +
   4.111 +    status = set_pEp_version(session, carol, 2, 1);
   4.112 +    
   4.113 +    // default should be 2.1 after setting pep status
   4.114 +    status = update_identity(session, carol);
   4.115 +    TEST_ASSERT(status == PEP_STATUS_OK);
   4.116 +    TEST_ASSERT(carol->major_ver == 2);
   4.117 +    TEST_ASSERT(carol->minor_ver == 1);
   4.118      // generate message
   4.119 +    pEp_identity* carol_to = new_identity(carol->address, NULL, NULL, NULL);
   4.120      
   4.121 -    // ensure sent message is in 2.1 format
   4.122 +    message* msg = new_message(PEP_dir_outgoing);
   4.123      
   4.124 +    msg->from = alice;
   4.125 +    msg->to = new_identity_list(carol_to);
   4.126 +    msg->shortmsg = strdup("Boom shaka laka");
   4.127 +    msg->longmsg = strdup("Don't you get sick of these?");
   4.128      
   4.129 +    message* enc_msg = NULL;
   4.130 +
   4.131 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   4.132 +    TEST_ASSERT(status == PEP_STATUS_OK);
   4.133 +    
   4.134 +    // ensure sent message is in 2.0 format
   4.135 +    unsigned int major = 2;
   4.136 +    unsigned int minor = 1;
   4.137 +    TEST_ASSERT_MSG(verify_message_version_produced(enc_msg, &major, &minor),
   4.138 +                                                    (to_string(major) + "." + to_string(minor)).c_str());
   4.139 +    
   4.140 +    free_identity(carol);
   4.141 +    free_message(msg);
   4.142 +    free_message(enc_msg);
   4.143      TEST_ASSERT(true);
   4.144  }
   4.145  
     5.1 --- a/test/src/util/test_util.cc	Wed Jun 26 17:37:18 2019 +0200
     5.2 +++ b/test/src/util/test_util.cc	Thu Jun 27 12:40:43 2019 +0200
     5.3 @@ -914,7 +914,11 @@
     5.4      retval = new_identity(email, NULL, user_id, name);
     5.5      if (!retval)
     5.6          return PEP_OUT_OF_MEMORY;
     5.7 -    
     5.8 +        
     5.9 +    // honestly probably happens anyway  
    5.10 +    if (set_ident && status == PEP_STATUS_OK)
    5.11 +        status = set_identity(session, retval);
    5.12 +
    5.13      if (set_own) {
    5.14          retval->me = true;
    5.15          status = set_own_key(session, retval, fpr);
    5.16 @@ -922,6 +926,7 @@
    5.17      
    5.18      if (set_pep && status == PEP_STATUS_OK)
    5.19          status = set_as_pEp_user(session, retval);
    5.20 +        
    5.21      if (trust && status == PEP_STATUS_OK) {
    5.22          if (!retval->me)
    5.23              status = update_identity(session, retval);
    5.24 @@ -931,9 +936,6 @@
    5.25          }
    5.26      }
    5.27      
    5.28 -    // honestly probably happens anyway  
    5.29 -    if (set_ident && status == PEP_STATUS_OK)
    5.30 -        status = set_identity(session, retval);
    5.31      
    5.32      if (ident)
    5.33          *ident = retval;