key reset tests now pass; mostly broken test assumptions, not code, though there was some. krista-local-7-Jan-2020
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Thu, 09 Jan 2020 08:43:26 +0100
branchkrista-local-7-Jan-2020
changeset 4316cad68db537c1
parent 4315 afece9dedddf
child 4317 c4b7c3eb348d
key reset tests now pass; mostly broken test assumptions, not code, though there was some.
src/key_reset.c
src/message_api.c
test/src/KeyResetMessageTest.cc
test/src/SyncTest.cc
test/src/test_util.cc
     1.1 --- a/src/key_reset.c	Wed Jan 08 13:20:06 2020 +0100
     1.2 +++ b/src/key_reset.c	Thu Jan 09 08:43:26 2020 +0100
     1.3 @@ -446,7 +446,10 @@
     1.4                      curr_ident->comm_type = PEP_ct_pEp_unconfirmed;
     1.5                  else    
     1.6                      curr_ident->comm_type = new_key_rating & (~PEP_ct_confirmed);
     1.7 -            }    
     1.8 +            }
     1.9 +            else
    1.10 +                curr_ident->comm_type = new_key_rating;
    1.11 +                
    1.12              status = set_identity(session, curr_ident);  
    1.13              if (status != PEP_STATUS_OK)
    1.14                  goto pEp_free; 
    1.15 @@ -827,8 +830,10 @@
    1.16              for (curr_key = keys; curr_key && curr_key->value; curr_key = curr_key->next) {
    1.17                  // FIXME: Is the ident really necessary?
    1.18                  status = key_reset(session, curr_key->value, tmp_ident);
    1.19 -                if (status != PEP_STATUS_OK)
    1.20 +                if (status != PEP_STATUS_OK && status != PEP_CANNOT_FIND_IDENTITY)
    1.21                      break;
    1.22 +                else 
    1.23 +                    status = PEP_STATUS_OK;
    1.24              }
    1.25          }
    1.26          goto pEp_free;
    1.27 @@ -919,12 +924,11 @@
    1.28                      // Ok, we've either now reset for each own identity with this key, or 
    1.29                      // we got an error and want to bail anyway.
    1.30                      goto pEp_free;
    1.31 -                }    
    1.32 +                }
    1.33 +                else 
    1.34 +                    return PEP_CANNOT_FIND_IDENTITY;
    1.35              }
    1.36              
    1.37 -            if (EMPTYSTR(tmp_ident->address)) {
    1.38 -                return PEP_UNKNOWN_ERROR; // FIXME - what case IS this?
    1.39 -            }
    1.40              
    1.41              // Ok, first we generate a new key.
    1.42              
     2.1 --- a/src/message_api.c	Wed Jan 08 13:20:06 2020 +0100
     2.2 +++ b/src/message_api.c	Thu Jan 09 08:43:26 2020 +0100
     2.3 @@ -4003,7 +4003,7 @@
     2.4                              goto pEp_error; // out of memory
     2.5  
     2.6                          identity_list* used_cc_ids = NULL;    
     2.7 -                        status = ident_list_intersect(my_rev_ids, msg->to, &used_cc_ids);
     2.8 +                        status = ident_list_intersect(my_rev_ids, msg->cc, &used_cc_ids);
     2.9                          if (status != PEP_STATUS_OK)
    2.10                              goto pEp_error;
    2.11  
     3.1 --- a/test/src/KeyResetMessageTest.cc	Wed Jan 08 13:20:06 2020 +0100
     3.2 +++ b/test/src/KeyResetMessageTest.cc	Thu Jan 09 08:43:26 2020 +0100
     3.3 @@ -967,8 +967,10 @@
     3.4  
     3.5      alex_id->me = true;
     3.6      status = set_own_key(session, alex_id, pubkey1);
     3.7 +    status = set_own_key(session, alex_id, pubkey4);
     3.8      status = set_own_key(session, alex_id, pubkey3);
     3.9 -    status = set_own_key(session, alex_id, pubkey4);
    3.10 +    
    3.11 +    status = myself(session, alex_id);
    3.12  
    3.13      status = key_reset_user(session, alex_id->user_id, pubkey3);
    3.14  
    3.15 @@ -1050,22 +1052,22 @@
    3.16  
    3.17  // FAIL
    3.18  TEST_F(KeyResetMessageTest, check_reset_all_own_keys) {
    3.19 -      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
    3.20 -      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
    3.21 -      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
    3.22 -      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
    3.23 +    char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
    3.24 +    char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
    3.25 +    char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
    3.26 +    char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
    3.27  
    3.28 -      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
    3.29 -                                            NULL,
    3.30 -                                            "AlexID",
    3.31 -                                            "Alexander Braithwaite");
    3.32 +    pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
    3.33 +                                         NULL,
    3.34 +                                         "AlexID",
    3.35 +                                         "Alexander Braithwaite");
    3.36  
    3.37 -/*
    3.38 -test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
    3.39 -test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
    3.40 -test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
    3.41 -test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
    3.42 -*/
    3.43 +    pEp_identity* alex_id2 = new_identity("pep.test.alexander6@darthmama.org",
    3.44 +                                          NULL,
    3.45 +                                          "AlexID",
    3.46 +                                          "Alexander Braithwaite");
    3.47 +
    3.48 +
    3.49      PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
    3.50      status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
    3.51      status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
    3.52 @@ -1076,9 +1078,14 @@
    3.53      status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xBDA17020_priv.asc");
    3.54  
    3.55      alex_id->me = true;
    3.56 +    status = set_own_key(session, alex_id, pubkey3);
    3.57 +    status = myself(session, alex_id);
    3.58      status = set_own_key(session, alex_id, pubkey1);
    3.59 -    status = set_own_key(session, alex_id, pubkey3);
    3.60 -    status = set_own_key(session, alex_id, pubkey4);
    3.61 +    status = myself(session, alex_id);
    3.62 +    
    3.63 +    alex_id2->me = true;
    3.64 +    status = set_own_key(session, alex_id2, pubkey4);
    3.65 +    status = myself(session, alex_id2);
    3.66  
    3.67      status = key_reset_all_own_keys(session);
    3.68  
    3.69 @@ -1104,16 +1111,16 @@
    3.70  
    3.71      alex_id->fpr = pubkey3;
    3.72      status = get_trust(session, alex_id);
    3.73 -    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
    3.74 +    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
    3.75      status = find_keys(session, pubkey3, &keylist);
    3.76      ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
    3.77  
    3.78      free_stringlist(keylist);
    3.79      keylist = NULL;
    3.80  
    3.81 -    alex_id->fpr = pubkey4;
    3.82 -    status = get_trust(session, alex_id);
    3.83 -    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
    3.84 +    alex_id2->fpr = pubkey4;
    3.85 +    status = get_trust(session, alex_id2);
    3.86 +    ASSERT_EQ(alex_id2->comm_type , PEP_ct_mistrusted);
    3.87      status = find_keys(session, pubkey4, &keylist);
    3.88      ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
    3.89  
    3.90 @@ -1132,6 +1139,14 @@
    3.91      ASSERT_STRNE(alex_id->fpr, pubkey4);
    3.92      ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
    3.93  
    3.94 +    alex_id2->fpr = NULL;
    3.95 +    status = myself(session, alex_id2);
    3.96 +    ASSERT_EQ(status , PEP_STATUS_OK);
    3.97 +    ASSERT_STRNE(alex_id2->fpr, pubkey1);
    3.98 +    ASSERT_STRNE(alex_id2->fpr, pubkey2);
    3.99 +    ASSERT_STRNE(alex_id2->fpr, pubkey3);
   3.100 +    ASSERT_STRNE(alex_id2->fpr, pubkey4);
   3.101 +
   3.102      free(pubkey1);
   3.103      free(pubkey2);
   3.104      free(pubkey3);
     4.1 --- a/test/src/SyncTest.cc	Wed Jan 08 13:20:06 2020 +0100
     4.2 +++ b/test/src/SyncTest.cc	Thu Jan 09 08:43:26 2020 +0100
     4.3 @@ -44,8 +44,9 @@
     4.4  void Sync_Adapter::processing()
     4.5  {
     4.6      output_stream << "waiting for processing\n";
     4.7 +    const struct timespec arr[] = {{0, 100000000L}};
     4.8      while (!q.empty()) {
     4.9 -        nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
    4.10 +        nanosleep(arr, NULL);
    4.11      }
    4.12  }
    4.13  
    4.14 @@ -90,7 +91,8 @@
    4.15              }
    4.16              i = 0;
    4.17          }
    4.18 -        nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
    4.19 +        const struct timespec arr[] = {{0, 100000000L}};        
    4.20 +        nanosleep(arr, NULL);
    4.21      }
    4.22  
    4.23      if (timeout)
     5.1 --- a/test/src/test_util.cc	Wed Jan 08 13:20:06 2020 +0100
     5.2 +++ b/test/src/test_util.cc	Thu Jan 09 08:43:26 2020 +0100
     5.3 @@ -25,6 +25,8 @@
     5.4  
     5.5  std::string _main_test_home_dir;
     5.6  
     5.7 +#define BUF_MAX_PATHLEN 4097
     5.8 +
     5.9  bool is_pEpmsg(const message *msg)
    5.10  {
    5.11      for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    5.12 @@ -53,7 +55,6 @@
    5.13  }
    5.14  
    5.15  std::string get_main_test_home_dir() {
    5.16 -    size_t BUF_MAX_PATHLEN = 4097;
    5.17      char buf[BUF_MAX_PATHLEN];// Linux max path size...
    5.18  
    5.19      if (_main_test_home_dir.empty()) {