test/src/engine_tests/BCCTests.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 29 Jan 2019 19:19:30 +0100
branchENGINE-448
changeset 3254 6e7f6bc9460a
parent 2740 cd666a204266
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
krista@2740
     1
// This file is under GNU General Public License 3.0
krista@2740
     2
// see LICENSE.txt
krista@2740
     3
krista@2740
     4
#include <stdlib.h>
krista@2740
     5
#include <string>
krista@2740
     6
#include <cstring>
krista@2740
     7
#include <assert.h>
krista@2740
     8
krista@2740
     9
#include "pEpEngine.h"
krista@2740
    10
#include "message_api.h"
krista@2740
    11
krista@2740
    12
#include <cpptest.h>
krista@2740
    13
#include "test_util.h"
krista@2740
    14
#include "EngineTestIndividualSuite.h"
krista@2740
    15
#include "BCCTests.h"
krista@2740
    16
krista@2740
    17
using namespace std;
krista@2740
    18
krista@2740
    19
BCCTests::BCCTests(string suitename, string test_home_dir) :
krista@2740
    20
    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
krista@2740
    21
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("BCCTests::check_single_BCC"),
krista@2740
    22
                                                                      static_cast<Func>(&BCCTests::check_single_BCC)));
krista@2740
    23
}
krista@2740
    24
krista@2740
    25
void BCCTests::setup() {
krista@2740
    26
    EngineTestIndividualSuite::setup();
krista@2740
    27
    string keystr = slurp("test_keys/priv/bcc_test_dude_0-0x1CCCFC41_priv.asc");
krista@2740
    28
    PEP_STATUS status = import_key(session, keystr.c_str(), keystr.size(), NULL);
krista@3254
    29
    assert(status == PEP_KEY_IMPORTED);    
krista@2740
    30
    pEp_identity * me = new_identity("bcc_test_dude_0@darthmama.cool", "0AE9AA3E320595CF93296BDFA155AC491CCCFC41", PEP_OWN_USERID, "BCC Test Sender");    
krista@2740
    31
    status = set_own_key(session, me, "0AE9AA3E320595CF93296BDFA155AC491CCCFC41");
krista@2740
    32
    keystr = slurp("test_keys/pub/bcc_test_dude_0-0x1CCCFC41_pub.asc");
krista@2740
    33
    status = import_key(session, keystr.c_str(), keystr.size(), NULL);
krista@3254
    34
    assert(status == PEP_KEY_IMPORTED);
krista@2740
    35
    keystr = slurp("test_keys/pub/bcc_test_dude_1-0xDAC746BE_pub.asc");
krista@2740
    36
    status = import_key(session, keystr.c_str(), keystr.size(), NULL);
krista@3254
    37
    assert(status == PEP_KEY_IMPORTED);
krista@2740
    38
    keystr = slurp("test_keys/pub/bcc_test_dude_2-0x53CECCF7_pub.asc");
krista@2740
    39
    status = import_key(session, keystr.c_str(), keystr.size(), NULL);
krista@3254
    40
    assert(status == PEP_KEY_IMPORTED);    
krista@2740
    41
}
krista@2740
    42
krista@2740
    43
void BCCTests::check_single_BCC() {
krista@2740
    44
    PEP_STATUS status = PEP_UNKNOWN_ERROR;
krista@2740
    45
    
krista@2740
    46
    // 0AE9AA3E320595CF93296BDFA155AC491CCCFC41
krista@2740
    47
    // D0AF2F9695E186A8DC058B935FE2793DDAC746BE
krista@2740
    48
    // B36E468E7A381946FCDBDDFA84B1F3E853CECCF7
krista@2740
    49
    pEp_identity* sender = new_identity("bcc_test_dude_0@darthmama.cool", NULL, PEP_OWN_USERID, "BCC Test Sender");
krista@2740
    50
    pEp_identity* open_recip = new_identity("bcc_test_dude_1@darthmama.cool", NULL, NULL, "BCC Test Recip");
krista@2740
    51
    pEp_identity* bcc_recip = new_identity("bcc_test_dude_2@darthmama.cool", NULL, NULL, "BCC Super Sekrit Test Recip");
krista@2740
    52
    
krista@2740
    53
    message *msg = new_message(PEP_dir_outgoing);
krista@2740
    54
    TEST_ASSERT_MSG((msg), "msg");
krista@2740
    55
    msg->from = sender;
krista@2740
    56
//    msg->to = new_identity_list(open_recip); FYI, this is supposed to fail for now. Unfortunately.
krista@2740
    57
    msg->bcc = new_identity_list(bcc_recip);
krista@2740
    58
    msg->shortmsg = strdup("Hello, world");
krista@2740
    59
    msg->longmsg = strdup("Your mother was a hamster and your father smelt of elderberries.");
krista@2740
    60
    msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
krista@2740
    61
krista@2740
    62
    message *enc_msg = nullptr;
krista@2740
    63
    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
krista@2740
    64
krista@2740
    65
    TEST_ASSERT(status == PEP_STATUS_OK);
krista@2740
    66
}