Another test bites the dust sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 30 Aug 2019 10:05:36 +0200
branchsync
changeset 4031cbedd24a8359
parent 4030 ba2eed4caacf
child 4032 0f2b0543b90a
Another test bites the dust
test/src/NewUpdateIdAndMyselfTests.cc.FIXME
test/src/UpdateIdAndMyselfTest.cc
     1.1 --- a/test/src/NewUpdateIdAndMyselfTests.cc.FIXME	Thu Aug 29 22:28:17 2019 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,650 +0,0 @@
     1.4 -// This file is under GNU General Public License 3.0
     1.5 -// see LICENSE.txt
     1.6 -
     1.7 -#include <stdlib.h>
     1.8 -#include <string>
     1.9 -#include <iostream>
    1.10 -#include <fstream>
    1.11 -#include <cstring> // for strcmp()
    1.12 -#include "TestConstants.h"
    1.13 -
    1.14 -#include "pEpEngine.h"
    1.15 -#include "message_api.h"
    1.16 -#include "keymanagement.h"
    1.17 -#include "test_util.h"
    1.18 -
    1.19 -#include <cpptest.h>
    1.20 -#include "EngineTestSessionSuite.h"
    1.21 -#include "NewUpdateIdAndMyselfTests.h"
    1.22 -
    1.23 -using namespace std;
    1.24 -
    1.25 -NewUpdateIdAndMyselfTests::NewUpdateIdAndMyselfTests(string suitename, string test_home_dir) :
    1.26 -    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
    1.27 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::myself_no_record_no_input_fpr"),
    1.28 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::myself_no_record_no_input_fpr)));
    1.29 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::myself_no_input_fpr_w_record"),
    1.30 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::myself_no_input_fpr_w_record)));
    1.31 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::myself_no_input_fpr_diff_user_id_w_record"),
    1.32 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::myself_no_input_fpr_diff_user_id_w_record)));
    1.33 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::myself_replace_fpr"),
    1.34 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::myself_replace_fpr)));
    1.35 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::myself_replace_fpr_revoke_key"),
    1.36 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::myself_replace_fpr_revoke_key)));
    1.37 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_username"),
    1.38 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_username)));
    1.39 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_new_username"),
    1.40 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_new_username)));
    1.41 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_only"),
    1.42 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_only)));
    1.43 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_use_address_username_only"),
    1.44 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_use_address_username_only)));
    1.45 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_use_address_only"),
    1.46 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_use_address_only)));
    1.47 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_use_address_only_on_own_ident"),
    1.48 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_use_address_only_on_own_ident)));
    1.49 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_non_existent_user_id_address"),
    1.50 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_non_existent_user_id_address)));
    1.51 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_address_username_userid_no_record"),
    1.52 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_address_username_userid_no_record)));
    1.53 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_address_username_no_record"),
    1.54 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_address_username_no_record)));
    1.55 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::update_identity_address_only_multiple_records"),
    1.56 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::update_identity_address_only_multiple_records)));
    1.57 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::key_elect_expired_key"),
    1.58 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::key_elect_expired_key)));
    1.59 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::key_elect_only_revoked_mistrusted"),
    1.60 -                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::key_elect_only_revoked_mistrusted)));
    1.61 -}
    1.62 -
    1.63 -void NewUpdateIdAndMyselfTests::setup() {
    1.64 -    EngineTestSessionSuite::setup();
    1.65 -    if (on_test_number == 1) {
    1.66 -        uniqname = strdup("AAAAtestuser@testdomain.org");
    1.67 -        srandom(time(NULL));
    1.68 -        for(int i=0; i < 4;i++)
    1.69 -        uniqname[i] += random() & 0xf;
    1.70 -        
    1.71 -        own_user_id = get_new_uuid();
    1.72 -        start_username = strdup("Unser Testkandidat");
    1.73 -        generated_fpr = NULL;
    1.74 -        default_own_id = NULL;
    1.75 -        alias_id = NULL;
    1.76 -        new_fpr = NULL;
    1.77 -        alex_address = "pep.test.alexander@peptest.ch";
    1.78 -        alex_fpr = "3AD9F60FAEB22675DB873A1362D6981326B54E4E";
    1.79 -        alex_userid = "Alex";
    1.80 -        alex_username = "SuperDuperAlex";
    1.81 -    }    
    1.82 -}
    1.83 -
    1.84 -void NewUpdateIdAndMyselfTests::tear_down() {
    1.85 -    if (on_test_number == number_of_tests) {
    1.86 -        free(uniqname);
    1.87 -        free(own_user_id);
    1.88 -        free(start_username);
    1.89 -        free(generated_fpr);
    1.90 -        free(default_own_id);
    1.91 -        free(alias_id);
    1.92 -        free(new_fpr);
    1.93 -    }
    1.94 -    EngineTestSessionSuite::tear_down();
    1.95 -}
    1.96 -
    1.97 -void NewUpdateIdAndMyselfTests::myself_no_record_no_input_fpr() {
    1.98 -    PEP_STATUS status = PEP_STATUS_OK;
    1.99 -    
   1.100 -    pEp_identity * new_me = new_identity(uniqname, NULL, own_user_id, start_username);
   1.101 -    
   1.102 -    status = myself(session, new_me);
   1.103 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.104 -    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
   1.105 -    
   1.106 -    generated_fpr = strdup(new_me->fpr);
   1.107 -    
   1.108 -    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
   1.109 -    
   1.110 -    free_identity(new_me);
   1.111 -}
   1.112 -
   1.113 -void NewUpdateIdAndMyselfTests::myself_no_input_fpr_w_record() {
   1.114 -    PEP_STATUS status = PEP_STATUS_OK;
   1.115 -    
   1.116 -    pEp_identity* new_me = new_identity(uniqname, NULL, own_user_id, NULL);
   1.117 -    status = myself(session, new_me);
   1.118 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.119 -    
   1.120 -    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
   1.121 -    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) == 0), "strcmp(new_me->fpr, generated_fpr) == 0");
   1.122 -    TEST_ASSERT_MSG((new_me->username), "new_me->username");
   1.123 -    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
   1.124 -    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
   1.125 -    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
   1.126 -    
   1.127 -    default_own_id = NULL;
   1.128 -    status = get_userid_alias_default(session, own_user_id, &default_own_id);
   1.129 -    if (status == PEP_CANNOT_FIND_ALIAS) {
   1.130 -        // Ok, we presume our own id above is the default (should be true if there was no existing DB as in test env)
   1.131 -        default_own_id = strdup(own_user_id);
   1.132 -    }
   1.133 -
   1.134 -    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
   1.135 -    
   1.136 -    output_stream << "PASS: myself() retrieved the correct fpr, username and default user id" << endl << endl;
   1.137 -
   1.138 -    free_identity(new_me);
   1.139 -}
   1.140 -
   1.141 -void NewUpdateIdAndMyselfTests::myself_no_input_fpr_diff_user_id_w_record() {
   1.142 -    PEP_STATUS status = PEP_STATUS_OK;
   1.143 -    alias_id = strdup("Huss Es El Mejor Presidente Del Mundo!");
   1.144 -
   1.145 -    pEp_identity* new_me = new_identity(uniqname, NULL, alias_id, NULL);
   1.146 -    status = myself(session, new_me);
   1.147 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.148 -    
   1.149 -    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
   1.150 -    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) == 0), "strcmp(new_me->fpr, generated_fpr) == 0");
   1.151 -    TEST_ASSERT_MSG((new_me->username), "new_me->username");
   1.152 -    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
   1.153 -    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
   1.154 -    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
   1.155 -    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
   1.156 -    
   1.157 -    char* tmp_def = NULL;
   1.158 -    
   1.159 -    status = get_userid_alias_default(session, alias_id, &tmp_def);
   1.160 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.161 -    TEST_ASSERT_MSG((strcmp(tmp_def, default_own_id) == 0), "strcmp(tmp_def, default_own_id) == 0");
   1.162 -
   1.163 -    output_stream << "PASS: myself() retrieved the correct fpr, username and default user id, and put the right alias in for the default";
   1.164 -    output_stream << endl << endl;
   1.165 -    
   1.166 -    free(tmp_def);
   1.167 -    free_identity(new_me); 
   1.168 -}
   1.169 -
   1.170 -void NewUpdateIdAndMyselfTests::myself_replace_fpr() {
   1.171 -    PEP_STATUS status = PEP_STATUS_OK;
   1.172 -    pEp_identity* new_me = new_identity(uniqname, NULL, alias_id, start_username);
   1.173 -    status = generate_keypair(session, new_me);
   1.174 -    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
   1.175 -    
   1.176 -    output_stream << "Generated fingerprint ";
   1.177 -    output_stream << new_me->fpr << "\n";
   1.178 -
   1.179 -    new_fpr = strdup(new_me->fpr);
   1.180 -
   1.181 -    status = set_own_key(session, new_me, new_fpr);
   1.182 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.183 -    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
   1.184 -    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) != 0), "strcmp(new_me->fpr, generated_fpr) != 0");
   1.185 -    TEST_ASSERT_MSG((strcmp(new_me->fpr, new_fpr) == 0), "strcmp(new_me->fpr, new_fpr) == 0");
   1.186 -    TEST_ASSERT_MSG((new_me->username), "new_me->username");
   1.187 -    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
   1.188 -    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
   1.189 -    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
   1.190 -    TEST_ASSERT_MSG((new_me->me), "new_me->me");
   1.191 -    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
   1.192 -
   1.193 -    output_stream << "PASS: myself() set and retrieved the new fpr, username and default user id, and put the right alias in for the default";
   1.194 -    output_stream << endl << endl;
   1.195 -
   1.196 -    // since that worked, we'll set it back as the default
   1.197 -    free(new_me->fpr);
   1.198 -    new_me->fpr = strdup(generated_fpr);
   1.199 -    new_me->comm_type = PEP_ct_unknown;
   1.200 -    status = set_own_key(session, new_me, generated_fpr);
   1.201 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.202 -    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) == 0), "strcmp(new_me->fpr, generated_fpr) == 0");
   1.203 -    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");    
   1.204 -    free_identity(new_me);
   1.205 -}
   1.206 -
   1.207 -void NewUpdateIdAndMyselfTests::myself_replace_fpr_revoke_key() {
   1.208 -    PEP_STATUS status = PEP_STATUS_OK;
   1.209 -    status = revoke_key(session, generated_fpr, "Because it's fun");
   1.210 -    TEST_ASSERT (status == PEP_STATUS_OK);
   1.211 -    
   1.212 -    pEp_identity* new_me = new_identity(uniqname, NULL, alias_id, start_username);
   1.213 -    
   1.214 -    status = set_own_key(session, new_me, new_fpr);
   1.215 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.216 -    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
   1.217 -    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) != 0), "strcmp(new_me->fpr, generated_fpr) != 0");
   1.218 -    TEST_ASSERT_MSG((new_me->username), "new_me->username");
   1.219 -    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
   1.220 -    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
   1.221 -    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
   1.222 -    TEST_ASSERT_MSG((new_me->me), "new_me->me");
   1.223 -    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
   1.224 -    
   1.225 -    output_stream << "PASS: myself() retrieved the new fpr, username and default user id, and put the right alias in for the default";
   1.226 -    output_stream << endl << endl;
   1.227 -    free_identity(new_me);
   1.228 -}
   1.229 -
   1.230 -void NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_username() {
   1.231 -    // 1. create original identity
   1.232 -    const char* alex_address = "pep.test.alexander@peptest.ch";
   1.233 -    const char* alex_fpr = "3AD9F60FAEB22675DB873A1362D6981326B54E4E";
   1.234 -    const char* alex_userid = "Alex";
   1.235 -    const char* alex_username = "SuperDuperAlex";
   1.236 -    const string alex_pub_key = slurp("test_keys/pub/pep.test.alexander-0x26B54E4E_pub.asc");
   1.237 -    
   1.238 -    PEP_STATUS statuspub = import_key(session, alex_pub_key.c_str(), alex_pub_key.length(), NULL);
   1.239 -    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   1.240 -
   1.241 -    pEp_identity* alex = new_identity(alex_address, alex_fpr, alex_userid, alex_username);
   1.242 -
   1.243 -    // 2. set identity
   1.244 -    PEP_STATUS status = set_identity(session, alex);
   1.245 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.246 -    free_identity(alex);
   1.247 -            
   1.248 -    alex = new_identity(alex_address, NULL, alex_userid, alex_username); 
   1.249 -    status = update_identity(session, alex);
   1.250 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.251 -    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
   1.252 -    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
   1.253 -    TEST_ASSERT_MSG((alex->username), "alex->username");
   1.254 -    TEST_ASSERT_MSG((strcmp(alex->username, alex_username) == 0), "strcmp(alex->username, alex_username) == 0");
   1.255 -    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
   1.256 -    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
   1.257 -    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
   1.258 -    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
   1.259 -    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
   1.260 -
   1.261 -    output_stream << "PASS: update_identity() correctly retrieved extant record with matching address, id, and username" << endl << endl;
   1.262 -    free_identity(alex);
   1.263 -}
   1.264 -
   1.265 -void NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_new_username() {
   1.266 -    PEP_STATUS status = PEP_STATUS_OK;
   1.267 -        
   1.268 -    const string alex_pub_key = slurp("test_keys/pub/pep.test.alexander-0x26B54E4E_pub.asc");
   1.269 -    
   1.270 -    PEP_STATUS statuspub = import_key(session, alex_pub_key.c_str(), alex_pub_key.length(), NULL);
   1.271 -    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   1.272 -
   1.273 -    pEp_identity* alex = new_identity(alex_address, alex_fpr, alex_userid, alex_username);
   1.274 -
   1.275 -    // 2. set identity
   1.276 -    status = set_identity(session, alex);
   1.277 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.278 -    free_identity(alex);
   1.279 -            
   1.280 -    alex = new_identity(alex_address, NULL, alex_userid, alex_username); 
   1.281 -    status = update_identity(session, alex);
   1.282 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.283 -    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
   1.284 -    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
   1.285 -    TEST_ASSERT_MSG((alex->username), "alex->username");
   1.286 -    TEST_ASSERT_MSG((strcmp(alex->username, alex_username) == 0), "strcmp(alex->username, alex_username) == 0");
   1.287 -    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
   1.288 -    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
   1.289 -    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
   1.290 -    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
   1.291 -    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
   1.292 -
   1.293 -    output_stream << "PASS: update_identity() correctly retrieved extant record with matching address, id, and username" << endl << endl;
   1.294 -    free_identity(alex);
   1.295 -}
   1.296 -
   1.297 -void NewUpdateIdAndMyselfTests::update_identity_w_matching_address_user_id_only() {
   1.298 -    PEP_STATUS status = PEP_STATUS_OK;
   1.299 -    new_username = "Test Patchy";
   1.300 -            
   1.301 -    pEp_identity* alex = new_identity(alex_address, NULL, alex_userid, new_username);
   1.302 -    status = update_identity(session, alex);
   1.303 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.304 -    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
   1.305 -    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
   1.306 -    TEST_ASSERT_MSG((alex->username), "alex->username");
   1.307 -    TEST_ASSERT_MSG((strcmp(alex->username, new_username) == 0), "strcmp(alex->username, new_username) == 0");
   1.308 -    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
   1.309 -    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
   1.310 -    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
   1.311 -    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
   1.312 -    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
   1.313 -
   1.314 -    free_identity(alex);
   1.315 -}
   1.316 -
   1.317 -void NewUpdateIdAndMyselfTests::update_identity_use_address_username_only() {
   1.318 -    pEp_identity* alex = new_identity(alex_address, NULL, NULL, new_username); 
   1.319 -    PEP_STATUS status = update_identity(session, alex);
   1.320 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.321 -    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
   1.322 -    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
   1.323 -    TEST_ASSERT_MSG((alex->username), "alex->username");
   1.324 -    TEST_ASSERT_MSG((strcmp(alex->username, new_username) == 0), "strcmp(alex->username, new_username) == 0");
   1.325 -    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
   1.326 -    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
   1.327 -    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
   1.328 -    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
   1.329 -    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
   1.330 -
   1.331 -    output_stream << "PASS: update_identity() correctly retrieved extant record with matching address and username" << endl << endl;
   1.332 -    free_identity(alex);
   1.333 -}
   1.334 -
   1.335 -void NewUpdateIdAndMyselfTests::update_identity_use_address_only() {
   1.336 -    pEp_identity* alex = new_identity(alex_address, NULL, NULL, NULL); 
   1.337 -    PEP_STATUS status = update_identity(session, alex);
   1.338 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.339 -    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
   1.340 -    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
   1.341 -    TEST_ASSERT_MSG((alex->username), "alex->username");
   1.342 -    TEST_ASSERT_MSG((strcmp(alex->username, new_username) == 0), "strcmp(alex->username, new_username) == 0");
   1.343 -    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
   1.344 -    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
   1.345 -    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
   1.346 -    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
   1.347 -    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
   1.348 -
   1.349 -    output_stream << "PASS: update_identity() correctly retrieved extant record with just matching address. Retrieved previously patched username." << endl << endl;
   1.350 -    free_identity(alex);
   1.351 -}
   1.352 -
   1.353 -void NewUpdateIdAndMyselfTests::update_identity_use_address_only_on_own_ident() {
   1.354 -    pEp_identity* somebody = new_identity(uniqname, NULL, NULL, NULL); 
   1.355 -    PEP_STATUS status = update_identity(session, somebody);
   1.356 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.357 -    myself(session, somebody);
   1.358 -    TEST_ASSERT_MSG((somebody->fpr), "somebody->fpr");
   1.359 -    TEST_ASSERT_MSG((strcmp(somebody->fpr, new_fpr) == 0), "strcmp(somebody->fpr, new_fpr) == 0");
   1.360 -    TEST_ASSERT_MSG((somebody->username), "somebody->username");
   1.361 -    TEST_ASSERT_MSG((strcmp(somebody->username, start_username) == 0), "strcmp(somebody->username, start_username) == 0");
   1.362 -    TEST_ASSERT_MSG((somebody->user_id), "somebody->user_id");
   1.363 -    TEST_ASSERT_MSG((strcmp(somebody->user_id, default_own_id) == 0), "strcmp(somebody->user_id, default_own_id) == 0");
   1.364 -    TEST_ASSERT_MSG((somebody->me), "somebody->me"); // true in this case, as it was an own identity
   1.365 -    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_pEp), "somebody->comm_type == PEP_ct_pEp");
   1.366 -    TEST_ASSERT_MSG((strcmp(somebody->address, uniqname) == 0), "strcmp(somebody->address, uniqname) == 0");
   1.367 -    
   1.368 -    output_stream << "PASS: update_identity() retrieved the right identity information given just an address";
   1.369 -    output_stream << endl << endl;
   1.370 -
   1.371 -    free_identity(somebody);
   1.372 -}
   1.373 -
   1.374 -void NewUpdateIdAndMyselfTests::update_identity_non_existent_user_id_address() {
   1.375 -    pEp_identity* somebody = new_identity("nope@nope.nope", NULL, "some_user_id", NULL); 
   1.376 -    PEP_STATUS status = update_identity(session, somebody);
   1.377 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.378 -    TEST_ASSERT_MSG((!somebody->fpr), "!somebody->fpr");
   1.379 -    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_key_not_found), "somebody->comm_type == PEP_ct_key_not_found");
   1.380 -    
   1.381 -    output_stream << "PASS: update_identity() returns identity with no key and unknown comm type" << endl << endl;
   1.382 -
   1.383 -    free_identity(somebody);
   1.384 -}
   1.385 -
   1.386 -void NewUpdateIdAndMyselfTests::update_identity_address_username_userid_no_record() {
   1.387 -    const char* rando_name = "Pickley BoofBoof";
   1.388 -    const char* rando_userid = "Boofy";
   1.389 -    const char* rando_address = "boof@pickles.org";
   1.390 -    pEp_identity* somebody = new_identity(rando_address, NULL, rando_userid, rando_name);
   1.391 -    PEP_STATUS status = update_identity(session, somebody);
   1.392 -
   1.393 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.394 -    TEST_ASSERT_MSG((!somebody->fpr || somebody->fpr[0] == '\0'), "!somebody->fpr || somebody->fpr[0] == '\0'");
   1.395 -    TEST_ASSERT_MSG((somebody->username), "somebody->username");
   1.396 -    TEST_ASSERT_MSG((strcmp(somebody->username, rando_name) == 0), "strcmp(somebody->username, rando_name) == 0");
   1.397 -    TEST_ASSERT_MSG((somebody->user_id), "somebody->user_id");
   1.398 -    TEST_ASSERT_MSG((strcmp(somebody->user_id, rando_userid) == 0), "strcmp(somebody->user_id, rando_userid) == 0"); // ???
   1.399 -    TEST_ASSERT_MSG((!somebody->me), "!somebody->me"); 
   1.400 -    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_key_not_found), "somebody->comm_type == PEP_ct_key_not_found");
   1.401 -    TEST_ASSERT_MSG((strcmp(somebody->address, rando_address) == 0), "strcmp(somebody->address, rando_address) == 0");
   1.402 -
   1.403 -    output_stream << "PASS: update_identity() correctly created record with no key" << endl << endl;
   1.404 -    free_identity(somebody);
   1.405 -}
   1.406 -
   1.407 -void NewUpdateIdAndMyselfTests::update_identity_address_username_no_record() {
   1.408 -    const char* rando2_name = "Pickles BoofyBoof";
   1.409 -    const char* rando2_address = "boof2@pickles.org";
   1.410 -    pEp_identity* somebody = new_identity(rando2_address, NULL, NULL, rando2_name);
   1.411 -    PEP_STATUS status = update_identity(session, somebody);
   1.412 -    const char* expected_rando2_userid = "TOFU_boof2@pickles.org";
   1.413 -
   1.414 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.415 -    TEST_ASSERT_MSG((!somebody->fpr || somebody->fpr[0] == '\0'), "!somebody->fpr || somebody->fpr[0] == '\0'");
   1.416 -    TEST_ASSERT_MSG((somebody->username), "somebody->username");
   1.417 -    TEST_ASSERT_MSG((strcmp(somebody->username, rando2_name) == 0), "strcmp(somebody->username, rando2_name) == 0");
   1.418 -    TEST_ASSERT_MSG((somebody->user_id), "somebody->user_id");
   1.419 -    TEST_ASSERT_MSG((strcmp(somebody->user_id, expected_rando2_userid) == 0), "strcmp(somebody->user_id, expected_rando2_userid) == 0"); // ???
   1.420 -    TEST_ASSERT_MSG((!somebody->me), "!somebody->me"); 
   1.421 -    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_key_not_found), "somebody->comm_type == PEP_ct_key_not_found");
   1.422 -    TEST_ASSERT_MSG((strcmp(somebody->address, rando2_address) == 0), "strcmp(somebody->address, rando2_address) == 0");
   1.423 -
   1.424 -    output_stream << "PASS: update_identity() correctly created record with no key" << endl << endl;
   1.425 -    free_identity(somebody);
   1.426 -}
   1.427 -
   1.428 -
   1.429 -void NewUpdateIdAndMyselfTests::update_identity_address_only_multiple_records() {
   1.430 -    PEP_STATUS status = PEP_STATUS_OK;
   1.431 -    // 1. create identity
   1.432 -    const char* bella_address = "pep.test.bella@peptest.ch";
   1.433 -    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
   1.434 -    const char* bella_userid = "TOFU_pep.test.bella@peptest.ch"; // simulate temp ID
   1.435 -    const char* bella_username = "Annabella the Great";
   1.436 -    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");
   1.437 -    
   1.438 -    PEP_STATUS statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
   1.439 -    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   1.440 -
   1.441 -    pEp_identity* bella = new_identity(bella_address, bella_fpr, bella_userid, bella_username);
   1.442 -    
   1.443 -    // 2. set identity
   1.444 -    status = set_identity(session, bella);
   1.445 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.446 -    free_identity(bella);
   1.447 -    
   1.448 -    const char* not_my_userid = "Bad Company";
   1.449 -            
   1.450 -    bella = new_identity(bella_address, NULL, not_my_userid, bella_username); 
   1.451 -    status = update_identity(session, bella);
   1.452 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.453 -    TEST_ASSERT_MSG((bella->fpr), "bella->fpr");
   1.454 -    TEST_ASSERT_MSG((strcmp(bella->fpr, bella_fpr) == 0), "strcmp(bella->fpr, bella_fpr) == 0");
   1.455 -    TEST_ASSERT_MSG((bella->username), "bella->username");
   1.456 -    TEST_ASSERT_MSG((strcmp(bella->username, bella_username) == 0), "strcmp(bella->username, bella_username) == 0");
   1.457 -    TEST_ASSERT_MSG((bella->user_id), "bella->user_id");
   1.458 -    TEST_ASSERT_MSG((strcmp(bella->user_id, not_my_userid) == 0), "strcmp(bella->user_id, not_my_userid) == 0"); // ???
   1.459 -    TEST_ASSERT_MSG((!bella->me), "!bella->me"); 
   1.460 -    TEST_ASSERT_MSG((bella->comm_type == PEP_ct_OpenPGP_unconfirmed), "bella->comm_type == PEP_ct_OpenPGP_unconfirmed");
   1.461 -    TEST_ASSERT_MSG((strcmp(bella->address, bella_address) == 0), "strcmp(bella->address, bella_address) == 0");
   1.462 -
   1.463 -    free_identity(bella);
   1.464 -    
   1.465 -    // ???? 
   1.466 -    const char* bella_id_2 = "Bella2";
   1.467 -    bella = new_identity(bella_address, NULL, bella_id_2, bella_username);
   1.468 -    
   1.469 -    status = set_identity(session, bella);
   1.470 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.471 -    free_identity(bella);
   1.472 -                
   1.473 -    bella = new_identity(bella_address, NULL, NULL, NULL); 
   1.474 -    status = update_identity(session, bella);
   1.475 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.476 -
   1.477 -}
   1.478 -
   1.479 -void NewUpdateIdAndMyselfTests::key_elect_expired_key() {
   1.480 -    // 1. create identity
   1.481 -    const char* bernd_address = "bernd.das.brot@darthmama.org";
   1.482 -    const char* bernd_fpr = "F8CE0F7E24EB190A2FCBFD38D4B088A7CAFAA422";
   1.483 -    const char* bernd_userid = "BERND_ID"; // simulate temp ID
   1.484 -    const char* bernd_username = "Bernd das Brot der Ultimative Testkandidat";
   1.485 -    const string bernd_pub_key = slurp("test_keys/pub/bernd.das.brot-0xCAFAA422_pub.asc");
   1.486 -    
   1.487 -    PEP_STATUS statuspub = import_key(session, bernd_pub_key.c_str(), bernd_pub_key.length(), NULL);
   1.488 -    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   1.489 -
   1.490 -    pEp_identity* bernd = new_identity(bernd_address, bernd_fpr, bernd_userid, bernd_username);
   1.491 -    
   1.492 -    // 2. set identity
   1.493 -    PEP_STATUS status = set_identity(session, bernd);
   1.494 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.495 -    free_identity(bernd);
   1.496 -                
   1.497 -    bernd = new_identity(bernd_address, NULL, bernd_userid, bernd_username); 
   1.498 -    status = update_identity(session, bernd);
   1.499 -    TEST_ASSERT_MSG((status != PEP_STATUS_OK), "status != PEP_STATUS_OK");
   1.500 -    TEST_ASSERT_MSG((!bernd->fpr || bernd->fpr[0] == '\0'), "!bernd->fpr || bernd->fpr[0] == '\0'");
   1.501 -    TEST_ASSERT_MSG((bernd->username), "bernd->username");
   1.502 -    TEST_ASSERT_MSG((strcmp(bernd->username, bernd_username) == 0), "strcmp(bernd->username, bernd_username) == 0");
   1.503 -    TEST_ASSERT_MSG((bernd->user_id), "bernd->user_id");
   1.504 -    TEST_ASSERT_MSG((strcmp(bernd->user_id, bernd_userid) == 0), "strcmp(bernd->user_id, bernd_userid) == 0"); // ???
   1.505 -    TEST_ASSERT_MSG((!bernd->me), "!bernd->me"); 
   1.506 -    TEST_ASSERT_MSG((bernd->comm_type == PEP_ct_key_not_found), tl_ct_string(bernd->comm_type));
   1.507 -    TEST_ASSERT_MSG((strcmp(bernd->address, bernd_address) == 0), "strcmp(bernd->address, bernd_address) == 0");
   1.508 -
   1.509 -    output_stream << "PASS: update_identity() correctly rejected expired key with PEP_KEY_UNSUITABLE and PEP_ct_key_not_found" << endl << endl;
   1.510 -    free_identity(bernd);
   1.511 -    
   1.512 -}
   1.513 -
   1.514 -void NewUpdateIdAndMyselfTests::key_elect_only_revoked_mistrusted() {
   1.515 -    // Create id with no key
   1.516 -    output_stream << "Creating new id with no key for : ";
   1.517 -    char *uniqname_10000 = strdup("AAAAtestfool@testdomain.org");
   1.518 -    for(int i=0; i < 4;i++)
   1.519 -        uniqname_10000[i] += random() & 0xf;
   1.520 -    
   1.521 -    output_stream << uniqname_10000 << "\n";
   1.522 -
   1.523 -    char* revoke_uuid = get_new_uuid();
   1.524 -
   1.525 -    pEp_identity * revokemaster_3000 = new_identity(uniqname_10000, NULL, revoke_uuid, start_username);
   1.526 -    
   1.527 -    output_stream << "Generate three keys for "  << uniqname_10000 << " who has user_id " << revoke_uuid << endl; 
   1.528 -
   1.529 -    char* revoke_fpr_arr[3];
   1.530 -    
   1.531 -    PEP_STATUS status = generate_keypair(session, revokemaster_3000);
   1.532 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK && revokemaster_3000->fpr), (string(tl_status_string(status)) + " " + revokemaster_3000->fpr).c_str());
   1.533 -    revoke_fpr_arr[0] = strdup(revokemaster_3000->fpr);
   1.534 -    free(revokemaster_3000->fpr);
   1.535 -    revokemaster_3000->fpr = NULL;
   1.536 -    output_stream << "revoke_fpr_arr[0] is " << revoke_fpr_arr[0] << endl; 
   1.537 -    
   1.538 -    status = generate_keypair(session, revokemaster_3000);
   1.539 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK && revokemaster_3000->fpr), (string(tl_status_string(status)) + " " + revokemaster_3000->fpr).c_str());
   1.540 -    revoke_fpr_arr[1] = strdup(revokemaster_3000->fpr);
   1.541 -    free(revokemaster_3000->fpr);
   1.542 -    revokemaster_3000->fpr = NULL;
   1.543 -    output_stream << "revoke_fpr_arr[1] is " << revoke_fpr_arr[1] << endl; 
   1.544 -    
   1.545 -    status = generate_keypair(session, revokemaster_3000);
   1.546 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK && revokemaster_3000->fpr), (string(tl_status_string(status)) + " " + revokemaster_3000->fpr).c_str());
   1.547 -    revoke_fpr_arr[2] = strdup(revokemaster_3000->fpr);
   1.548 -    free(revokemaster_3000->fpr);
   1.549 -    revokemaster_3000->fpr = NULL;
   1.550 -    output_stream << "revoke_fpr_arr[2] is " << revoke_fpr_arr[2] << endl; 
   1.551 -    
   1.552 -    output_stream << "Trust "  << revoke_fpr_arr[2] << " (default for identity) and " << revoke_fpr_arr[0] << endl;
   1.553 -    
   1.554 -    free(revokemaster_3000->fpr);
   1.555 -    revokemaster_3000->fpr = strdup(revoke_fpr_arr[2]);
   1.556 -    status = trust_personal_key(session, revokemaster_3000);
   1.557 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.558 -    status = get_trust(session, revokemaster_3000);
   1.559 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.560 -    TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), tl_ct_string(revokemaster_3000->comm_type));
   1.561 -
   1.562 -    free(revokemaster_3000->fpr);
   1.563 -    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
   1.564 -    status = trust_personal_key(session, revokemaster_3000);
   1.565 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.566 -    status = get_trust(session, revokemaster_3000);
   1.567 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.568 -    TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), tl_ct_string(revokemaster_3000->comm_type));
   1.569 -    
   1.570 -    status = update_identity(session, revokemaster_3000);
   1.571 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.572 -    TEST_ASSERT_MSG((revokemaster_3000->fpr), revokemaster_3000->fpr);
   1.573 -    TEST_ASSERT_MSG((strcmp(revokemaster_3000->fpr, revoke_fpr_arr[2]) == 0), (string("Expected ") + revoke_fpr_arr[2] + ", Got " + revokemaster_3000->fpr).c_str());
   1.574 -    TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), tl_ct_string(revokemaster_3000->comm_type));
   1.575 -
   1.576 -    output_stream << "update_identity returns the correct identity default." << endl;
   1.577 -    
   1.578 -    output_stream << "Ok, now... we revoke the default..." << endl;
   1.579 -    
   1.580 -    output_stream << "Revoking " << revoke_fpr_arr[2] << endl;
   1.581 -
   1.582 -    status = revoke_key(session, revoke_fpr_arr[2], "This little pubkey went to market");
   1.583 -    TEST_ASSERT (status == PEP_STATUS_OK);
   1.584 -
   1.585 -    bool is_revoked;
   1.586 -    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
   1.587 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.588 -    TEST_ASSERT_MSG((is_revoked), "is_revoked");
   1.589 -
   1.590 -    output_stream << "Success revoking " << revoke_fpr_arr[2] << "!!! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   1.591 -
   1.592 -//  BAD ASSUMPTION - this only works if we query the trust DB in elect_pubkey, and we don't.    
   1.593 -//    output_stream << "Now see if update_identity gives us " << revoke_fpr_arr[0] << ", the only trusted key left." << endl;
   1.594 -    status = update_identity(session, revokemaster_3000);
   1.595 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.596 -    TEST_ASSERT_MSG((revokemaster_3000->fpr), revokemaster_3000->fpr);
   1.597 -    bool was_key_0 = (strcmp(revokemaster_3000->fpr, revoke_fpr_arr[0]) == 0); 
   1.598 -    bool was_key_1 = (strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0); 
   1.599 -    TEST_ASSERT_MSG(was_key_0 || was_key_1,    
   1.600 -                    (string("Expected ") + revoke_fpr_arr[0] + " or " + revoke_fpr_arr[1] + ", Got " + revokemaster_3000->fpr).c_str());                
   1.601 -    if (was_key_0) {               
   1.602 -        TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), tl_ct_string(revokemaster_3000->comm_type));    
   1.603 -    }    
   1.604 -    else {   
   1.605 -        TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_OpenPGP_unconfirmed), tl_ct_string(revokemaster_3000->comm_type));
   1.606 -    }
   1.607 -                
   1.608 -    output_stream << "Success! So let's mistrust " << revoke_fpr_arr[0] << ", because seriously, that key was so uncool." << endl;
   1.609 -    
   1.610 -    free(revokemaster_3000->fpr);
   1.611 -    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
   1.612 -    status = key_mistrusted(session, revokemaster_3000);
   1.613 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.614 -
   1.615 -    status = get_trust(session, revokemaster_3000);
   1.616 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.617 -    TEST_ASSERT_MSG((revokemaster_3000->comm_type == PEP_ct_mistrusted), tl_ct_string(revokemaster_3000->comm_type));
   1.618 -    
   1.619 -    output_stream << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   1.620 -
   1.621 -    output_stream << "The only fpr left is an untrusted one - let's make sure this is what we get from update_identity." << endl;
   1.622 -
   1.623 -    status = update_identity(session, revokemaster_3000);
   1.624 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.625 -    TEST_ASSERT_MSG((revokemaster_3000->fpr), revokemaster_3000->fpr);
   1.626 -    TEST_ASSERT_MSG((strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0), (string("Expected ") + revoke_fpr_arr[1] + ", Got " + revokemaster_3000->fpr).c_str());
   1.627 -    TEST_ASSERT_MSG((!(revokemaster_3000->comm_type & PEP_ct_confirmed)), tl_ct_string(revokemaster_3000->comm_type));    
   1.628 -
   1.629 -    output_stream << "Success! We got " << revoke_fpr_arr[1] << "as the fpr with comm_type " << revokemaster_3000->comm_type << endl;
   1.630 -    
   1.631 -    output_stream << "But, you know... let's revoke that one too and see what update_identity gives us." << endl;
   1.632 -
   1.633 -    status = revoke_key(session, revoke_fpr_arr[1], "Because it's more fun to revoke ALL of someone's keys");
   1.634 -    TEST_ASSERT (status == PEP_STATUS_OK);
   1.635 -
   1.636 -    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
   1.637 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   1.638 -    TEST_ASSERT_MSG((is_revoked), "is_revoked");
   1.639 -    
   1.640 -    output_stream << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   1.641 -
   1.642 -    output_stream << "Call update_identity - we expect nothing, plus an error comm type." << endl;
   1.643 -
   1.644 -    status = update_identity(session, revokemaster_3000);
   1.645 -    TEST_ASSERT_MSG((status != PEP_STATUS_OK), tl_status_string(status));
   1.646 -    TEST_ASSERT_MSG((!revokemaster_3000->fpr), revokemaster_3000->fpr);
   1.647 -    TEST_ASSERT_MSG((revokemaster_3000->username), "No revokemaster_3000->username");
   1.648 -    TEST_ASSERT_MSG((strcmp(revokemaster_3000->user_id, revoke_uuid) == 0), (string("Expected ") + revoke_uuid + ", Got " + revokemaster_3000->user_id).c_str());
   1.649 -    TEST_ASSERT_MSG((revokemaster_3000->comm_type == PEP_ct_key_not_found), tl_ct_string(revokemaster_3000->comm_type));
   1.650 -    output_stream << "Success! No key found. The comm_status error was " << revokemaster_3000->comm_type << "and the return status was " << tl_status_string(status) << endl;
   1.651 -
   1.652 -    free_identity(revokemaster_3000);    
   1.653 -}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/src/UpdateIdAndMyselfTest.cc	Fri Aug 30 10:05:36 2019 +0200
     2.3 @@ -0,0 +1,676 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +// N.B. This is now one big monolithic test - however, it probably needs to remain that way,
     2.8 +// as it tests incremental insertion, deletion, and modification of the identity DB on
     2.9 +// different paths.
    2.10 +
    2.11 +#include <stdlib.h>
    2.12 +#include <string>
    2.13 +#include <iostream>
    2.14 +#include <fstream>
    2.15 +#include <cstring> // for strcmp()
    2.16 +#include "TestConstants.h"
    2.17 +
    2.18 +#include "pEpEngine.h"
    2.19 +#include "message_api.h"
    2.20 +#include "keymanagement.h"
    2.21 +#include "test_util.h"
    2.22 +
    2.23 +#include "Engine.h"
    2.24 +
    2.25 +#include <gtest/gtest.h>
    2.26 +
    2.27 +
    2.28 +namespace {
    2.29 +
    2.30 +    //The fixture for UpdateIdAndMyselfTest
    2.31 +    class UpdateIdAndMyselfTest : public ::testing::Test {
    2.32 +        public:
    2.33 +            Engine* engine;
    2.34 +            PEP_SESSION session;
    2.35 +
    2.36 +        protected:
    2.37 +            // You can remove any or all of the following functions if its body
    2.38 +            // is empty.
    2.39 +            UpdateIdAndMyselfTest() {
    2.40 +                // You can do set-up work for each test here.
    2.41 +                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
    2.42 +                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
    2.43 +                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
    2.44 +            }
    2.45 +
    2.46 +            ~UpdateIdAndMyselfTest() override {
    2.47 +                // You can do clean-up work that doesn't throw exceptions here.
    2.48 +            }
    2.49 +
    2.50 +            // If the constructor and destructor are not enough for setting up
    2.51 +            // and cleaning up each test, you can define the following methods:
    2.52 +
    2.53 +            void SetUp() override {
    2.54 +                // Code here will be called immediately after the constructor (right
    2.55 +                // before each test).
    2.56 +
    2.57 +                // Leave this empty if there are no files to copy to the home directory path
    2.58 +                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
    2.59 +
    2.60 +                // Get a new test Engine.
    2.61 +                engine = new Engine(test_path);
    2.62 +                ASSERT_NE(engine, nullptr);
    2.63 +
    2.64 +                // Ok, let's initialize test directories etc.
    2.65 +                engine->prep(NULL, NULL, init_files);
    2.66 +
    2.67 +                // Ok, try to start this bugger.
    2.68 +                engine->start();
    2.69 +                ASSERT_NE(engine->session, nullptr);
    2.70 +                session = engine->session;
    2.71 +
    2.72 +                // Engine is up. Keep on truckin'
    2.73 +            }
    2.74 +
    2.75 +            void TearDown() override {
    2.76 +                // Code here will be called immediately after each test (right
    2.77 +                // before the destructor).
    2.78 +                engine->shut_down();
    2.79 +                delete engine;
    2.80 +                engine = NULL;
    2.81 +                session = NULL;
    2.82 +            }
    2.83 +
    2.84 +        private:
    2.85 +            const char* test_suite_name;
    2.86 +            const char* test_name;
    2.87 +            string test_path;
    2.88 +            // Objects declared here can be used by all tests in the UpdateIdAndMyselfTest suite.
    2.89 +
    2.90 +    };
    2.91 +
    2.92 +}  // namespace
    2.93 +
    2.94 +TEST_F(UpdateIdAndMyselfTest, check_update_identity_and_myself) {
    2.95 +
    2.96 +    // SetUp
    2.97 +    char* uniqname;
    2.98 +    char* own_user_id;
    2.99 +    char* start_username;
   2.100 +    char* generated_fpr;
   2.101 +    char* default_own_id;
   2.102 +    char* alias_id;
   2.103 +    char* new_fpr;
   2.104 +    const char* alex_address;
   2.105 +    const char* alex_fpr;
   2.106 +    const char* alex_userid;
   2.107 +    const char* alex_username;
   2.108 +    const char* new_username;
   2.109 +
   2.110 +    uniqname = strdup("AAAAtestuser@testdomain.org");
   2.111 +    srandom(time(NULL));
   2.112 +    for(int i=0; i < 4;i++)
   2.113 +    uniqname[i] += random() & 0xf;
   2.114 +
   2.115 +    own_user_id = get_new_uuid();
   2.116 +    start_username = strdup("Unser Testkandidat");
   2.117 +    generated_fpr = NULL;
   2.118 +    default_own_id = NULL;
   2.119 +    alias_id = NULL;
   2.120 +    new_fpr = NULL;
   2.121 +
   2.122 +    // 1.   myself_no_record_no_input_fpr
   2.123 +    alex_address = "pep.test.alexander@peptest.ch";
   2.124 +    alex_fpr = "3AD9F60FAEB22675DB873A1362D6981326B54E4E";
   2.125 +    alex_userid = "Alex";
   2.126 +    alex_username = "SuperDuperAlex";
   2.127 +
   2.128 +    PEP_STATUS status = PEP_STATUS_OK;
   2.129 +
   2.130 +    pEp_identity * new_me = new_identity(uniqname, NULL, own_user_id, start_username);
   2.131 +
   2.132 +    status = myself(session, new_me);
   2.133 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.134 +    ASSERT_NE(new_me->fpr, nullptr);
   2.135 +
   2.136 +    generated_fpr = strdup(new_me->fpr);
   2.137 +
   2.138 +    ASSERT_EQ(new_me->comm_type, PEP_ct_pEp);
   2.139 +
   2.140 +    free_identity(new_me);
   2.141 +
   2.142 +    // 2. myself_no_input_fpr_w_record()
   2.143 +    status = PEP_STATUS_OK;
   2.144 +
   2.145 +    new_me = new_identity(uniqname, NULL, own_user_id, NULL);
   2.146 +    status = myself(session, new_me);
   2.147 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.148 +
   2.149 +    ASSERT_NE(new_me->fpr, nullptr);
   2.150 +    ASSERT_STREQ(new_me->fpr, generated_fpr);
   2.151 +    ASSERT_NE(new_me->username, nullptr);
   2.152 +    ASSERT_STREQ(new_me->username, start_username);
   2.153 +    ASSERT_NE(new_me->user_id, nullptr);
   2.154 +    ASSERT_EQ(new_me->comm_type, PEP_ct_pEp);
   2.155 +
   2.156 +    default_own_id = NULL;
   2.157 +    status = get_userid_alias_default(session, own_user_id, &default_own_id);
   2.158 +    if (status == PEP_CANNOT_FIND_ALIAS) {
   2.159 +        // Ok, we presume our own id above is the default (should be true if there was no existing DB as in test env)
   2.160 +        default_own_id = strdup(own_user_id);
   2.161 +    }
   2.162 +
   2.163 +    ASSERT_STREQ(new_me->user_id, default_own_id);
   2.164 +
   2.165 +    output_stream << "PASS: myself() retrieved the correct fpr, username and default user id" << endl << endl;
   2.166 +
   2.167 +    free_identity(new_me);
   2.168 +    new_me = NULL;
   2.169 +
   2.170 +    // 3. myself_no_input_fpr_diff_user_id_w_record() {
   2.171 +    status = PEP_STATUS_OK;
   2.172 +    alias_id = strdup("Huss Es El Mejor Presidente Del Mundo!");
   2.173 +
   2.174 +    new_me = new_identity(uniqname, NULL, alias_id, NULL);
   2.175 +    status = myself(session, new_me);
   2.176 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.177 +
   2.178 +    ASSERT_NE(new_me->fpr, nullptr);
   2.179 +    ASSERT_STREQ(new_me->fpr, generated_fpr);
   2.180 +    ASSERT_NE(new_me->username, nullptr);
   2.181 +    ASSERT_STREQ(new_me->username, start_username);
   2.182 +    ASSERT_NE(new_me->user_id, nullptr);
   2.183 +    ASSERT_STREQ(new_me->user_id, default_own_id);
   2.184 +    ASSERT_EQ(new_me->comm_type, PEP_ct_pEp);
   2.185 +
   2.186 +    char* tmp_def = NULL;
   2.187 +
   2.188 +    status = get_userid_alias_default(session, alias_id, &tmp_def);
   2.189 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.190 +    ASSERT_STREQ(tmp_def, default_own_id);
   2.191 +
   2.192 +    output_stream << "PASS: myself() retrieved the correct fpr, username and default user id, and put the right alias in for the default";
   2.193 +    output_stream << endl << endl;
   2.194 +
   2.195 +    free(tmp_def);
   2.196 +    tmp_def = NULL;
   2.197 +    free_identity(new_me);
   2.198 +    new_me = NULL;
   2.199 +
   2.200 +    // 4. myself_replace_fpr() {
   2.201 +    status = PEP_STATUS_OK;
   2.202 +    new_me = new_identity(uniqname, NULL, alias_id, start_username);
   2.203 +    status = generate_keypair(session, new_me);
   2.204 +    ASSERT_NE(new_me->fpr, nullptr);
   2.205 +
   2.206 +    output_stream << "Generated fingerprint ";
   2.207 +    output_stream << new_me->fpr << "\n";
   2.208 +
   2.209 +    new_fpr = strdup(new_me->fpr);
   2.210 +
   2.211 +    status = set_own_key(session, new_me, new_fpr);
   2.212 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.213 +    ASSERT_NE(new_me->fpr, nullptr);
   2.214 +    ASSERT_STRNE(new_me->fpr, generated_fpr);
   2.215 +    ASSERT_STREQ(new_me->fpr, new_fpr);
   2.216 +    ASSERT_NE(new_me->username, nullptr);
   2.217 +    ASSERT_STREQ(new_me->username, start_username);
   2.218 +    ASSERT_NE(new_me->user_id, nullptr);
   2.219 +    ASSERT_STREQ(new_me->user_id, default_own_id);
   2.220 +    ASSERT_TRUE(new_me->me);
   2.221 +    ASSERT_EQ(new_me->comm_type, PEP_ct_pEp);
   2.222 +
   2.223 +    output_stream << "PASS: myself() set and retrieved the new fpr, username and default user id, and put the right alias in for the default";
   2.224 +    output_stream << endl << endl;
   2.225 +
   2.226 +    // since that worked, we'll set it back as the default
   2.227 +    free(new_me->fpr);
   2.228 +    new_me->fpr = strdup(generated_fpr);
   2.229 +    new_me->comm_type = PEP_ct_unknown;
   2.230 +    status = set_own_key(session, new_me, generated_fpr);
   2.231 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.232 +    ASSERT_STREQ(new_me->fpr, generated_fpr);
   2.233 +    ASSERT_EQ(new_me->comm_type, PEP_ct_pEp);
   2.234 +    free_identity(new_me);
   2.235 +    new_me = NULL;
   2.236 +
   2.237 +    // 5. myself_replace_fpr_revoke_key() {
   2.238 +    status = PEP_STATUS_OK;
   2.239 +    status = revoke_key(session, generated_fpr, "Because it's fun");
   2.240 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.241 +
   2.242 +    new_me = new_identity(uniqname, NULL, alias_id, start_username);
   2.243 +
   2.244 +    status = set_own_key(session, new_me, new_fpr);
   2.245 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.246 +    ASSERT_NE(new_me->fpr, nullptr);
   2.247 +    ASSERT_STRNE(new_me->fpr, generated_fpr);
   2.248 +    ASSERT_NE(new_me->username, nullptr);
   2.249 +    ASSERT_STREQ(new_me->username, start_username);
   2.250 +    ASSERT_NE(new_me->user_id, nullptr);
   2.251 +    ASSERT_STREQ(new_me->user_id, default_own_id);
   2.252 +    ASSERT_TRUE(new_me->me);
   2.253 +    ASSERT_EQ(new_me->comm_type, PEP_ct_pEp);
   2.254 +
   2.255 +    output_stream << "PASS: myself() retrieved the new fpr, username and default user id, and put the right alias in for the default";
   2.256 +    output_stream << endl << endl;
   2.257 +    free_identity(new_me);
   2.258 +    new_me = NULL;
   2.259 +
   2.260 +    // 6. update_identity_w_matching_address_user_id_username() {
   2.261 +    // 1. create original identity
   2.262 +    const string alex_pub_key = slurp("test_keys/pub/pep.test.alexander-0x26B54E4E_pub.asc");
   2.263 +
   2.264 +    PEP_STATUS statuspub = import_key(session, alex_pub_key.c_str(), alex_pub_key.length(), NULL);
   2.265 +    ASSERT_EQ(statuspub, PEP_TEST_KEY_IMPORT_SUCCESS);
   2.266 +
   2.267 +    pEp_identity* alex = new_identity(alex_address, alex_fpr, alex_userid, alex_username);
   2.268 +
   2.269 +    // 2. set identity
   2.270 +    status = set_identity(session, alex);
   2.271 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.272 +    free_identity(alex);
   2.273 +
   2.274 +    alex = new_identity(alex_address, NULL, alex_userid, alex_username);
   2.275 +    ASSERT_NE(alex, nullptr);
   2.276 +    status = update_identity(session, alex);
   2.277 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.278 +    ASSERT_NE(alex->fpr, nullptr);
   2.279 +    ASSERT_STREQ(alex->fpr, alex_fpr);
   2.280 +    ASSERT_NE(alex->username, nullptr);
   2.281 +    ASSERT_STREQ(alex->username, alex_username);
   2.282 +    ASSERT_NE(alex->user_id, nullptr);
   2.283 +    ASSERT_STREQ(alex->user_id, alex_userid);
   2.284 +    ASSERT_FALSE(alex->me);
   2.285 +    ASSERT_EQ(alex->comm_type, PEP_ct_OpenPGP_unconfirmed);
   2.286 +    ASSERT_STREQ(alex->address, alex_address);
   2.287 +
   2.288 +    output_stream << "PASS: update_identity() correctly retrieved extant record with matching address, id, and username" << endl << endl;
   2.289 +    free_identity(alex);
   2.290 +    alex = NULL;
   2.291 +
   2.292 +    // 7. update_identity_w_matching_address_user_id_new_username() {
   2.293 +    status = PEP_STATUS_OK;
   2.294 +
   2.295 +    alex = new_identity(alex_address, alex_fpr, alex_userid, alex_username);
   2.296 +    status = set_identity(session, alex);
   2.297 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.298 +    free_identity(alex);
   2.299 +
   2.300 +    alex = new_identity(alex_address, NULL, alex_userid, alex_username);
   2.301 +    status = update_identity(session, alex);
   2.302 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.303 +    ASSERT_NE(alex->fpr, nullptr);
   2.304 +    ASSERT_STREQ(alex->fpr, alex_fpr);
   2.305 +    ASSERT_NE(alex->username, nullptr);
   2.306 +    ASSERT_STREQ(alex->username, alex_username);
   2.307 +    ASSERT_NE(alex->user_id, nullptr);
   2.308 +    ASSERT_STREQ(alex->user_id, alex_userid);
   2.309 +    ASSERT_FALSE(alex->me);
   2.310 +    ASSERT_EQ(alex->comm_type, PEP_ct_OpenPGP_unconfirmed);
   2.311 +    ASSERT_STREQ(alex->address, alex_address);
   2.312 +
   2.313 +    output_stream << "PASS: update_identity() correctly retrieved extant record with matching address, id, and username" << endl << endl;
   2.314 +    free_identity(alex);
   2.315 +    alex = NULL;
   2.316 +
   2.317 +    // 8. update_identity_w_matching_address_user_id_only() {
   2.318 +    status = PEP_STATUS_OK;
   2.319 +    new_username = "Test Patchy";
   2.320 +
   2.321 +    alex = new_identity(alex_address, NULL, alex_userid, new_username);
   2.322 +    status = update_identity(session, alex);
   2.323 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.324 +    ASSERT_NE(alex->fpr, nullptr);
   2.325 +    ASSERT_STREQ(alex->fpr, alex_fpr);
   2.326 +    ASSERT_NE(alex->username, nullptr);
   2.327 +    ASSERT_STREQ(alex->username, new_username);
   2.328 +    ASSERT_NE(alex->user_id, nullptr);
   2.329 +    ASSERT_STREQ(alex->user_id, alex_userid);
   2.330 +    ASSERT_FALSE(alex->me);
   2.331 +    ASSERT_EQ(alex->comm_type, PEP_ct_OpenPGP_unconfirmed);
   2.332 +    ASSERT_STREQ(alex->address, alex_address);
   2.333 +
   2.334 +    free_identity(alex);
   2.335 +    alex = NULL;
   2.336 +
   2.337 +    // 9. UpdateIdAndMyselfTests::update_identity_use_address_username_only() {
   2.338 +    alex = new_identity(alex_address, NULL, NULL, new_username);
   2.339 +    status = update_identity(session, alex);
   2.340 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.341 +    ASSERT_NE(alex->fpr, nullptr);
   2.342 +    ASSERT_STREQ(alex->fpr, alex_fpr);
   2.343 +    ASSERT_NE(alex->username, nullptr);
   2.344 +    ASSERT_STREQ(alex->username, new_username);
   2.345 +    ASSERT_NE(alex->user_id, nullptr);
   2.346 +    ASSERT_STREQ(alex->user_id, alex_userid);
   2.347 +    ASSERT_FALSE(alex->me);
   2.348 +    ASSERT_EQ(alex->comm_type, PEP_ct_OpenPGP_unconfirmed);
   2.349 +    ASSERT_STREQ(alex->address, alex_address);
   2.350 +
   2.351 +    output_stream << "PASS: update_identity() correctly retrieved extant record with matching address and username" << endl << endl;
   2.352 +    free_identity(alex);
   2.353 +    alex = NULL;
   2.354 +
   2.355 +    // 10. update_identity_use_address_only() {
   2.356 +    alex = new_identity(alex_address, NULL, NULL, NULL);
   2.357 +    status = update_identity(session, alex);
   2.358 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.359 +    ASSERT_NE(alex->fpr, nullptr);
   2.360 +    ASSERT_STREQ(alex->fpr, alex_fpr);
   2.361 +    ASSERT_NE(alex->username, nullptr);
   2.362 +    ASSERT_STREQ(alex->username, new_username);
   2.363 +    ASSERT_NE(alex->user_id, nullptr);
   2.364 +    ASSERT_STREQ(alex->user_id, alex_userid);
   2.365 +    ASSERT_FALSE(alex->me);
   2.366 +    ASSERT_EQ(alex->comm_type, PEP_ct_OpenPGP_unconfirmed);
   2.367 +    ASSERT_STREQ(alex->address, alex_address);
   2.368 +
   2.369 +    output_stream << "PASS: update_identity() correctly retrieved extant record with just matching address. Retrieved previously patched username." << endl << endl;
   2.370 +    free_identity(alex);
   2.371 +    alex = NULL;
   2.372 +
   2.373 +    // 11. update_identity_use_address_only_on_own_ident() {
   2.374 +    pEp_identity* somebody = new_identity(uniqname, NULL, NULL, NULL);
   2.375 +    status = update_identity(session, somebody);
   2.376 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.377 +    myself(session, somebody);
   2.378 +    ASSERT_NE(somebody->fpr, nullptr);
   2.379 +    ASSERT_STREQ(somebody->fpr, new_fpr);
   2.380 +    ASSERT_NE(somebody->username, nullptr);
   2.381 +    ASSERT_STREQ(somebody->username, start_username);
   2.382 +    ASSERT_NE(somebody->user_id, nullptr);
   2.383 +    ASSERT_STREQ(somebody->user_id, default_own_id);
   2.384 +    ASSERT_TRUE(somebody->me); // true in this case, as it was an own identity
   2.385 +    ASSERT_EQ(somebody->comm_type, PEP_ct_pEp);
   2.386 +    ASSERT_STREQ(somebody->address, uniqname);
   2.387 +
   2.388 +    output_stream << "PASS: update_identity() retrieved the right identity information given just an address";
   2.389 +    output_stream << endl << endl;
   2.390 +
   2.391 +    free_identity(somebody);
   2.392 +    somebody = NULL;
   2.393 +
   2.394 +    // 12. update_identity_non_existent_user_id_address() {
   2.395 +    somebody = new_identity("nope@nope.nope", NULL, "some_user_id", NULL);
   2.396 +    status= update_identity(session, somebody);
   2.397 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.398 +    ASSERT_EQ(somebody->fpr, nullptr);
   2.399 +    ASSERT_EQ(somebody->comm_type, PEP_ct_key_not_found);
   2.400 +
   2.401 +    output_stream << "PASS: update_identity() returns identity with no key and unknown comm type" << endl << endl;
   2.402 +
   2.403 +    free_identity(somebody);
   2.404 +    somebody = NULL;
   2.405 +
   2.406 +    // 13. update_identity_address_username_userid_no_record() {
   2.407 +    const char* rando_name = "Pickley BoofBoof";
   2.408 +    const char* rando_userid = "Boofy";
   2.409 +    const char* rando_address = "boof@pickles.org";
   2.410 +    somebody = new_identity(rando_address, NULL, rando_userid, rando_name);
   2.411 +    status = update_identity(session, somebody);
   2.412 +
   2.413 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.414 +    ASSERT_TRUE(somebody->fpr == nullptr || somebody->fpr[0] == '\0');
   2.415 +    ASSERT_NE(somebody->username, nullptr);
   2.416 +    ASSERT_STREQ(somebody->username, rando_name);
   2.417 +    ASSERT_NE(somebody->user_id, nullptr);
   2.418 +    ASSERT_STREQ(somebody->user_id, rando_userid); // ???
   2.419 +    ASSERT_TRUE(!somebody->me);
   2.420 +    ASSERT_EQ(somebody->comm_type, PEP_ct_key_not_found);
   2.421 +    ASSERT_STREQ(somebody->address, rando_address);
   2.422 +
   2.423 +    output_stream << "PASS: update_identity() correctly created record with no key" << endl << endl;
   2.424 +    free_identity(somebody);
   2.425 +    somebody = NULL;
   2.426 +
   2.427 +    // 14. update_identity_address_username_no_record() {
   2.428 +    const char* rando2_name = "Pickles BoofyBoof";
   2.429 +    const char* rando2_address = "boof2@pickles.org";
   2.430 +    somebody = new_identity(rando2_address, NULL, NULL, rando2_name);
   2.431 +    status = update_identity(session, somebody);
   2.432 +    const char* expected_rando2_userid = "TOFU_boof2@pickles.org";
   2.433 +
   2.434 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.435 +    ASSERT_TRUE(somebody->fpr == nullptr || somebody->fpr[0] == '\0');
   2.436 +    ASSERT_NE(somebody->username, nullptr);
   2.437 +    ASSERT_STREQ(somebody->username, rando2_name);
   2.438 +    ASSERT_NE(somebody->user_id, nullptr);
   2.439 +    ASSERT_STREQ(somebody->user_id, expected_rando2_userid); // ???
   2.440 +    ASSERT_TRUE(!somebody->me);
   2.441 +    ASSERT_EQ(somebody->comm_type, PEP_ct_key_not_found);
   2.442 +    ASSERT_STREQ(somebody->address, rando2_address);
   2.443 +
   2.444 +    output_stream << "PASS: update_identity() correctly created record with no key" << endl << endl;
   2.445 +    free_identity(somebody);
   2.446 +    somebody = NULL;
   2.447 +
   2.448 +    // 15. update_identity_address_only_multiple_records() {
   2.449 +    status= PEP_STATUS_OK;
   2.450 +    // 1. create identity
   2.451 +    const char* bella_address = "pep.test.bella@peptest.ch";
   2.452 +    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
   2.453 +    const char* bella_userid = "TOFU_pep.test.bella@peptest.ch"; // simulate temp ID
   2.454 +    const char* bella_username = "Annabella the Great";
   2.455 +    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");
   2.456 +
   2.457 +    statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
   2.458 +    ASSERT_EQ(statuspub, PEP_TEST_KEY_IMPORT_SUCCESS);
   2.459 +
   2.460 +    pEp_identity* bella = new_identity(bella_address, bella_fpr, bella_userid, bella_username);
   2.461 +
   2.462 +    // 2. set identity
   2.463 +    status = set_identity(session, bella);
   2.464 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.465 +    free_identity(bella);
   2.466 +
   2.467 +    const char* not_my_userid = "Bad Company";
   2.468 +
   2.469 +    bella = new_identity(bella_address, NULL, not_my_userid, bella_username);
   2.470 +    status = update_identity(session, bella);
   2.471 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.472 +    ASSERT_NE(bella->fpr, nullptr);
   2.473 +    ASSERT_STREQ(bella->fpr, bella_fpr);
   2.474 +    ASSERT_NE(bella->username, nullptr);
   2.475 +    ASSERT_STREQ(bella->username, bella_username);
   2.476 +    ASSERT_NE(bella->user_id, nullptr);
   2.477 +    ASSERT_STREQ(bella->user_id, not_my_userid); // ???
   2.478 +    ASSERT_TRUE(!bella->me);
   2.479 +    ASSERT_EQ(bella->comm_type, PEP_ct_OpenPGP_unconfirmed);
   2.480 +    ASSERT_STREQ(bella->address, bella_address);
   2.481 +
   2.482 +    free_identity(bella);
   2.483 +
   2.484 +    // ????
   2.485 +    const char* bella_id_2 = "Bella2";
   2.486 +    bella = new_identity(bella_address, NULL, bella_id_2, bella_username);
   2.487 +
   2.488 +    status = set_identity(session, bella);
   2.489 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.490 +    free_identity(bella);
   2.491 +
   2.492 +    bella = new_identity(bella_address, NULL, NULL, NULL);
   2.493 +    status = update_identity(session, bella);
   2.494 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.495 +    free_identity(bella);
   2.496 +    bella = NULL;
   2.497 +
   2.498 +    // 16. key_elect_expired_key() {
   2.499 +    // 1. create identity
   2.500 +    const char* bernd_address = "bernd.das.brot@darthmama.org";
   2.501 +    const char* bernd_fpr = "F8CE0F7E24EB190A2FCBFD38D4B088A7CAFAA422";
   2.502 +    const char* bernd_userid = "BERND_ID"; // simulate temp ID
   2.503 +    const char* bernd_username = "Bernd das Brot der Ultimative Testkandidat";
   2.504 +    const string bernd_pub_key = slurp("test_keys/pub/bernd.das.brot-0xCAFAA422_pub.asc");
   2.505 +
   2.506 +    statuspub = import_key(session, bernd_pub_key.c_str(), bernd_pub_key.length(), NULL);
   2.507 +    ASSERT_EQ(statuspub, PEP_TEST_KEY_IMPORT_SUCCESS);
   2.508 +
   2.509 +    pEp_identity* bernd = new_identity(bernd_address, bernd_fpr, bernd_userid, bernd_username);
   2.510 +
   2.511 +    // 2. set identity
   2.512 +    status = set_identity(session, bernd);
   2.513 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.514 +    free_identity(bernd);
   2.515 +
   2.516 +    bernd = new_identity(bernd_address, NULL, bernd_userid, bernd_username);
   2.517 +    status = update_identity(session, bernd);
   2.518 +    ASSERT_NE(status, PEP_STATUS_OK);
   2.519 +    ASSERT_TRUE(bernd->fpr == nullptr || bernd->fpr[0] == '\0');
   2.520 +    ASSERT_NE(bernd->username, nullptr);
   2.521 +    ASSERT_STREQ(bernd->username, bernd_username);
   2.522 +    ASSERT_NE(bernd->user_id, nullptr);
   2.523 +    ASSERT_STREQ(bernd->user_id, bernd_userid); // ???
   2.524 +    ASSERT_TRUE(!bernd->me);
   2.525 +    ASSERT_EQ(bernd->comm_type, PEP_ct_key_not_found);
   2.526 +    ASSERT_STREQ(bernd->address, bernd_address);
   2.527 +
   2.528 +    output_stream << "PASS: update_identity() correctly rejected expired key with PEP_KEY_UNSUITABLE and PEP_ct_key_not_found" << endl << endl;
   2.529 +    free_identity(bernd);
   2.530 +    bernd = NULL;
   2.531 +
   2.532 +    // 17. key_elect_only_revoked_mistrusted() {
   2.533 +    // Create id with no key
   2.534 +    output_stream << "Creating new id with no key for : ";
   2.535 +    char *uniqname_10000 = strdup("AAAAtestfool@testdomain.org");
   2.536 +    for(int i=0; i < 4;i++)
   2.537 +        uniqname_10000[i] += random() & 0xf;
   2.538 +
   2.539 +    output_stream << uniqname_10000 << "\n";
   2.540 +
   2.541 +    char* revoke_uuid = get_new_uuid();
   2.542 +
   2.543 +    pEp_identity * revokemaster_3000 = new_identity(uniqname_10000, NULL, revoke_uuid, start_username);
   2.544 +
   2.545 +    output_stream << "Generate three keys for "  << uniqname_10000 << " who has user_id " << revoke_uuid << endl;
   2.546 +
   2.547 +    char* revoke_fpr_arr[3];
   2.548 +
   2.549 +    status = generate_keypair(session, revokemaster_3000);
   2.550 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.551 +    ASSERT_NE(revokemaster_3000->fpr, nullptr);
   2.552 +    revoke_fpr_arr[0] = strdup(revokemaster_3000->fpr);
   2.553 +    free(revokemaster_3000->fpr);
   2.554 +    revokemaster_3000->fpr = NULL;
   2.555 +    output_stream << "revoke_fpr_arr[0] is " << revoke_fpr_arr[0] << endl;
   2.556 +
   2.557 +    status = generate_keypair(session, revokemaster_3000);
   2.558 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.559 +    ASSERT_NE(revokemaster_3000->fpr, nullptr);
   2.560 +    revoke_fpr_arr[1] = strdup(revokemaster_3000->fpr);
   2.561 +    free(revokemaster_3000->fpr);
   2.562 +    revokemaster_3000->fpr = NULL;
   2.563 +    output_stream << "revoke_fpr_arr[1] is " << revoke_fpr_arr[1] << endl;
   2.564 +
   2.565 +    status = generate_keypair(session, revokemaster_3000);
   2.566 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.567 +    ASSERT_NE(revokemaster_3000->fpr, nullptr);
   2.568 +    revoke_fpr_arr[2] = strdup(revokemaster_3000->fpr);
   2.569 +    free(revokemaster_3000->fpr);
   2.570 +    revokemaster_3000->fpr = NULL;
   2.571 +    output_stream << "revoke_fpr_arr[2] is " << revoke_fpr_arr[2] << endl;
   2.572 +
   2.573 +    output_stream << "Trust "  << revoke_fpr_arr[2] << " (default for identity) and " << revoke_fpr_arr[0] << endl;
   2.574 +
   2.575 +    free(revokemaster_3000->fpr);
   2.576 +    revokemaster_3000->fpr = strdup(revoke_fpr_arr[2]);
   2.577 +    status = trust_personal_key(session, revokemaster_3000);
   2.578 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.579 +    status = get_trust(session, revokemaster_3000);
   2.580 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.581 +    ASSERT_GT(revokemaster_3000->comm_type & PEP_ct_confirmed, 0);
   2.582 +
   2.583 +    free(revokemaster_3000->fpr);
   2.584 +    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
   2.585 +    status = trust_personal_key(session, revokemaster_3000);
   2.586 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.587 +    status = get_trust(session, revokemaster_3000);
   2.588 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.589 +    ASSERT_GT(revokemaster_3000->comm_type & PEP_ct_confirmed, 0);
   2.590 +
   2.591 +    status = update_identity(session, revokemaster_3000);
   2.592 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.593 +    ASSERT_NE(revokemaster_3000->fpr, nullptr);
   2.594 +    ASSERT_STREQ(revokemaster_3000->fpr, revoke_fpr_arr[2]);
   2.595 +    ASSERT_GT(revokemaster_3000->comm_type & PEP_ct_confirmed, 0);
   2.596 +
   2.597 +    output_stream << "update_identity returns the correct identity default." << endl;
   2.598 +
   2.599 +    output_stream << "Ok, now... we revoke the default..." << endl;
   2.600 +
   2.601 +    output_stream << "Revoking " << revoke_fpr_arr[2] << endl;
   2.602 +
   2.603 +    status = revoke_key(session, revoke_fpr_arr[2], "This little pubkey went to market");
   2.604 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.605 +
   2.606 +    bool is_revoked;
   2.607 +    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);
   2.608 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.609 +    ASSERT_TRUE(is_revoked);
   2.610 +
   2.611 +    output_stream << "Success revoking " << revoke_fpr_arr[2] << "!!! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   2.612 +
   2.613 +//  KB: Is this still an issue, or did we delete some problematic code here, or...? 30.08.2019
   2.614 +//  BAD ASSUMPTION - this only works if we query the trust DB in elect_pubkey, and we don't.
   2.615 +//    output_stream << "Now see if update_identity gives us " << revoke_fpr_arr[0] << ", the only trusted key left." << endl;
   2.616 +    status = update_identity(session, revokemaster_3000);
   2.617 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.618 +    ASSERT_NE(revokemaster_3000->fpr, nullptr);
   2.619 +    bool was_key_0 = (strcmp(revokemaster_3000->fpr, revoke_fpr_arr[0]) == 0);
   2.620 +    bool was_key_1 = (strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0);
   2.621 +    ASSERT_TRUE(was_key_0 || was_key_1);
   2.622 +    if (was_key_0)
   2.623 +        ASSERT_GT(revokemaster_3000->comm_type & PEP_ct_confirmed, 0);
   2.624 +    else
   2.625 +        ASSERT_GT(revokemaster_3000->comm_type & PEP_ct_OpenPGP_unconfirmed, 0);
   2.626 +
   2.627 +    output_stream << "Success! So let's mistrust " << revoke_fpr_arr[0] << ", because seriously, that key was so uncool." << endl;
   2.628 +
   2.629 +    free(revokemaster_3000->fpr);
   2.630 +    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
   2.631 +    status = key_mistrusted(session, revokemaster_3000);
   2.632 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.633 +
   2.634 +    status = get_trust(session, revokemaster_3000);
   2.635 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.636 +    ASSERT_EQ(revokemaster_3000->comm_type, PEP_ct_mistrusted);
   2.637 +
   2.638 +    output_stream << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   2.639 +
   2.640 +    output_stream << "The only fpr left is an untrusted one - let's make sure this is what we get from update_identity." << endl;
   2.641 +
   2.642 +    status = update_identity(session, revokemaster_3000);
   2.643 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.644 +    ASSERT_NE(revokemaster_3000->fpr, nullptr);
   2.645 +    ASSERT_STREQ(revokemaster_3000->fpr, revoke_fpr_arr[1]);
   2.646 +    ASSERT_EQ(revokemaster_3000->comm_type & PEP_ct_confirmed, 0);
   2.647 +
   2.648 +    output_stream << "Success! We got " << revoke_fpr_arr[1] << "as the fpr with comm_type " << revokemaster_3000->comm_type << endl;
   2.649 +
   2.650 +    output_stream << "But, you know... let's revoke that one too and see what update_identity gives us." << endl;
   2.651 +
   2.652 +    status = revoke_key(session, revoke_fpr_arr[1], "Because it's more fun to revoke ALL of someone's keys");
   2.653 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.654 +
   2.655 +    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);
   2.656 +    ASSERT_EQ(status, PEP_STATUS_OK);
   2.657 +    ASSERT_TRUE(is_revoked);
   2.658 +
   2.659 +    output_stream << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   2.660 +
   2.661 +    output_stream << "Call update_identity - we expect nothing, plus an error comm type." << endl;
   2.662 +
   2.663 +    status = update_identity(session, revokemaster_3000);
   2.664 +    ASSERT_NE(status, PEP_STATUS_OK);
   2.665 +    ASSERT_EQ(revokemaster_3000->fpr, nullptr);
   2.666 +    ASSERT_NE(revokemaster_3000->username, nullptr);
   2.667 +    ASSERT_STREQ(revokemaster_3000->user_id, revoke_uuid);
   2.668 +    ASSERT_EQ(revokemaster_3000->comm_type, PEP_ct_key_not_found);
   2.669 +    output_stream << "Success! No key found. The comm_status error was " << revokemaster_3000->comm_type << "and the return status was " << tl_status_string(status) << endl;
   2.670 +
   2.671 +    free_identity(revokemaster_3000);
   2.672 +    free(uniqname);
   2.673 +    free(own_user_id);
   2.674 +    free(start_username);
   2.675 +    free(generated_fpr);
   2.676 +    free(default_own_id);
   2.677 +    free(alias_id);
   2.678 +    free(new_fpr);    
   2.679 +}