Merged in key_reset tests and minor doc changes; closing badly-named branch sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 16 Apr 2019 13:09:57 +0200
branchsync
changeset 3530abcad7cdfedc
parent 3508 55bada5a0fed
parent 3529 134adf5bd9b7
child 3532 4fff402f6c9f
Merged in key_reset tests and minor doc changes; closing badly-named branch
     1.1 --- a/src/key_reset.h	Thu Apr 11 18:57:19 2019 +0200
     1.2 +++ b/src/key_reset.h	Tue Apr 16 13:09:57 2019 +0200
     1.3 @@ -57,7 +57,7 @@
     1.4  //  parameters:
     1.5  //      session (in)            session handle
     1.6  //      user_id (in)            user_id for which the key reset should occur. If this 
     1.7 -//                              is the own user_id, for MUST NOT be NULL.
     1.8 +//                              is the own user_id, fpr MUST NOT be NULL.
     1.9  //      fpr (in)                fingerprint of key to reset.
    1.10  //                              If NULL, we reset all default 
    1.11  //                              keys for this user and all of its identities.
    1.12 @@ -76,6 +76,14 @@
    1.13  //                             own identities, and opportunistically communicate
    1.14  //                             key reset information to people we have recently 
    1.15  //                             contacted. 
    1.16 +//
    1.17 +// caveat: this will return PEP_CANNOT_FIND_IDENTITY if no own user yet exists.
    1.18 +//         HOWEVER, apps and adapters must decide if this is a reasonable state;
    1.19 +//         since the period where no own user exists will necessarily be very short
    1.20 +//         in most implementations, PEP_CANNOT_FIND_IDENTITY may be returned when 
    1.21 +//         there is some sort of DB corruption and we expect there to be an own user.
    1.22 +//         Apps are responsible for deciding whether or not this is an error condition;
    1.23 +//         one would expect that it generally is (rather than the uninitialised DB case)
    1.24  //                             
    1.25  //  parameters:
    1.26  //      session (in)            session handle
     2.1 --- a/test/include/KeyResetMessageTests.h	Thu Apr 11 18:57:19 2019 +0200
     2.2 +++ b/test/include/KeyResetMessageTests.h	Tue Apr 16 13:09:57 2019 +0200
     2.3 @@ -54,6 +54,12 @@
     2.4          void check_reset_ident_own_pub_fpr();
     2.5          void check_reset_ident_own_priv_fpr();
     2.6          void check_reset_ident_own_priv_no_fpr();
     2.7 +        void check_reset_user_other_no_fpr();
     2.8 +        void check_reset_user_other_fpr();
     2.9 +        void check_reset_user_own_fpr();
    2.10 +        void check_reset_user_no_fpr();
    2.11 +        void check_reset_all_own_keys();
    2.12 +        void check_reset_all_own_no_own();
    2.13  
    2.14          void send_setup();
    2.15          void receive_setup();     
     3.1 --- a/test/src/engine_tests/KeyResetMessageTests.cc	Thu Apr 11 18:57:19 2019 +0200
     3.2 +++ b/test/src/engine_tests/KeyResetMessageTests.cc	Tue Apr 16 13:09:57 2019 +0200
     3.3 @@ -65,6 +65,19 @@
     3.4                                                                        static_cast<Func>(&KeyResetMessageTests::check_reset_ident_own_priv_fpr)));
     3.5      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_ident_own_priv_no_fpr"),
     3.6                                                                        static_cast<Func>(&KeyResetMessageTests::check_reset_ident_own_priv_no_fpr)));
     3.7 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_user_other_no_fpr"),
     3.8 +                                                                      static_cast<Func>(&KeyResetMessageTests::check_reset_user_other_no_fpr)));
     3.9 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_user_other_fpr"),
    3.10 +                                                                      static_cast<Func>(&KeyResetMessageTests::check_reset_user_other_fpr)));
    3.11 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_user_own_fpr"),
    3.12 +                                                                      static_cast<Func>(&KeyResetMessageTests::check_reset_user_own_fpr)));
    3.13 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_user_no_fpr"),
    3.14 +                                                                      static_cast<Func>(&KeyResetMessageTests::check_reset_user_no_fpr)));
    3.15 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_all_own_keys"),
    3.16 +                                                                      static_cast<Func>(&KeyResetMessageTests::check_reset_all_own_keys)));
    3.17 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_all_own_no_own"),
    3.18 +                                                                      static_cast<Func>(&KeyResetMessageTests::check_reset_all_own_no_own)));
    3.19 +
    3.20      fake_this = this;                                                                  
    3.21      
    3.22      cached_messageToSend = &KeyResetMessageTests::message_send_callback;
    3.23 @@ -761,3 +774,421 @@
    3.24      TEST_ASSERT(alice_new_fpr && alice_new_fpr[0]);
    3.25      TEST_ASSERT_MSG(strcmp(alice_fpr, alice_new_fpr) != 0, alice_new_fpr);
    3.26  }
    3.27 +
    3.28 +void KeyResetMessageTests::check_reset_user_other_no_fpr() {
    3.29 +      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
    3.30 +      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
    3.31 +      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
    3.32 +      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
    3.33 +
    3.34 +      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
    3.35 +                                            NULL,
    3.36 +                                            "AlexID",
    3.37 +                                            "Alexander Braithwaite");
    3.38 +
    3.39 +/*                                          
    3.40 +test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
    3.41 +test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
    3.42 +test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
    3.43 +test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
    3.44 +*/
    3.45 +    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
    3.46 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
    3.47 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
    3.48 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
    3.49 +
    3.50 +    alex_id->fpr = pubkey1;
    3.51 +    status = trust_personal_key(session, alex_id);
    3.52 +    alex_id->fpr = pubkey3;
    3.53 +    status = trust_personal_key(session, alex_id);
    3.54 +    status = set_as_pEp_user(session, alex_id);
    3.55 +    alex_id->fpr = pubkey4;
    3.56 +    status = trust_personal_key(session, alex_id);
    3.57 +
    3.58 +    status = key_reset_user(session, alex_id->user_id, NULL);
    3.59 +
    3.60 +    stringlist_t* keylist = NULL;
    3.61 +
    3.62 +    alex_id->fpr = pubkey1;
    3.63 +    status = get_trust(session, alex_id);
    3.64 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
    3.65 +    status = find_keys(session, pubkey1, &keylist);
    3.66 +    TEST_ASSERT_MSG(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value),
    3.67 +                    (string(pubkey1) + " was unfortunately not deleted.").c_str());        
    3.68 +
    3.69 +    alex_id->fpr = pubkey2;
    3.70 +    status = get_trust(session, alex_id);
    3.71 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
    3.72 +    status = find_keys(session, pubkey2, &keylist);
    3.73 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
    3.74 +                    (string(pubkey2) + " was deleted and should not have been").c_str());        
    3.75 +
    3.76 +    alex_id->fpr = pubkey3;
    3.77 +    status = get_trust(session, alex_id);
    3.78 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
    3.79 +    status = find_keys(session, pubkey3, &keylist);
    3.80 +    TEST_ASSERT_MSG(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value),
    3.81 +                    (string(pubkey3) + " was unfortunately not deleted.").c_str());        
    3.82 +
    3.83 +    alex_id->fpr = pubkey4;
    3.84 +    status = get_trust(session, alex_id);    
    3.85 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
    3.86 +    status = find_keys(session, pubkey4, &keylist);
    3.87 +    TEST_ASSERT_MSG(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value),
    3.88 +                    (string(pubkey4) + " was unfortunately not deleted.").c_str());        
    3.89 +
    3.90 +    TEST_ASSERT(true);
    3.91 +}
    3.92 +
    3.93 +void KeyResetMessageTests::check_reset_user_other_fpr() {
    3.94 +      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
    3.95 +      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
    3.96 +      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
    3.97 +      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
    3.98 +
    3.99 +      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
   3.100 +                                            NULL,
   3.101 +                                            "AlexID",
   3.102 +                                            "Alexander Braithwaite");
   3.103 +
   3.104 +/*                                          
   3.105 +test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
   3.106 +test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
   3.107 +test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
   3.108 +test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
   3.109 +*/
   3.110 +    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
   3.111 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
   3.112 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
   3.113 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
   3.114 +
   3.115 +    alex_id->fpr = pubkey1;
   3.116 +    status = trust_personal_key(session, alex_id);
   3.117 +    alex_id->fpr = pubkey3;
   3.118 +    status = trust_personal_key(session, alex_id);
   3.119 +    status = set_as_pEp_user(session, alex_id);
   3.120 +    alex_id->fpr = pubkey4;
   3.121 +    status = trust_personal_key(session, alex_id);
   3.122 +
   3.123 +    status = key_reset_user(session, alex_id->user_id, pubkey3);
   3.124 +
   3.125 +    stringlist_t* keylist = NULL;
   3.126 +
   3.127 +    alex_id->fpr = pubkey1;
   3.128 +    status = get_trust(session, alex_id);
   3.129 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_pEp, tl_ct_string(alex_id->comm_type));
   3.130 +    status = find_keys(session, pubkey1, &keylist);
   3.131 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.132 +                    (string(pubkey1) + " was deleted and should not have been").c_str());        
   3.133 +
   3.134 +    free_stringlist(keylist);
   3.135 +    keylist = NULL;
   3.136 +    
   3.137 +    alex_id->fpr = pubkey2;
   3.138 +    status = get_trust(session, alex_id);
   3.139 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
   3.140 +    status = find_keys(session, pubkey2, &keylist);
   3.141 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.142 +                    (string(pubkey2) + " was deleted and should not have been").c_str());        
   3.143 +
   3.144 +    alex_id->fpr = pubkey3;
   3.145 +    status = get_trust(session, alex_id);
   3.146 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
   3.147 +    status = find_keys(session, pubkey3, &keylist);
   3.148 +    TEST_ASSERT_MSG(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value),
   3.149 +                    (string(pubkey3) + " was unfortunately not deleted.").c_str());        
   3.150 +
   3.151 +    alex_id->fpr = pubkey4;
   3.152 +    status = get_trust(session, alex_id);    
   3.153 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_pEp, tl_ct_string(alex_id->comm_type));
   3.154 +    status = find_keys(session, pubkey4, &keylist);
   3.155 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.156 +                    (string(pubkey4) + " was deleted and should not have been").c_str());        
   3.157 +
   3.158 +    // next line is for readability.
   3.159 +    alex_id->fpr = NULL;
   3.160 +    free_stringlist(keylist);
   3.161 +    free(pubkey1);
   3.162 +    free(pubkey2);
   3.163 +    free(pubkey3);
   3.164 +    free(pubkey4);
   3.165 +    free_identity(alex_id);
   3.166 +}
   3.167 +
   3.168 +void KeyResetMessageTests::check_reset_user_own_fpr() {
   3.169 +      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
   3.170 +      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
   3.171 +      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
   3.172 +      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
   3.173 +
   3.174 +      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
   3.175 +                                            NULL,
   3.176 +                                            "AlexID",
   3.177 +                                            "Alexander Braithwaite");
   3.178 +
   3.179 +/*                                          
   3.180 +test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
   3.181 +test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
   3.182 +test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
   3.183 +test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
   3.184 +*/
   3.185 +    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
   3.186 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
   3.187 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
   3.188 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
   3.189 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
   3.190 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
   3.191 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
   3.192 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xBDA17020_priv.asc");
   3.193 +
   3.194 +    alex_id->me = true;
   3.195 +    status = set_own_key(session, alex_id, pubkey1);
   3.196 +    status = set_own_key(session, alex_id, pubkey3);
   3.197 +    status = set_own_key(session, alex_id, pubkey4);
   3.198 +
   3.199 +    status = key_reset_user(session, alex_id->user_id, pubkey3);
   3.200 +
   3.201 +    alex_id->fpr = pubkey1;
   3.202 +    status = get_trust(session, alex_id);
   3.203 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_pEp, tl_ct_string(alex_id->comm_type));
   3.204 +    
   3.205 +    alex_id->fpr = pubkey2;
   3.206 +    status = get_trust(session, alex_id);
   3.207 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
   3.208 +
   3.209 +    stringlist_t* keylist = NULL;
   3.210 +    
   3.211 +    alex_id->fpr = pubkey3;
   3.212 +    status = get_trust(session, alex_id);
   3.213 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_mistrusted, tl_ct_string(alex_id->comm_type));
   3.214 +    status = find_keys(session, pubkey4, &keylist);
   3.215 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.216 +                    (string(pubkey3) + " was deleted and should not have been. Status is " + tl_status_string(status)).c_str());        
   3.217 +
   3.218 +    free_stringlist(keylist);
   3.219 +    keylist = NULL;
   3.220 +    
   3.221 +    alex_id->fpr = pubkey4;
   3.222 +    status = get_trust(session, alex_id);    
   3.223 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_pEp, tl_ct_string(alex_id->comm_type));
   3.224 +
   3.225 +    // next line is for readability.
   3.226 +    alex_id->fpr = NULL;
   3.227 +    free_stringlist(keylist);
   3.228 +    free(pubkey1);
   3.229 +    free(pubkey2);
   3.230 +    free(pubkey3);
   3.231 +    free(pubkey4);
   3.232 +    free_identity(alex_id);
   3.233 +}
   3.234 +
   3.235 +void KeyResetMessageTests::check_reset_user_no_fpr() {
   3.236 +      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
   3.237 +      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
   3.238 +      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
   3.239 +      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
   3.240 +
   3.241 +      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
   3.242 +                                            NULL,
   3.243 +                                            "AlexID",
   3.244 +                                            "Alexander Braithwaite");
   3.245 +
   3.246 +/*                                          
   3.247 +test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
   3.248 +test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
   3.249 +test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
   3.250 +test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
   3.251 +*/
   3.252 +    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
   3.253 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
   3.254 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
   3.255 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
   3.256 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
   3.257 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
   3.258 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
   3.259 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xBDA17020_priv.asc");
   3.260 +
   3.261 +    alex_id->me = true;
   3.262 +    status = set_own_key(session, alex_id, pubkey1);
   3.263 +    status = set_own_key(session, alex_id, pubkey3);
   3.264 +    status = set_own_key(session, alex_id, pubkey4);
   3.265 +
   3.266 +    status = key_reset_user(session, alex_id->user_id, NULL);
   3.267 +    
   3.268 +    TEST_ASSERT_MSG(status == PEP_ILLEGAL_VALUE, tl_status_string(status));
   3.269 +
   3.270 +    free(pubkey1);
   3.271 +    free(pubkey2);
   3.272 +    free(pubkey3);
   3.273 +    free(pubkey4);
   3.274 +    free_identity(alex_id);
   3.275 +}
   3.276 +
   3.277 +void KeyResetMessageTests::check_reset_all_own_keys() {
   3.278 +      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
   3.279 +      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
   3.280 +      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
   3.281 +      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
   3.282 +
   3.283 +      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
   3.284 +                                            NULL,
   3.285 +                                            "AlexID",
   3.286 +                                            "Alexander Braithwaite");
   3.287 +
   3.288 +/*                                          
   3.289 +test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
   3.290 +test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
   3.291 +test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
   3.292 +test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
   3.293 +*/
   3.294 +    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
   3.295 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
   3.296 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
   3.297 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
   3.298 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
   3.299 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
   3.300 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
   3.301 +    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xBDA17020_priv.asc");
   3.302 +
   3.303 +    alex_id->me = true;
   3.304 +    status = set_own_key(session, alex_id, pubkey1);
   3.305 +    status = set_own_key(session, alex_id, pubkey3);
   3.306 +    status = set_own_key(session, alex_id, pubkey4);
   3.307 +
   3.308 +    status = key_reset_all_own_keys(session);
   3.309 +
   3.310 +    stringlist_t* keylist = NULL;
   3.311 +
   3.312 +    alex_id->fpr = pubkey1;
   3.313 +    status = get_trust(session, alex_id);
   3.314 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_mistrusted, tl_ct_string(alex_id->comm_type));
   3.315 +    status = find_keys(session, pubkey1, &keylist);
   3.316 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.317 +                    (string(pubkey1) + " was deleted and should not have been. Status is " + tl_status_string(status)).c_str());        
   3.318 +    
   3.319 +    free_stringlist(keylist);
   3.320 +    keylist = NULL;
   3.321 +    
   3.322 +    alex_id->fpr = pubkey2;
   3.323 +    status = get_trust(session, alex_id);
   3.324 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
   3.325 +    status = find_keys(session, pubkey2, &keylist);
   3.326 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.327 +                    (string(pubkey2) + " was deleted and should not have been. Status is " + tl_status_string(status)).c_str());        
   3.328 +
   3.329 +    free_stringlist(keylist);
   3.330 +    keylist = NULL;
   3.331 +
   3.332 +    alex_id->fpr = pubkey3;
   3.333 +    status = get_trust(session, alex_id);
   3.334 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_mistrusted, tl_ct_string(alex_id->comm_type));
   3.335 +    status = find_keys(session, pubkey3, &keylist);
   3.336 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.337 +                    (string(pubkey3) + " was deleted and should not have been. Status is " + tl_status_string(status)).c_str());        
   3.338 +
   3.339 +    free_stringlist(keylist);
   3.340 +    keylist = NULL;
   3.341 +
   3.342 +    alex_id->fpr = pubkey4;
   3.343 +    status = get_trust(session, alex_id);    
   3.344 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_mistrusted, tl_ct_string(alex_id->comm_type));
   3.345 +    status = find_keys(session, pubkey4, &keylist);
   3.346 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.347 +                    (string(pubkey4) + " was deleted and should not have been. Status is " + tl_status_string(status)).c_str());        
   3.348 +
   3.349 +    free_stringlist(keylist);
   3.350 +    keylist = NULL;
   3.351 +
   3.352 +    alex_id->fpr = NULL;
   3.353 +    status = myself(session, alex_id);
   3.354 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   3.355 +
   3.356 +    TEST_ASSERT(alex_id->fpr);
   3.357 +    TEST_ASSERT(strcmp(alex_id->fpr, pubkey1));
   3.358 +    TEST_ASSERT(strcmp(alex_id->fpr, pubkey2));
   3.359 +    TEST_ASSERT(strcmp(alex_id->fpr, pubkey3));
   3.360 +    TEST_ASSERT(strcmp(alex_id->fpr, pubkey4));
   3.361 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_pEp, tl_ct_string(alex_id->comm_type));
   3.362 +    
   3.363 +    free(pubkey1);
   3.364 +    free(pubkey2);
   3.365 +    free(pubkey3);
   3.366 +    free(pubkey4);
   3.367 +    free_identity(alex_id);
   3.368 +}
   3.369 +
   3.370 +void KeyResetMessageTests::check_reset_all_own_no_own() {
   3.371 +      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
   3.372 +      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
   3.373 +      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
   3.374 +      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
   3.375 +
   3.376 +      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
   3.377 +                                            NULL,
   3.378 +                                            "AlexID",
   3.379 +                                            "Alexander Braithwaite");
   3.380 +
   3.381 +/*                                          
   3.382 +test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
   3.383 +test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
   3.384 +test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
   3.385 +test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
   3.386 +*/
   3.387 +    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
   3.388 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
   3.389 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
   3.390 +    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
   3.391 +
   3.392 +    alex_id->fpr = pubkey1;
   3.393 +    status = trust_personal_key(session, alex_id);
   3.394 +    alex_id->fpr = pubkey3;
   3.395 +    status = trust_personal_key(session, alex_id);
   3.396 +    alex_id->fpr = pubkey4;
   3.397 +    status = trust_personal_key(session, alex_id);
   3.398 +
   3.399 +    status = key_reset_all_own_keys(session);
   3.400 +    TEST_ASSERT_MSG(status == PEP_CANNOT_FIND_IDENTITY, tl_status_string(status));
   3.401 +
   3.402 +    stringlist_t* keylist = NULL;
   3.403 +
   3.404 +    alex_id->fpr = pubkey1;
   3.405 +    status = get_trust(session, alex_id);
   3.406 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_OpenPGP, tl_ct_string(alex_id->comm_type));
   3.407 +    status = find_keys(session, pubkey1, &keylist);
   3.408 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.409 +                    (string(pubkey1) + " was deleted and should not have been").c_str());        
   3.410 +
   3.411 +    free_stringlist(keylist);
   3.412 +    keylist = NULL;
   3.413 +    
   3.414 +    alex_id->fpr = pubkey2;
   3.415 +    status = get_trust(session, alex_id);
   3.416 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_unknown, tl_ct_string(alex_id->comm_type));
   3.417 +    status = find_keys(session, pubkey2, &keylist);
   3.418 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.419 +                    (string(pubkey2) + " was deleted and should not have been").c_str());        
   3.420 +
   3.421 +    alex_id->fpr = pubkey3;
   3.422 +    status = get_trust(session, alex_id);
   3.423 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_OpenPGP, tl_ct_string(alex_id->comm_type));
   3.424 +    status = find_keys(session, pubkey3, &keylist);
   3.425 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.426 +                    (string(pubkey3) + " was deleted and should not have been").c_str());        
   3.427 +
   3.428 +    alex_id->fpr = pubkey4;
   3.429 +    status = get_trust(session, alex_id);    
   3.430 +    TEST_ASSERT_MSG(alex_id->comm_type == PEP_ct_OpenPGP, tl_ct_string(alex_id->comm_type));
   3.431 +    status = find_keys(session, pubkey4, &keylist);
   3.432 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value),
   3.433 +                    (string(pubkey4) + " was deleted and should not have been").c_str());        
   3.434 +
   3.435 +    // next line is for readability.
   3.436 +    alex_id->fpr = NULL;
   3.437 +    free_stringlist(keylist);
   3.438 +    free(pubkey1);
   3.439 +    free(pubkey2);
   3.440 +    free(pubkey3);
   3.441 +    free(pubkey4);
   3.442 +    free_identity(alex_id);
   3.443 +
   3.444 +}