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