test/mistrust_undo_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 14:12:02 +0100
changeset 2418 05678e77bc6a
parent 2370 b37530bf26fa
child 2471 4f1c2d62b2dd
permissions -rw-r--r--
fixed update_identity call that could be called on a myself value in outgoing_message_rating
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <stdlib.h>
     5 #include <string.h>
     6 #include <time.h>
     7 #include "platform.h"
     8 #include <iostream>
     9 #include <fstream>
    10 #include <assert.h>
    11 #include "mime.h"
    12 #include "message_api.h"
    13 #include "test_util.h"
    14 
    15 using namespace std;
    16 
    17 int main() {
    18     cout << "\n*** mistrust_undo_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     cout << "importing key 0x39E5DAB5." << endl;
    29     const string pub_key = slurp("test_keys/pub/mistrust.undo.test-0x39E5DAB5_pub.asc");
    30 
    31     assert(pub_key.length() != 0);
    32     
    33     PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
    34     assert(statuspub == PEP_STATUS_OK);
    35     cout << "Key imported." << endl << endl;
    36     
    37     cout << "Setting up identity for mistrust.undo.test@pep-project.org and making comm_type PEP_ct_pEp."  << endl;
    38     pEp_identity* recip1 = new_identity("mistrust.undo.test@pep-project.org", NULL, "TOFU_mistrust.undo.test@pep-project.org", "Mistrust Undo");
    39     status = update_identity(session,recip1);
    40     assert(status == PEP_STATUS_OK);
    41     assert(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
    42     
    43     // First, we need the fpr to be in the DB system.
    44     status = set_identity(session,recip1);
    45     // Then we update the trust.
    46     // This is not an external function. We use it to expedite the test since we don't do a sync exchange here.
    47     status = update_trust_for_fpr(session, recip1->fpr, PEP_ct_pEp);
    48     // Then we retrieve the new trust.
    49     status = update_identity(session,recip1);
    50     assert(status == PEP_STATUS_OK);
    51     assert(recip1->comm_type == PEP_ct_pEp);
    52     assert(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
    53     cout << "mistrust.undo.test@pep-project.org set up and comm_type is PEP_ct_pEp."  << endl << endl;
    54 
    55     // Ok, mistrust away
    56     cout << "Mistrusting mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5)."  << endl;   
    57     status = key_mistrusted(session, recip1);
    58     assert(status == PEP_STATUS_OK);
    59     status = update_identity(session,recip1);
    60     assert(status == PEP_STATUS_OK);
    61     assert(recip1->comm_type == PEP_ct_mistrusted);
    62     cout << "Mistrusted mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5) and comm_type set to PEP_ct_mistrusted)." << endl  << endl;    
    63     
    64     cout << "Undo mistrust (restore identity and trust in DB)" << endl;
    65     // Undo it
    66     status = undo_last_mistrust(session);
    67     assert(status == PEP_STATUS_OK);
    68     status = update_identity(session, recip1);
    69     assert(recip1->comm_type == PEP_ct_pEp);
    70     assert(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
    71     cout << "Undo mistrust (restore identity and trust in DB) - trust is now PEP_ct_pEp." << endl << endl;
    72 
    73     cout << "Success!!!" << endl << endl;
    74     
    75     free_identity(recip1);
    76     release(session);
    77 
    78     return 0;
    79 }