test/src/engine_tests/MistrustUndoTests.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 29 Jan 2019 19:19:30 +0100
branchENGINE-448
changeset 3254 6e7f6bc9460a
parent 2669 1b103e8a95f7
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@2132
     1
// This file is under GNU General Public License 3.0
krista@2132
     2
// see LICENSE.txt
krista@2132
     3
krista@2132
     4
#include <stdlib.h>
krista@2661
     5
#include <string>
krista@2661
     6
#include <cstring>
krista@2132
     7
#include <time.h>
krista@2132
     8
#include <iostream>
krista@2132
     9
#include <fstream>
krista@2661
    10
krista@2661
    11
#include "pEpEngine.h"
krista@2661
    12
#include "platform.h"
krista@2132
    13
#include "mime.h"
krista@2132
    14
#include "message_api.h"
krista@2132
    15
#include "test_util.h"
krista@2132
    16
krista@2661
    17
#include <cpptest.h>
krista@2661
    18
#include "EngineTestSessionSuite.h"
krista@2661
    19
#include "MistrustUndoTests.h"
krista@2661
    20
krista@2132
    21
using namespace std;
krista@2132
    22
krista@2661
    23
MistrustUndoTests::MistrustUndoTests(string suitename, string test_home_dir) :
krista@2661
    24
    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
krista@2661
    25
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MistrustUndoTests::check_mistrust_undo"),
krista@2661
    26
                                                                      static_cast<Func>(&MistrustUndoTests::check_mistrust_undo)));
krista@2661
    27
}
krista@2132
    28
krista@2661
    29
void MistrustUndoTests::check_mistrust_undo() {
krista@2661
    30
    PEP_STATUS status = PEP_STATUS_OK;
krista@2132
    31
krista@2132
    32
    cout << "importing key 0x39E5DAB5." << endl;
krista@2132
    33
    const string pub_key = slurp("test_keys/pub/mistrust.undo.test-0x39E5DAB5_pub.asc");
krista@2132
    34
krista@2669
    35
    TEST_ASSERT_MSG((pub_key.length() != 0), "pub_key.length() != 0");
krista@2132
    36
    
krista@2132
    37
    PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
krista@3254
    38
    TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
krista@2132
    39
    cout << "Key imported." << endl << endl;
krista@2132
    40
    
krista@2132
    41
    cout << "Setting up identity for mistrust.undo.test@pep-project.org and making comm_type PEP_ct_pEp."  << endl;
krista@2132
    42
    pEp_identity* recip1 = new_identity("mistrust.undo.test@pep-project.org", NULL, "TOFU_mistrust.undo.test@pep-project.org", "Mistrust Undo");
krista@2132
    43
    status = update_identity(session,recip1);
krista@2669
    44
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
    45
    TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
krista@2132
    46
    
krista@2370
    47
    // First, we need the fpr to be in the DB system.
krista@2370
    48
    status = set_identity(session,recip1);
krista@2370
    49
    // Then we update the trust.
krista@2132
    50
    // This is not an external function. We use it to expedite the test since we don't do a sync exchange here.
krista@2132
    51
    status = update_trust_for_fpr(session, recip1->fpr, PEP_ct_pEp);
krista@2370
    52
    // Then we retrieve the new trust.
krista@2132
    53
    status = update_identity(session,recip1);
krista@2669
    54
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
    55
    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_pEp), "recip1->comm_type == PEP_ct_pEp");
krista@2669
    56
    TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
krista@2132
    57
    cout << "mistrust.undo.test@pep-project.org set up and comm_type is PEP_ct_pEp."  << endl << endl;
krista@2132
    58
krista@2132
    59
    // Ok, mistrust away
krista@2132
    60
    cout << "Mistrusting mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5)."  << endl;   
krista@2132
    61
    status = key_mistrusted(session, recip1);
krista@2669
    62
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2132
    63
    status = update_identity(session,recip1);
krista@2669
    64
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2669
    65
    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_key_not_found), "recip1->comm_type == PEP_ct_key_not_found");
krista@2471
    66
    recip1->fpr = strdup("BACC7A60A88A39A25D99B4A545D7542F39E5DAB5");
krista@2471
    67
    status = get_trust(session, recip1);
krista@2669
    68
    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_mistrusted), "recip1->comm_type == PEP_ct_mistrusted");
krista@2471
    69
     
krista@2471
    70
    cout << "Mistrusted mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5) and comm_type IN DB set to PEP_ct_mistrusted)." << endl  << endl;    
krista@2132
    71
    
krista@2132
    72
    cout << "Undo mistrust (restore identity and trust in DB)" << endl;
krista@2132
    73
    // Undo it
krista@2132
    74
    status = undo_last_mistrust(session);
krista@2669
    75
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
krista@2132
    76
    status = update_identity(session, recip1);
krista@2669
    77
    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_pEp), "recip1->comm_type == PEP_ct_pEp");
krista@2669
    78
    TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
krista@2132
    79
    cout << "Undo mistrust (restore identity and trust in DB) - trust is now PEP_ct_pEp." << endl << endl;
krista@2132
    80
krista@2132
    81
    cout << "Success!!!" << endl << endl;
krista@2132
    82
    
krista@2132
    83
    free_identity(recip1);
krista@2132
    84
}