test/userid_alias_test.cc
author Krista Bennett <krista@pep-project.org>
Mon, 05 Feb 2018 10:58:03 +0100
branchENGINE-250
changeset 2477 45e8ed722fec
parent 2462 48b526a0daac
permissions -rw-r--r--
Intermittent commit
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <iostream>
     5 #include <iostream>
     6 #include <fstream>
     7 #include <string>
     8 #include <cstring> // for strcmp()
     9 #include <assert.h>
    10 #include "pEpEngine.h"
    11 #include "message_api.h"
    12 #include "keymanagement.h"
    13 #include "test_util.h"
    14 
    15 using namespace std;
    16 
    17 int main() {
    18     cout << "\n*** userid_alias_test ***\n\n";
    19 
    20     PEP_SESSION session;
    21     
    22     cout << "calling init()\n";
    23     PEP_STATUS status = init(&session);
    24     assert(status == PEP_STATUS_OK);
    25     assert(session);
    26     cout << "init() completed.\n";
    27 
    28     const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    29     const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
    30     
    31     PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    32     PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
    33     assert(statuspub == PEP_STATUS_OK);
    34     assert(statuspriv == PEP_STATUS_OK);
    35 
    36     pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
    37 
    38     const char* alias1 = "TheBigCheese";
    39     const char* alias2 = "PEBKAC";
    40 
    41     char* own_id = NULL;
    42     status = get_default_own_userid(session, &own_id);
    43     if (!own_id)
    44         own_id = strdup(PEP_OWN_USERID);
    45     
    46     cout << "First, set up an identity with PEP_OWN_USERID as user_id." << endl;
    47     status = myself(session, alice);
    48     assert(status == PEP_STATUS_OK);
    49     cout << "After myself, user_id is " << alice->user_id << endl;
    50     assert(strcmp(alice->user_id, own_id) == 0);
    51     
    52     cout << "Now set up an identity with " << alias1 << " as user_id." << endl;
    53     free(alice->user_id);
    54     
    55     alice->user_id = strdup(alias1);
    56     status = myself(session, alice);
    57     assert(status == PEP_STATUS_OK);
    58     cout << "After myself, user_id is " << alice->user_id << endl;
    59     assert(strcmp(alice->user_id, own_id) == 0);
    60 
    61     cout << "Now set up an identity with " << alias2 << " as user_id." << endl;
    62     free(alice->user_id);
    63     
    64     alice->user_id = strdup(alias2);
    65     status = myself(session, alice);
    66     assert(status == PEP_STATUS_OK);
    67     cout << "After myself, user_id is " << alice->user_id << endl;
    68     assert(strcmp(alice->user_id, own_id) == 0);    
    69 
    70     char* default_id = NULL;
    71     status = get_userid_alias_default(session, alias1, &default_id);
    72     assert(status == PEP_STATUS_OK);
    73     cout << "Default user_id for " << alias1 << " is " << default_id << endl;
    74     assert(strcmp(default_id, own_id) == 0);
    75     
    76     free(default_id);
    77     default_id = NULL;
    78     status = get_userid_alias_default(session, alias2, &default_id);
    79     assert(status == PEP_STATUS_OK);
    80     cout << "Default user_id for " << alias2 << " is " << default_id << endl;
    81     assert(strcmp(default_id, own_id) == 0);
    82     
    83     
    84     return 0;
    85 }