test/src/engine_tests/NewUpdateIdAndMyselfTests.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 29 Jan 2019 19:19:30 +0100
branchENGINE-448
changeset 3254 6e7f6bc9460a
parent 2669 1b103e8a95f7
child 3276 c0b3430f1f1d
permissions -rw-r--r--
ENGINE-448: made key removal much less aggressive. NetPGP will still be a problem, but versions built against gpg will now only remove actual keys
krista@2461
     1
// This file is under GNU General Public License 3.0
krista@2461
     2
// see LICENSE.txt
krista@2461
     3
krista@2661
     4
#include <stdlib.h>
krista@2661
     5
#include <string>
krista@2461
     6
#include <iostream>
krista@2461
     7
#include <fstream>
krista@2461
     8
#include <cstring> // for strcmp()
krista@2661
     9
krista@2461
    10
#include "pEpEngine.h"
krista@2461
    11
#include "message_api.h"
krista@2461
    12
#include "keymanagement.h"
krista@2461
    13
#include "test_util.h"
krista@2461
    14
krista@2661
    15
#include <cpptest.h>
krista@2661
    16
#include "EngineTestSessionSuite.h"
krista@2661
    17
#include "NewUpdateIdAndMyselfTests.h"
krista@2661
    18
krista@2461
    19
using namespace std;
krista@2461
    20
krista@2661
    21
NewUpdateIdAndMyselfTests::NewUpdateIdAndMyselfTests(string suitename, string test_home_dir) :
krista@2661
    22
    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
krista@2661
    23
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::check_new_update_id_and_myself"),
krista@2661
    24
                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::check_new_update_id_and_myself)));
krista@2661
    25
}
krista@2661
    26
krista@2661
    27
void NewUpdateIdAndMyselfTests::check_new_update_id_and_myself() {
krista@2461
    28
    
krista@2661
    29
    PEP_STATUS status = PEP_STATUS_OK;
krista@2477
    30
    
krista@2461
    31
    cout << "***********************************************************************" << endl;
krista@2461
    32
    cout << "* Section I. myself()" << endl;
krista@2461
    33
    cout << "***********************************************************************" << endl << endl;
krista@2461
    34
krista@2461
    35
    // Create id with no key
krista@2461
    36
    cout << "Creating new own id with no key for : ";
krista@2461
    37
    char *uniqname = strdup("AAAAtestuser@testdomain.org");
krista@2461
    38
    srandom(time(NULL));
krista@2461
    39
    for(int i=0; i < 4;i++)
krista@2461
    40
        uniqname[i] += random() & 0xf;
krista@2461
    41
    
krista@2461
    42
    cout << uniqname << "\n";
krista@2461
    43
    
krista@2467
    44
    const char* own_user_id = get_new_uuid();
krista@2461
    45
    const char* start_username = "Unser Testkandidat";
krista@2461
    46
krista@2461
    47
    pEp_identity * new_me = new_identity(uniqname, NULL, own_user_id, start_username);
krista@2461
    48
    
krista@2461
    49
    cout << "***********************************************************************" << endl;
krista@2461
    50
    cout << "* I: 1. myself() on id with no record in the DB and no input fpr" << endl;
krista@2461
    51
    cout << "***********************************************************************" << endl << endl;
krista@2461
    52
    status = myself(session, new_me);
krista@2669
    53
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
    54
    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
krista@2461
    55
    
krista@2461
    56
    cout << "PASS: myself() generated fingerprint ";
krista@2461
    57
    cout << new_me->fpr << endl << endl;
krista@2461
    58
krista@2461
    59
    char* generated_fpr = strdup(new_me->fpr);
krista@2461
    60
    
krista@2669
    61
    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
krista@2461
    62
    
krista@2461
    63
    free_identity(new_me);
krista@2461
    64
krista@2461
    65
    cout << "***********************************************************************" << endl;
krista@2461
    66
    cout << "* I: 2. myself() on id with no input fpr and a record in the DB" << endl;
krista@2461
    67
    cout << "***********************************************************************" << endl << endl;
krista@2461
    68
krista@2461
    69
    new_me = new_identity(uniqname, NULL, own_user_id, NULL);
krista@2461
    70
    status = myself(session, new_me);
krista@2669
    71
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
    72
    
krista@2669
    73
    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
krista@2669
    74
    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) == 0), "strcmp(new_me->fpr, generated_fpr) == 0");
krista@2669
    75
    TEST_ASSERT_MSG((new_me->username), "new_me->username");
krista@2669
    76
    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
krista@2669
    77
    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
krista@2669
    78
    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
krista@2461
    79
    
krista@2461
    80
    char* default_own_id = NULL;
krista@2461
    81
    status = get_userid_alias_default(session, own_user_id, &default_own_id);
krista@2461
    82
    if (status == PEP_CANNOT_FIND_ALIAS) {
krista@2461
    83
        // Ok, we presume our own id above is the default (should be true if there was no existing DB as in test env)
krista@2461
    84
        default_own_id = strdup(own_user_id);
krista@2461
    85
    }
krista@2461
    86
krista@2669
    87
    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
krista@2461
    88
    
krista@2461
    89
    cout << "PASS: myself() retrieved the correct fpr, username and default user id" << endl << endl;
krista@2461
    90
krista@2461
    91
    free_identity(new_me);
krista@2461
    92
     
krista@2461
    93
    cout << "****************************************************************************************" << endl;
krista@2461
    94
    cout << "* I: 3. myself() on id with no input fpr, a different user_id, and a record in the DB" << endl;
krista@2461
    95
    cout << "****************************************************************************************" << endl << endl;
krista@2461
    96
krista@2461
    97
    const char* alias_id = "Huss Es El Mejor Presidente Del Mundo!";
krista@2461
    98
krista@2461
    99
    new_me = new_identity(uniqname, NULL, alias_id, NULL);
krista@2461
   100
    status = myself(session, new_me);
krista@2669
   101
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
   102
    
krista@2669
   103
    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
krista@2669
   104
    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) == 0), "strcmp(new_me->fpr, generated_fpr) == 0");
krista@2669
   105
    TEST_ASSERT_MSG((new_me->username), "new_me->username");
krista@2669
   106
    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
krista@2669
   107
    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
krista@2669
   108
    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
krista@2669
   109
    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
krista@2461
   110
    
krista@2461
   111
    char* tmp_def = NULL;
krista@2461
   112
    
krista@2461
   113
    status = get_userid_alias_default(session, alias_id, &tmp_def);
krista@2669
   114
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   115
    TEST_ASSERT_MSG((strcmp(tmp_def, default_own_id) == 0), "strcmp(tmp_def, default_own_id) == 0");
krista@2461
   116
krista@2461
   117
    cout << "PASS: myself() retrieved the correct fpr, username and default user id, and put the right alias in for the default";
krista@2461
   118
    cout << endl << endl;
krista@2461
   119
    
krista@2461
   120
    free(tmp_def);
krista@2461
   121
    free_identity(new_me);
krista@2461
   122
krista@2461
   123
    cout << "****************************************************************************************" << endl;
krista@2461
   124
    cout << "* I: 4. myself(), replace fpr" << endl;
krista@2461
   125
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   126
krista@2461
   127
    new_me = new_identity(uniqname, NULL, alias_id, start_username);
krista@2461
   128
    status = generate_keypair(session, new_me);
krista@2669
   129
    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
krista@2461
   130
    
krista@2461
   131
    cout << "Generated fingerprint ";
krista@2461
   132
    cout << new_me->fpr << "\n";
krista@2461
   133
krista@2461
   134
    char* new_fpr = strdup(new_me->fpr);
krista@2461
   135
vb@2535
   136
    status = set_own_key(session, new_me, new_fpr);
krista@2669
   137
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   138
    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
krista@2669
   139
    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) != 0), "strcmp(new_me->fpr, generated_fpr) != 0");
krista@2669
   140
    TEST_ASSERT_MSG((strcmp(new_me->fpr, new_fpr) == 0), "strcmp(new_me->fpr, new_fpr) == 0");
krista@2669
   141
    TEST_ASSERT_MSG((new_me->username), "new_me->username");
krista@2669
   142
    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
krista@2669
   143
    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
krista@2669
   144
    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
krista@2669
   145
    TEST_ASSERT_MSG((new_me->me), "new_me->me");
krista@2669
   146
    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
krista@2461
   147
krista@2461
   148
    cout << "PASS: myself() set and retrieved the new fpr, username and default user id, and put the right alias in for the default";
krista@2461
   149
    cout << endl << endl;
krista@2461
   150
krista@2461
   151
    // since that worked, we'll set it back as the default
krista@2461
   152
    free(new_me->fpr);
krista@2461
   153
    new_me->fpr = strdup(generated_fpr);
krista@2461
   154
    new_me->comm_type = PEP_ct_unknown;
vb@2535
   155
    status = set_own_key(session, new_me, generated_fpr);
krista@2669
   156
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   157
    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) == 0), "strcmp(new_me->fpr, generated_fpr) == 0");
krista@2669
   158
    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
krista@2461
   159
    
krista@2461
   160
    cout << "****************************************************************************************" << endl;
krista@2461
   161
    cout << "* I: 5. myself(), replace fpr, revoke key" << endl;
krista@2461
   162
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   163
krista@2461
   164
    status = revoke_key(session, generated_fpr, "Because it's fun");
krista@2661
   165
    TEST_ASSERT (status == PEP_STATUS_OK);
krista@2461
   166
    
vb@2535
   167
    new_me = new_identity(uniqname, NULL, alias_id, start_username);
krista@2461
   168
    
vb@2535
   169
    status = set_own_key(session, new_me, new_fpr);
krista@2669
   170
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   171
    TEST_ASSERT_MSG((new_me->fpr), "new_me->fpr");
krista@2669
   172
    TEST_ASSERT_MSG((strcmp(new_me->fpr, generated_fpr) != 0), "strcmp(new_me->fpr, generated_fpr) != 0");
krista@2669
   173
    TEST_ASSERT_MSG((new_me->username), "new_me->username");
krista@2669
   174
    TEST_ASSERT_MSG((strcmp(new_me->username, start_username) == 0), "strcmp(new_me->username, start_username) == 0");
krista@2669
   175
    TEST_ASSERT_MSG((new_me->user_id), "new_me->user_id");
krista@2669
   176
    TEST_ASSERT_MSG((strcmp(new_me->user_id, default_own_id) == 0), "strcmp(new_me->user_id, default_own_id) == 0");
krista@2669
   177
    TEST_ASSERT_MSG((new_me->me), "new_me->me");
krista@2669
   178
    TEST_ASSERT_MSG((new_me->comm_type == PEP_ct_pEp), "new_me->comm_type == PEP_ct_pEp");
krista@2461
   179
    
krista@2461
   180
    cout << "PASS: myself() retrieved the new fpr, username and default user id, and put the right alias in for the default";
krista@2461
   181
    cout << endl << endl;
krista@2461
   182
        
krista@2461
   183
    cout << "***********************************************************************" << endl;
krista@2461
   184
    cout << "* Section II. update_identity()" << endl;
krista@2461
   185
    cout << "***********************************************************************" << endl << endl;
krista@2461
   186
krista@2461
   187
    cout << "****************************************************************************************" << endl;
krista@2461
   188
    cout << "* II: 1. update_identity() - get identity with matching address and user_id and username" << endl;
krista@2461
   189
    cout << "****************************************************************************************" << endl << endl;    
krista@2461
   190
    // 1. create original identity
krista@2461
   191
    const char* alex_address = "pep.test.alexander@peptest.ch";
krista@2461
   192
    const char* alex_fpr = "3AD9F60FAEB22675DB873A1362D6981326B54E4E";
krista@2461
   193
    const char* alex_userid = "Alex";
krista@2461
   194
    const char* alex_username = "SuperDuperAlex";
krista@2461
   195
    const string alex_pub_key = slurp("test_keys/pub/pep.test.alexander-0x26B54E4E_pub.asc");
krista@2461
   196
    
krista@2461
   197
    PEP_STATUS statuspub = import_key(session, alex_pub_key.c_str(), alex_pub_key.length(), NULL);
krista@3254
   198
    TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
krista@2461
   199
krista@2461
   200
    pEp_identity* alex = new_identity(alex_address, alex_fpr, alex_userid, alex_username);
krista@2461
   201
krista@2461
   202
    // 2. set identity
krista@2461
   203
    status = set_identity(session, alex);
krista@2669
   204
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
   205
    free_identity(alex);
krista@2461
   206
            
krista@2461
   207
    alex = new_identity(alex_address, NULL, alex_userid, alex_username); 
krista@2461
   208
    status = update_identity(session, alex);
krista@2669
   209
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   210
    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
krista@2669
   211
    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
krista@2669
   212
    TEST_ASSERT_MSG((alex->username), "alex->username");
krista@2669
   213
    TEST_ASSERT_MSG((strcmp(alex->username, alex_username) == 0), "strcmp(alex->username, alex_username) == 0");
krista@2669
   214
    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
krista@2669
   215
    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
krista@2669
   216
    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
krista@2669
   217
    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
krista@2669
   218
    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
krista@2461
   219
krista@2461
   220
    cout << "PASS: update_identity() correctly retrieved extant record with matching address, id, and username" << endl << endl;
krista@2461
   221
    free_identity(alex);
krista@2461
   222
krista@2461
   223
    cout << "****************************************************************************************" << endl;
krista@2461
   224
    cout << "* II: 2. update_identity() - get identity with matching address and user_id and new username" << endl;
krista@2461
   225
    cout << "****************************************************************************************" << endl << endl;    
krista@2461
   226
krista@2461
   227
    const char* new_username = "Test Patchy";
krista@2461
   228
            
krista@2477
   229
    alex = new_identity(alex_address, NULL, alex_userid, new_username);
krista@2477
   230
    cout << "Timing is everything" << endl; 
krista@2461
   231
    status = update_identity(session, alex);
krista@2669
   232
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   233
    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
krista@2669
   234
    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
krista@2669
   235
    TEST_ASSERT_MSG((alex->username), "alex->username");
krista@2669
   236
    TEST_ASSERT_MSG((strcmp(alex->username, new_username) == 0), "strcmp(alex->username, new_username) == 0");
krista@2669
   237
    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
krista@2669
   238
    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
krista@2669
   239
    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
krista@2669
   240
    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
krista@2669
   241
    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
krista@2461
   242
krista@2461
   243
    cout << "PASS: update_identity() correctly retrieved extant record with matching address and id, and patched username" << endl << endl;
krista@2461
   244
    free_identity(alex);
krista@2461
   245
krista@2461
   246
    cout << "****************************************************************************************" << endl;
krista@2461
   247
    cout << "* II: 3. update_identity() - get identity with matching address and user_id only" << endl;
krista@2461
   248
    cout << "****************************************************************************************" << endl << endl;    
krista@2461
   249
        
krista@2461
   250
    alex = new_identity(alex_address, NULL, alex_userid, NULL); 
krista@2461
   251
    status = update_identity(session, alex);
krista@2669
   252
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   253
    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
krista@2669
   254
    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
krista@2669
   255
    TEST_ASSERT_MSG((alex->username), "alex->username");
krista@2669
   256
    TEST_ASSERT_MSG((strcmp(alex->username, new_username) == 0), "strcmp(alex->username, new_username) == 0");
krista@2669
   257
    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
krista@2669
   258
    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
krista@2669
   259
    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
krista@2669
   260
    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
krista@2669
   261
    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
krista@2461
   262
krista@2461
   263
    cout << "PASS: update_identity() correctly retrieved extant record with matching address and id, and patched username" << endl << endl;
krista@2461
   264
    free_identity(alex);
krista@2461
   265
krista@2461
   266
    cout << "****************************************************************************************" << endl;
krista@2461
   267
    cout << "* II: 4. update_identity() - get identity with just address and username" << endl;
krista@2461
   268
    cout << "****************************************************************************************" << endl << endl;    
krista@2461
   269
krista@2461
   270
    alex = new_identity(alex_address, NULL, NULL, new_username); 
krista@2461
   271
    status = update_identity(session, alex);
krista@2669
   272
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   273
    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
krista@2669
   274
    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
krista@2669
   275
    TEST_ASSERT_MSG((alex->username), "alex->username");
krista@2669
   276
    TEST_ASSERT_MSG((strcmp(alex->username, new_username) == 0), "strcmp(alex->username, new_username) == 0");
krista@2669
   277
    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
krista@2669
   278
    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
krista@2669
   279
    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
krista@2669
   280
    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
krista@2669
   281
    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
krista@2461
   282
krista@2461
   283
    cout << "PASS: update_identity() correctly retrieved extant record with matching address and username" << endl << endl;
krista@2461
   284
    free_identity(alex);
krista@2461
   285
krista@2461
   286
    cout << "****************************************************************************************" << endl;
krista@2461
   287
    cout << "* II: 5. update_identity() with just address " << endl;
krista@2461
   288
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   289
    
krista@2461
   290
    alex = new_identity(alex_address, NULL, NULL, NULL); 
krista@2461
   291
    status = update_identity(session, alex);
krista@2669
   292
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   293
    TEST_ASSERT_MSG((alex->fpr), "alex->fpr");
krista@2669
   294
    TEST_ASSERT_MSG((strcmp(alex->fpr, alex_fpr) == 0), "strcmp(alex->fpr, alex_fpr) == 0");
krista@2669
   295
    TEST_ASSERT_MSG((alex->username), "alex->username");
krista@2669
   296
    TEST_ASSERT_MSG((strcmp(alex->username, new_username) == 0), "strcmp(alex->username, new_username) == 0");
krista@2669
   297
    TEST_ASSERT_MSG((alex->user_id), "alex->user_id");
krista@2669
   298
    TEST_ASSERT_MSG((strcmp(alex->user_id, alex_userid) == 0), "strcmp(alex->user_id, alex_userid) == 0");
krista@2669
   299
    TEST_ASSERT_MSG((!alex->me), "!alex->me"); 
krista@2669
   300
    TEST_ASSERT_MSG((alex->comm_type == PEP_ct_OpenPGP_unconfirmed), "alex->comm_type == PEP_ct_OpenPGP_unconfirmed");
krista@2669
   301
    TEST_ASSERT_MSG((strcmp(alex->address, alex_address) == 0), "strcmp(alex->address, alex_address) == 0");
krista@2461
   302
krista@2461
   303
    cout << "PASS: update_identity() correctly retrieved extant record with just matching address. Retrieved previously patched username." << endl << endl;
krista@2461
   304
    free_identity(alex);
krista@2461
   305
krista@2461
   306
krista@2461
   307
    cout << "****************************************************************************************" << endl;
krista@2461
   308
    cout << "* II: 6. update_identity() with just address on own identity (only case where this is legal)" << endl;
krista@2461
   309
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   310
    
krista@2461
   311
    pEp_identity* somebody = new_identity(uniqname, NULL, NULL, NULL); 
krista@2461
   312
    status = update_identity(session, somebody);
krista@2669
   313
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
   314
    myself(session, somebody);
krista@2669
   315
    TEST_ASSERT_MSG((somebody->fpr), "somebody->fpr");
krista@2669
   316
    TEST_ASSERT_MSG((strcmp(somebody->fpr, new_fpr) == 0), "strcmp(somebody->fpr, new_fpr) == 0");
krista@2669
   317
    TEST_ASSERT_MSG((somebody->username), "somebody->username");
krista@2669
   318
    TEST_ASSERT_MSG((strcmp(somebody->username, start_username) == 0), "strcmp(somebody->username, start_username) == 0");
krista@2669
   319
    TEST_ASSERT_MSG((somebody->user_id), "somebody->user_id");
krista@2669
   320
    TEST_ASSERT_MSG((strcmp(somebody->user_id, default_own_id) == 0), "strcmp(somebody->user_id, default_own_id) == 0");
krista@2669
   321
    TEST_ASSERT_MSG((somebody->me), "somebody->me"); // true in this case, as it was an own identity
krista@2669
   322
    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_pEp), "somebody->comm_type == PEP_ct_pEp");
krista@2669
   323
    TEST_ASSERT_MSG((strcmp(somebody->address, uniqname) == 0), "strcmp(somebody->address, uniqname) == 0");
krista@2461
   324
    
krista@2461
   325
    cout << "PASS: update_identity() retrieved the right identity information given just an address";
krista@2461
   326
    cout << endl << endl;
krista@2461
   327
krista@2461
   328
    free_identity(somebody);
krista@2461
   329
krista@2461
   330
    cout << "****************************************************************************************" << endl;
krista@2461
   331
    cout << "* II: 7. update_identity() for address and user_id that don't exist" << endl;
krista@2461
   332
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   333
krista@2461
   334
    somebody = new_identity("nope@nope.nope", NULL, "some_user_id", NULL); 
krista@2461
   335
    status = update_identity(session, somebody);
krista@2669
   336
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   337
    TEST_ASSERT_MSG((!somebody->fpr), "!somebody->fpr");
krista@2669
   338
    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_key_not_found), "somebody->comm_type == PEP_ct_key_not_found");
krista@2493
   339
    
krista@2493
   340
    cout << "PASS: update_identity() returns identity with no key and unknown comm type" << endl << endl;
krista@2461
   341
krista@2461
   342
    free_identity(somebody);
krista@2461
   343
    
krista@2461
   344
    cout << "****************************************************************************************" << endl;
krista@2461
   345
    cout << "* II: 8. update_identity() for address and and username, but non-matching temp user_id" << endl;
krista@2461
   346
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   347
krista@2461
   348
    // 1. create identity
krista@2461
   349
    const char* bella_address = "pep.test.bella@peptest.ch";
krista@2461
   350
    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
krista@2461
   351
    const char* bella_userid = "TOFU_pep.test.bella@peptest.ch"; // simulate temp ID
krista@2461
   352
    const char* bella_username = "Annabella the Great";
krista@2461
   353
    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");
krista@2461
   354
    
krista@2461
   355
    statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
krista@3254
   356
    TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
krista@2461
   357
krista@2461
   358
    pEp_identity* bella = new_identity(bella_address, bella_fpr, bella_userid, bella_username);
krista@2461
   359
    
krista@2461
   360
    // 2. set identity
krista@2461
   361
    status = set_identity(session, bella);
krista@2669
   362
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
   363
    free_identity(bella);
krista@2461
   364
    
krista@2461
   365
    const char* not_my_userid = "Bad Company";
krista@2461
   366
            
krista@2461
   367
    bella = new_identity(bella_address, NULL, not_my_userid, bella_username); 
krista@2461
   368
    status = update_identity(session, bella);
krista@2669
   369
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   370
    TEST_ASSERT_MSG((bella->fpr), "bella->fpr");
krista@2669
   371
    TEST_ASSERT_MSG((strcmp(bella->fpr, bella_fpr) == 0), "strcmp(bella->fpr, bella_fpr) == 0");
krista@2669
   372
    TEST_ASSERT_MSG((bella->username), "bella->username");
krista@2669
   373
    TEST_ASSERT_MSG((strcmp(bella->username, bella_username) == 0), "strcmp(bella->username, bella_username) == 0");
krista@2669
   374
    TEST_ASSERT_MSG((bella->user_id), "bella->user_id");
krista@2669
   375
    TEST_ASSERT_MSG((strcmp(bella->user_id, not_my_userid) == 0), "strcmp(bella->user_id, not_my_userid) == 0"); // ???
krista@2669
   376
    TEST_ASSERT_MSG((!bella->me), "!bella->me"); 
krista@2669
   377
    TEST_ASSERT_MSG((bella->comm_type == PEP_ct_OpenPGP_unconfirmed), "bella->comm_type == PEP_ct_OpenPGP_unconfirmed");
krista@2669
   378
    TEST_ASSERT_MSG((strcmp(bella->address, bella_address) == 0), "strcmp(bella->address, bella_address) == 0");
krista@2461
   379
krista@2461
   380
    cout << "PASS: update_identity() correctly retrieved extant record with matching address and username; temp user_id in DB patched" << endl << endl;
krista@2461
   381
    free_identity(bella);
krista@2461
   382
krista@2461
   383
    cout << "****************************************************************************************" << endl;
krista@2461
   384
    cout << "* II: 9. update_identity() for address, username, and user_id, but no matching record" << endl;
krista@2461
   385
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   386
    
krista@2461
   387
    const char* rando_name = "Pickley BoofBoof";
krista@2461
   388
    const char* rando_userid = "Boofy";
krista@2461
   389
    const char* rando_address = "boof@pickles.org";
krista@2461
   390
    somebody = new_identity(rando_address, NULL, rando_userid, rando_name);
krista@2461
   391
    status = update_identity(session, somebody);
krista@2461
   392
krista@2669
   393
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   394
    TEST_ASSERT_MSG((!somebody->fpr || somebody->fpr[0] == '\0'), "!somebody->fpr || somebody->fpr[0] == '\0'");
krista@2669
   395
    TEST_ASSERT_MSG((somebody->username), "somebody->username");
krista@2669
   396
    TEST_ASSERT_MSG((strcmp(somebody->username, rando_name) == 0), "strcmp(somebody->username, rando_name) == 0");
krista@2669
   397
    TEST_ASSERT_MSG((somebody->user_id), "somebody->user_id");
krista@2669
   398
    TEST_ASSERT_MSG((strcmp(somebody->user_id, rando_userid) == 0), "strcmp(somebody->user_id, rando_userid) == 0"); // ???
krista@2669
   399
    TEST_ASSERT_MSG((!somebody->me), "!somebody->me"); 
krista@2669
   400
    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_key_not_found), "somebody->comm_type == PEP_ct_key_not_found");
krista@2669
   401
    TEST_ASSERT_MSG((strcmp(somebody->address, rando_address) == 0), "strcmp(somebody->address, rando_address) == 0");
krista@2461
   402
krista@2461
   403
    cout << "PASS: update_identity() correctly created record with no key" << endl << endl;
krista@2461
   404
    free_identity(somebody);
krista@2461
   405
    
krista@2461
   406
    cout << "****************************************************************************************" << endl;
krista@2461
   407
    cout << "* II: 10. update_identity() for address, username, but no matching record" << endl;
krista@2461
   408
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   409
krista@2461
   410
    const char* rando2_name = "Pickles BoofyBoof";
krista@2461
   411
    const char* rando2_address = "boof2@pickles.org";
krista@2461
   412
    somebody = new_identity(rando2_address, NULL, NULL, rando2_name);
krista@2461
   413
    status = update_identity(session, somebody);
krista@2461
   414
    const char* expected_rando2_userid = "TOFU_boof2@pickles.org";
krista@2461
   415
krista@2669
   416
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   417
    TEST_ASSERT_MSG((!somebody->fpr || somebody->fpr[0] == '\0'), "!somebody->fpr || somebody->fpr[0] == '\0'");
krista@2669
   418
    TEST_ASSERT_MSG((somebody->username), "somebody->username");
krista@2669
   419
    TEST_ASSERT_MSG((strcmp(somebody->username, rando2_name) == 0), "strcmp(somebody->username, rando2_name) == 0");
krista@2669
   420
    TEST_ASSERT_MSG((somebody->user_id), "somebody->user_id");
krista@2669
   421
    TEST_ASSERT_MSG((strcmp(somebody->user_id, expected_rando2_userid) == 0), "strcmp(somebody->user_id, expected_rando2_userid) == 0"); // ???
krista@2669
   422
    TEST_ASSERT_MSG((!somebody->me), "!somebody->me"); 
krista@2669
   423
    TEST_ASSERT_MSG((somebody->comm_type == PEP_ct_key_not_found), "somebody->comm_type == PEP_ct_key_not_found");
krista@2669
   424
    TEST_ASSERT_MSG((strcmp(somebody->address, rando2_address) == 0), "strcmp(somebody->address, rando2_address) == 0");
krista@2461
   425
krista@2461
   426
    cout << "PASS: update_identity() correctly created record with no key" << endl << endl;
krista@2461
   427
    free_identity(somebody);
krista@2461
   428
krista@2461
   429
    cout << "****************************************************************************************" << endl;
krista@2461
   430
    cout << "* II: 11. update_identity() for address only, but multiple matching records" << endl;
krista@2461
   431
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   432
krista@2461
   433
    const char* bella_id_2 = "Bella2";
krista@2461
   434
    bella = new_identity(bella_address, NULL, bella_id_2, bella_username);
krista@2461
   435
    
krista@2461
   436
    // 2. set identity
krista@2461
   437
    status = set_identity(session, bella);
krista@2669
   438
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
   439
    free_identity(bella);
krista@2461
   440
                
krista@2461
   441
    bella = new_identity(bella_address, NULL, NULL, NULL); 
krista@2461
   442
    status = update_identity(session, bella);
krista@2669
   443
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
   444
krista@2496
   445
//    cout << "PASS: update_identity() correctly failed with no matching records (too little info)" << endl << endl;
krista@2461
   446
    
krista@2461
   447
    cout << "****************************************************************************************" << endl;
krista@2461
   448
    cout << "* III: key election " << endl;
krista@2461
   449
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   450
krista@2461
   451
    cout << "****************************************************************************************" << endl;
krista@2461
   452
    cout << "* III: 1. key election: get identity for user with expired key" << endl;
krista@2461
   453
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   454
krista@2461
   455
    // 1. create identity
krista@2461
   456
    const char* bernd_address = "bernd.das.brot@darthmama.org";
krista@2461
   457
    const char* bernd_fpr = "F8CE0F7E24EB190A2FCBFD38D4B088A7CAFAA422";
krista@2461
   458
    const char* bernd_userid = "BERND_ID"; // simulate temp ID
krista@2461
   459
    const char* bernd_username = "Bernd das Brot der Ultimative Testkandidat";
krista@2461
   460
    const string bernd_pub_key = slurp("test_keys/pub/bernd.das.brot-0xCAFAA422_pub.asc");
krista@2461
   461
    
krista@2461
   462
    statuspub = import_key(session, bernd_pub_key.c_str(), bernd_pub_key.length(), NULL);
krista@3254
   463
    TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
krista@2461
   464
krista@2461
   465
    pEp_identity* bernd = new_identity(bernd_address, bernd_fpr, bernd_userid, bernd_username);
krista@2461
   466
    
krista@2461
   467
    // 2. set identity
krista@2461
   468
    status = set_identity(session, bernd);
krista@2669
   469
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2461
   470
    free_identity(bernd);
krista@2461
   471
                
krista@2461
   472
    bernd = new_identity(bernd_address, NULL, bernd_userid, bernd_username); 
krista@2461
   473
    status = update_identity(session, bernd);
krista@2669
   474
    TEST_ASSERT_MSG((status != PEP_STATUS_OK), "status != PEP_STATUS_OK");
krista@2669
   475
    TEST_ASSERT_MSG((!bernd->fpr || bernd->fpr[0] == '\0'), "!bernd->fpr || bernd->fpr[0] == '\0'");
krista@2669
   476
    TEST_ASSERT_MSG((bernd->username), "bernd->username");
krista@2669
   477
    TEST_ASSERT_MSG((strcmp(bernd->username, bernd_username) == 0), "strcmp(bernd->username, bernd_username) == 0");
krista@2669
   478
    TEST_ASSERT_MSG((bernd->user_id), "bernd->user_id");
krista@2669
   479
    TEST_ASSERT_MSG((strcmp(bernd->user_id, bernd_userid) == 0), "strcmp(bernd->user_id, bernd_userid) == 0"); // ???
krista@2669
   480
    TEST_ASSERT_MSG((!bernd->me), "!bernd->me"); 
krista@2669
   481
    TEST_ASSERT_MSG((bernd->comm_type == PEP_ct_key_expired), "bernd->comm_type == PEP_ct_key_expired");
krista@2669
   482
    TEST_ASSERT_MSG((strcmp(bernd->address, bernd_address) == 0), "strcmp(bernd->address, bernd_address) == 0");
krista@2461
   483
krista@2461
   484
    cout << "PASS: update_identity() correctly rejected expired key with PEP_KEY_UNSUITABLE and PEP_ct_key_expired" << endl << endl;
krista@2461
   485
    free_identity(bernd);
krista@2461
   486
krista@2461
   487
krista@2461
   488
    cout << "****************************************************************************************" << endl;
krista@2467
   489
    cout << "* III: 2. key election: get identity for user with only revoked or mistrusted keys " << endl;
krista@2461
   490
    cout << "****************************************************************************************" << endl << endl;
krista@2467
   491
krista@2467
   492
    // Create id with no key
krista@2467
   493
    cout << "Creating new id with no key for : ";
krista@2467
   494
    char *uniqname_10000 = strdup("AAAAtestuser@testdomain.org");
krista@2467
   495
    srandom(time(NULL));
krista@2467
   496
    for(int i=0; i < 4;i++)
krista@2467
   497
        uniqname_10000[i] += random() & 0xf;
krista@2461
   498
    
krista@2467
   499
    cout << uniqname_10000 << "\n";
krista@2467
   500
krista@2467
   501
    char* revoke_uuid = get_new_uuid();
krista@2467
   502
krista@2467
   503
    pEp_identity * revokemaster_3000 = new_identity(uniqname_10000, NULL, revoke_uuid, start_username);
krista@2467
   504
    
krista@2467
   505
    cout << "Generate three keys for "  << uniqname_10000 << " who has user_id " << revoke_uuid << endl; 
krista@2467
   506
krista@2467
   507
    char* revoke_fpr_arr[3];
krista@2467
   508
    
krista@2467
   509
    status = generate_keypair(session, revokemaster_3000);
krista@2669
   510
    TEST_ASSERT_MSG((status == PEP_STATUS_OK && revokemaster_3000->fpr), "status == PEP_STATUS_OK && revokemaster_3000->fpr");
krista@2467
   511
    revoke_fpr_arr[0] = strdup(revokemaster_3000->fpr);
krista@2467
   512
    free(revokemaster_3000->fpr);
krista@2467
   513
    revokemaster_3000->fpr = NULL;
krista@2467
   514
    
krista@2467
   515
    status = generate_keypair(session, revokemaster_3000);
krista@2669
   516
    TEST_ASSERT_MSG((status == PEP_STATUS_OK && revokemaster_3000->fpr), "status == PEP_STATUS_OK && revokemaster_3000->fpr");
krista@2467
   517
    revoke_fpr_arr[1] = strdup(revokemaster_3000->fpr);
krista@2467
   518
    free(revokemaster_3000->fpr);
krista@2467
   519
    revokemaster_3000->fpr = NULL;
krista@2467
   520
    
krista@2467
   521
    status = generate_keypair(session, revokemaster_3000);
krista@2669
   522
    TEST_ASSERT_MSG((status == PEP_STATUS_OK && revokemaster_3000->fpr), "status == PEP_STATUS_OK && revokemaster_3000->fpr");
krista@2467
   523
    revoke_fpr_arr[2] = strdup(revokemaster_3000->fpr);
krista@2467
   524
    free(revokemaster_3000->fpr);
krista@2467
   525
    revokemaster_3000->fpr = NULL;
krista@2467
   526
    
krista@2467
   527
    cout << "Trust "  << revoke_fpr_arr[2] << " (default for identity) and " << revoke_fpr_arr[0] << endl;
krista@2467
   528
    
krista@2467
   529
    free(revokemaster_3000->fpr);
krista@2467
   530
    revokemaster_3000->fpr = strdup(revoke_fpr_arr[2]);
krista@2467
   531
    status = trust_personal_key(session, revokemaster_3000);
krista@2669
   532
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2494
   533
    status = get_trust(session, revokemaster_3000);
krista@2669
   534
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   535
    TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), "revokemaster_3000->comm_type & PEP_ct_confirmed");
krista@2467
   536
krista@2467
   537
    free(revokemaster_3000->fpr);
krista@2467
   538
    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
krista@2467
   539
    status = trust_personal_key(session, revokemaster_3000);
krista@2669
   540
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2494
   541
    status = get_trust(session, revokemaster_3000);
krista@2669
   542
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   543
    TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), "revokemaster_3000->comm_type & PEP_ct_confirmed");
krista@2467
   544
    
krista@2467
   545
    status = update_identity(session, revokemaster_3000);
krista@2669
   546
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   547
    TEST_ASSERT_MSG((revokemaster_3000->fpr), "revokemaster_3000->fpr");
krista@2669
   548
    TEST_ASSERT_MSG((strcmp(revokemaster_3000->fpr, revoke_fpr_arr[2]) == 0), "strcmp(revokemaster_3000->fpr, revoke_fpr_arr[2]) == 0");
krista@2669
   549
    TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), "revokemaster_3000->comm_type & PEP_ct_confirmed");
krista@2467
   550
krista@2467
   551
    cout << "update_identity returns the correct identity default." << endl;
krista@2467
   552
    
krista@2467
   553
    cout << "Ok, now... we revoke the default..." << endl;
krista@2467
   554
    
krista@2467
   555
    cout << "Revoking " << revoke_fpr_arr[2] << endl;
krista@2467
   556
krista@2467
   557
    status = revoke_key(session, revoke_fpr_arr[2], "This little pubkey went to market");
krista@2661
   558
    TEST_ASSERT (status == PEP_STATUS_OK);
krista@2467
   559
krista@2467
   560
    bool is_revoked;
krista@2467
   561
    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
krista@2669
   562
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   563
    TEST_ASSERT_MSG((is_revoked), "is_revoked");
krista@2467
   564
krista@2467
   565
    cout << "Success revoking " << revoke_fpr_arr[2] << "!!! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
krista@2461
   566
    
krista@2467
   567
    cout << "Now see if update_identity gives us " << revoke_fpr_arr[0] << ", the only trusted key left." << endl;
krista@2467
   568
    status = update_identity(session, revokemaster_3000);
krista@2669
   569
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   570
    TEST_ASSERT_MSG((revokemaster_3000->fpr), "revokemaster_3000->fpr");
krista@2669
   571
    TEST_ASSERT_MSG((strcmp(revokemaster_3000->fpr, revoke_fpr_arr[0]) == 0), "strcmp(revokemaster_3000->fpr, revoke_fpr_arr[0]) == 0");
krista@2669
   572
    TEST_ASSERT_MSG((revokemaster_3000->comm_type & PEP_ct_confirmed), "revokemaster_3000->comm_type & PEP_ct_confirmed");    
krista@2461
   573
    
krista@2467
   574
    cout << "Success! So let's mistrust it, because seriously, that key was so uncool." << endl;
krista@2467
   575
    
krista@2467
   576
    status = key_mistrusted(session, revokemaster_3000);
krista@2669
   577
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2467
   578
krista@2467
   579
    status = get_trust(session, revokemaster_3000);
krista@2669
   580
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   581
    TEST_ASSERT_MSG((revokemaster_3000->comm_type == PEP_ct_mistrusted), "revokemaster_3000->comm_type == PEP_ct_mistrusted");
krista@2467
   582
    
krista@2467
   583
    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
krista@2467
   584
krista@2467
   585
    cout << "The only fpr left is an untrusted one - let's make sure this is what we get from update_identity." << endl;
krista@2467
   586
krista@2467
   587
    status = update_identity(session, revokemaster_3000);
krista@2669
   588
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   589
    TEST_ASSERT_MSG((revokemaster_3000->fpr), "revokemaster_3000->fpr");
krista@2669
   590
    TEST_ASSERT_MSG((strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0), "strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0");
krista@2669
   591
    TEST_ASSERT_MSG((!(revokemaster_3000->comm_type & PEP_ct_confirmed)), "!(revokemaster_3000->comm_type & PEP_ct_confirmed)");    
krista@2467
   592
krista@2467
   593
    cout << "Success! We got " << revoke_fpr_arr[1] << "as the fpr with comm_type " << revokemaster_3000->comm_type << endl;
krista@2467
   594
    
krista@2467
   595
    cout << "But, you know... let's revoke that one too and see what update_identity gives us." << endl;
krista@2467
   596
krista@2467
   597
    status = revoke_key(session, revoke_fpr_arr[1], "Because it's more fun to revoke ALL of someone's keys");
krista@2661
   598
    TEST_ASSERT (status == PEP_STATUS_OK);
krista@2467
   599
krista@2467
   600
    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
krista@2669
   601
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
   602
    TEST_ASSERT_MSG((is_revoked), "is_revoked");
krista@2467
   603
    
krista@2467
   604
    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
krista@2467
   605
krista@2467
   606
    cout << "Call update_identity - we expect nothing, plus an error comm type." << endl;
krista@2467
   607
krista@2467
   608
    status = update_identity(session, revokemaster_3000);
krista@2669
   609
    TEST_ASSERT_MSG((status != PEP_STATUS_OK), "status != PEP_STATUS_OK");
krista@2669
   610
    TEST_ASSERT_MSG((!revokemaster_3000->fpr), "!revokemaster_3000->fpr");
krista@2669
   611
    TEST_ASSERT_MSG((revokemaster_3000->username), "revokemaster_3000->username");
krista@2669
   612
    TEST_ASSERT_MSG((strcmp(revokemaster_3000->user_id, revoke_uuid) == 0), "strcmp(revokemaster_3000->user_id, revoke_uuid) == 0");
krista@2669
   613
    TEST_ASSERT_MSG((revokemaster_3000->comm_type == PEP_ct_key_not_found), "revokemaster_3000->comm_type == PEP_ct_key_not_found");
krista@2467
   614
    cout << "Success! No key found. The comm_status error was " << revokemaster_3000->comm_type << "and the return status was " << tl_status_string(status) << endl;
krista@2461
   615
krista@2467
   616
    free_identity(revokemaster_3000);
krista@2461
   617
krista@2461
   618
    cout << "****************************************************************************************" << endl;
krista@2461
   619
    cout << "* III: 100000000. key election: more to come " << endl;
krista@2461
   620
    cout << "****************************************************************************************" << endl << endl;
krista@2461
   621
krista@2461
   622
}