test/src/engine_tests/RevocationTests.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Thu, 27 Jun 2019 15:12:42 +0200
branchENGINE-581
changeset 3886 ebd61a1cf6db
parent 3657 ee9abaa0e34b
child 3994 eb76ac4d84c8
permissions -rw-r--r--
Fixed hole in update_identity spec for extant identities without saved fprs.
neal@3657
     1
// This file is under GNU General Public License 3.0
neal@3657
     2
// see LICENSE.txt
neal@3657
     3
neal@3657
     4
#include <stdlib.h>
neal@3657
     5
#include <string>
neal@3657
     6
#include <iostream>
neal@3657
     7
#include <fstream>
neal@3657
     8
#include <cstring> // for strcmp()
neal@3657
     9
#include "TestConstants.h"
neal@3657
    10
neal@3657
    11
#include "pEpEngine.h"
neal@3657
    12
#include "message_api.h"
neal@3657
    13
#include "keymanagement.h"
neal@3657
    14
#include "test_util.h"
neal@3657
    15
neal@3657
    16
#include <cpptest.h>
neal@3657
    17
#include "EngineTestSessionSuite.h"
neal@3657
    18
#include "RevocationTests.h"
neal@3657
    19
neal@3657
    20
using namespace std;
neal@3657
    21
neal@3657
    22
RevocationTests::RevocationTests(string suitename, string test_home_dir) :
neal@3657
    23
    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
neal@3657
    24
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("RevocationTests::revocation"),
neal@3657
    25
                                                                      static_cast<Func>(&RevocationTests::revocation)));
neal@3657
    26
}
neal@3657
    27
neal@3657
    28
void RevocationTests::setup() {
neal@3657
    29
    EngineTestSessionSuite::setup();
neal@3657
    30
}
neal@3657
    31
neal@3657
    32
void RevocationTests::tear_down() {
neal@3657
    33
    EngineTestSessionSuite::tear_down();
neal@3657
    34
}
neal@3657
    35
neal@3657
    36
void RevocationTests::revocation() {
neal@3657
    37
    // Read the key.
neal@3657
    38
    const string key = slurp("test_keys/priv/pep-test-linda-0xDCD555B6055ADE22_priv.asc");
neal@3657
    39
neal@3657
    40
    PEP_STATUS status = import_key(session, key.c_str(), key.length(), NULL);
neal@3657
    41
    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), "status == PEP_STATUS_OK");
neal@3657
    42
neal@3657
    43
    pEp_identity* pre = new_identity("linda@example.org", NULL, NULL, NULL);
neal@3657
    44
    status = update_identity(session, pre);
neal@3657
    45
    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
neal@3657
    46
    TEST_ASSERT_MSG((pre->comm_type == PEP_ct_OpenPGP_unconfirmed), tl_ct_string(pre->comm_type));
neal@3657
    47
neal@3657
    48
    // Read in the revocation certificate.
neal@3657
    49
    const string rev = slurp("test_keys/priv/pep-test-linda-0xDCD555B6055ADE22.rev");
neal@3657
    50
neal@3657
    51
    status = import_key(session, rev.c_str(), rev.length(), NULL);
neal@3657
    52
    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), "status == PEP_STATUS_OK");
neal@3657
    53
neal@3657
    54
    pEp_identity* post = new_identity("linda@example.org", NULL, NULL, NULL);
krista@3886
    55
    
krista@3886
    56
//    string save_fpr = post->fpr;
krista@3886
    57
krista@3886
    58
    stringlist_t* keylist = NULL;
krista@3886
    59
    
krista@3886
    60
    status = find_keys(session, "linda@example.org", &keylist);
krista@3886
    61
    TEST_ASSERT(status == PEP_STATUS_OK);
krista@3886
    62
    
neal@3657
    63
    status = update_identity(session, post);
neal@3657
    64
    // PEP_KEY_UNSUITABLE => revoked (or something similar).
neal@3657
    65
    TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
krista@3886
    66
    TEST_ASSERT_MSG((post->comm_type == PEP_ct_key_not_found), tl_ct_string(post->comm_type));
krista@3886
    67
    free(post->fpr);
krista@3886
    68
    post->fpr = strdup(keylist->value);
krista@3886
    69
    status = get_trust(session, post);
krista@3886
    70
    TEST_ASSERT(status == PEP_STATUS_OK);
neal@3657
    71
    TEST_ASSERT_MSG((post->comm_type == PEP_ct_key_revoked), tl_ct_string(post->comm_type));
krista@3886
    72
    free_identity(pre);
krista@3886
    73
    free_identity(post);
krista@3886
    74
    free_stringlist(keylist);    
neal@3657
    75
}