ENGINE-289: Ooops... ACTUALLY added tests for myself() default user_id aliases ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Wed, 17 Jan 2018 12:24:54 +0100
branchENGINE-289
changeset 24026b3073104e07
parent 2401 f5aa974726e1
child 2403 6091e86174d7
ENGINE-289: Ooops... ACTUALLY added tests for myself() default user_id aliases
test/userid_alias_test.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/userid_alias_test.cc	Wed Jan 17 12:24:54 2018 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#include <iostream>
     1.8 +#include <iostream>
     1.9 +#include <fstream>
    1.10 +#include <string>
    1.11 +#include <cstring> // for strcmp()
    1.12 +#include <assert.h>
    1.13 +#include "pEpEngine.h"
    1.14 +#include "message_api.h"
    1.15 +#include "keymanagement.h"
    1.16 +#include "test_util.h"
    1.17 +
    1.18 +using namespace std;
    1.19 +
    1.20 +int main() {
    1.21 +    cout << "\n*** test user_id aliases ***\n\n";
    1.22 +
    1.23 +    PEP_SESSION session;
    1.24 +    
    1.25 +    cout << "calling init()\n";
    1.26 +    PEP_STATUS status = init(&session);
    1.27 +    assert(status == PEP_STATUS_OK);
    1.28 +    assert(session);
    1.29 +    cout << "init() completed.\n";
    1.30 +
    1.31 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    1.32 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
    1.33 +    
    1.34 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    1.35 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
    1.36 +    assert(statuspub == PEP_STATUS_OK);
    1.37 +    assert(statuspriv == PEP_STATUS_OK);
    1.38 +
    1.39 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
    1.40 +
    1.41 +    const char* alias1 = "TheBigCheese";
    1.42 +    const char* alias2 = "PEBKAC";
    1.43 +
    1.44 +    cout << "First, set up an identity with PEP_OWN_USERID as user_id." << endl;
    1.45 +    status = myself(session, alice);
    1.46 +    assert(status == PEP_STATUS_OK);
    1.47 +    cout << "After myself, user_id is " << alice->user_id << endl;
    1.48 +    assert(strcmp(alice->user_id, PEP_OWN_USERID) == 0);
    1.49 +    
    1.50 +    cout << "Now set up an identity with " << alias1 << " as user_id." << endl;
    1.51 +    free(alice->user_id);
    1.52 +    
    1.53 +    alice->user_id = strdup(alias1);
    1.54 +    status = myself(session, alice);
    1.55 +    assert(status == PEP_STATUS_OK);
    1.56 +    cout << "After myself, user_id is " << alice->user_id << endl;
    1.57 +    assert(strcmp(alice->user_id, PEP_OWN_USERID) == 0);
    1.58 +
    1.59 +    cout << "Now set up an identity with " << alias2 << " as user_id." << endl;
    1.60 +    free(alice->user_id);
    1.61 +    
    1.62 +    alice->user_id = strdup(alias2);
    1.63 +    status = myself(session, alice);
    1.64 +    assert(status == PEP_STATUS_OK);
    1.65 +    cout << "After myself, user_id is " << alice->user_id << endl;
    1.66 +    assert(strcmp(alice->user_id, PEP_OWN_USERID) == 0);    
    1.67 +
    1.68 +    char* default_id = NULL;
    1.69 +    status = get_userid_alias_default(session, alias1, &default_id);
    1.70 +    assert(status == PEP_STATUS_OK);
    1.71 +    cout << "Default user_id for " << alias1 << " is " << default_id << endl;
    1.72 +    assert(strcmp(default_id, PEP_OWN_USERID) == 0);
    1.73 +    
    1.74 +    free(default_id);
    1.75 +    default_id = NULL;
    1.76 +    status = get_userid_alias_default(session, alias2, &default_id);
    1.77 +    assert(status == PEP_STATUS_OK);
    1.78 +    cout << "Default user_id for " << alias2 << " is " << default_id << endl;
    1.79 +    assert(strcmp(default_id, PEP_OWN_USERID) == 0);
    1.80 +    
    1.81 +    
    1.82 +    return 0;
    1.83 +}