test/src/engine_tests/UserIDAliasTests.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 29 Jan 2019 19:19:30 +0100
branchENGINE-448
changeset 3254 6e7f6bc9460a
parent 3121 f33a2ae77177
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
     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 "pEpEngine.h"
    10 #include "message_api.h"
    11 #include "keymanagement.h"
    12 #include "test_util.h"
    13 
    14 #include "EngineTestSuite.h"
    15 #include "EngineTestSessionSuite.h"
    16 #include "UserIDAliasTests.h"
    17 
    18 using namespace std;
    19 
    20 UserIDAliasTests::UserIDAliasTests(string suitename, string test_home_dir) : 
    21     EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
    22     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("UserIDAliasTests::check_userid_aliases"),
    23                                                                       static_cast<Func>(&UserIDAliasTests::check_userid_aliases)));
    24 }
    25 
    26 void UserIDAliasTests::check_userid_aliases() {
    27     cout << "\n*** userid_alias_test ***\n\n";
    28 
    29     PEP_STATUS status = PEP_STATUS_OK;
    30 
    31     const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    32     const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
    33     
    34     PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    35     PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
    36     TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
    37     TEST_ASSERT_MSG((statuspriv == PEP_KEY_IMPORTED), "statuspriv == PEP_STATUS_OK");
    38 
    39     pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
    40 
    41     const char* alias1 = "TheBigCheese";
    42     const char* alias2 = "PEBKAC";
    43 
    44     char* own_id = NULL;
    45     status = get_default_own_userid(session, &own_id);
    46     if (!own_id)
    47         own_id = strdup(PEP_OWN_USERID);
    48     
    49     cout << "First, set up an identity with PEP_OWN_USERID as user_id." << endl;
    50     status = myself(session, alice);
    51     TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    52     cout << "After myself, user_id is " << alice->user_id << endl;
    53     TEST_ASSERT_MSG((strcmp(alice->user_id, own_id) == 0), "strcmp(alice->user_id, own_id) == 0");
    54     
    55     cout << "Now set up an identity with " << alias1 << " as user_id." << endl;
    56     free(alice->user_id);
    57     
    58     alice->user_id = strdup(alias1);
    59     status = myself(session, alice);
    60     TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    61     cout << "After myself, user_id is " << alice->user_id << endl;
    62     TEST_ASSERT_MSG((strcmp(alice->user_id, own_id) == 0), "strcmp(alice->user_id, own_id) == 0");
    63 
    64     cout << "Now set up an identity with " << alias2 << " as user_id." << endl;
    65     free(alice->user_id);
    66     
    67     alice->user_id = strdup(alias2);
    68     status = myself(session, alice);
    69     TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    70     cout << "After myself, user_id is " << alice->user_id << endl;
    71     TEST_ASSERT_MSG((strcmp(alice->user_id, own_id) == 0), "strcmp(alice->user_id, own_id) == 0");    
    72 
    73     char* default_id = NULL;
    74     status = get_userid_alias_default(session, alias1, &default_id);
    75     TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    76     cout << "Default user_id for " << alias1 << " is " << default_id << endl;
    77     TEST_ASSERT_MSG((strcmp(default_id, own_id) == 0), "strcmp(default_id, own_id) == 0");
    78     
    79     free(default_id);
    80     default_id = NULL;
    81     status = get_userid_alias_default(session, alias2, &default_id);
    82     TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    83     cout << "Default user_id for " << alias2 << " is " << default_id << endl;
    84     TEST_ASSERT_MSG((strcmp(default_id, own_id) == 0), "strcmp(default_id, own_id) == 0");
    85     
    86 }