More tests + all the new header files. Current status is one of the tests seems to be corrupting something - valgrind agrees but is a little bananas to sort through, so we'll check it once the rest of the tests are in. local_cpptest
authorKrista Bennett <krista@pep-project.org>
Mon, 07 May 2018 16:47:22 +0200
branchlocal_cpptest
changeset 2654be057a8a002e
parent 2653 232367954cc5
child 2655 6ace263181b8
More tests + all the new header files. Current status is one of the tests seems to be corrupting something - valgrind agrees but is a little bananas to sort through, so we'll check it once the rest of the tests are in.
test/blacklist_accept_new_key_test.cc
test/blacklist_test.cc
test/crashdump_test.cc
test/decrypt_attach_private_key_trusted_test.cc
test/decrypt_attach_private_key_untrusted_test.cc
test/encrypt_attach_private_key_test.cc
test/encrypt_for_identity_test.cc
test/gentestshell.py
test/include/BlacklistAcceptNewKeyTests.h
test/include/BlacklistTests.h
test/include/CrashdumpTests.h
test/include/DecryptAttachPrivateKeyTrustedTests.h
test/include/DecryptAttachPrivateKeyUntrustedTests.h
test/include/EncryptAttachPrivateKeyTests.h
test/include/EncryptForIdentityTests.h
test/include/EncryptMissingPrivateKeyTests.h
test/include/EngineTestSessionSuite.h
test/include/ExternalRevokeTests.h
test/include/I18nTests.h
test/include/IdentityListTests.h
test/include/KeyeditTests.h
test/include/LeastColorGroupTests.h
test/include/LeastCommonDenomColorTests.h
test/include/MapAsn1Tests.h
test/include/Message2_0Tests.h
test/include/MessageApiTests.h
test/include/MessageTwoPointOhTests.h
test/include/MimeTests.h
test/include/MistrustUndoTests.h
test/include/NewUpdateIdAndMyselfTests.h
test/include/PepSubjectReceivedTests.h
test/include/PgpBinaryTests.h
test/include/PgpListKeysTests.h
test/include/ReencryptPlusExtraKeysTests.h
test/include/RevokeRegenAttachTests.h
test/message_2.0_test.cc
test/message_two_point_oh_test.cc
test/src/SuiteMaker.cc
test/src/engine_tests/BlacklistAcceptNewKeyTests.cc
test/src/engine_tests/BlacklistTests.cc
test/src/engine_tests/CrashdumpTests.cc
test/src/engine_tests/DecryptAttachPrivateKeyTrustedTests.cc
test/src/engine_tests/DecryptAttachPrivateKeyUntrustedTests.cc
test/src/engine_tests/EncryptAttachPrivateKeyTests.cc
test/src/engine_tests/EncryptForIdentityTests.cc
     1.1 --- a/test/blacklist_accept_new_key_test.cc	Mon May 07 15:34:55 2018 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,105 +0,0 @@
     1.4 -// This file is under GNU General Public License 3.0
     1.5 -// see LICENSE.txt
     1.6 -
     1.7 -#include <iostream>
     1.8 -#include <iostream>
     1.9 -#include <fstream>
    1.10 -#include <string>
    1.11 -#include <cstring> // for strcmp()
    1.12 -#include <assert.h>
    1.13 -#include "blacklist.h"
    1.14 -#include "keymanagement.h"
    1.15 -#include "message_api.h"
    1.16 -#include "mime.h"
    1.17 -#include "test_util.h"
    1.18 -
    1.19 -using namespace std;
    1.20 -
    1.21 -int main() {
    1.22 -    cout << "\n*** blacklist_test ***\n\n";
    1.23 -
    1.24 -    PEP_SESSION session;
    1.25 -    
    1.26 -    cout << "calling init()\n";
    1.27 -    PEP_STATUS status1 = init(&session);   
    1.28 -    assert(status1 == PEP_STATUS_OK);
    1.29 -    assert(session);
    1.30 -    cout << "init() completed.\n";
    1.31 -
    1.32 -    // blacklist test code
    1.33 -
    1.34 -    cout << "blacklist only key for identity / add key / check which key is used" << endl;
    1.35 -    
    1.36 -    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    1.37 -
    1.38 -    /* read the key into memory */
    1.39 -    const string keytext = slurp("blacklisted_pub.asc");
    1.40 -    
    1.41 -    /* import it into pep */
    1.42 -    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    1.43 -    
    1.44 -    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
    1.45 -    bool is_blacklisted = false;
    1.46 -    
    1.47 -    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
    1.48 -                                                      bl_fpr_1,
    1.49 -                                                      NULL,
    1.50 -                                                      "Blacklist Keypair");
    1.51 -    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
    1.52 -    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    1.53 -    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    1.54 -    assert(is_blacklisted);
    1.55 -    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
    1.56 -    assert(status11 == PEP_STATUS_OK);
    1.57 -    assert(_streq(bl_fpr_1, blacklisted_identity->fpr));
    1.58 -    
    1.59 -    bool id_def, us_def, addr_def;
    1.60 -    status11 = get_valid_pubkey(session, blacklisted_identity,
    1.61 -                                &id_def, &us_def, &addr_def, true);
    1.62 -    assert(blacklisted_identity->comm_type == PEP_ct_unknown);
    1.63 -                        
    1.64 -    if (!(blacklisted_identity->fpr))
    1.65 -        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
    1.66 -    else
    1.67 -        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
    1.68 -             << "Expected it to be empty." << endl;
    1.69 -    assert(!(blacklisted_identity->fpr) || blacklisted_identity->fpr[0] == '\0');
    1.70 -
    1.71 -    /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
    1.72 -    
    1.73 -    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
    1.74 -    const string mailtext = slurp("test_mails/blacklist_new_key_attached.eml");
    1.75 -    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    1.76 -
    1.77 -    PEP_STATUS status = update_identity(session, me1);
    1.78 -    message* msg_ptr = nullptr;
    1.79 -    message* dest_msg = nullptr;
    1.80 -    stringlist_t* keylist = nullptr;
    1.81 -    PEP_rating rating;
    1.82 -    PEP_decrypt_flags_t flags = 0;
    1.83 -    
    1.84 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    1.85 -    assert(status == PEP_STATUS_OK);
    1.86 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    1.87 -
    1.88 -    PEP_STATUS status12 = get_valid_pubkey(session, blacklisted_identity,
    1.89 -                                           &id_def, &us_def, &addr_def, true);
    1.90 -
    1.91 -    assert(strcasecmp(blacklisted_identity->fpr, new_key) == 0);
    1.92 -
    1.93 -    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
    1.94 -    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
    1.95 -
    1.96 -    status = delete_keypair(session, new_key);
    1.97 -    update_identity(session, blacklisted_identity);
    1.98 -    status = delete_keypair(session, bl_fpr_1);
    1.99 -    update_identity(session, blacklisted_identity);
   1.100 -    
   1.101 -    free_message(msg_ptr);
   1.102 -    free_message(dest_msg);
   1.103 -    free_stringlist(keylist);
   1.104 -    
   1.105 -    cout << "calling release()\n";
   1.106 -    release(session);
   1.107 -    return 0;
   1.108 -}
     2.1 --- a/test/blacklist_test.cc	Mon May 07 15:34:55 2018 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,171 +0,0 @@
     2.4 -// This file is under GNU General Public License 3.0
     2.5 -// see LICENSE.txt
     2.6 -
     2.7 -#include <iostream>
     2.8 -#include <iostream>
     2.9 -#include <fstream>
    2.10 -#include <string>
    2.11 -#include <cstring> // for strcmp()
    2.12 -#include <assert.h>
    2.13 -#include "blacklist.h"
    2.14 -#include "keymanagement.h"
    2.15 -#include "test_util.h"
    2.16 -
    2.17 -using namespace std;
    2.18 -
    2.19 -int main() {
    2.20 -    cout << "\n*** blacklist_test ***\n\n";
    2.21 -
    2.22 -    PEP_SESSION session;
    2.23 -    
    2.24 -    cout << "calling init()\n";
    2.25 -    PEP_STATUS status1 = init(&session);   
    2.26 -    assert(status1 == PEP_STATUS_OK);
    2.27 -    assert(session);
    2.28 -    cout << "init() completed.\n";
    2.29 -
    2.30 -    // blacklist test code
    2.31 -
    2.32 -    cout << "adding 23 to blacklist\n";
    2.33 -    PEP_STATUS status2 = blacklist_add(session, "23");
    2.34 -    assert(status2 == PEP_STATUS_OK);
    2.35 -    cout << "added.\n";
    2.36 -
    2.37 -    bool listed;
    2.38 -    PEP_STATUS status3 = blacklist_is_listed(session, "23", &listed);
    2.39 -    assert(status3 == PEP_STATUS_OK);
    2.40 -    assert(listed);
    2.41 -    cout << "23 is listed.\n";
    2.42 -
    2.43 -    stringlist_t *blacklist;
    2.44 -    PEP_STATUS status6 = blacklist_retrieve(session, &blacklist);
    2.45 -    assert(status6 == PEP_STATUS_OK);
    2.46 -    assert(blacklist);
    2.47 -
    2.48 -    bool in23 = false;
    2.49 -    cout << "the blacklist contains now: ";
    2.50 -    for (stringlist_t *bl = blacklist; bl && bl->value; bl = bl->next) {
    2.51 -        cout << bl->value << ", ";
    2.52 -        if (std::strcmp(bl->value, "23") == 0)
    2.53 -            in23 = true;
    2.54 -    }
    2.55 -    cout << "END\n";
    2.56 -    assert(in23);
    2.57 -    free_stringlist(blacklist);
    2.58 -
    2.59 -    cout << "deleting 23 from blacklist\n";
    2.60 -    PEP_STATUS status4 = blacklist_delete(session, "23");
    2.61 -    assert(status4 == PEP_STATUS_OK);
    2.62 -    cout << "deleted.\n";
    2.63 -    
    2.64 -    PEP_STATUS status5 = blacklist_is_listed(session, "23", &listed);
    2.65 -    assert(status5 == PEP_STATUS_OK);
    2.66 -    assert(!listed);
    2.67 -    cout << "23 is not listed any more.\n";
    2.68 -
    2.69 -    cout << "blacklist only key for identity / unblacklist key / add key" << endl;
    2.70 -
    2.71 -    
    2.72 -    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    2.73 -
    2.74 -    const string keytext = slurp("blacklisted_pub.asc");
    2.75 -    
    2.76 -    /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
    2.77 -     *        fix in */
    2.78 -    /* import it into pep */
    2.79 -    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    2.80 -    
    2.81 -    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
    2.82 -    const char* bl_fpr_2 = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B"; 
    2.83 -    bool is_blacklisted = false;
    2.84 -
    2.85 -    // Clean up from previous runs
    2.86 -    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    2.87 -    if (is_blacklisted) {
    2.88 -        is_blacklisted = false;
    2.89 -        blacklist_delete(session, bl_fpr_1);
    2.90 -    }
    2.91 -    
    2.92 -    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
    2.93 -                                                      bl_fpr_1,
    2.94 -                                                      NULL,
    2.95 -                                                      "Blacklist Keypair");
    2.96 -
    2.97 -    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
    2.98 -        
    2.99 -    // THERE IS NO BLACKLISTING OF PEP KEYS
   2.100 -    //blacklisted_identity->comm_type = PEP_ct_pEp;
   2.101 -    blacklisted_identity->comm_type = PEP_ct_OpenPGP_unconfirmed;
   2.102 -
   2.103 -    PEP_STATUS status99 = set_identity(session, blacklisted_identity);
   2.104 -    
   2.105 -    trust_personal_key(session, blacklisted_identity);
   2.106 -
   2.107 -    PEP_STATUS status999 = update_identity(session, blacklisted_identity);
   2.108 -
   2.109 -    assert(blacklisted_identity->comm_type == PEP_ct_OpenPGP);
   2.110 -
   2.111 -    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
   2.112 -    status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
   2.113 -    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
   2.114 -    /* new!!! */
   2.115 -    assert(is_blacklisted);
   2.116 -    assert(status11 == PEP_STATUS_OK);
   2.117 -    assert(_streq(bl_fpr_1, blacklisted_identity->fpr));
   2.118 -    
   2.119 -    bool id_def, us_def, addr_def;
   2.120 -    status11 = get_valid_pubkey(session, blacklisted_identity,
   2.121 -                                &id_def, &us_def, &addr_def, true);
   2.122 -    
   2.123 -    if (!(blacklisted_identity->fpr))
   2.124 -        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
   2.125 -    else if (strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0)
   2.126 -        cout << "OK! While this should be empty, you are probably running " << 
   2.127 -                "this in your home directory instead of the test environment " << 
   2.128 -                "and have leftover keys. This is an acceptable result here then. But you " <<
   2.129 -                "should probably clean up after yourself :)" << endl;
   2.130 -    else
   2.131 -        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
   2.132 -             << "Expected it to be empty or (possibly) " << bl_fpr_2 << endl;
   2.133 -    assert(!(blacklisted_identity->fpr) || blacklisted_identity->fpr[0] == '\0'|| (strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0));
   2.134 -
   2.135 -    const string keytext2 = slurp("blacklisted_pub2.asc");
   2.136 -    PEP_STATUS status14 = import_key(session, keytext2.c_str(), keytext2.length(), NULL);
   2.137 -    
   2.138 -    pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
   2.139 -                                                       bl_fpr_2,
   2.140 -                                                        NULL,
   2.141 -                                                       "Blacklist Keypair");
   2.142 -    PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
   2.143 -    // 
   2.144 -    // assert(blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) == 0);
   2.145 -    // if (blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) == 0)
   2.146 -    //     cout << "blacklisted identity's fpr successfully replaced by the unblacklisted one" << endl;
   2.147 -    // // else
   2.148 -    // //     cout << "blacklisted_identity->fpr should be " << bl_fpr_2 << " but is " << blacklisted_identity->fpr << endl;
   2.149 -    // 
   2.150 -    // PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
   2.151 -    // PEP_STATUS status13 = update_identity(session, blacklisted_identity);
   2.152 -    //     
   2.153 -    // pEp_identity* stored_identity = new_identity("blacklistedkeys@kgrothoff.org",
   2.154 -    //                                               NULL,
   2.155 -    //                                               blacklisted_identity->user_id,
   2.156 -    //                                               "Blacklist Keypair");
   2.157 -    //  
   2.158 -    // PEP_STATUS status00 = update_identity(session, stored_identity);
   2.159 -    // 
   2.160 -    // // FIXME
   2.161 -    // // assert(stored_identity->comm_type == PEP_ct_pEp);    
   2.162 -    
   2.163 -    PEP_STATUS status16 = delete_keypair(session, bl_fpr_1);
   2.164 -    update_identity(session, blacklisted_identity);
   2.165 -    PEP_STATUS status17 = delete_keypair(session, bl_fpr_2);
   2.166 -    update_identity(session, blacklisted_identity2);
   2.167 -        
   2.168 -    free_identity(blacklisted_identity);
   2.169 -    free_identity(blacklisted_identity2);
   2.170 -    
   2.171 -    cout << "calling release()\n";
   2.172 -    release(session);
   2.173 -    return 0;
   2.174 -}
     3.1 --- a/test/crashdump_test.cc	Mon May 07 15:34:55 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,33 +0,0 @@
     3.4 -// This file is under GNU General Public License 3.0
     3.5 -// see LICENSE.txt
     3.6 -
     3.7 -#include <iostream>
     3.8 -#include <string>
     3.9 -#include <assert.h>
    3.10 -#include "pEpEngine.h"
    3.11 -
    3.12 -using namespace std;
    3.13 -
    3.14 -int main() {
    3.15 -    cout << "\n*** crashdump_test ***\n\n";
    3.16 -
    3.17 -    PEP_SESSION session;
    3.18 -    
    3.19 -    cout << "calling init()\n";
    3.20 -    PEP_STATUS status1 = init(&session);   
    3.21 -    assert(status1 == PEP_STATUS_OK);
    3.22 -    assert(session);
    3.23 -    cout << "init() completed.\n";
    3.24 -
    3.25 -    // MODULE test code
    3.26 -
    3.27 -    char *text;
    3.28 -    PEP_STATUS status2 = get_crashdump_log(session, 0, &text);
    3.29 -    assert(status2 == PEP_STATUS_OK);
    3.30 -    cout << text;
    3.31 -
    3.32 -    cout << "calling release()\n";
    3.33 -    release(session);
    3.34 -    return 0;
    3.35 -}
    3.36 -
     4.1 --- a/test/decrypt_attach_private_key_trusted_test.cc	Mon May 07 15:34:55 2018 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,151 +0,0 @@
     4.4 -// This file is under GNU General Public License 3.0
     4.5 -// see LICENSE.txt
     4.6 -
     4.7 -#include <stdlib.h>
     4.8 -#include <string.h>
     4.9 -#include "platform.h"
    4.10 -#include <iostream>
    4.11 -#include <fstream>
    4.12 -#include <assert.h>
    4.13 -#include "mime.h"
    4.14 -#include "message_api.h"
    4.15 -#include "keymanagement.h"
    4.16 -#include "test_util.h"
    4.17 -
    4.18 -using namespace std;
    4.19 -
    4.20 -int main() {
    4.21 -    cout << "\n*** decrypt_attach_private_key_trusted_test ***\n\n";
    4.22 -
    4.23 -    PEP_SESSION session;
    4.24 -    
    4.25 -    cout << "calling init()\n";
    4.26 -    PEP_STATUS status1 = init(&session);
    4.27 -    assert(status1 == PEP_STATUS_OK);
    4.28 -    assert(session);
    4.29 -    cout << "init() completed.\n";
    4.30 -
    4.31 -    const char* own_uid = PEP_OWN_USERID;
    4.32 -
    4.33 -    cout << "Importing keys..." << endl;
    4.34 -    
    4.35 -    string input_key;
    4.36 -    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
    4.37 -    pEp_identity* main_me = NULL;
    4.38 -    const char* fpr_main_me = "13A9F97964A2B52520CAA40E51BCA783C065A213";    
    4.39 -    pEp_identity* same_addr_same_uid = NULL;
    4.40 -    const char* fpr_same_addr_same_uid = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
    4.41 -        
    4.42 -    PEP_STATUS status = PEP_STATUS_OK;
    4.43 -
    4.44 -    // key for main own user
    4.45 -    // 
    4.46 -    // 13A9F97964A2B52520CAA40E51BCA783C065A213    
    4.47 -    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0xC065A213_pub.asc");
    4.48 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    4.49 -    assert(status == PEP_STATUS_OK);
    4.50 -
    4.51 -    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0xC065A213_priv.asc");
    4.52 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    4.53 -    assert(status == PEP_STATUS_OK);
    4.54 -
    4.55 -    // ensure there's no private key - doesn't work in automated tests, sadly. Uncommon when running script manually.
    4.56 -    bool has_priv = false;
    4.57 -    // status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
    4.58 -    // if (status == PEP_STATUS_OK && has_priv) {
    4.59 -    //     cout << "SORRY, have to delete keys here to run test correctly..." << endl;
    4.60 -    //     status = delete_keypair(session, fpr_same_addr_same_uid);
    4.61 -    //     if (status == PEP_STATUS_OK) {
    4.62 -    //         has_priv = false;
    4.63 -    //         status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
    4.64 -    //         assert(has_priv == false);
    4.65 -    //         cout << "Successfully deleted keypair for " << fpr_same_addr_same_uid << " - will now import the public key only" << endl;
    4.66 -    //     }
    4.67 -    //     else
    4.68 -    //         cout << "Warning - delete keypair returned status " << tl_status_string(status) << ". This may or may not be an error, depending on what you expect." << endl;            
    4.69 -    // }
    4.70 -        
    4.71 -    // key with same address and user_id
    4.72 -    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
    4.73 -    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
    4.74 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    4.75 -    assert(status == PEP_STATUS_OK);
    4.76 -
    4.77 -    
    4.78 -    cout << "Setting up own identity with default key " << fpr_main_me << endl;
    4.79 -    // Own identity with default key etc
    4.80 -    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
    4.81 -    status = set_own_key(session, main_me, fpr_main_me);
    4.82 -    assert(status == PEP_STATUS_OK);
    4.83 -
    4.84 -    assert(strcmp(main_me->fpr, fpr_main_me) == 0);
    4.85 -    cout << "Done!" << endl << endl;
    4.86 -    
    4.87 -    cout << "Setting up sender identities and resetting key trust." << endl;
    4.88 -    cout << "Same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
    4.89 -    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
    4.90 -    assert(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
    4.91 -    assert((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed);
    4.92 -
    4.93 -    status = key_reset_trust(session, same_addr_same_uid);
    4.94 -    
    4.95 -    cout << "Done!" << endl << endl;
    4.96 -
    4.97 -    cout << "Reading in message..." << endl;
    4.98 -    
    4.99 -    string encoded_text = slurp("test_mails/priv_key_attach.eml");
   4.100 -
   4.101 -    cout << "Starting test..." << endl;
   4.102 -    // Case 1:
   4.103 -    // Same address, same user_id, untrusted
   4.104 -    cout << "decrypt with attached private key: Same address, same user_id, trusted" << endl;
   4.105 -    char* decrypted_text = NULL;
   4.106 -    stringlist_t* keylist_used = NULL;
   4.107 -    PEP_rating rating;
   4.108 -    PEP_decrypt_flags_t flags = 0;
   4.109 -    char* modified_src = NULL;
   4.110 -    
   4.111 -    cout << "Trusting personal key for " << same_addr_same_uid->user_id << " and " << same_addr_same_uid->fpr << endl;
   4.112 -    status = trust_personal_key(session, same_addr_same_uid);
   4.113 -    cout << "Status is " << tl_status_string(status) << endl;  
   4.114 -    assert(status == PEP_STATUS_OK);
   4.115 -    free(decrypted_text);
   4.116 -    decrypted_text = NULL;
   4.117 -
   4.118 -    status = get_trust(session, same_addr_same_uid);
   4.119 -    cout << tl_ct_string(same_addr_same_uid->comm_type) << endl;
   4.120 -    
   4.121 -    assert(same_addr_same_uid->comm_type == PEP_ct_pEp);
   4.122 -    
   4.123 -    flags = 0;
   4.124 -    status = MIME_decrypt_message(session, encoded_text.c_str(), 
   4.125 -                                  encoded_text.size(), &decrypted_text, 
   4.126 -                                  &keylist_used, &rating, &flags,
   4.127 -                                  &modified_src);
   4.128 -
   4.129 -    status = get_trust(session, same_addr_same_uid);
   4.130 -    assert(same_addr_same_uid->comm_type == PEP_ct_pEp);
   4.131 -    
   4.132 -    flags = 0;
   4.133 -    status = MIME_decrypt_message(session, encoded_text.c_str(), 
   4.134 -                                  encoded_text.size(), &decrypted_text, 
   4.135 -                                  &keylist_used, &rating, &flags,
   4.136 -                                  &modified_src);
   4.137 -    
   4.138 -    cout << "Status: " << tl_status_string(status) << endl;
   4.139 -    assert(status == PEP_STATUS_OK);
   4.140 -
   4.141 -    cout << decrypted_text << endl;
   4.142 -    
   4.143 -    has_priv = false;
   4.144 -    status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
   4.145 -    assert(has_priv == true);
   4.146 -    cout << "Private key was also imported." << endl;
   4.147 -    
   4.148 -    cout << "PASS!" << endl;
   4.149 -    status = key_reset_trust(session, main_me);      
   4.150 -    status = key_reset_trust(session, same_addr_same_uid);      
   4.151 -    release(session);
   4.152 -    
   4.153 -    return 0;
   4.154 -}
     5.1 --- a/test/decrypt_attach_private_key_untrusted_test.cc	Mon May 07 15:34:55 2018 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,128 +0,0 @@
     5.4 -// This file is under GNU General Public License 3.0
     5.5 -// see LICENSE.txt
     5.6 -
     5.7 -#include <stdlib.h>
     5.8 -#include <string.h>
     5.9 -#include "platform.h"
    5.10 -#include <iostream>
    5.11 -#include <fstream>
    5.12 -#include <assert.h>
    5.13 -#include "mime.h"
    5.14 -#include "message_api.h"
    5.15 -#include "keymanagement.h"
    5.16 -#include "test_util.h"
    5.17 -
    5.18 -using namespace std;
    5.19 -
    5.20 -int main() {
    5.21 -    cout << "\n*** decrypt_attach_private_key_untrusted_test ***\n\n";
    5.22 -
    5.23 -    PEP_SESSION session;
    5.24 -    
    5.25 -    cout << "calling init()\n";
    5.26 -    PEP_STATUS status1 = init(&session);
    5.27 -    assert(status1 == PEP_STATUS_OK);
    5.28 -    assert(session);
    5.29 -    cout << "init() completed.\n";
    5.30 -
    5.31 -    const char* own_uid = PEP_OWN_USERID;
    5.32 -
    5.33 -    cout << "Importing keys..." << endl;
    5.34 -    
    5.35 -    string input_key;
    5.36 -    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
    5.37 -    pEp_identity* main_me = NULL;
    5.38 -    const char* fpr_main_me = "13A9F97964A2B52520CAA40E51BCA783C065A213";    
    5.39 -    pEp_identity* same_addr_same_uid = NULL;
    5.40 -    const char* fpr_same_addr_same_uid = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
    5.41 -        
    5.42 -    PEP_STATUS status = PEP_STATUS_OK;
    5.43 -
    5.44 -    // key for main own user
    5.45 -    // 
    5.46 -    // 13A9F97964A2B52520CAA40E51BCA783C065A213    
    5.47 -    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0xC065A213_pub.asc");
    5.48 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.49 -    assert(status == PEP_STATUS_OK);
    5.50 -
    5.51 -    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0xC065A213_priv.asc");
    5.52 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.53 -    assert(status == PEP_STATUS_OK);
    5.54 -
    5.55 -    // ensure there's no private key - doesn't work in automated tests, sadly. Uncommon when running script manually.
    5.56 -    bool has_priv = false;
    5.57 -    // status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
    5.58 -    // if (status == PEP_STATUS_OK && has_priv) {
    5.59 -    //     cout << "SORRY, have to delete keys here to run test correctly..." << endl;
    5.60 -    //     status = delete_keypair(session, fpr_same_addr_same_uid);
    5.61 -    //     if (status == PEP_STATUS_OK)
    5.62 -    //         cout << "Successfully deleted keypair for " << fpr_same_addr_same_uid << " - will now import the public key only" << endl;
    5.63 -    // }
    5.64 -        
    5.65 -    // key with same address and user_id
    5.66 -    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
    5.67 -    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
    5.68 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.69 -    assert(status == PEP_STATUS_OK);
    5.70 -
    5.71 -    
    5.72 -    cout << "Setting up own identity with default key " << fpr_main_me << endl;
    5.73 -    // Own identity with default key etc
    5.74 -    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
    5.75 -    status = set_own_key(session, main_me, fpr_main_me);
    5.76 -    assert(status == PEP_STATUS_OK);
    5.77 -
    5.78 -    assert(strcmp(main_me->fpr, fpr_main_me) == 0);
    5.79 -    cout << "Done!" << endl << endl;
    5.80 -    
    5.81 -    cout << "Setting up sender identities and resetting key trust." << endl;
    5.82 -    cout << "Same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
    5.83 -    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
    5.84 -    assert(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
    5.85 -    assert((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed);
    5.86 -
    5.87 -    status = key_reset_trust(session, same_addr_same_uid);
    5.88 -    
    5.89 -    cout << "Done!" << endl << endl;
    5.90 -
    5.91 -    cout << "Reading in message..." << endl;
    5.92 -    
    5.93 -    string encoded_text = slurp("test_mails/priv_key_attach.eml");
    5.94 -
    5.95 -    cout << "Starting tests..." << endl;
    5.96 -    // Case 1:
    5.97 -    // Same address, same user_id, untrusted
    5.98 -    cout << "Same address, same user_id, untrusted" << endl;
    5.99 -    char* decrypted_text = NULL;
   5.100 -    stringlist_t* keylist_used = NULL;
   5.101 -    PEP_rating rating;
   5.102 -    PEP_decrypt_flags_t flags;
   5.103 -    char* modified_src = NULL;
   5.104 -    
   5.105 -    status = get_trust(session, same_addr_same_uid);
   5.106 -    cout << tl_ct_string(same_addr_same_uid->comm_type) << endl;
   5.107 -    
   5.108 -    assert((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed);
   5.109 -    
   5.110 -    flags = 0;
   5.111 -    status = MIME_decrypt_message(session, encoded_text.c_str(), 
   5.112 -                                  encoded_text.size(), &decrypted_text, 
   5.113 -                                  &keylist_used, &rating, &flags,
   5.114 -				  &modified_src);
   5.115 -
   5.116 -    status = get_trust(session, same_addr_same_uid);
   5.117 -    assert(same_addr_same_uid->comm_type == PEP_ct_pEp_unconfirmed);
   5.118 -
   5.119 -    cout << "Case 1 Status: " << tl_status_string(status) << endl; 
   5.120 -    cout << "Private key is not trusted for " << same_addr_same_uid->fpr << ", as desired, as the public key was not trusted." << endl;
   5.121 -    cout << "PASS!" << endl;
   5.122 -
   5.123 -    // Case 2:
   5.124 -    cout << decrypted_text << endl;
   5.125 -    
   5.126 -    status = key_reset_trust(session, main_me);      
   5.127 -    status = key_reset_trust(session, same_addr_same_uid);      
   5.128 -    release(session);
   5.129 -    
   5.130 -    return 0;
   5.131 -}
     6.1 --- a/test/encrypt_attach_private_key_test.cc	Mon May 07 15:34:55 2018 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,293 +0,0 @@
     6.4 -// This file is under GNU General Public License 3.0
     6.5 -// see LICENSE.txt
     6.6 -
     6.7 -#include <stdlib.h>
     6.8 -#include <string.h>
     6.9 -#include "platform.h"
    6.10 -#include <iostream>
    6.11 -#include <fstream>
    6.12 -#include <assert.h>
    6.13 -#include "mime.h"
    6.14 -#include "message_api.h"
    6.15 -#include "keymanagement.h"
    6.16 -#include "test_util.h"
    6.17 -
    6.18 -using namespace std;
    6.19 -
    6.20 -int main() {
    6.21 -    cout << "\n*** encrypt_attach_private_key_test ***\n\n";
    6.22 -
    6.23 -    PEP_SESSION session;
    6.24 -    
    6.25 -    cout << "calling init()\n";
    6.26 -    PEP_STATUS status1 = init(&session);
    6.27 -    assert(status1 == PEP_STATUS_OK);
    6.28 -    assert(session);
    6.29 -    cout << "init() completed.\n";
    6.30 -
    6.31 -    const char* own_uid = PEP_OWN_USERID;
    6.32 -    const char* diff_uid_0 = "TASTY_TEST_UID_0";
    6.33 -    const char* diff_uid_1 = "TASTY_TEST_UID_1";
    6.34 -
    6.35 -    cout << "Importing keys..." << endl;
    6.36 -    
    6.37 -    string input_key;
    6.38 -    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
    6.39 -    pEp_identity* main_me = NULL;
    6.40 -    const char* fpr_main_me = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
    6.41 -    pEp_identity* same_addr_same_uid = NULL;
    6.42 -    const char* fpr_same_addr_same_uid = "359DD8AC87D1F5E4304D08338D7185F180C8CD87";
    6.43 -    
    6.44 -    pEp_identity* same_addr_diff_uid = NULL;
    6.45 -    const char* fpr_same_addr_diff_uid = "B044B83639E292283A3F6E14C2E64B520B74809C";
    6.46 -
    6.47 -    const char* diff_addr_0 = "priv-key-import-test-other_0@darthmama.cool";
    6.48 -    pEp_identity* diff_addr_same_uid = NULL;
    6.49 -    const char* fpr_diff_addr_same_uid = "C52911EBA0D34B0F549594A15A7A363BD11252C9";
    6.50 -    
    6.51 -    const char* diff_addr_1 = "priv-key-import-test-other_1@darthmama.cool";
    6.52 -    pEp_identity* diff_addr_diff_uid = NULL;
    6.53 -    const char* fpr_diff_addr_diff_uid = "567212EFB8A3A76B1D32B9565F45BEA9C785F20A";
    6.54 -    
    6.55 -    PEP_STATUS status = PEP_STATUS_OK;
    6.56 -
    6.57 -    // key for main own user
    6.58 -    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
    6.59 -    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
    6.60 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    6.61 -    assert(status == PEP_STATUS_OK);
    6.62 -
    6.63 -    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0x3276D2E5_priv.asc");
    6.64 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    6.65 -    assert(status == PEP_STATUS_OK);
    6.66 -        
    6.67 -    // key with same address and user_id (initially untrusted, then trusted)
    6.68 -    // 359DD8AC87D1F5E4304D08338D7185F180C8CD87
    6.69 -    input_key = slurp("test_keys/pub/priv-key-import-test-main_1-0x80C8CD87_pub.asc");
    6.70 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    6.71 -    assert(status == PEP_STATUS_OK);
    6.72 -
    6.73 -    // key with same address and to have different (non-aliased) user_id (initially untrusted, then trusted)
    6.74 -    // B044B83639E292283A3F6E14C2E64B520B74809C
    6.75 -    input_key = slurp("test_keys/pub/priv-key-import-test-main_2-0x0B74809C_pub.asc");
    6.76 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    6.77 -    assert(status == PEP_STATUS_OK);
    6.78 -
    6.79 -    // key with different address to have same user_id (initially untrusted, then trusted)
    6.80 -    // C52911EBA0D34B0F549594A15A7A363BD11252C9
    6.81 -    input_key = slurp("test_keys/pub/priv-key-import-test-other_0-0xD11252C9_pub.asc");
    6.82 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    6.83 -    assert(status == PEP_STATUS_OK);
    6.84 -        
    6.85 -    // key with different address to have different user_id (initially untrusted, then trusted)
    6.86 -    // 567212EFB8A3A76B1D32B9565F45BEA9C785F20A
    6.87 -    input_key = slurp("test_keys/pub/priv-key-import-test-other_1-0xC785F20A_pub.asc");
    6.88 -    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    6.89 -    assert(status == PEP_STATUS_OK);
    6.90 -    cout << "Done!" << endl << endl;
    6.91 -    
    6.92 -    cout << "Setting up own identity with default key " << fpr_main_me << endl;
    6.93 -    // Own identity with default key etc
    6.94 -    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
    6.95 -    status = set_own_key(session, main_me, fpr_main_me);
    6.96 -    assert(status == PEP_STATUS_OK);
    6.97 -
    6.98 -    assert(strcmp(main_me->fpr, fpr_main_me) == 0);
    6.99 -    cout << "Done!" << endl << endl;
   6.100 -    
   6.101 -    cout << "Setting up recipient identities and resetting key trust." << endl;
   6.102 -    cout << "#1: same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
   6.103 -    // Identity with same address and user_id - the fpr here will be ignored in update_identity and friends.
   6.104 -    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
   6.105 -    status = key_reset_trust(session, same_addr_same_uid);
   6.106 -    assert(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
   6.107 -    assert(strcmp(same_addr_same_uid->fpr, fpr_same_addr_same_uid) == 0);
   6.108 -    
   6.109 -    // Identity with same address and different user_id
   6.110 -    cout << "#2: same address, different user_id - address: " << main_addr << ", user_id: " << diff_uid_0 << ", fpr: " << fpr_same_addr_diff_uid << endl;  
   6.111 -    same_addr_diff_uid = new_identity(main_addr, fpr_same_addr_diff_uid, diff_uid_0, "PrivateKey Import Test");
   6.112 -    assert(same_addr_diff_uid);
   6.113 -    status = key_reset_trust(session, same_addr_diff_uid);
   6.114 -    assert(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
   6.115 -    assert(strcmp(same_addr_diff_uid->fpr, fpr_same_addr_diff_uid) == 0);
   6.116 -    
   6.117 -    // Identity with diff address and same user_id
   6.118 -    cout << "#3: different address, same user_id - address: " << diff_addr_0 << ", user_id: " << own_uid << ", fpr: " << fpr_diff_addr_same_uid << endl;      
   6.119 -    diff_addr_same_uid = new_identity(diff_addr_0, fpr_diff_addr_same_uid, own_uid, "PrivateKey Import Test");
   6.120 -    assert(diff_addr_same_uid);
   6.121 -    status = key_reset_trust(session, diff_addr_same_uid);
   6.122 -    assert(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
   6.123 -    assert(strcmp(diff_addr_same_uid->fpr, fpr_diff_addr_same_uid) == 0);
   6.124 -
   6.125 -    // Identity with different address and different user_id
   6.126 -    cout << "#4: different address, different user_id - address: " << diff_addr_1 << ", user_id: " << diff_uid_1 << ", fpr: " << fpr_diff_addr_diff_uid << endl;      
   6.127 -    diff_addr_diff_uid = new_identity(diff_addr_1, fpr_diff_addr_diff_uid, diff_uid_1, "PrivateKey Import Test");
   6.128 -    assert(diff_addr_diff_uid);
   6.129 -    status = key_reset_trust(session, diff_addr_diff_uid);
   6.130 -    assert(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
   6.131 -    assert(strcmp(diff_addr_diff_uid->fpr, fpr_diff_addr_diff_uid) == 0);
   6.132 -    cout << "Done!" << endl << endl;
   6.133 -
   6.134 -    message* msg_same_addr_same_uid = new_message(PEP_dir_outgoing);
   6.135 -    msg_same_addr_same_uid->from = main_me;
   6.136 -    msg_same_addr_same_uid->shortmsg = strdup("Greetings, humans!");
   6.137 -    msg_same_addr_same_uid->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   6.138 -    msg_same_addr_same_uid->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   6.139 -
   6.140 -    message* msg_same_addr_diff_uid = message_dup(msg_same_addr_same_uid);
   6.141 -    message* msg_diff_addr_same_uid = message_dup(msg_same_addr_same_uid);       
   6.142 -    message* msg_diff_addr_diff_uid = message_dup(msg_same_addr_same_uid);       
   6.143 -
   6.144 -    cout << "Starting tests..." << endl;
   6.145 -    // Case 1:
   6.146 -    // Same address, same user_id, untrusted
   6.147 -    cout << "Case 1: Same address, same user_id, untrusted" << endl;
   6.148 -    assert(msg_same_addr_same_uid);        
   6.149 -    identity_list* to_list = new_identity_list(same_addr_same_uid);
   6.150 -    msg_same_addr_same_uid->to = to_list;
   6.151 -    message* enc_same_addr_same_uid_untrusted = NULL;
   6.152 -    status = encrypt_message_and_add_priv_key(session,
   6.153 -                                              msg_same_addr_same_uid,
   6.154 -                                              &enc_same_addr_same_uid_untrusted,
   6.155 -                                              fpr_same_addr_same_uid,
   6.156 -                                              PEP_enc_PGP_MIME,
   6.157 -                                              0);
   6.158 -
   6.159 -    cout << "Case 1 Status: " << tl_status_string(status) << endl;
   6.160 -    assert(status == PEP_ILLEGAL_VALUE);
   6.161 -    cout << "PASS!" << endl;
   6.162 -    
   6.163 -    // Case 2:
   6.164 -    // Same address, same_user_id, trusted
   6.165 -    cout << "Case 2: Same address, same user_id, trusted" << endl;
   6.166 -    status = trust_personal_key(session, same_addr_same_uid);
   6.167 -    cout << "Trust personal key for " << same_addr_same_uid << " gives status " << tl_status_string(status) << " (" << status << ")" << endl;
   6.168 -    assert(status == PEP_STATUS_OK);
   6.169 -    message* enc_same_addr_same_uid_trusted = NULL;
   6.170 -    status = encrypt_message_and_add_priv_key(session,
   6.171 -                                              msg_same_addr_same_uid,
   6.172 -                                              &enc_same_addr_same_uid_trusted,
   6.173 -                                              fpr_same_addr_same_uid,
   6.174 -                                              PEP_enc_PGP_MIME,
   6.175 -                                              0);
   6.176 -
   6.177 -    cout << "Case 2 Status: " << tl_status_string(status) << endl;
   6.178 -    assert(status == PEP_STATUS_OK);
   6.179 -    cout << "PASS!" << endl;
   6.180 -
   6.181 -    // Case 3:
   6.182 -    // Different address, same user_id, untrusted
   6.183 -    cout << "Case 3: Different address, same user_id, untrusted" << endl;
   6.184 -    assert(msg_diff_addr_same_uid);        
   6.185 -    identity_list* to_list_1 = new_identity_list(diff_addr_same_uid);
   6.186 -    msg_diff_addr_same_uid->to = to_list_1;
   6.187 -    message* enc_diff_addr_same_uid_untrusted = NULL;
   6.188 -    status = encrypt_message_and_add_priv_key(session,
   6.189 -                                              msg_diff_addr_same_uid,
   6.190 -                                              &enc_diff_addr_same_uid_untrusted,
   6.191 -                                              fpr_diff_addr_same_uid,
   6.192 -                                              PEP_enc_PGP_MIME,
   6.193 -                                              0);
   6.194 -    
   6.195 -    cout << "Case 3 Status: " << tl_status_string(status) << endl;
   6.196 -    assert(status == PEP_ILLEGAL_VALUE);
   6.197 -    cout << "PASS!" << endl;
   6.198 -
   6.199 -    // Case 4:
   6.200 -    // Different address, same user_id, trusted
   6.201 -    cout << "Case 4: Different address, same user_id, trusted" << endl;
   6.202 -    status = trust_personal_key(session, diff_addr_same_uid);
   6.203 -    assert(status == PEP_STATUS_OK);
   6.204 -    message* enc_diff_addr_same_uid_trusted = NULL;
   6.205 -    status = encrypt_message_and_add_priv_key(session,
   6.206 -                                              msg_diff_addr_same_uid,
   6.207 -                                              &enc_diff_addr_same_uid_trusted,
   6.208 -                                              fpr_diff_addr_same_uid,
   6.209 -                                              PEP_enc_PGP_MIME,
   6.210 -                                              0);
   6.211 -                                              
   6.212 -    cout << "Case 4 Status: " << tl_status_string(status) << endl;
   6.213 -    assert(status == PEP_ILLEGAL_VALUE);
   6.214 -    cout << "PASS!" << endl;
   6.215 -
   6.216 -    // Case 5:
   6.217 -    // Same address, different user_id, untrusted
   6.218 -    cout << "Case 5: Same address, different user_id, untrusted" << endl;    
   6.219 -    assert(msg_same_addr_diff_uid);        
   6.220 -    identity_list* to_list_2 = new_identity_list(same_addr_diff_uid);
   6.221 -    msg_same_addr_diff_uid->to = to_list_2;
   6.222 -    message* enc_same_addr_diff_uid_untrusted = NULL;
   6.223 -    status = encrypt_message_and_add_priv_key(session,
   6.224 -                                              msg_same_addr_diff_uid,
   6.225 -                                              &enc_same_addr_diff_uid_untrusted,
   6.226 -                                              fpr_same_addr_diff_uid,
   6.227 -                                              PEP_enc_PGP_MIME,
   6.228 -                                              0);
   6.229 -
   6.230 -    cout << "Case 5 Status: " << tl_status_string(status) << endl;
   6.231 -    assert(status == PEP_ILLEGAL_VALUE);    
   6.232 -    cout << "PASS!" << endl;
   6.233 -    
   6.234 -    // Case 6:
   6.235 -    // Same address, different user_id, trusted
   6.236 -    cout << "Case 6: Same address, different user_id, trusted" << endl;        
   6.237 -    status = trust_personal_key(session, same_addr_diff_uid);
   6.238 -    assert(status == PEP_STATUS_OK);
   6.239 -    message* enc_same_addr_diff_uid_trusted = NULL;
   6.240 -    status = encrypt_message_and_add_priv_key(session,
   6.241 -                                              msg_same_addr_diff_uid,
   6.242 -                                              &enc_same_addr_diff_uid_untrusted,
   6.243 -                                              fpr_same_addr_diff_uid,
   6.244 -                                              PEP_enc_PGP_MIME,
   6.245 -                                              0);
   6.246 -
   6.247 -    cout << "Case 6 Status: " << tl_status_string(status) << endl;
   6.248 -    assert(status == PEP_ILLEGAL_VALUE);    
   6.249 -    cout << "PASS!" << endl;
   6.250 -
   6.251 -    // Case 7:
   6.252 -    // Different address, different user_id, untrusted
   6.253 -    cout << "Case 7: Different address, different user_id, untrusted" << endl;    
   6.254 -    assert(msg_diff_addr_diff_uid);        
   6.255 -    identity_list* to_list_3 = new_identity_list(diff_addr_diff_uid);
   6.256 -    msg_diff_addr_diff_uid->to = to_list_3;
   6.257 -    message* enc_diff_addr_diff_uid_untrusted = NULL;
   6.258 -    status = encrypt_message_and_add_priv_key(session,
   6.259 -                                              msg_diff_addr_diff_uid,
   6.260 -                                              &enc_diff_addr_diff_uid_untrusted,
   6.261 -                                              fpr_diff_addr_diff_uid,
   6.262 -                                              PEP_enc_PGP_MIME,
   6.263 -                                              0);
   6.264 -
   6.265 -    cout << "Case 7 Status: " << tl_status_string(status) << endl;
   6.266 -    assert(status == PEP_ILLEGAL_VALUE);
   6.267 -    cout << "PASS!" << endl;
   6.268 -
   6.269 -    // Case 8:
   6.270 -    // Different address, different user_id, trusted
   6.271 -    cout << "Case 8: Different address, different user_id, trusted" << endl;    
   6.272 -    status = trust_personal_key(session, diff_addr_diff_uid);
   6.273 -    assert(status == PEP_STATUS_OK);
   6.274 -    message* enc_diff_addr_diff_uid_trusted = NULL;
   6.275 -    status = encrypt_message_and_add_priv_key(session,
   6.276 -                                              msg_diff_addr_diff_uid,
   6.277 -                                              &enc_diff_addr_diff_uid_trusted,
   6.278 -                                              fpr_diff_addr_diff_uid,
   6.279 -                                              PEP_enc_PGP_MIME,
   6.280 -                                              0);
   6.281 -
   6.282 -    cout << "Case 8 Status: " << tl_status_string(status) << endl;
   6.283 -    assert(status == PEP_ILLEGAL_VALUE);
   6.284 -    cout << "PASS!" << endl;
   6.285 -    
   6.286 -    cout << "Correctly encrypted message:" << endl << endl;                
   6.287 -    char* encrypted_msg_text = NULL;
   6.288 -    mime_encode_message(enc_same_addr_same_uid_trusted, false, &encrypted_msg_text);                                    
   6.289 -    cout << encrypted_msg_text << endl << endl;
   6.290 -    
   6.291 -    // FIXME: Free all the damned things
   6.292 -      
   6.293 -    release(session);
   6.294 -    
   6.295 -    return 0;
   6.296 -}
     7.1 --- a/test/encrypt_for_identity_test.cc	Mon May 07 15:34:55 2018 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,291 +0,0 @@
     7.4 -// This file is under GNU General Public License 3.0
     7.5 -// see LICENSE.txt
     7.6 -
     7.7 -#include <stdlib.h>
     7.8 -#include <string.h>
     7.9 -#include "platform.h"
    7.10 -#include <iostream>
    7.11 -#include <fstream>
    7.12 -#include <assert.h>
    7.13 -#include "mime.h"
    7.14 -#include "message_api.h"
    7.15 -#include "keymanagement.h"
    7.16 -#include "test_util.h"
    7.17 -
    7.18 -using namespace std;
    7.19 -
    7.20 -int main() {
    7.21 -    cout << "\n*** encrypt_for_identity_test ***\n\n";
    7.22 -
    7.23 -    PEP_SESSION session;
    7.24 -    
    7.25 -    cout << "calling init()\n";
    7.26 -    PEP_STATUS status1 = init(&session);
    7.27 -    assert(status1 == PEP_STATUS_OK);
    7.28 -    assert(session);
    7.29 -    cout << "init() completed.\n";
    7.30 -
    7.31 -    // message_api test code
    7.32 -
    7.33 -    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    7.34 -    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
    7.35 -    const string gabrielle_pub_key = slurp("test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc");
    7.36 -    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");    
    7.37 -
    7.38 -    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    7.39 -    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
    7.40 -    assert(statuspub == PEP_STATUS_OK);
    7.41 -    assert(statuspriv == PEP_STATUS_OK);
    7.42 -    
    7.43 -    statuspub = import_key(session, gabrielle_pub_key.c_str(), gabrielle_pub_key.length(), NULL);
    7.44 -    assert(statuspub == PEP_STATUS_OK);
    7.45 -    statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
    7.46 -    assert(statuspub == PEP_STATUS_OK);
    7.47 -
    7.48 -    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    7.49 -    const char* gabrielle_fpr = "906C9B8349954E82C5623C3C8C541BD4E203586C";
    7.50 -    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
    7.51 -    const char* nobody_fpr = "1111111111111111111111111111111111111111";
    7.52 -
    7.53 -    cout << "creating message…\n";
    7.54 -    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Test");
    7.55 -    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
    7.56 -    
    7.57 -    alice->me = true;
    7.58 -
    7.59 -    PEP_STATUS mystatus = set_own_key(session, alice, alice_fpr);
    7.60 -    assert(mystatus == PEP_STATUS_OK);
    7.61 -
    7.62 -    identity_list* to_list = new_identity_list(bob); // to bob
    7.63 -    message* outgoing_message = new_message(PEP_dir_outgoing);
    7.64 -    assert(outgoing_message);
    7.65 -    outgoing_message->from = alice;
    7.66 -    outgoing_message->to = to_list;
    7.67 -    outgoing_message->shortmsg = strdup("Greetings, humans!");
    7.68 -    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
    7.69 -    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    7.70 -    cout << "message created.\n";
    7.71 -
    7.72 -    char* encoded_text = nullptr;
    7.73 -    PEP_STATUS status = mime_encode_message(outgoing_message, false, &encoded_text);
    7.74 -    assert(status == PEP_STATUS_OK);
    7.75 -    assert(encoded_text);
    7.76 -
    7.77 -    cout << "decrypted:\n\n";
    7.78 -    cout << encoded_text << "\n";
    7.79 -
    7.80 -    free(encoded_text);
    7.81 -
    7.82 -    message* encrypted_msg = nullptr;
    7.83 -    cout << "calling encrypt_message_for_identity()\n";
    7.84 -    status = encrypt_message_for_self(session, alice, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
    7.85 -    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
    7.86 -    assert(status == PEP_STATUS_OK);
    7.87 -    assert(encrypted_msg);
    7.88 -    cout << "message encrypted.\n";
    7.89 -    
    7.90 -    status = mime_encode_message(encrypted_msg, false, &encoded_text);
    7.91 -    assert(status == PEP_STATUS_OK);
    7.92 -    assert(encoded_text);
    7.93 -
    7.94 -    cout << "encrypted:\n\n";
    7.95 -    cout << encoded_text << "\n";
    7.96 -
    7.97 -    message* decoded_msg = nullptr;
    7.98 -    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
    7.99 -    assert(status == PEP_STATUS_OK);
   7.100 -    const string string3 = encoded_text;
   7.101 -
   7.102 -    unlink("msg_encrypt_for_self.asc");
   7.103 -    ofstream outFile3("msg_encrypt_for_self.asc");
   7.104 -    outFile3.write(string3.c_str(), string3.size());
   7.105 -    outFile3.close();
   7.106 -
   7.107 -    message* decrypted_msg = nullptr;
   7.108 -    stringlist_t* keylist_used = nullptr;
   7.109 -
   7.110 -    PEP_rating rating;
   7.111 -    PEP_decrypt_flags_t flags;
   7.112 -
   7.113 -    flags = 0;
   7.114 -    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
   7.115 -    assert(decrypted_msg);
   7.116 -    assert(keylist_used);
   7.117 -    assert(rating);
   7.118 -    assert(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
   7.119 -    PEP_comm_type ct = encrypted_msg->from->comm_type;
   7.120 -    assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
   7.121 -
   7.122 -    cout << "keys used:\n";
   7.123 -
   7.124 -    int i = 0;
   7.125 -
   7.126 -    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
   7.127 -    {
   7.128 -        if (i == 0)
   7.129 -            assert(strcasecmp("",kl4->value) == 0);
   7.130 -        else {
   7.131 -            cout << "\t " << kl4->value << endl;
   7.132 -            assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
   7.133 -            cout << "Encrypted for Alice! Yay! It worked!" << endl;
   7.134 -        }
   7.135 -        assert(i < 2);
   7.136 -    }
   7.137 -    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
   7.138 - 
   7.139 -    cout << "freeing messages…\n";
   7.140 -    free_message(encrypted_msg);
   7.141 -    free_message(decrypted_msg);
   7.142 -    free_stringlist (keylist_used);
   7.143 -    cout << "done.\n";
   7.144 -
   7.145 -    cout << "Now encrypt for self with extra keys." << endl;
   7.146 -    stringlist_t* extra_keys = new_stringlist(gabrielle_fpr);
   7.147 -    stringlist_add(extra_keys, bella_fpr);
   7.148 -    encrypted_msg = NULL;
   7.149 -    decrypted_msg = NULL;
   7.150 -    keylist_used = NULL;
   7.151 -
   7.152 -    cout << "calling encrypt_message_for_identity()\n";
   7.153 -    status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
   7.154 -    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
   7.155 -    assert(status == PEP_STATUS_OK);
   7.156 -    assert(encrypted_msg);
   7.157 -    cout << "message encrypted.\n";
   7.158 -    
   7.159 -    flags = 0;
   7.160 -    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
   7.161 -    assert(decrypted_msg);
   7.162 -    assert(keylist_used);
   7.163 -    assert(rating);
   7.164 -    assert(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
   7.165 -    ct = encrypted_msg->from->comm_type;
   7.166 -    assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
   7.167 -
   7.168 -    cout << "keys used:\n";
   7.169 -
   7.170 -    for (stringlist_t* incoming_kl = extra_keys; incoming_kl && incoming_kl->value; incoming_kl = incoming_kl->next) {
   7.171 -        bool found = false;
   7.172 -        cout << "Encrypted for: ";
   7.173 -        for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++) {
   7.174 -            if (strcasecmp(incoming_kl->value, kl4->value) == 0) {
   7.175 -                cout << "\t " << kl4->value;
   7.176 -                found = true;
   7.177 -                break;
   7.178 -            }
   7.179 -        }
   7.180 -        cout << endl;
   7.181 -        assert(found);
   7.182 -    }
   7.183 -    cout << "Encrypted for all the extra keys!" << endl;
   7.184 -
   7.185 -    bool found = false;
   7.186 -    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
   7.187 -    {
   7.188 -        if (strcasecmp(alice_fpr, kl4->value) == 0) {
   7.189 -            found = true;
   7.190 -            cout << "Encrypted also for Alice! Yay!" << endl;
   7.191 -            break;
   7.192 -        }
   7.193 -    }
   7.194 -    assert(found);
   7.195 -
   7.196 -    free_message(encrypted_msg);
   7.197 -    encrypted_msg = NULL;
   7.198 -    free_message(decrypted_msg);
   7.199 -    decrypted_msg = NULL;
   7.200 -    free_stringlist(keylist_used);
   7.201 -    keylist_used = NULL;
   7.202 -
   7.203 -    cout << "Now add a bad fpr." << endl;
   7.204 -    
   7.205 -    stringlist_add(extra_keys, nobody_fpr);
   7.206 -    
   7.207 -    cout << "calling encrypt_message_for_identity()\n";
   7.208 -    status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
   7.209 -    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
   7.210 -    assert(status != PEP_STATUS_OK);
   7.211 -
   7.212 -    free_message(outgoing_message);
   7.213 -    outgoing_message = NULL;
   7.214 -    free_message(encrypted_msg);
   7.215 -    encrypted_msg = NULL;
   7.216 -    free_message(decrypted_msg);
   7.217 -    decrypted_msg = NULL;
   7.218 -    free_stringlist(keylist_used);
   7.219 -    keylist_used = NULL;
   7.220 -
   7.221 -
   7.222 -    cout << "*** Now testing MIME_encrypt_for_self ***" << endl;
   7.223 -
   7.224 -    alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
   7.225 -    bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
   7.226 -
   7.227 -    cout << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl;
   7.228 -    
   7.229 -    const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
   7.230 -
   7.231 -    cout << "Text read:" << endl;
   7.232 -    cout << mimetext.c_str() << endl;
   7.233 -    char* encrypted_mimetext = nullptr;
   7.234 -    
   7.235 -    cout << "Calling MIME_encrypt_message_for_self" << endl;
   7.236 -    status = MIME_encrypt_message_for_self(session, alice, mimetext.c_str(),
   7.237 -                                           mimetext.size(), 
   7.238 -                                           NULL,
   7.239 -                                           &encrypted_mimetext, 
   7.240 -                                           PEP_enc_PGP_MIME, 
   7.241 -                                           PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
   7.242 -    
   7.243 -    cout << "Encrypted message:" << endl;
   7.244 -    cout << encrypted_mimetext << endl;
   7.245 -
   7.246 -    cout << "Calling MIME_decrypt_message" << endl;
   7.247 -    
   7.248 -    char* decrypted_mimetext = nullptr;
   7.249 -    free_stringlist(keylist_used);
   7.250 -    keylist_used = nullptr;
   7.251 -    PEP_decrypt_flags_t mimeflags;
   7.252 -    PEP_rating mimerating;
   7.253 -    char* modified_src = NULL;
   7.254 -
   7.255 -    mimeflags = 0;
   7.256 -    status = MIME_decrypt_message(session,
   7.257 -                                  encrypted_mimetext,
   7.258 -                                  strlen(encrypted_mimetext),
   7.259 -                                  &decrypted_mimetext,
   7.260 -                                  &keylist_used,
   7.261 -                                  &mimerating,
   7.262 -                                  &mimeflags,
   7.263 -				  &modified_src);
   7.264 -
   7.265 -    assert(decrypted_mimetext);
   7.266 -    assert(keylist_used);
   7.267 -    assert(mimerating);
   7.268 -                             
   7.269 -    assert(status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable);
   7.270 -
   7.271 -    cout << "Decrypted message:" << endl;
   7.272 -    cout << decrypted_mimetext << endl;
   7.273 -
   7.274 -    cout << "keys used:\n";
   7.275 -
   7.276 -    i = 0;
   7.277 -
   7.278 -    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
   7.279 -    {
   7.280 -        if (i == 0)
   7.281 -            assert(strcasecmp("",kl4->value) == 0);
   7.282 -        else {
   7.283 -            cout << "\t " << kl4->value << endl;
   7.284 -            assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
   7.285 -            cout << "Encrypted for Alice! Yay! It worked!" << endl;
   7.286 -        }
   7.287 -        assert(i < 2);
   7.288 -    }
   7.289 -    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
   7.290 -    
   7.291 -    cout << "calling release()\n";
   7.292 -    release(session);
   7.293 -    return 0;
   7.294 -}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/gentestshell.py	Mon May 07 16:47:22 2018 +0200
     8.3 @@ -0,0 +1,119 @@
     8.4 +import argparse
     8.5 +import os
     8.6 +import subprocess
     8.7 +import re
     8.8 +
     8.9 +def decamel(name):
    8.10 +    retval = re.sub('([A-Z])', r'_\1', name).lower()
    8.11 +    return re.sub('^_', r'', retval) 
    8.12 +
    8.13 +parser = argparse.ArgumentParser()
    8.14 +parser.add_argument("suite_name", help="(convention is <NameInUpperCamelCase>, e.g. StringpairList - suite created will then be StringpairListTests)")
    8.15 +parser.add_argument("--clobber", "-c", help="Overwrite extant files (must be explicitly indicated)", action='store_true')
    8.16 +
    8.17 +gengroup = parser.add_mutually_exclusive_group()
    8.18 +gengroup.add_argument("--no_src", help="Generate header only, no source", action='store_true')
    8.19 +gengroup.add_argument("--no_hdr", help="Generate source only, no header", action='store_true')
    8.20 +
    8.21 +typegroup = parser.add_mutually_exclusive_group()
    8.22 +typegroup.add_argument("--test", "-t", help="Just generate a generic test suite (no engine initialisation or db/gpg setup/teardown - default)", action='store_true')
    8.23 +typegroup.add_argument("--indiv", "-i", help="Generate a test suite with engine initialisation/release and gpg/db teardown between each test function", action='store_true')
    8.24 +typegroup.add_argument("--session", "-s", help="Generate a test suite with engine initialisation/release and gpg/db teardown only at the beginning and end of the test suite", action='store_true')
    8.25 +
    8.26 +args = parser.parse_args()
    8.27 +
    8.28 +suitename = args.suite_name
    8.29 +test_suite = suitename + "Tests"
    8.30 +
    8.31 +superclass = "EngineTestSuite"
    8.32 +
    8.33 +if args.indiv: 
    8.34 +    superclass = "EngineTestIndividualSuite"
    8.35 +elif args.session:
    8.36 +    superclass = "EngineTestSessionSuite"
    8.37 +
    8.38 +print("\nCreating " + test_suite + " as an " + superclass + "\n")
    8.39 +
    8.40 +uncamel = decamel(suitename)
    8.41 +print(uncamel)
    8.42 +
    8.43 +
    8.44 +nspace = "using namespace std;\n\n"
    8.45 +
    8.46 +license = ("// This file is under GNU General Public License 3.0\n"
    8.47 +           "// see LICENSE.txt\n\n")
    8.48 +
    8.49 +default_single_testname = "check_" + re.sub('_tests$', r'', uncamel) 
    8.50 +
    8.51 +if not args.no_hdr:
    8.52 +    
    8.53 +    header_def = uncamel.upper() + "_H"
    8.54 +
    8.55 +    deftxt = "#ifndef " + header_def + "\n#define " + header_def + "\n\n"
    8.56 +
    8.57 +    header_inc = ("#include <string>\n" 
    8.58 +                  "#include \"" + superclass + ".h\"\n\n")
    8.59 +
    8.60 +    header = license + deftxt + header_inc + nspace
    8.61 +
    8.62 +
    8.63 +    classdef = "class " + test_suite + " : public " + superclass + " {\n" + \
    8.64 +               "    public:\n" + \
    8.65 +               "        " + test_suite + "(string test_suite, string test_home_dir);\n" + \
    8.66 +               "    private:\n" \
    8.67 +               "        void " + default_single_testname + "();\n" + \
    8.68 +               "};\n" 
    8.69 +
    8.70 +    header_file = header + classdef + "\n#endif\n"
    8.71 +
    8.72 +    #print(header_file)
    8.73 +
    8.74 +    do_write = True
    8.75 +    hfile_name = test_suite + ".h"
    8.76 +    hfile_path = os.path.join(os.path.join(os.getcwd(), "include"), hfile_name)
    8.77 +
    8.78 +    if not args.clobber:
    8.79 +        if (os.path.isfile(hfile_path)):
    8.80 +            print(hfile_path + " exists. Not writing header file. Use --clobber to overwrite.")
    8.81 +            do_write = False
    8.82 +
    8.83 +    if do_write:
    8.84 +        header_out = open(hfile_path, 'w')
    8.85 +        header_out.write(header_file)
    8.86 +        header_out.close()
    8.87 +
    8.88 +if not args.no_src:
    8.89 +    src_inc = ('#include <stdlib.h>\n'
    8.90 +               '#include <string>\n\n'
    8.91 +               '#include "pEpEngine.h"\n\n'
    8.92 +               '#include "' + superclass +'.h"\n'
    8.93 +               '#include "' + test_suite + '.h"\n\n')
    8.94 +
    8.95 +    test_suite_prefix = test_suite + "::"
    8.96 +    fname = test_suite_prefix + default_single_testname
    8.97 +
    8.98 +    constructor = test_suite_prefix + test_suite + "(string suitename, string test_home_dir) :\n" + \
    8.99 +                  "    " + superclass + "::" + superclass + "(suitename, test_home_dir) {\n" + \
   8.100 +                  "    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string(\"" + fname + "\"),\n" + \
   8.101 +                  "                                                                      static_cast<Func>(&" + fname + ")));\n" + \
   8.102 +                  "}\n\n"
   8.103 +                  
   8.104 +    def_funct = "void " + test_suite_prefix + default_single_testname + "() {\n" + \
   8.105 +                "    TEST_ASSERT(true);\n" + \
   8.106 +                "}\n\n"
   8.107 +
   8.108 +    src_file = license + src_inc + nspace + constructor + def_funct
   8.109 +
   8.110 +    do_write = True
   8.111 +    sfile_name = test_suite + ".cc"
   8.112 +    sfile_path = os.path.join(os.path.join(os.getcwd(), "src/engine_tests"), sfile_name)
   8.113 +
   8.114 +    if not args.clobber:
   8.115 +        if (os.path.isfile(sfile_path)):
   8.116 +            print(sfile_path + " exists. Not writing source file. Use --clobber to overwrite.")
   8.117 +            do_write = False
   8.118 +
   8.119 +    if do_write:
   8.120 +        src_out = open(sfile_path, 'w')
   8.121 +        src_out.write(src_file)
   8.122 +        src_out.close()
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/include/BlacklistAcceptNewKeyTests.h	Mon May 07 16:47:22 2018 +0200
     9.3 @@ -0,0 +1,19 @@
     9.4 +// This file is under GNU General Public License 3.0
     9.5 +// see LICENSE.txt
     9.6 +
     9.7 +#ifndef BLACKLIST_ACCEPT_NEW_KEY_H
     9.8 +#define BLACKLIST_ACCEPT_NEW_KEY_H
     9.9 +
    9.10 +#include <string>
    9.11 +#include "EngineTestSessionSuite.h"
    9.12 +
    9.13 +using namespace std;
    9.14 +
    9.15 +class BlacklistAcceptNewKeyTests : public EngineTestSessionSuite {
    9.16 +    public:
    9.17 +        BlacklistAcceptNewKeyTests(string test_suite, string test_home_dir);
    9.18 +    private:
    9.19 +        void check_blacklist_accept_new_key();
    9.20 +};
    9.21 +
    9.22 +#endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/include/BlacklistTests.h	Mon May 07 16:47:22 2018 +0200
    10.3 @@ -0,0 +1,19 @@
    10.4 +// This file is under GNU General Public License 3.0
    10.5 +// see LICENSE.txt
    10.6 +
    10.7 +#ifndef BLACKLIST_H
    10.8 +#define BLACKLIST_H
    10.9 +
   10.10 +#include <string>
   10.11 +#include "EngineTestSessionSuite.h"
   10.12 +
   10.13 +using namespace std;
   10.14 +
   10.15 +class BlacklistTests : public EngineTestSessionSuite {
   10.16 +    public:
   10.17 +        BlacklistTests(string test_suite, string test_home_dir);
   10.18 +    private:
   10.19 +        void check_blacklist();
   10.20 +};
   10.21 +
   10.22 +#endif
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/include/CrashdumpTests.h	Mon May 07 16:47:22 2018 +0200
    11.3 @@ -0,0 +1,19 @@
    11.4 +// This file is under GNU General Public License 3.0
    11.5 +// see LICENSE.txt
    11.6 +
    11.7 +#ifndef CRASHDUMP_H
    11.8 +#define CRASHDUMP_H
    11.9 +
   11.10 +#include <string>
   11.11 +#include "EngineTestSessionSuite.h"
   11.12 +
   11.13 +using namespace std;
   11.14 +
   11.15 +class CrashdumpTests : public EngineTestSessionSuite {
   11.16 +    public:
   11.17 +        CrashdumpTests(string test_suite, string test_home_dir);
   11.18 +    private:
   11.19 +        void check_crashdump();
   11.20 +};
   11.21 +
   11.22 +#endif
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/include/DecryptAttachPrivateKeyTrustedTests.h	Mon May 07 16:47:22 2018 +0200
    12.3 @@ -0,0 +1,19 @@
    12.4 +// This file is under GNU General Public License 3.0
    12.5 +// see LICENSE.txt
    12.6 +
    12.7 +#ifndef DECRYPT_ATTACH_PRIVATE_KEY_TRUSTED_H
    12.8 +#define DECRYPT_ATTACH_PRIVATE_KEY_TRUSTED_H
    12.9 +
   12.10 +#include <string>
   12.11 +#include "EngineTestSessionSuite.h"
   12.12 +
   12.13 +using namespace std;
   12.14 +
   12.15 +class DecryptAttachPrivateKeyTrustedTests : public EngineTestSessionSuite {
   12.16 +    public:
   12.17 +        DecryptAttachPrivateKeyTrustedTests(string test_suite, string test_home_dir);
   12.18 +    private:
   12.19 +        void check_decrypt_attach_private_key_trusted();
   12.20 +};
   12.21 +
   12.22 +#endif
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/include/DecryptAttachPrivateKeyUntrustedTests.h	Mon May 07 16:47:22 2018 +0200
    13.3 @@ -0,0 +1,19 @@
    13.4 +// This file is under GNU General Public License 3.0
    13.5 +// see LICENSE.txt
    13.6 +
    13.7 +#ifndef DECRYPT_ATTACH_PRIVATE_KEY_UNTRUSTED_H
    13.8 +#define DECRYPT_ATTACH_PRIVATE_KEY_UNTRUSTED_H
    13.9 +
   13.10 +#include <string>
   13.11 +#include "EngineTestSessionSuite.h"
   13.12 +
   13.13 +using namespace std;
   13.14 +
   13.15 +class DecryptAttachPrivateKeyUntrustedTests : public EngineTestSessionSuite {
   13.16 +    public:
   13.17 +        DecryptAttachPrivateKeyUntrustedTests(string test_suite, string test_home_dir);
   13.18 +    private:
   13.19 +        void check_decrypt_attach_private_key_untrusted();
   13.20 +};
   13.21 +
   13.22 +#endif
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/include/EncryptAttachPrivateKeyTests.h	Mon May 07 16:47:22 2018 +0200
    14.3 @@ -0,0 +1,19 @@
    14.4 +// This file is under GNU General Public License 3.0
    14.5 +// see LICENSE.txt
    14.6 +
    14.7 +#ifndef ENCRYPT_ATTACH_PRIVATE_KEY_H
    14.8 +#define ENCRYPT_ATTACH_PRIVATE_KEY_H
    14.9 +
   14.10 +#include <string>
   14.11 +#include "EngineTestSessionSuite.h"
   14.12 +
   14.13 +using namespace std;
   14.14 +
   14.15 +class EncryptAttachPrivateKeyTests : public EngineTestSessionSuite {
   14.16 +    public:
   14.17 +        EncryptAttachPrivateKeyTests(string test_suite, string test_home_dir);
   14.18 +    private:
   14.19 +        void check_encrypt_attach_private_key();
   14.20 +};
   14.21 +
   14.22 +#endif
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/include/EncryptForIdentityTests.h	Mon May 07 16:47:22 2018 +0200
    15.3 @@ -0,0 +1,19 @@
    15.4 +// This file is under GNU General Public License 3.0
    15.5 +// see LICENSE.txt
    15.6 +
    15.7 +#ifndef ENCRYPT_FOR_IDENTITY_H
    15.8 +#define ENCRYPT_FOR_IDENTITY_H
    15.9 +
   15.10 +#include <string>
   15.11 +#include "EngineTestSessionSuite.h"
   15.12 +
   15.13 +using namespace std;
   15.14 +
   15.15 +class EncryptForIdentityTests : public EngineTestSessionSuite {
   15.16 +    public:
   15.17 +        EncryptForIdentityTests(string test_suite, string test_home_dir);
   15.18 +    private:
   15.19 +        void check_encrypt_for_identity();
   15.20 +};
   15.21 +
   15.22 +#endif
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/include/EncryptMissingPrivateKeyTests.h	Mon May 07 16:47:22 2018 +0200
    16.3 @@ -0,0 +1,19 @@
    16.4 +// This file is under GNU General Public License 3.0
    16.5 +// see LICENSE.txt
    16.6 +
    16.7 +#ifndef ENCRYPT_MISSING_PRIVATE_KEY_H
    16.8 +#define ENCRYPT_MISSING_PRIVATE_KEY_H
    16.9 +
   16.10 +#include <string>
   16.11 +#include "EngineTestSessionSuite.h"
   16.12 +
   16.13 +using namespace std;
   16.14 +
   16.15 +class EncryptMissingPrivateKeyTests : public EngineTestSessionSuite {
   16.16 +    public:
   16.17 +        EncryptMissingPrivateKeyTests(string test_suite, string test_home_dir);
   16.18 +    private:
   16.19 +        void check_encrypt_missing_private_key();
   16.20 +};
   16.21 +
   16.22 +#endif
    17.1 --- a/test/include/EngineTestSessionSuite.h	Mon May 07 15:34:55 2018 +0200
    17.2 +++ b/test/include/EngineTestSessionSuite.h	Mon May 07 16:47:22 2018 +0200
    17.3 @@ -7,6 +7,8 @@
    17.4  #include <string>
    17.5  #include "pEpEngine.h"
    17.6  
    17.7 +#include "EngineTestSuite.h"
    17.8 +
    17.9  using namespace std;
   17.10  
   17.11  class EngineTestSessionSuite : public EngineTestSuite {
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/test/include/ExternalRevokeTests.h	Mon May 07 16:47:22 2018 +0200
    18.3 @@ -0,0 +1,19 @@
    18.4 +// This file is under GNU General Public License 3.0
    18.5 +// see LICENSE.txt
    18.6 +
    18.7 +#ifndef EXTERNAL_REVOKE_H
    18.8 +#define EXTERNAL_REVOKE_H
    18.9 +
   18.10 +#include <string>
   18.11 +#include "EngineTestSessionSuite.h"
   18.12 +
   18.13 +using namespace std;
   18.14 +
   18.15 +class ExternalRevokeTests : public EngineTestSessionSuite {
   18.16 +    public:
   18.17 +        ExternalRevokeTests(string test_suite, string test_home_dir);
   18.18 +    private:
   18.19 +        void check_external_revoke();
   18.20 +};
   18.21 +
   18.22 +#endif
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/test/include/I18nTests.h	Mon May 07 16:47:22 2018 +0200
    19.3 @@ -0,0 +1,19 @@
    19.4 +// This file is under GNU General Public License 3.0
    19.5 +// see LICENSE.txt
    19.6 +
    19.7 +#ifndef I18N_H
    19.8 +#define I18N_H
    19.9 +
   19.10 +#include <string>
   19.11 +#include "EngineTestSessionSuite.h"
   19.12 +
   19.13 +using namespace std;
   19.14 +
   19.15 +class I18nTests : public EngineTestSessionSuite {
   19.16 +    public:
   19.17 +        I18nTests(string test_suite, string test_home_dir);
   19.18 +    private:
   19.19 +        void check_i18n();
   19.20 +};
   19.21 +
   19.22 +#endif
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/test/include/IdentityListTests.h	Mon May 07 16:47:22 2018 +0200
    20.3 @@ -0,0 +1,19 @@
    20.4 +// This file is under GNU General Public License 3.0
    20.5 +// see LICENSE.txt
    20.6 +
    20.7 +#ifndef IDENTITY_LIST_H
    20.8 +#define IDENTITY_LIST_H
    20.9 +
   20.10 +#include <string>
   20.11 +#include "EngineTestSessionSuite.h"
   20.12 +
   20.13 +using namespace std;
   20.14 +
   20.15 +class IdentityListTests : public EngineTestSessionSuite {
   20.16 +    public:
   20.17 +        IdentityListTests(string test_suite, string test_home_dir);
   20.18 +    private:
   20.19 +        void check_identity_list();
   20.20 +};
   20.21 +
   20.22 +#endif
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/test/include/KeyeditTests.h	Mon May 07 16:47:22 2018 +0200
    21.3 @@ -0,0 +1,19 @@
    21.4 +// This file is under GNU General Public License 3.0
    21.5 +// see LICENSE.txt
    21.6 +
    21.7 +#ifndef KEYEDIT_H
    21.8 +#define KEYEDIT_H
    21.9 +
   21.10 +#include <string>
   21.11 +#include "EngineTestSessionSuite.h"
   21.12 +
   21.13 +using namespace std;
   21.14 +
   21.15 +class KeyeditTests : public EngineTestSessionSuite {
   21.16 +    public:
   21.17 +        KeyeditTests(string test_suite, string test_home_dir);
   21.18 +    private:
   21.19 +        void check_keyedit();
   21.20 +};
   21.21 +
   21.22 +#endif
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/test/include/LeastColorGroupTests.h	Mon May 07 16:47:22 2018 +0200
    22.3 @@ -0,0 +1,19 @@
    22.4 +// This file is under GNU General Public License 3.0
    22.5 +// see LICENSE.txt
    22.6 +
    22.7 +#ifndef LEAST_COLOR_GROUP_H
    22.8 +#define LEAST_COLOR_GROUP_H
    22.9 +
   22.10 +#include <string>
   22.11 +#include "EngineTestSessionSuite.h"
   22.12 +
   22.13 +using namespace std;
   22.14 +
   22.15 +class LeastColorGroupTests : public EngineTestSessionSuite {
   22.16 +    public:
   22.17 +        LeastColorGroupTests(string test_suite, string test_home_dir);
   22.18 +    private:
   22.19 +        void check_least_color_group();
   22.20 +};
   22.21 +
   22.22 +#endif
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/test/include/LeastCommonDenomColorTests.h	Mon May 07 16:47:22 2018 +0200
    23.3 @@ -0,0 +1,19 @@
    23.4 +// This file is under GNU General Public License 3.0
    23.5 +// see LICENSE.txt
    23.6 +
    23.7 +#ifndef LEAST_COMMON_DENOM_COLOR_H
    23.8 +#define LEAST_COMMON_DENOM_COLOR_H
    23.9 +
   23.10 +#include <string>
   23.11 +#include "EngineTestSessionSuite.h"
   23.12 +
   23.13 +using namespace std;
   23.14 +
   23.15 +class LeastCommonDenomColorTests : public EngineTestSessionSuite {
   23.16 +    public:
   23.17 +        LeastCommonDenomColorTests(string test_suite, string test_home_dir);
   23.18 +    private:
   23.19 +        void check_least_common_denom_color();
   23.20 +};
   23.21 +
   23.22 +#endif
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/test/include/MapAsn1Tests.h	Mon May 07 16:47:22 2018 +0200
    24.3 @@ -0,0 +1,19 @@
    24.4 +// This file is under GNU General Public License 3.0
    24.5 +// see LICENSE.txt
    24.6 +
    24.7 +#ifndef MAP_ASN1_H
    24.8 +#define MAP_ASN1_H
    24.9 +
   24.10 +#include <string>
   24.11 +#include "EngineTestSessionSuite.h"
   24.12 +
   24.13 +using namespace std;
   24.14 +
   24.15 +class MapAsn1Tests : public EngineTestSessionSuite {
   24.16 +    public:
   24.17 +        MapAsn1Tests(string test_suite, string test_home_dir);
   24.18 +    private:
   24.19 +        void check_map_asn1();
   24.20 +};
   24.21 +
   24.22 +#endif
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/test/include/Message2_0Tests.h	Mon May 07 16:47:22 2018 +0200
    25.3 @@ -0,0 +1,19 @@
    25.4 +// This file is under GNU General Public License 3.0
    25.5 +// see LICENSE.txt
    25.6 +
    25.7 +#ifndef MESSAGE2_0_H
    25.8 +#define MESSAGE2_0_H
    25.9 +
   25.10 +#include <string>
   25.11 +#include "EngineTestSessionSuite.h"
   25.12 +
   25.13 +using namespace std;
   25.14 +
   25.15 +class Message2_0Tests : public EngineTestSessionSuite {
   25.16 +    public:
   25.17 +        Message2_0Tests(string test_suite, string test_home_dir);
   25.18 +    private:
   25.19 +        void check_message2_0();
   25.20 +};
   25.21 +
   25.22 +#endif
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/test/include/MessageApiTests.h	Mon May 07 16:47:22 2018 +0200
    26.3 @@ -0,0 +1,19 @@
    26.4 +// This file is under GNU General Public License 3.0
    26.5 +// see LICENSE.txt
    26.6 +
    26.7 +#ifndef MESSAGE_API_H
    26.8 +#define MESSAGE_API_H
    26.9 +
   26.10 +#include <string>
   26.11 +#include "EngineTestSessionSuite.h"
   26.12 +
   26.13 +using namespace std;
   26.14 +
   26.15 +class MessageApiTests : public EngineTestSessionSuite {
   26.16 +    public:
   26.17 +        MessageApiTests(string test_suite, string test_home_dir);
   26.18 +    private:
   26.19 +        void check_message_api();
   26.20 +};
   26.21 +
   26.22 +#endif
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/include/MessageTwoPointOhTests.h	Mon May 07 16:47:22 2018 +0200
    27.3 @@ -0,0 +1,19 @@
    27.4 +// This file is under GNU General Public License 3.0
    27.5 +// see LICENSE.txt
    27.6 +
    27.7 +#ifndef MESSAGE_TWO_POINT_OH_H
    27.8 +#define MESSAGE_TWO_POINT_OH_H
    27.9 +
   27.10 +#include <string>
   27.11 +#include "EngineTestSessionSuite.h"
   27.12 +
   27.13 +using namespace std;
   27.14 +
   27.15 +class MessageTwoPointOhTests : public EngineTestSessionSuite {
   27.16 +    public:
   27.17 +        MessageTwoPointOhTests(string test_suite, string test_home_dir);
   27.18 +    private:
   27.19 +        void check_message_two_point_oh();
   27.20 +};
   27.21 +
   27.22 +#endif
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/include/MimeTests.h	Mon May 07 16:47:22 2018 +0200
    28.3 @@ -0,0 +1,19 @@
    28.4 +// This file is under GNU General Public License 3.0
    28.5 +// see LICENSE.txt
    28.6 +
    28.7 +#ifndef MIME_H
    28.8 +#define MIME_H
    28.9 +
   28.10 +#include <string>
   28.11 +#include "EngineTestSessionSuite.h"
   28.12 +
   28.13 +using namespace std;
   28.14 +
   28.15 +class MimeTests : public EngineTestSessionSuite {
   28.16 +    public:
   28.17 +        MimeTests(string test_suite, string test_home_dir);
   28.18 +    private:
   28.19 +        void check_mime();
   28.20 +};
   28.21 +
   28.22 +#endif
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/test/include/MistrustUndoTests.h	Mon May 07 16:47:22 2018 +0200
    29.3 @@ -0,0 +1,19 @@
    29.4 +// This file is under GNU General Public License 3.0
    29.5 +// see LICENSE.txt
    29.6 +
    29.7 +#ifndef MISTRUST_UNDO_H
    29.8 +#define MISTRUST_UNDO_H
    29.9 +
   29.10 +#include <string>
   29.11 +#include "EngineTestSessionSuite.h"
   29.12 +
   29.13 +using namespace std;
   29.14 +
   29.15 +class MistrustUndoTests : public EngineTestSessionSuite {
   29.16 +    public:
   29.17 +        MistrustUndoTests(string test_suite, string test_home_dir);
   29.18 +    private:
   29.19 +        void check_mistrust_undo();
   29.20 +};
   29.21 +
   29.22 +#endif
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/include/NewUpdateIdAndMyselfTests.h	Mon May 07 16:47:22 2018 +0200
    30.3 @@ -0,0 +1,19 @@
    30.4 +// This file is under GNU General Public License 3.0
    30.5 +// see LICENSE.txt
    30.6 +
    30.7 +#ifndef NEW_UPDATE_ID_AND_MYSELF_H
    30.8 +#define NEW_UPDATE_ID_AND_MYSELF_H
    30.9 +
   30.10 +#include <string>
   30.11 +#include "EngineTestSessionSuite.h"
   30.12 +
   30.13 +using namespace std;
   30.14 +
   30.15 +class NewUpdateIdAndMyselfTests : public EngineTestSessionSuite {
   30.16 +    public:
   30.17 +        NewUpdateIdAndMyselfTests(string test_suite, string test_home_dir);
   30.18 +    private:
   30.19 +        void check_new_update_id_and_myself();
   30.20 +};
   30.21 +
   30.22 +#endif
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/test/include/PepSubjectReceivedTests.h	Mon May 07 16:47:22 2018 +0200
    31.3 @@ -0,0 +1,19 @@
    31.4 +// This file is under GNU General Public License 3.0
    31.5 +// see LICENSE.txt
    31.6 +
    31.7 +#ifndef PEP_SUBJECT_RECEIVED_H
    31.8 +#define PEP_SUBJECT_RECEIVED_H
    31.9 +
   31.10 +#include <string>
   31.11 +#include "EngineTestSessionSuite.h"
   31.12 +
   31.13 +using namespace std;
   31.14 +
   31.15 +class PepSubjectReceivedTests : public EngineTestSessionSuite {
   31.16 +    public:
   31.17 +        PepSubjectReceivedTests(string test_suite, string test_home_dir);
   31.18 +    private:
   31.19 +        void check_pep_subject_received();
   31.20 +};
   31.21 +
   31.22 +#endif
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/test/include/PgpBinaryTests.h	Mon May 07 16:47:22 2018 +0200
    32.3 @@ -0,0 +1,19 @@
    32.4 +// This file is under GNU General Public License 3.0
    32.5 +// see LICENSE.txt
    32.6 +
    32.7 +#ifndef PGP_BINARY_H
    32.8 +#define PGP_BINARY_H
    32.9 +
   32.10 +#include <string>
   32.11 +#include "EngineTestSessionSuite.h"
   32.12 +
   32.13 +using namespace std;
   32.14 +
   32.15 +class PgpBinaryTests : public EngineTestSessionSuite {
   32.16 +    public:
   32.17 +        PgpBinaryTests(string test_suite, string test_home_dir);
   32.18 +    private:
   32.19 +        void check_pgp_binary();
   32.20 +};
   32.21 +
   32.22 +#endif
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/test/include/PgpListKeysTests.h	Mon May 07 16:47:22 2018 +0200
    33.3 @@ -0,0 +1,19 @@
    33.4 +// This file is under GNU General Public License 3.0
    33.5 +// see LICENSE.txt
    33.6 +
    33.7 +#ifndef PGP_LIST_KEYS_H
    33.8 +#define PGP_LIST_KEYS_H
    33.9 +
   33.10 +#include <string>
   33.11 +#include "EngineTestSessionSuite.h"
   33.12 +
   33.13 +using namespace std;
   33.14 +
   33.15 +class PgpListKeysTests : public EngineTestSessionSuite {
   33.16 +    public:
   33.17 +        PgpListKeysTests(string test_suite, string test_home_dir);
   33.18 +    private:
   33.19 +        void check_pgp_list_keys();
   33.20 +};
   33.21 +
   33.22 +#endif
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/test/include/ReencryptPlusExtraKeysTests.h	Mon May 07 16:47:22 2018 +0200
    34.3 @@ -0,0 +1,19 @@
    34.4 +// This file is under GNU General Public License 3.0
    34.5 +// see LICENSE.txt
    34.6 +
    34.7 +#ifndef REENCRYPT_PLUS_EXTRA_KEYS_H
    34.8 +#define REENCRYPT_PLUS_EXTRA_KEYS_H
    34.9 +
   34.10 +#include <string>
   34.11 +#include "EngineTestSessionSuite.h"
   34.12 +
   34.13 +using namespace std;
   34.14 +
   34.15 +class ReencryptPlusExtraKeysTests : public EngineTestSessionSuite {
   34.16 +    public:
   34.17 +        ReencryptPlusExtraKeysTests(string test_suite, string test_home_dir);
   34.18 +    private:
   34.19 +        void check_reencrypt_plus_extra_keys();
   34.20 +};
   34.21 +
   34.22 +#endif
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/test/include/RevokeRegenAttachTests.h	Mon May 07 16:47:22 2018 +0200
    35.3 @@ -0,0 +1,19 @@
    35.4 +// This file is under GNU General Public License 3.0
    35.5 +// see LICENSE.txt
    35.6 +
    35.7 +#ifndef REVOKE_REGEN_ATTACH_H
    35.8 +#define REVOKE_REGEN_ATTACH_H
    35.9 +
   35.10 +#include <string>
   35.11 +#include "EngineTestSessionSuite.h"
   35.12 +
   35.13 +using namespace std;
   35.14 +
   35.15 +class RevokeRegenAttachTests : public EngineTestSessionSuite {
   35.16 +    public:
   35.17 +        RevokeRegenAttachTests(string test_suite, string test_home_dir);
   35.18 +    private:
   35.19 +        void check_revoke_regen_attach();
   35.20 +};
   35.21 +
   35.22 +#endif
    36.1 --- a/test/message_2.0_test.cc	Mon May 07 15:34:55 2018 +0200
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,169 +0,0 @@
    36.4 -// This file is under GNU General Public License 3.0
    36.5 -// see LICENSE.txt
    36.6 -
    36.7 -#include <stdlib.h>
    36.8 -#include <string.h>
    36.9 -#include "platform.h"
   36.10 -#include <iostream>
   36.11 -#include <fstream>
   36.12 -#include <assert.h>
   36.13 -#include "mime.h"
   36.14 -#include "message_api.h"
   36.15 -#include "keymanagement.h"
   36.16 -#include "test_util.h"
   36.17 -
   36.18 -using namespace std;
   36.19 -
   36.20 -int main() {
   36.21 -    cout << "\n*** message_2.0_test ***\n\n";
   36.22 -
   36.23 -    PEP_SESSION session;
   36.24 -    
   36.25 -    cout << "calling init()\n";
   36.26 -    PEP_STATUS status1 = init(&session);
   36.27 -    assert(status1 == PEP_STATUS_OK);
   36.28 -    assert(session);
   36.29 -    cout << "init() completed.\n";
   36.30 -
   36.31 -    PEP_comm_type carol_comm_type = PEP_ct_OpenPGP_unconfirmed;
   36.32 -
   36.33 -    // message_api test code
   36.34 -
   36.35 -    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   36.36 -    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   36.37 -    const string carol_pub_key = slurp("test_keys/pub/pep-test-carol-0x42A85A42_pub.asc");
   36.38 -    const string carol_priv_key = slurp("test_keys/priv/pep-test-carol-0x42A85A42_priv.asc");
   36.39 -
   36.40 -    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   36.41 -    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   36.42 -    assert(statuspub == PEP_STATUS_OK);
   36.43 -    assert(statuspriv == PEP_STATUS_OK);
   36.44 -    statuspub = import_key(session, carol_pub_key.c_str(), carol_pub_key.length(), NULL);
   36.45 -    statuspriv = import_key(session, carol_priv_key.c_str(), carol_priv_key.length(), NULL);
   36.46 -    assert(statuspub == PEP_STATUS_OK);
   36.47 -    assert(statuspriv == PEP_STATUS_OK);
   36.48 -
   36.49 -    cout << "creating message…\n";
   36.50 -    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
   36.51 -    pEp_identity* carol = new_identity("pep-test-carol@pep-project.org", NULL, "TOFU_pep-test-carol@pep-project.org", "Carol Test");
   36.52 -
   36.53 -    PEP_STATUS alice_status = update_identity(session, alice);
   36.54 -    PEP_STATUS carol_status = update_identity(session, carol);
   36.55 -
   36.56 -    PEP_STATUS status = update_trust_for_fpr(session, alice->fpr, PEP_ct_pEp);
   36.57 -    status = update_trust_for_fpr(session, carol->fpr, carol_comm_type);
   36.58 -    
   36.59 -    PEP_STATUS mystatus = myself(session, alice);
   36.60 -    assert(mystatus == PEP_STATUS_OK);
   36.61 -    alice_status = update_identity(session, alice);
   36.62 -    alice_status = update_identity(session, carol);
   36.63 -    assert(alice->comm_type == PEP_ct_pEp);
   36.64 -    assert(carol->comm_type == carol_comm_type);
   36.65 -    
   36.66 -    identity_list* to_list = new_identity_list(carol); // to carol
   36.67 -    message* outgoing_message = new_message(PEP_dir_outgoing);
   36.68 -    assert(outgoing_message);
   36.69 -    outgoing_message->from = alice;
   36.70 -    outgoing_message->to = to_list;
   36.71 -    outgoing_message->shortmsg = strdup("Greetings, humans!");
   36.72 -    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   36.73 -    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   36.74 -//    outgoing_message->id = strdup("blahblahyourmama@pep-project.org");
   36.75 -    outgoing_message->references = new_stringlist("one-839274982347239847@pep-project.org");
   36.76 -    stringlist_add(outgoing_message->references, "two-dfddffd839274982347239847@pep-project.org");
   36.77 -    stringlist_add(outgoing_message->references, "three-OMGWTFBBQ.edfddffd839274982347239847@pep-project.org");
   36.78 -    
   36.79 -    cout << "message created.\n";
   36.80 -
   36.81 -    char* encoded_text = nullptr;
   36.82 -    status = mime_encode_message(outgoing_message, false, &encoded_text);
   36.83 -    assert(status == PEP_STATUS_OK);
   36.84 -    assert(encoded_text);
   36.85 -
   36.86 -    cout << "unencrypted:\n\n";
   36.87 -    cout << encoded_text << "\n";
   36.88 -
   36.89 -    free(encoded_text);
   36.90 -
   36.91 -    cout << "encrypting message as MIME multipart…\n";
   36.92 -    message* encrypted_msg = nullptr;
   36.93 -    cout << "calling encrypt_message\n";
   36.94 -    status = encrypt_message(session, outgoing_message, NULL, 
   36.95 -        &encrypted_msg, PEP_enc_PGP_MIME, 0);
   36.96 -    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
   36.97 -    assert(status == PEP_STATUS_OK);
   36.98 -    assert(encrypted_msg);
   36.99 -    cout << "message encrypted.\n";
  36.100 -    
  36.101 -    encrypted_msg->enc_format = PEP_enc_none;
  36.102 -    status = mime_encode_message(encrypted_msg, false, &encoded_text);
  36.103 -    assert(status == PEP_STATUS_OK);
  36.104 -    assert(encoded_text);
  36.105 -     
  36.106 -    cout << "encrypted:\n\n";
  36.107 -    cout << encoded_text << "\n";
  36.108 -     
  36.109 -    char* decrypted_text;
  36.110 -    
  36.111 -    message* decrypted_msg = nullptr;
  36.112 -    stringlist_t* keylist_used = nullptr;
  36.113 -    
  36.114 -    PEP_rating rating;
  36.115 -    PEP_decrypt_flags_t flags;
  36.116 -     
  36.117 -//    MIME_decrypt_message(session, encoded_text, strlen(encoded_text), &decrypted_text, &keylist_used, &rating, &flags);
  36.118 -    
  36.119 -//    cout << "HEY!" << endl;
  36.120 -//    cout << decrypted_text << endl;
  36.121 -    
  36.122 -    message* decoded_msg = nullptr;
  36.123 -    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
  36.124 -    assert(status == PEP_STATUS_OK);
  36.125 -    const string string3 = encoded_text;
  36.126 -      
  36.127 -    unlink("msg_2.0.asc");
  36.128 -    ofstream outFile3("msg_2.0.asc");
  36.129 -    outFile3.write(string3.c_str(), string3.size());
  36.130 -    outFile3.close();
  36.131 -    
  36.132 -    // message* decrypted_msg = nullptr;
  36.133 -    // stringlist_t* keylist_used = nullptr;
  36.134 -    // 
  36.135 -    // PEP_rating rating;
  36.136 -    // PEP_decrypt_flags_t flags;
  36.137 -    // 
  36.138 -    stringpair_t* autoconsume = new_stringpair("pEp-auto-consume", "yes");
  36.139 -    stringpair_list_add(encrypted_msg->opt_fields, autoconsume);
  36.140 -    flags = 0;
  36.141 -    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  36.142 -    assert(decrypted_msg);
  36.143 -    assert(keylist_used);
  36.144 -    assert(rating);
  36.145 -    //assert(status == PEP_STATUS_OK && rating == PEP_rating_reliable);
  36.146 -    //PEP_comm_type ct = encrypted_msg->from->comm_type;
  36.147 -    //assert(ct == PEP_ct_pEp);
  36.148 -    
  36.149 -    cout << "keys used:\n";
  36.150 -    
  36.151 -    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
  36.152 -    {
  36.153 -       cout << "\t " << kl4->value << endl;
  36.154 -    }
  36.155 -     
  36.156 -    decrypted_msg->enc_format = PEP_enc_none; 
  36.157 -    status = _mime_encode_message_internal(decrypted_msg, false, &encoded_text, false);
  36.158 -    assert(status == PEP_STATUS_OK);
  36.159 -    assert(encoded_text);
  36.160 -    cout << "Decrypted message: " << endl;
  36.161 -    cout << encoded_text << endl;
  36.162 -     
  36.163 -    cout << "freeing messages…\n";
  36.164 -    free_message(encrypted_msg);
  36.165 -    free_message(decrypted_msg);
  36.166 -    free_message(outgoing_message);
  36.167 -    cout << "done.\n";
  36.168 -    
  36.169 -    cout << "calling release()\n";
  36.170 -    release(session);
  36.171 -    return 0;
  36.172 -}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/message_two_point_oh_test.cc	Mon May 07 16:47:22 2018 +0200
    37.3 @@ -0,0 +1,169 @@
    37.4 +// This file is under GNU General Public License 3.0
    37.5 +// see LICENSE.txt
    37.6 +
    37.7 +#include <stdlib.h>
    37.8 +#include <string.h>
    37.9 +#include "platform.h"
   37.10 +#include <iostream>
   37.11 +#include <fstream>
   37.12 +#include <assert.h>
   37.13 +#include "mime.h"
   37.14 +#include "message_api.h"
   37.15 +#include "keymanagement.h"
   37.16 +#include "test_util.h"
   37.17 +
   37.18 +using namespace std;
   37.19 +
   37.20 +int main() {
   37.21 +    cout << "\n*** message_2.0_test ***\n\n";
   37.22 +
   37.23 +    PEP_SESSION session;
   37.24 +    
   37.25 +    cout << "calling init()\n";
   37.26 +    PEP_STATUS status1 = init(&session);
   37.27 +    assert(status1 == PEP_STATUS_OK);
   37.28 +    assert(session);
   37.29 +    cout << "init() completed.\n";
   37.30 +
   37.31 +    PEP_comm_type carol_comm_type = PEP_ct_OpenPGP_unconfirmed;
   37.32 +
   37.33 +    // message_api test code
   37.34 +
   37.35 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   37.36 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   37.37 +    const string carol_pub_key = slurp("test_keys/pub/pep-test-carol-0x42A85A42_pub.asc");
   37.38 +    const string carol_priv_key = slurp("test_keys/priv/pep-test-carol-0x42A85A42_priv.asc");
   37.39 +
   37.40 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   37.41 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   37.42 +    assert(statuspub == PEP_STATUS_OK);
   37.43 +    assert(statuspriv == PEP_STATUS_OK);
   37.44 +    statuspub = import_key(session, carol_pub_key.c_str(), carol_pub_key.length(), NULL);
   37.45 +    statuspriv = import_key(session, carol_priv_key.c_str(), carol_priv_key.length(), NULL);
   37.46 +    assert(statuspub == PEP_STATUS_OK);
   37.47 +    assert(statuspriv == PEP_STATUS_OK);
   37.48 +
   37.49 +    cout << "creating message…\n";
   37.50 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
   37.51 +    pEp_identity* carol = new_identity("pep-test-carol@pep-project.org", NULL, "TOFU_pep-test-carol@pep-project.org", "Carol Test");
   37.52 +
   37.53 +    PEP_STATUS alice_status = update_identity(session, alice);
   37.54 +    PEP_STATUS carol_status = update_identity(session, carol);
   37.55 +
   37.56 +    PEP_STATUS status = update_trust_for_fpr(session, alice->fpr, PEP_ct_pEp);
   37.57 +    status = update_trust_for_fpr(session, carol->fpr, carol_comm_type);
   37.58 +    
   37.59 +    PEP_STATUS mystatus = myself(session, alice);
   37.60 +    assert(mystatus == PEP_STATUS_OK);
   37.61 +    alice_status = update_identity(session, alice);
   37.62 +    alice_status = update_identity(session, carol);
   37.63 +    assert(alice->comm_type == PEP_ct_pEp);
   37.64 +    assert(carol->comm_type == carol_comm_type);
   37.65 +    
   37.66 +    identity_list* to_list = new_identity_list(carol); // to carol
   37.67 +    message* outgoing_message = new_message(PEP_dir_outgoing);
   37.68 +    assert(outgoing_message);
   37.69 +    outgoing_message->from = alice;
   37.70 +    outgoing_message->to = to_list;
   37.71 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
   37.72 +    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   37.73 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   37.74 +//    outgoing_message->id = strdup("blahblahyourmama@pep-project.org");
   37.75 +    outgoing_message->references = new_stringlist("one-839274982347239847@pep-project.org");
   37.76 +    stringlist_add(outgoing_message->references, "two-dfddffd839274982347239847@pep-project.org");
   37.77 +    stringlist_add(outgoing_message->references, "three-OMGWTFBBQ.edfddffd839274982347239847@pep-project.org");
   37.78 +    
   37.79 +    cout << "message created.\n";
   37.80 +
   37.81 +    char* encoded_text = nullptr;
   37.82 +    status = mime_encode_message(outgoing_message, false, &encoded_text);
   37.83 +    assert(status == PEP_STATUS_OK);
   37.84 +    assert(encoded_text);
   37.85 +
   37.86 +    cout << "unencrypted:\n\n";
   37.87 +    cout << encoded_text << "\n";
   37.88 +
   37.89 +    free(encoded_text);
   37.90 +
   37.91 +    cout << "encrypting message as MIME multipart…\n";
   37.92 +    message* encrypted_msg = nullptr;
   37.93 +    cout << "calling encrypt_message\n";
   37.94 +    status = encrypt_message(session, outgoing_message, NULL, 
   37.95 +        &encrypted_msg, PEP_enc_PGP_MIME, 0);
   37.96 +    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
   37.97 +    assert(status == PEP_STATUS_OK);
   37.98 +    assert(encrypted_msg);
   37.99 +    cout << "message encrypted.\n";
  37.100 +    
  37.101 +    encrypted_msg->enc_format = PEP_enc_none;
  37.102 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
  37.103 +    assert(status == PEP_STATUS_OK);
  37.104 +    assert(encoded_text);
  37.105 +     
  37.106 +    cout << "encrypted:\n\n";
  37.107 +    cout << encoded_text << "\n";
  37.108 +     
  37.109 +    char* decrypted_text;
  37.110 +    
  37.111 +    message* decrypted_msg = nullptr;
  37.112 +    stringlist_t* keylist_used = nullptr;
  37.113 +    
  37.114 +    PEP_rating rating;
  37.115 +    PEP_decrypt_flags_t flags;
  37.116 +     
  37.117 +//    MIME_decrypt_message(session, encoded_text, strlen(encoded_text), &decrypted_text, &keylist_used, &rating, &flags);
  37.118 +    
  37.119 +//    cout << "HEY!" << endl;
  37.120 +//    cout << decrypted_text << endl;
  37.121 +    
  37.122 +    message* decoded_msg = nullptr;
  37.123 +    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
  37.124 +    assert(status == PEP_STATUS_OK);
  37.125 +    const string string3 = encoded_text;
  37.126 +      
  37.127 +    unlink("msg_2.0.asc");
  37.128 +    ofstream outFile3("msg_2.0.asc");
  37.129 +    outFile3.write(string3.c_str(), string3.size());
  37.130 +    outFile3.close();
  37.131 +    
  37.132 +    // message* decrypted_msg = nullptr;
  37.133 +    // stringlist_t* keylist_used = nullptr;
  37.134 +    // 
  37.135 +    // PEP_rating rating;
  37.136 +    // PEP_decrypt_flags_t flags;
  37.137 +    // 
  37.138 +    stringpair_t* autoconsume = new_stringpair("pEp-auto-consume", "yes");
  37.139 +    stringpair_list_add(encrypted_msg->opt_fields, autoconsume);
  37.140 +    flags = 0;
  37.141 +    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  37.142 +    assert(decrypted_msg);
  37.143 +    assert(keylist_used);
  37.144 +    assert(rating);
  37.145 +    //assert(status == PEP_STATUS_OK && rating == PEP_rating_reliable);
  37.146 +    //PEP_comm_type ct = encrypted_msg->from->comm_type;
  37.147 +    //assert(ct == PEP_ct_pEp);
  37.148 +    
  37.149 +    cout << "keys used:\n";
  37.150 +    
  37.151 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
  37.152 +    {
  37.153 +       cout << "\t " << kl4->value << endl;
  37.154 +    }
  37.155 +     
  37.156 +    decrypted_msg->enc_format = PEP_enc_none; 
  37.157 +    status = _mime_encode_message_internal(decrypted_msg, false, &encoded_text, false);
  37.158 +    assert(status == PEP_STATUS_OK);
  37.159 +    assert(encoded_text);
  37.160 +    cout << "Decrypted message: " << endl;
  37.161 +    cout << encoded_text << endl;
  37.162 +     
  37.163 +    cout << "freeing messages…\n";
  37.164 +    free_message(encrypted_msg);
  37.165 +    free_message(decrypted_msg);
  37.166 +    free_message(outgoing_message);
  37.167 +    cout << "done.\n";
  37.168 +    
  37.169 +    cout << "calling release()\n";
  37.170 +    release(session);
  37.171 +    return 0;
  37.172 +}
    38.1 --- a/test/src/SuiteMaker.cc	Mon May 07 15:34:55 2018 +0200
    38.2 +++ b/test/src/SuiteMaker.cc	Mon May 07 16:47:22 2018 +0200
    38.3 @@ -12,53 +12,153 @@
    38.4  #include "SuiteMaker.h"
    38.5  
    38.6  // Begin where we generate stuff
    38.7 +#include "MapAsn1Tests.h"
    38.8  #include "DecorateTests.h"
    38.9 +#include "EncryptMissingPrivateKeyTests.h"
   38.10 +#include "KeyeditTests.h"
   38.11 +#include "BlacklistAcceptNewKeyTests.h"
   38.12 +#include "DecryptAttachPrivateKeyUntrustedTests.h"
   38.13  #include "AppleMailTests.h"
   38.14  #include "CaseAndDotAddressTests.h"
   38.15  #include "SequenceTests.h"
   38.16 +#include "MessageApiTests.h"
   38.17 +#include "I18nTests.h"
   38.18 +#include "CrashdumpTests.h"
   38.19 +#include "PgpBinaryTests.h"
   38.20 +#include "RevokeRegenAttachTests.h"
   38.21 +#include "BlacklistTests.h"
   38.22 +#include "LeastCommonDenomColorTests.h"
   38.23 +#include "PepSubjectReceivedTests.h"
   38.24 +#include "MistrustUndoTests.h"
   38.25  #include "StringpairListTests.h"
   38.26 +#include "PgpListKeysTests.h"
   38.27 +#include "ReencryptPlusExtraKeysTests.h"
   38.28 +#include "MimeTests.h"
   38.29  #include "BloblistTests.h"
   38.30 +#include "NewUpdateIdAndMyselfTests.h"
   38.31  #include "StringlistTests.h"
   38.32 +#include "LeastColorGroupTests.h"
   38.33 +#include "ExternalRevokeTests.h"
   38.34 +#include "EncryptForIdentityTests.h"
   38.35  #include "TrustwordsTests.h"
   38.36  #include "TrustManipulationTests.h"
   38.37 +#include "MessageTwoPointOhTests.h"
   38.38 +#include "EncryptAttachPrivateKeyTests.h"
   38.39 +#include "DecryptAttachPrivateKeyTrustedTests.h"
   38.40 +#include "IdentityListTests.h"
   38.41  #include "UserIDAliasTests.h"
   38.42  
   38.43  
   38.44  const char* SuiteMaker::all_suites[] = {
   38.45 +    "MapAsn1Tests",
   38.46      "DecorateTests",
   38.47 +    "EncryptMissingPrivateKeyTests",
   38.48 +    "KeyeditTests",
   38.49 +    "BlacklistAcceptNewKeyTests",
   38.50 +    "DecryptAttachPrivateKeyUntrustedTests",
   38.51      "AppleMailTests",
   38.52      "CaseAndDotAddressTests",
   38.53      "SequenceTests",
   38.54 +    "MessageApiTests",
   38.55 +    "I18nTests",
   38.56 +    "CrashdumpTests",
   38.57 +    "PgpBinaryTests",
   38.58 +    "RevokeRegenAttachTests",
   38.59 +    "BlacklistTests",
   38.60 +    "LeastCommonDenomColorTests",
   38.61 +    "PepSubjectReceivedTests",
   38.62 +    "MistrustUndoTests",
   38.63      "StringpairListTests",
   38.64 +    "PgpListKeysTests",
   38.65 +    "ReencryptPlusExtraKeysTests",
   38.66 +    "MimeTests",
   38.67      "BloblistTests",
   38.68 +    "NewUpdateIdAndMyselfTests",
   38.69      "StringlistTests",
   38.70 +    "LeastColorGroupTests",
   38.71 +    "ExternalRevokeTests",
   38.72 +    "EncryptForIdentityTests",
   38.73      "TrustwordsTests",
   38.74      "TrustManipulationTests",
   38.75 +    "MessageTwoPointOhTests",
   38.76 +    "EncryptAttachPrivateKeyTests",
   38.77 +    "DecryptAttachPrivateKeyTrustedTests",
   38.78 +    "IdentityListTests",
   38.79      "UserIDAliasTests",
   38.80  };
   38.81  
   38.82  // This file is generated, so magic constants are ok.
   38.83 -int SuiteMaker::num_suites = 10;
   38.84 +int SuiteMaker::num_suites = 35;
   38.85  
   38.86  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
   38.87 -    if (strcmp(test_class_name, "DecorateTests") == 0)
   38.88 +    if (strcmp(test_class_name, "MapAsn1Tests") == 0)
   38.89 +        *test_suite = new MapAsn1Tests(test_class_name, test_home);
   38.90 +    else if (strcmp(test_class_name, "DecorateTests") == 0)
   38.91          *test_suite = new DecorateTests(test_class_name, test_home);
   38.92 +    else if (strcmp(test_class_name, "EncryptMissingPrivateKeyTests") == 0)
   38.93 +        *test_suite = new EncryptMissingPrivateKeyTests(test_class_name, test_home);
   38.94 +    else if (strcmp(test_class_name, "KeyeditTests") == 0)
   38.95 +        *test_suite = new KeyeditTests(test_class_name, test_home);
   38.96 +    else if (strcmp(test_class_name, "BlacklistAcceptNewKeyTests") == 0)
   38.97 +        *test_suite = new BlacklistAcceptNewKeyTests(test_class_name, test_home);
   38.98 +    else if (strcmp(test_class_name, "DecryptAttachPrivateKeyUntrustedTests") == 0)
   38.99 +        *test_suite = new DecryptAttachPrivateKeyUntrustedTests(test_class_name, test_home);
  38.100      else if (strcmp(test_class_name, "AppleMailTests") == 0)
  38.101          *test_suite = new AppleMailTests(test_class_name, test_home);
  38.102      else if (strcmp(test_class_name, "CaseAndDotAddressTests") == 0)
  38.103          *test_suite = new CaseAndDotAddressTests(test_class_name, test_home);
  38.104      else if (strcmp(test_class_name, "SequenceTests") == 0)
  38.105          *test_suite = new SequenceTests(test_class_name, test_home);
  38.106 +    else if (strcmp(test_class_name, "MessageApiTests") == 0)
  38.107 +        *test_suite = new MessageApiTests(test_class_name, test_home);
  38.108 +    else if (strcmp(test_class_name, "I18nTests") == 0)
  38.109 +        *test_suite = new I18nTests(test_class_name, test_home);
  38.110 +    else if (strcmp(test_class_name, "CrashdumpTests") == 0)
  38.111 +        *test_suite = new CrashdumpTests(test_class_name, test_home);
  38.112 +    else if (strcmp(test_class_name, "PgpBinaryTests") == 0)
  38.113 +        *test_suite = new PgpBinaryTests(test_class_name, test_home);
  38.114 +    else if (strcmp(test_class_name, "RevokeRegenAttachTests") == 0)
  38.115 +        *test_suite = new RevokeRegenAttachTests(test_class_name, test_home);
  38.116 +    else if (strcmp(test_class_name, "BlacklistTests") == 0)
  38.117 +        *test_suite = new BlacklistTests(test_class_name, test_home);
  38.118 +    else if (strcmp(test_class_name, "LeastCommonDenomColorTests") == 0)
  38.119 +        *test_suite = new LeastCommonDenomColorTests(test_class_name, test_home);
  38.120 +    else if (strcmp(test_class_name, "PepSubjectReceivedTests") == 0)
  38.121 +        *test_suite = new PepSubjectReceivedTests(test_class_name, test_home);
  38.122 +    else if (strcmp(test_class_name, "MistrustUndoTests") == 0)
  38.123 +        *test_suite = new MistrustUndoTests(test_class_name, test_home);
  38.124      else if (strcmp(test_class_name, "StringpairListTests") == 0)
  38.125          *test_suite = new StringpairListTests(test_class_name, test_home);
  38.126 +    else if (strcmp(test_class_name, "PgpListKeysTests") == 0)
  38.127 +        *test_suite = new PgpListKeysTests(test_class_name, test_home);
  38.128 +    else if (strcmp(test_class_name, "ReencryptPlusExtraKeysTests") == 0)
  38.129 +        *test_suite = new ReencryptPlusExtraKeysTests(test_class_name, test_home);
  38.130 +    else if (strcmp(test_class_name, "MimeTests") == 0)
  38.131 +        *test_suite = new MimeTests(test_class_name, test_home);
  38.132      else if (strcmp(test_class_name, "BloblistTests") == 0)
  38.133          *test_suite = new BloblistTests(test_class_name, test_home);
  38.134 +    else if (strcmp(test_class_name, "NewUpdateIdAndMyselfTests") == 0)
  38.135 +        *test_suite = new NewUpdateIdAndMyselfTests(test_class_name, test_home);
  38.136      else if (strcmp(test_class_name, "StringlistTests") == 0)
  38.137          *test_suite = new StringlistTests(test_class_name, test_home);
  38.138 +    else if (strcmp(test_class_name, "LeastColorGroupTests") == 0)
  38.139 +        *test_suite = new LeastColorGroupTests(test_class_name, test_home);
  38.140 +    else if (strcmp(test_class_name, "ExternalRevokeTests") == 0)
  38.141 +        *test_suite = new ExternalRevokeTests(test_class_name, test_home);
  38.142 +    else if (strcmp(test_class_name, "EncryptForIdentityTests") == 0)
  38.143 +        *test_suite = new EncryptForIdentityTests(test_class_name, test_home);
  38.144      else if (strcmp(test_class_name, "TrustwordsTests") == 0)
  38.145          *test_suite = new TrustwordsTests(test_class_name, test_home);
  38.146      else if (strcmp(test_class_name, "TrustManipulationTests") == 0)
  38.147          *test_suite = new TrustManipulationTests(test_class_name, test_home);
  38.148 +    else if (strcmp(test_class_name, "MessageTwoPointOhTests") == 0)
  38.149 +        *test_suite = new MessageTwoPointOhTests(test_class_name, test_home);
  38.150 +    else if (strcmp(test_class_name, "EncryptAttachPrivateKeyTests") == 0)
  38.151 +        *test_suite = new EncryptAttachPrivateKeyTests(test_class_name, test_home);
  38.152 +    else if (strcmp(test_class_name, "DecryptAttachPrivateKeyTrustedTests") == 0)
  38.153 +        *test_suite = new DecryptAttachPrivateKeyTrustedTests(test_class_name, test_home);
  38.154 +    else if (strcmp(test_class_name, "IdentityListTests") == 0)
  38.155 +        *test_suite = new IdentityListTests(test_class_name, test_home);
  38.156      else if (strcmp(test_class_name, "UserIDAliasTests") == 0)
  38.157          *test_suite = new UserIDAliasTests(test_class_name, test_home);
  38.158  }
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/test/src/engine_tests/BlacklistAcceptNewKeyTests.cc	Mon May 07 16:47:22 2018 +0200
    39.3 @@ -0,0 +1,102 @@
    39.4 +// This file is under GNU General Public License 3.0
    39.5 +// see LICENSE.txt
    39.6 +
    39.7 +#include <stdlib.h>
    39.8 +#include <string>
    39.9 +#include <cstring> // for strcmp()
   39.10 +#include <cpptest.h>
   39.11 +
   39.12 +#include "test_util.h"
   39.13 +
   39.14 +#include "pEpEngine.h"
   39.15 +#include "blacklist.h"
   39.16 +#include "keymanagement.h"
   39.17 +#include "message_api.h"
   39.18 +#include "mime.h"
   39.19 +
   39.20 +#include "EngineTestSessionSuite.h"
   39.21 +#include "BlacklistAcceptNewKeyTests.h"
   39.22 +
   39.23 +using namespace std;
   39.24 +
   39.25 +BlacklistAcceptNewKeyTests::BlacklistAcceptNewKeyTests(string suitename, string test_home_dir) :
   39.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   39.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("BlacklistAcceptNewKeyTests::check_blacklist_accept_new_key"),
   39.28 +                                                                      static_cast<Func>(&BlacklistAcceptNewKeyTests::check_blacklist_accept_new_key)));
   39.29 +}
   39.30 +
   39.31 +void BlacklistAcceptNewKeyTests::check_blacklist_accept_new_key() {
   39.32 +
   39.33 +    // blacklist test code
   39.34 +
   39.35 +    cout << "blacklist only key for identity / add key / check which key is used" << endl;
   39.36 +    
   39.37 +    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
   39.38 +
   39.39 +    /* read the key into memory */
   39.40 +    const string keytext = slurp("blacklisted_pub.asc");
   39.41 +    
   39.42 +    /* import it into pep */
   39.43 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
   39.44 +    
   39.45 +    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
   39.46 +    bool is_blacklisted = false;
   39.47 +    
   39.48 +    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
   39.49 +                                                      bl_fpr_1,
   39.50 +                                                      NULL,
   39.51 +                                                      "Blacklist Keypair");
   39.52 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
   39.53 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
   39.54 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
   39.55 +    TEST_ASSERT(is_blacklisted);
   39.56 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
   39.57 +    TEST_ASSERT(status11 == PEP_STATUS_OK);
   39.58 +    TEST_ASSERT(_streq(bl_fpr_1, blacklisted_identity->fpr));
   39.59 +    
   39.60 +    bool id_def, us_def, addr_def;
   39.61 +    status11 = get_valid_pubkey(session, blacklisted_identity,
   39.62 +                                &id_def, &us_def, &addr_def, true);
   39.63 +    TEST_ASSERT(blacklisted_identity->comm_type == PEP_ct_unknown);
   39.64 +                        
   39.65 +    if (!(blacklisted_identity->fpr))
   39.66 +        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
   39.67 +    else
   39.68 +        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
   39.69 +             << "Expected it to be empty." << endl;
   39.70 +    TEST_ASSERT(!(blacklisted_identity->fpr) || blacklisted_identity->fpr[0] == '\0');
   39.71 +
   39.72 +    /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
   39.73 +    
   39.74 +    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
   39.75 +    const string mailtext = slurp("test_mails/blacklist_new_key_attached.eml");
   39.76 +    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
   39.77 +
   39.78 +    PEP_STATUS status = update_identity(session, me1);
   39.79 +    message* msg_ptr = nullptr;
   39.80 +    message* dest_msg = nullptr;
   39.81 +    stringlist_t* keylist = nullptr;
   39.82 +    PEP_rating rating;
   39.83 +    PEP_decrypt_flags_t flags = 0;
   39.84 +    
   39.85 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   39.86 +    TEST_ASSERT(status == PEP_STATUS_OK);
   39.87 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   39.88 +
   39.89 +    PEP_STATUS status12 = get_valid_pubkey(session, blacklisted_identity,
   39.90 +                                           &id_def, &us_def, &addr_def, true);
   39.91 +
   39.92 +    TEST_ASSERT(strcasecmp(blacklisted_identity->fpr, new_key) == 0);
   39.93 +
   39.94 +    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
   39.95 +    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
   39.96 +
   39.97 +    status = delete_keypair(session, new_key);
   39.98 +    update_identity(session, blacklisted_identity);
   39.99 +    status = delete_keypair(session, bl_fpr_1);
  39.100 +    update_identity(session, blacklisted_identity);
  39.101 +    
  39.102 +    free_message(msg_ptr);
  39.103 +    free_message(dest_msg);
  39.104 +    free_stringlist(keylist);
  39.105 +}
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/test/src/engine_tests/BlacklistTests.cc	Mon May 07 16:47:22 2018 +0200
    40.3 @@ -0,0 +1,181 @@
    40.4 +// This file is under GNU General Public License 3.0
    40.5 +// see LICENSE.txt
    40.6 +
    40.7 +// #include <iostream>
    40.8 +// #include <iostream>
    40.9 +// #include <fstream>
   40.10 +// #include <string>
   40.11 +// #include <cstring> // for strcmp()
   40.12 +// #include <TEST_ASSERT.h>
   40.13 +// #include "blacklist.h"
   40.14 +// #include "keymanagement.h"
   40.15 +// #include "test_util.h"
   40.16 +// 
   40.17 +// // This file is under GNU General Public License 3.0
   40.18 +// // see LICENSE.txt
   40.19 +
   40.20 +#include <stdlib.h>
   40.21 +#include <string>
   40.22 +#include <cstring> // for strcmp()
   40.23 +
   40.24 +#include <cpptest.h>
   40.25 +
   40.26 +#include "pEpEngine.h"
   40.27 +
   40.28 +#include "blacklist.h"
   40.29 +#include "keymanagement.h"
   40.30 +#include "test_util.h"
   40.31 +
   40.32 +#include "EngineTestSessionSuite.h"
   40.33 +#include "BlacklistTests.h"
   40.34 +
   40.35 +using namespace std;
   40.36 +
   40.37 +BlacklistTests::BlacklistTests(string suitename, string test_home_dir) :
   40.38 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   40.39 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("BlacklistTests::check_blacklist"),
   40.40 +                                                                      static_cast<Func>(&BlacklistTests::check_blacklist)));
   40.41 +}
   40.42 +
   40.43 +void BlacklistTests::check_blacklist() {
   40.44 +    // blacklist test code
   40.45 +
   40.46 +    cout << "adding 23 to blacklist\n";
   40.47 +    PEP_STATUS status2 = blacklist_add(session, "23");
   40.48 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   40.49 +    cout << "added.\n";
   40.50 +
   40.51 +    bool listed;
   40.52 +    PEP_STATUS status3 = blacklist_is_listed(session, "23", &listed);
   40.53 +    TEST_ASSERT(status3 == PEP_STATUS_OK);
   40.54 +    TEST_ASSERT(listed);
   40.55 +    cout << "23 is listed.\n";
   40.56 +
   40.57 +    stringlist_t *blacklist;
   40.58 +    PEP_STATUS status6 = blacklist_retrieve(session, &blacklist);
   40.59 +    TEST_ASSERT(status6 == PEP_STATUS_OK);
   40.60 +    TEST_ASSERT(blacklist);
   40.61 +
   40.62 +    bool in23 = false;
   40.63 +    cout << "the blacklist contains now: ";
   40.64 +    for (stringlist_t *bl = blacklist; bl && bl->value; bl = bl->next) {
   40.65 +        cout << bl->value << ", ";
   40.66 +        if (std::strcmp(bl->value, "23") == 0)
   40.67 +            in23 = true;
   40.68 +    }
   40.69 +    cout << "END\n";
   40.70 +    TEST_ASSERT(in23);
   40.71 +    free_stringlist(blacklist);
   40.72 +
   40.73 +    cout << "deleting 23 from blacklist\n";
   40.74 +    PEP_STATUS status4 = blacklist_delete(session, "23");
   40.75 +    TEST_ASSERT(status4 == PEP_STATUS_OK);
   40.76 +    cout << "deleted.\n";
   40.77 +    
   40.78 +    PEP_STATUS status5 = blacklist_is_listed(session, "23", &listed);
   40.79 +    TEST_ASSERT(status5 == PEP_STATUS_OK);
   40.80 +    TEST_ASSERT(!listed);
   40.81 +    cout << "23 is not listed any more.\n";
   40.82 +
   40.83 +    cout << "blacklist only key for identity / unblacklist key / add key" << endl;
   40.84 +
   40.85 +    
   40.86 +    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
   40.87 +
   40.88 +    const string keytext = slurp("blacklisted_pub.asc");
   40.89 +    
   40.90 +    /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
   40.91 +     *        fix in */
   40.92 +    /* import it into pep */
   40.93 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
   40.94 +    
   40.95 +    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
   40.96 +    const char* bl_fpr_2 = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B"; 
   40.97 +    bool is_blacklisted = false;
   40.98 +
   40.99 +    // Clean up from previous runs
  40.100 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
  40.101 +    if (is_blacklisted) {
  40.102 +        is_blacklisted = false;
  40.103 +        blacklist_delete(session, bl_fpr_1);
  40.104 +    }
  40.105 +    
  40.106 +    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
  40.107 +                                                      bl_fpr_1,
  40.108 +                                                      NULL,
  40.109 +                                                      "Blacklist Keypair");
  40.110 +
  40.111 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
  40.112 +        
  40.113 +    // THERE IS NO BLACKLISTING OF PEP KEYS
  40.114 +    //blacklisted_identity->comm_type = PEP_ct_pEp;
  40.115 +    blacklisted_identity->comm_type = PEP_ct_OpenPGP_unconfirmed;
  40.116 +
  40.117 +    PEP_STATUS status99 = set_identity(session, blacklisted_identity);
  40.118 +    
  40.119 +    trust_personal_key(session, blacklisted_identity);
  40.120 +
  40.121 +    PEP_STATUS status999 = update_identity(session, blacklisted_identity);
  40.122 +
  40.123 +    TEST_ASSERT(blacklisted_identity->comm_type == PEP_ct_OpenPGP);
  40.124 +
  40.125 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
  40.126 +    status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
  40.127 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
  40.128 +    /* new!!! */
  40.129 +    TEST_ASSERT(is_blacklisted);
  40.130 +    TEST_ASSERT(status11 == PEP_STATUS_OK);
  40.131 +    TEST_ASSERT(_streq(bl_fpr_1, blacklisted_identity->fpr));
  40.132 +    
  40.133 +    bool id_def, us_def, addr_def;
  40.134 +    status11 = get_valid_pubkey(session, blacklisted_identity,
  40.135 +                                &id_def, &us_def, &addr_def, true);
  40.136 +    
  40.137 +    if (!(blacklisted_identity->fpr))
  40.138 +        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
  40.139 +    else if (strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0)
  40.140 +        cout << "OK! While this should be empty, you are probably running " << 
  40.141 +                "this in your home directory instead of the test environment " << 
  40.142 +                "and have leftover keys. This is an acceptable result here then. But you " <<
  40.143 +                "should probably clean up after yourself :)" << endl;
  40.144 +    else
  40.145 +        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
  40.146 +             << "Expected it to be empty or (possibly) " << bl_fpr_2 << endl;
  40.147 +    TEST_ASSERT(!(blacklisted_identity->fpr) || blacklisted_identity->fpr[0] == '\0'|| (strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0));
  40.148 +
  40.149 +    const string keytext2 = slurp("blacklisted_pub2.asc");
  40.150 +    PEP_STATUS status14 = import_key(session, keytext2.c_str(), keytext2.length(), NULL);
  40.151 +    
  40.152 +    pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
  40.153 +                                                       bl_fpr_2,
  40.154 +                                                        NULL,
  40.155 +                                                       "Blacklist Keypair");
  40.156 +    PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
  40.157 +    // 
  40.158 +    // TEST_ASSERT(blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) == 0);
  40.159 +    // if (blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) == 0)
  40.160 +    //     cout << "blacklisted identity's fpr successfully replaced by the unblacklisted one" << endl;
  40.161 +    // // else
  40.162 +    // //     cout << "blacklisted_identity->fpr should be " << bl_fpr_2 << " but is " << blacklisted_identity->fpr << endl;
  40.163 +    // 
  40.164 +    // PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
  40.165 +    // PEP_STATUS status13 = update_identity(session, blacklisted_identity);
  40.166 +    //     
  40.167 +    // pEp_identity* stored_identity = new_identity("blacklistedkeys@kgrothoff.org",
  40.168 +    //                                               NULL,
  40.169 +    //                                               blacklisted_identity->user_id,
  40.170 +    //                                               "Blacklist Keypair");
  40.171 +    //  
  40.172 +    // PEP_STATUS status00 = update_identity(session, stored_identity);
  40.173 +    // 
  40.174 +    // // FIXME
  40.175 +    // // TEST_ASSERT(stored_identity->comm_type == PEP_ct_pEp);    
  40.176 +    
  40.177 +    PEP_STATUS status16 = delete_keypair(session, bl_fpr_1);
  40.178 +    update_identity(session, blacklisted_identity);
  40.179 +    PEP_STATUS status17 = delete_keypair(session, bl_fpr_2);
  40.180 +    update_identity(session, blacklisted_identity2);
  40.181 +        
  40.182 +    free_identity(blacklisted_identity);
  40.183 +    free_identity(blacklisted_identity2);
  40.184 +}
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/test/src/engine_tests/CrashdumpTests.cc	Mon May 07 16:47:22 2018 +0200
    41.3 @@ -0,0 +1,25 @@
    41.4 +// This file is under GNU General Public License 3.0
    41.5 +// see LICENSE.txt
    41.6 +
    41.7 +#include <stdlib.h>
    41.8 +#include <string>
    41.9 +
   41.10 +#include "pEpEngine.h"
   41.11 +
   41.12 +#include "EngineTestSessionSuite.h"
   41.13 +#include "CrashdumpTests.h"
   41.14 +
   41.15 +using namespace std;
   41.16 +
   41.17 +CrashdumpTests::CrashdumpTests(string suitename, string test_home_dir) :
   41.18 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   41.19 +    TEST_ADD(CrashdumpTests::check_crashdump);
   41.20 +}
   41.21 +
   41.22 +void CrashdumpTests::check_crashdump() {
   41.23 +    // MODULE test code
   41.24 +    char *text;
   41.25 +    PEP_STATUS status2 = get_crashdump_log(session, 0, &text);
   41.26 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   41.27 +    cout << text;
   41.28 +}
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/test/src/engine_tests/DecryptAttachPrivateKeyTrustedTests.cc	Mon May 07 16:47:22 2018 +0200
    42.3 @@ -0,0 +1,152 @@
    42.4 +// This file is under GNU General Public License 3.0
    42.5 +// see LICENSE.txt
    42.6 +
    42.7 +// FIXME: the private key tests should be combined
    42.8 +
    42.9 +#include <stdlib.h>
   42.10 +#include <string>
   42.11 +#include <cstring>
   42.12 +
   42.13 +#include "pEpEngine.h"
   42.14 +
   42.15 +#include "mime.h"
   42.16 +#include "message_api.h"
   42.17 +#include "keymanagement.h"
   42.18 +#include "test_util.h"
   42.19 +
   42.20 +#include "EngineTestSessionSuite.h"
   42.21 +#include "DecryptAttachPrivateKeyTrustedTests.h"
   42.22 +
   42.23 +using namespace std;
   42.24 +
   42.25 +DecryptAttachPrivateKeyTrustedTests::DecryptAttachPrivateKeyTrustedTests(string suitename, string test_home_dir) :
   42.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   42.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DecryptAttachPrivateKeyTrustedTests::check_decrypt_attach_private_key_trusted"),
   42.28 +                                                                      static_cast<Func>(&DecryptAttachPrivateKeyTrustedTests::check_decrypt_attach_private_key_trusted)));
   42.29 +}
   42.30 +
   42.31 +void DecryptAttachPrivateKeyTrustedTests::check_decrypt_attach_private_key_trusted() {
   42.32 +
   42.33 +    const char* own_uid = PEP_OWN_USERID;
   42.34 +
   42.35 +    cout << "Importing keys..." << endl;
   42.36 +    
   42.37 +    string input_key;
   42.38 +    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
   42.39 +    pEp_identity* main_me = NULL;
   42.40 +    const char* fpr_main_me = "13A9F97964A2B52520CAA40E51BCA783C065A213";    
   42.41 +    pEp_identity* same_addr_same_uid = NULL;
   42.42 +    const char* fpr_same_addr_same_uid = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
   42.43 +        
   42.44 +    PEP_STATUS status = PEP_STATUS_OK;
   42.45 +
   42.46 +    // key for main own user
   42.47 +    // 
   42.48 +    // 13A9F97964A2B52520CAA40E51BCA783C065A213    
   42.49 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0xC065A213_pub.asc");
   42.50 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   42.51 +    TEST_ASSERT(status == PEP_STATUS_OK);
   42.52 +
   42.53 +    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0xC065A213_priv.asc");
   42.54 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   42.55 +    TEST_ASSERT(status == PEP_STATUS_OK);
   42.56 +
   42.57 +    // ensure there's no private key - doesn't work in automated tests, sadly. Uncommon when running script manually.
   42.58 +    bool has_priv = false;
   42.59 +    // status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
   42.60 +    // if (status == PEP_STATUS_OK && has_priv) {
   42.61 +    //     cout << "SORRY, have to delete keys here to run test correctly..." << endl;
   42.62 +    //     status = delete_keypair(session, fpr_same_addr_same_uid);
   42.63 +    //     if (status == PEP_STATUS_OK) {
   42.64 +    //         has_priv = false;
   42.65 +    //         status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
   42.66 +    //         TEST_ASSERT(has_priv == false);
   42.67 +    //         cout << "Successfully deleted keypair for " << fpr_same_addr_same_uid << " - will now import the public key only" << endl;
   42.68 +    //     }
   42.69 +    //     else
   42.70 +    //         cout << "Warning - delete keypair returned status " << tl_status_string(status) << ". This may or may not be an error, depending on what you expect." << endl;            
   42.71 +    // }
   42.72 +        
   42.73 +    // key with same address and user_id
   42.74 +    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
   42.75 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
   42.76 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   42.77 +    TEST_ASSERT(status == PEP_STATUS_OK);
   42.78 +
   42.79 +    
   42.80 +    cout << "Setting up own identity with default key " << fpr_main_me << endl;
   42.81 +    // Own identity with default key etc
   42.82 +    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
   42.83 +    status = set_own_key(session, main_me, fpr_main_me);
   42.84 +    TEST_ASSERT(status == PEP_STATUS_OK);
   42.85 +
   42.86 +    TEST_ASSERT(strcmp(main_me->fpr, fpr_main_me) == 0);
   42.87 +    cout << "Done!" << endl << endl;
   42.88 +    
   42.89 +    cout << "Setting up sender identities and resetting key trust." << endl;
   42.90 +    cout << "Same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
   42.91 +    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
   42.92 +    TEST_ASSERT(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
   42.93 +    TEST_ASSERT((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed);
   42.94 +
   42.95 +    status = key_reset_trust(session, same_addr_same_uid);
   42.96 +    
   42.97 +    cout << "Done!" << endl << endl;
   42.98 +
   42.99 +    cout << "Reading in message..." << endl;
  42.100 +    
  42.101 +    string encoded_text = slurp("test_mails/priv_key_attach.eml");
  42.102 +
  42.103 +    cout << "Starting test..." << endl;
  42.104 +    // Case 1:
  42.105 +    // Same address, same user_id, untrusted
  42.106 +    cout << "decrypt with attached private key: Same address, same user_id, trusted" << endl;
  42.107 +    char* decrypted_text = NULL;
  42.108 +    stringlist_t* keylist_used = NULL;
  42.109 +    PEP_rating rating;
  42.110 +    PEP_decrypt_flags_t flags = 0;
  42.111 +    char* modified_src = NULL;
  42.112 +    
  42.113 +    cout << "Trusting personal key for " << same_addr_same_uid->user_id << " and " << same_addr_same_uid->fpr << endl;
  42.114 +    status = trust_personal_key(session, same_addr_same_uid);
  42.115 +    cout << "Status is " << tl_status_string(status) << endl;  
  42.116 +    TEST_ASSERT(status == PEP_STATUS_OK);
  42.117 +    free(decrypted_text);
  42.118 +    decrypted_text = NULL;
  42.119 +
  42.120 +    status = get_trust(session, same_addr_same_uid);
  42.121 +    cout << tl_ct_string(same_addr_same_uid->comm_type) << endl;
  42.122 +    
  42.123 +    TEST_ASSERT(same_addr_same_uid->comm_type == PEP_ct_pEp);
  42.124 +    
  42.125 +    flags = 0;
  42.126 +    status = MIME_decrypt_message(session, encoded_text.c_str(), 
  42.127 +                                  encoded_text.size(), &decrypted_text, 
  42.128 +                                  &keylist_used, &rating, &flags,
  42.129 +                                  &modified_src);
  42.130 +
  42.131 +    status = get_trust(session, same_addr_same_uid);
  42.132 +    TEST_ASSERT(same_addr_same_uid->comm_type == PEP_ct_pEp);
  42.133 +    
  42.134 +    flags = 0;
  42.135 +    status = MIME_decrypt_message(session, encoded_text.c_str(), 
  42.136 +                                  encoded_text.size(), &decrypted_text, 
  42.137 +                                  &keylist_used, &rating, &flags,
  42.138 +                                  &modified_src);
  42.139 +    
  42.140 +    cout << "Status: " << tl_status_string(status) << endl;
  42.141 +    TEST_ASSERT(status == PEP_STATUS_OK);
  42.142 +
  42.143 +    cout << decrypted_text << endl;
  42.144 +    
  42.145 +    has_priv = false;
  42.146 +    status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
  42.147 +    TEST_ASSERT(has_priv == true);
  42.148 +    cout << "Private key was also imported." << endl;
  42.149 +    
  42.150 +    cout << "PASS!" << endl;
  42.151 +    
  42.152 +    // FIXME: rework this in new framework
  42.153 +    status = key_reset_trust(session, main_me);      
  42.154 +    status = key_reset_trust(session, same_addr_same_uid);      
  42.155 +}
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/test/src/engine_tests/DecryptAttachPrivateKeyUntrustedTests.cc	Mon May 07 16:47:22 2018 +0200
    43.3 @@ -0,0 +1,126 @@
    43.4 +// This file is under GNU General Public License 3.0
    43.5 +// see LICENSE.txt
    43.6 +
    43.7 +#include <stdlib.h>
    43.8 +#include <string>
    43.9 +#include <cstring>
   43.10 +#include <cpptest.h>
   43.11 +
   43.12 +#include "mime.h"
   43.13 +#include "message_api.h"
   43.14 +#include "keymanagement.h"
   43.15 +#include "test_util.h"
   43.16 +
   43.17 +#include "pEpEngine.h"
   43.18 +
   43.19 +#include "EngineTestSessionSuite.h"
   43.20 +#include "DecryptAttachPrivateKeyUntrustedTests.h"
   43.21 +
   43.22 +using namespace std;
   43.23 +
   43.24 +DecryptAttachPrivateKeyUntrustedTests::DecryptAttachPrivateKeyUntrustedTests(string suitename, string test_home_dir) :
   43.25 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   43.26 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DecryptAttachPrivateKeyUntrustedTests::check_decrypt_attach_private_key_untrusted"),
   43.27 +                                                                      static_cast<Func>(&DecryptAttachPrivateKeyUntrustedTests::check_decrypt_attach_private_key_untrusted)));
   43.28 +}
   43.29 +
   43.30 +void DecryptAttachPrivateKeyUntrustedTests::check_decrypt_attach_private_key_untrusted() {
   43.31 +
   43.32 +    const char* own_uid = PEP_OWN_USERID;
   43.33 +
   43.34 +    cout << "Importing keys..." << endl;
   43.35 +    
   43.36 +    string input_key;
   43.37 +    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
   43.38 +    pEp_identity* main_me = NULL;
   43.39 +    const char* fpr_main_me = "13A9F97964A2B52520CAA40E51BCA783C065A213";    
   43.40 +    pEp_identity* same_addr_same_uid = NULL;
   43.41 +    const char* fpr_same_addr_same_uid = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
   43.42 +        
   43.43 +    PEP_STATUS status = PEP_STATUS_OK;
   43.44 +
   43.45 +    // key for main own user
   43.46 +    // 
   43.47 +    // 13A9F97964A2B52520CAA40E51BCA783C065A213    
   43.48 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0xC065A213_pub.asc");
   43.49 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   43.50 +    TEST_ASSERT(status == PEP_STATUS_OK);
   43.51 +
   43.52 +    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0xC065A213_priv.asc");
   43.53 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   43.54 +    TEST_ASSERT(status == PEP_STATUS_OK);
   43.55 +
   43.56 +    // ensure there's no private key - doesn't work in automated tests, sadly. Uncommon when running script manually.
   43.57 +    bool has_priv = false;
   43.58 +    // status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
   43.59 +    // if (status == PEP_STATUS_OK && has_priv) {
   43.60 +    //     cout << "SORRY, have to delete keys here to run test correctly..." << endl;
   43.61 +    //     status = delete_keypair(session, fpr_same_addr_same_uid);
   43.62 +    //     if (status == PEP_STATUS_OK)
   43.63 +    //         cout << "Successfully deleted keypair for " << fpr_same_addr_same_uid << " - will now import the public key only" << endl;
   43.64 +    // }
   43.65 +        
   43.66 +    // key with same address and user_id
   43.67 +    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
   43.68 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
   43.69 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   43.70 +    TEST_ASSERT(status == PEP_STATUS_OK);
   43.71 +
   43.72 +    
   43.73 +    cout << "Setting up own identity with default key " << fpr_main_me << endl;
   43.74 +    // Own identity with default key etc
   43.75 +    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
   43.76 +    status = set_own_key(session, main_me, fpr_main_me);
   43.77 +    TEST_ASSERT(status == PEP_STATUS_OK);
   43.78 +
   43.79 +    TEST_ASSERT(strcmp(main_me->fpr, fpr_main_me) == 0);
   43.80 +    cout << "Done!" << endl << endl;
   43.81 +    
   43.82 +    cout << "Setting up sender identities and resetting key trust." << endl;
   43.83 +    cout << "Same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
   43.84 +    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
   43.85 +    TEST_ASSERT(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
   43.86 +    TEST_ASSERT((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed);
   43.87 +
   43.88 +    status = key_reset_trust(session, same_addr_same_uid);
   43.89 +    
   43.90 +    cout << "Done!" << endl << endl;
   43.91 +
   43.92 +    cout << "Reading in message..." << endl;
   43.93 +    
   43.94 +    string encoded_text = slurp("test_mails/priv_key_attach.eml");
   43.95 +
   43.96 +    cout << "Starting tests..." << endl;
   43.97 +    // Case 1:
   43.98 +    // Same address, same user_id, untrusted
   43.99 +    cout << "Same address, same user_id, untrusted" << endl;
  43.100 +    char* decrypted_text = NULL;
  43.101 +    stringlist_t* keylist_used = NULL;
  43.102 +    PEP_rating rating;
  43.103 +    PEP_decrypt_flags_t flags;
  43.104 +    char* modified_src = NULL;
  43.105 +    
  43.106 +    status = get_trust(session, same_addr_same_uid);
  43.107 +    cout << tl_ct_string(same_addr_same_uid->comm_type) << endl;
  43.108 +    
  43.109 +    TEST_ASSERT((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed);
  43.110 +    
  43.111 +    flags = 0;
  43.112 +    status = MIME_decrypt_message(session, encoded_text.c_str(), 
  43.113 +                                  encoded_text.size(), &decrypted_text, 
  43.114 +                                  &keylist_used, &rating, &flags,
  43.115 +				  &modified_src);
  43.116 +
  43.117 +    status = get_trust(session, same_addr_same_uid);
  43.118 +    TEST_ASSERT(same_addr_same_uid->comm_type == PEP_ct_pEp_unconfirmed);
  43.119 +
  43.120 +    cout << "Case 1 Status: " << tl_status_string(status) << endl; 
  43.121 +    cout << "Private key is not trusted for " << same_addr_same_uid->fpr << ", as desired, as the public key was not trusted." << endl;
  43.122 +    cout << "PASS!" << endl;
  43.123 +
  43.124 +    // Case 2:
  43.125 +    cout << decrypted_text << endl;
  43.126 +    
  43.127 +    status = key_reset_trust(session, main_me);      
  43.128 +    status = key_reset_trust(session, same_addr_same_uid);      
  43.129 +}
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/test/src/engine_tests/EncryptAttachPrivateKeyTests.cc	Mon May 07 16:47:22 2018 +0200
    44.3 @@ -0,0 +1,290 @@
    44.4 +// This file is under GNU General Public License 3.0
    44.5 +// see LICENSE.txt
    44.6 +
    44.7 +#include <stdlib.h>
    44.8 +#include <string>
    44.9 +#include <cstring>
   44.10 +#include <cpptest.h>
   44.11 +
   44.12 +#include "pEpEngine.h"
   44.13 +
   44.14 +#include "mime.h"
   44.15 +#include "message_api.h"
   44.16 +#include "keymanagement.h"
   44.17 +#include "test_util.h"
   44.18 +
   44.19 +#include "EngineTestSessionSuite.h"
   44.20 +#include "EncryptAttachPrivateKeyTests.h"
   44.21 +
   44.22 +using namespace std;
   44.23 +
   44.24 +EncryptAttachPrivateKeyTests::EncryptAttachPrivateKeyTests(string suitename, string test_home_dir) :
   44.25 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   44.26 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EncryptAttachPrivateKeyTests::check_encrypt_attach_private_key"),
   44.27 +                                                                      static_cast<Func>(&EncryptAttachPrivateKeyTests::check_encrypt_attach_private_key)));
   44.28 +}
   44.29 +
   44.30 +void EncryptAttachPrivateKeyTests::check_encrypt_attach_private_key() {
   44.31 +
   44.32 +    const char* own_uid = PEP_OWN_USERID;
   44.33 +    const char* diff_uid_0 = "TASTY_TEST_UID_0";
   44.34 +    const char* diff_uid_1 = "TASTY_TEST_UID_1";
   44.35 +
   44.36 +    cout << "Importing keys..." << endl;
   44.37 +    
   44.38 +    string input_key;
   44.39 +    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
   44.40 +    pEp_identity* main_me = NULL;
   44.41 +    const char* fpr_main_me = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
   44.42 +    pEp_identity* same_addr_same_uid = NULL;
   44.43 +    const char* fpr_same_addr_same_uid = "359DD8AC87D1F5E4304D08338D7185F180C8CD87";
   44.44 +    
   44.45 +    pEp_identity* same_addr_diff_uid = NULL;
   44.46 +    const char* fpr_same_addr_diff_uid = "B044B83639E292283A3F6E14C2E64B520B74809C";
   44.47 +
   44.48 +    const char* diff_addr_0 = "priv-key-import-test-other_0@darthmama.cool";
   44.49 +    pEp_identity* diff_addr_same_uid = NULL;
   44.50 +    const char* fpr_diff_addr_same_uid = "C52911EBA0D34B0F549594A15A7A363BD11252C9";
   44.51 +    
   44.52 +    const char* diff_addr_1 = "priv-key-import-test-other_1@darthmama.cool";
   44.53 +    pEp_identity* diff_addr_diff_uid = NULL;
   44.54 +    const char* fpr_diff_addr_diff_uid = "567212EFB8A3A76B1D32B9565F45BEA9C785F20A";
   44.55 +    
   44.56 +    PEP_STATUS status = PEP_STATUS_OK;
   44.57 +
   44.58 +    // key for main own user
   44.59 +    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
   44.60 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
   44.61 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   44.62 +    TEST_ASSERT(status == PEP_STATUS_OK);
   44.63 +
   44.64 +    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0x3276D2E5_priv.asc");
   44.65 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   44.66 +    TEST_ASSERT(status == PEP_STATUS_OK);
   44.67 +        
   44.68 +    // key with same address and user_id (initially untrusted, then trusted)
   44.69 +    // 359DD8AC87D1F5E4304D08338D7185F180C8CD87
   44.70 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_1-0x80C8CD87_pub.asc");
   44.71 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   44.72 +    TEST_ASSERT(status == PEP_STATUS_OK);
   44.73 +
   44.74 +    // key with same address and to have different (non-aliased) user_id (initially untrusted, then trusted)
   44.75 +    // B044B83639E292283A3F6E14C2E64B520B74809C
   44.76 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_2-0x0B74809C_pub.asc");
   44.77 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   44.78 +    TEST_ASSERT(status == PEP_STATUS_OK);
   44.79 +
   44.80 +    // key with different address to have same user_id (initially untrusted, then trusted)
   44.81 +    // C52911EBA0D34B0F549594A15A7A363BD11252C9
   44.82 +    input_key = slurp("test_keys/pub/priv-key-import-test-other_0-0xD11252C9_pub.asc");
   44.83 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   44.84 +    TEST_ASSERT(status == PEP_STATUS_OK);
   44.85 +        
   44.86 +    // key with different address to have different user_id (initially untrusted, then trusted)
   44.87 +    // 567212EFB8A3A76B1D32B9565F45BEA9C785F20A
   44.88 +    input_key = slurp("test_keys/pub/priv-key-import-test-other_1-0xC785F20A_pub.asc");
   44.89 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   44.90 +    TEST_ASSERT(status == PEP_STATUS_OK);
   44.91 +    cout << "Done!" << endl << endl;
   44.92 +    
   44.93 +    cout << "Setting up own identity with default key " << fpr_main_me << endl;
   44.94 +    // Own identity with default key etc
   44.95 +    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
   44.96 +    status = set_own_key(session, main_me, fpr_main_me);
   44.97 +    TEST_ASSERT(status == PEP_STATUS_OK);
   44.98 +
   44.99 +    TEST_ASSERT(strcmp(main_me->fpr, fpr_main_me) == 0);
  44.100 +    cout << "Done!" << endl << endl;
  44.101 +    
  44.102 +    cout << "Setting up recipient identities and resetting key trust." << endl;
  44.103 +    cout << "#1: same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
  44.104 +    // Identity with same address and user_id - the fpr here will be ignored in update_identity and friends.
  44.105 +    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
  44.106 +    status = key_reset_trust(session, same_addr_same_uid);
  44.107 +    TEST_ASSERT(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
  44.108 +    TEST_ASSERT(strcmp(same_addr_same_uid->fpr, fpr_same_addr_same_uid) == 0);
  44.109 +    
  44.110 +    // Identity with same address and different user_id
  44.111 +    cout << "#2: same address, different user_id - address: " << main_addr << ", user_id: " << diff_uid_0 << ", fpr: " << fpr_same_addr_diff_uid << endl;  
  44.112 +    same_addr_diff_uid = new_identity(main_addr, fpr_same_addr_diff_uid, diff_uid_0, "PrivateKey Import Test");
  44.113 +    TEST_ASSERT(same_addr_diff_uid);
  44.114 +    status = key_reset_trust(session, same_addr_diff_uid);
  44.115 +    TEST_ASSERT(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
  44.116 +    TEST_ASSERT(strcmp(same_addr_diff_uid->fpr, fpr_same_addr_diff_uid) == 0);
  44.117 +    
  44.118 +    // Identity with diff address and same user_id
  44.119 +    cout << "#3: different address, same user_id - address: " << diff_addr_0 << ", user_id: " << own_uid << ", fpr: " << fpr_diff_addr_same_uid << endl;      
  44.120 +    diff_addr_same_uid = new_identity(diff_addr_0, fpr_diff_addr_same_uid, own_uid, "PrivateKey Import Test");
  44.121 +    TEST_ASSERT(diff_addr_same_uid);
  44.122 +    status = key_reset_trust(session, diff_addr_same_uid);
  44.123 +    TEST_ASSERT(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
  44.124 +    TEST_ASSERT(strcmp(diff_addr_same_uid->fpr, fpr_diff_addr_same_uid) == 0);
  44.125 +
  44.126 +    // Identity with different address and different user_id
  44.127 +    cout << "#4: different address, different user_id - address: " << diff_addr_1 << ", user_id: " << diff_uid_1 << ", fpr: " << fpr_diff_addr_diff_uid << endl;      
  44.128 +    diff_addr_diff_uid = new_identity(diff_addr_1, fpr_diff_addr_diff_uid, diff_uid_1, "PrivateKey Import Test");
  44.129 +    TEST_ASSERT(diff_addr_diff_uid);
  44.130 +    status = key_reset_trust(session, diff_addr_diff_uid);
  44.131 +    TEST_ASSERT(status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY);
  44.132 +    TEST_ASSERT(strcmp(diff_addr_diff_uid->fpr, fpr_diff_addr_diff_uid) == 0);
  44.133 +    cout << "Done!" << endl << endl;
  44.134 +
  44.135 +    message* msg_same_addr_same_uid = new_message(PEP_dir_outgoing);
  44.136 +    msg_same_addr_same_uid->from = main_me;
  44.137 +    msg_same_addr_same_uid->shortmsg = strdup("Greetings, humans!");
  44.138 +    msg_same_addr_same_uid->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
  44.139 +    msg_same_addr_same_uid->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  44.140 +
  44.141 +    message* msg_same_addr_diff_uid = message_dup(msg_same_addr_same_uid);
  44.142 +    message* msg_diff_addr_same_uid = message_dup(msg_same_addr_same_uid);       
  44.143 +    message* msg_diff_addr_diff_uid = message_dup(msg_same_addr_same_uid);       
  44.144 +
  44.145 +    cout << "Starting tests..." << endl;
  44.146 +    // Case 1:
  44.147 +    // Same address, same user_id, untrusted
  44.148 +    cout << "Case 1: Same address, same user_id, untrusted" << endl;
  44.149 +    TEST_ASSERT(msg_same_addr_same_uid);        
  44.150 +    identity_list* to_list = new_identity_list(same_addr_same_uid);
  44.151 +    msg_same_addr_same_uid->to = to_list;
  44.152 +    message* enc_same_addr_same_uid_untrusted = NULL;
  44.153 +    status = encrypt_message_and_add_priv_key(session,
  44.154 +                                              msg_same_addr_same_uid,
  44.155 +                                              &enc_same_addr_same_uid_untrusted,
  44.156 +                                              fpr_same_addr_same_uid,
  44.157 +                                              PEP_enc_PGP_MIME,
  44.158 +                                              0);
  44.159 +
  44.160 +    cout << "Case 1 Status: " << tl_status_string(status) << endl;
  44.161 +    TEST_ASSERT(status == PEP_ILLEGAL_VALUE);
  44.162 +    cout << "PASS!" << endl;
  44.163 +    
  44.164 +    // Case 2:
  44.165 +    // Same address, same_user_id, trusted
  44.166 +    cout << "Case 2: Same address, same user_id, trusted" << endl;
  44.167 +    status = trust_personal_key(session, same_addr_same_uid);
  44.168 +    cout << "Trust personal key for " << same_addr_same_uid << " gives status " << tl_status_string(status) << " (" << status << ")" << endl;
  44.169 +    TEST_ASSERT(status == PEP_STATUS_OK);
  44.170 +    message* enc_same_addr_same_uid_trusted = NULL;
  44.171 +    status = encrypt_message_and_add_priv_key(session,
  44.172 +                                              msg_same_addr_same_uid,
  44.173 +                                              &enc_same_addr_same_uid_trusted,
  44.174 +                                              fpr_same_addr_same_uid,
  44.175 +                                              PEP_enc_PGP_MIME,
  44.176 +                                              0);
  44.177 +
  44.178 +    cout << "Case 2 Status: " << tl_status_string(status) << endl;
  44.179 +    TEST_ASSERT(status == PEP_STATUS_OK);
  44.180 +    cout << "PASS!" << endl;
  44.181 +
  44.182 +    // Case 3:
  44.183 +    // Different address, same user_id, untrusted
  44.184 +    cout << "Case 3: Different address, same user_id, untrusted" << endl;
  44.185 +    TEST_ASSERT(msg_diff_addr_same_uid);        
  44.186 +    identity_list* to_list_1 = new_identity_list(diff_addr_same_uid);
  44.187 +    msg_diff_addr_same_uid->to = to_list_1;
  44.188 +    message* enc_diff_addr_same_uid_untrusted = NULL;
  44.189 +    status = encrypt_message_and_add_priv_key(session,
  44.190 +                                              msg_diff_addr_same_uid,
  44.191 +                                              &enc_diff_addr_same_uid_untrusted,
  44.192 +                                              fpr_diff_addr_same_uid,
  44.193 +                                              PEP_enc_PGP_MIME,
  44.194 +                                              0);
  44.195 +    
  44.196 +    cout << "Case 3 Status: " << tl_status_string(status) << endl;
  44.197 +    TEST_ASSERT(status == PEP_ILLEGAL_VALUE);
  44.198 +    cout << "PASS!" << endl;
  44.199 +
  44.200 +    // Case 4:
  44.201 +    // Different address, same user_id, trusted
  44.202 +    cout << "Case 4: Different address, same user_id, trusted" << endl;
  44.203 +    status = trust_personal_key(session, diff_addr_same_uid);
  44.204 +    TEST_ASSERT(status == PEP_STATUS_OK);
  44.205 +    message* enc_diff_addr_same_uid_trusted = NULL;
  44.206 +    status = encrypt_message_and_add_priv_key(session,
  44.207 +                                              msg_diff_addr_same_uid,
  44.208 +                                              &enc_diff_addr_same_uid_trusted,
  44.209 +                                              fpr_diff_addr_same_uid,
  44.210 +                                              PEP_enc_PGP_MIME,
  44.211 +                                              0);
  44.212 +                                              
  44.213 +    cout << "Case 4 Status: " << tl_status_string(status) << endl;
  44.214 +    TEST_ASSERT(status == PEP_ILLEGAL_VALUE);
  44.215 +    cout << "PASS!" << endl;
  44.216 +
  44.217 +    // Case 5:
  44.218 +    // Same address, different user_id, untrusted
  44.219 +    cout << "Case 5: Same address, different user_id, untrusted" << endl;    
  44.220 +    TEST_ASSERT(msg_same_addr_diff_uid);        
  44.221 +    identity_list* to_list_2 = new_identity_list(same_addr_diff_uid);
  44.222 +    msg_same_addr_diff_uid->to = to_list_2;
  44.223 +    message* enc_same_addr_diff_uid_untrusted = NULL;
  44.224 +    status = encrypt_message_and_add_priv_key(session,
  44.225 +                                              msg_same_addr_diff_uid,
  44.226 +                                              &enc_same_addr_diff_uid_untrusted,
  44.227 +                                              fpr_same_addr_diff_uid,
  44.228 +                                              PEP_enc_PGP_MIME,
  44.229 +                                              0);
  44.230 +
  44.231 +    cout << "Case 5 Status: " << tl_status_string(status) << endl;
  44.232 +    TEST_ASSERT(status == PEP_ILLEGAL_VALUE);    
  44.233 +    cout << "PASS!" << endl;
  44.234 +    
  44.235 +    // Case 6:
  44.236 +    // Same address, different user_id, trusted
  44.237 +    cout << "Case 6: Same address, different user_id, trusted" << endl;        
  44.238 +    status = trust_personal_key(session, same_addr_diff_uid);
  44.239 +    TEST_ASSERT(status == PEP_STATUS_OK);
  44.240 +    message* enc_same_addr_diff_uid_trusted = NULL;
  44.241 +    status = encrypt_message_and_add_priv_key(session,
  44.242 +                                              msg_same_addr_diff_uid,
  44.243 +                                              &enc_same_addr_diff_uid_untrusted,
  44.244 +                                              fpr_same_addr_diff_uid,
  44.245 +                                              PEP_enc_PGP_MIME,
  44.246 +                                              0);
  44.247 +
  44.248 +    cout << "Case 6 Status: " << tl_status_string(status) << endl;
  44.249 +    TEST_ASSERT(status == PEP_ILLEGAL_VALUE);    
  44.250 +    cout << "PASS!" << endl;
  44.251 +
  44.252 +    // Case 7:
  44.253 +    // Different address, different user_id, untrusted
  44.254 +    cout << "Case 7: Different address, different user_id, untrusted" << endl;    
  44.255 +    TEST_ASSERT(msg_diff_addr_diff_uid);        
  44.256 +    identity_list* to_list_3 = new_identity_list(diff_addr_diff_uid);
  44.257 +    msg_diff_addr_diff_uid->to = to_list_3;
  44.258 +    message* enc_diff_addr_diff_uid_untrusted = NULL;
  44.259 +    status = encrypt_message_and_add_priv_key(session,
  44.260 +                                              msg_diff_addr_diff_uid,
  44.261 +                                              &enc_diff_addr_diff_uid_untrusted,
  44.262 +                                              fpr_diff_addr_diff_uid,
  44.263 +                                              PEP_enc_PGP_MIME,
  44.264 +                                              0);
  44.265 +
  44.266 +    cout << "Case 7 Status: " << tl_status_string(status) << endl;
  44.267 +    TEST_ASSERT(status == PEP_ILLEGAL_VALUE);
  44.268 +    cout << "PASS!" << endl;
  44.269 +
  44.270 +    // Case 8:
  44.271 +    // Different address, different user_id, trusted
  44.272 +    cout << "Case 8: Different address, different user_id, trusted" << endl;    
  44.273 +    status = trust_personal_key(session, diff_addr_diff_uid);
  44.274 +    TEST_ASSERT(status == PEP_STATUS_OK);
  44.275 +    message* enc_diff_addr_diff_uid_trusted = NULL;
  44.276 +    status = encrypt_message_and_add_priv_key(session,
  44.277 +                                              msg_diff_addr_diff_uid,
  44.278 +                                              &enc_diff_addr_diff_uid_trusted,
  44.279 +                                              fpr_diff_addr_diff_uid,
  44.280 +                                              PEP_enc_PGP_MIME,
  44.281 +                                              0);
  44.282 +
  44.283 +    cout << "Case 8 Status: " << tl_status_string(status) << endl;
  44.284 +    TEST_ASSERT(status == PEP_ILLEGAL_VALUE);
  44.285 +    cout << "PASS!" << endl;
  44.286 +    
  44.287 +    cout << "Correctly encrypted message:" << endl << endl;                
  44.288 +    char* encrypted_msg_text = NULL;
  44.289 +    mime_encode_message(enc_same_addr_same_uid_trusted, false, &encrypted_msg_text);                                    
  44.290 +    cout << encrypted_msg_text << endl << endl;
  44.291 +    
  44.292 +    // FIXME: Free all the damned things
  44.293 +}
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/test/src/engine_tests/EncryptForIdentityTests.cc	Mon May 07 16:47:22 2018 +0200
    45.3 @@ -0,0 +1,292 @@
    45.4 +// This file is under GNU General Public License 3.0
    45.5 +// see LICENSE.txt
    45.6 +
    45.7 +#include <stdlib.h>
    45.8 +#include <unistd.h>
    45.9 +#include <string>
   45.10 +#include <cstring>
   45.11 +#include <iostream>
   45.12 +#include <fstream>
   45.13 +
   45.14 +#include "pEpEngine.h"
   45.15 +#include "mime.h"
   45.16 +#include "message_api.h"
   45.17 +#include "keymanagement.h"
   45.18 +#include "test_util.h"
   45.19 +
   45.20 +#include <cpptest.h>
   45.21 +#include "EngineTestSessionSuite.h"
   45.22 +#include "EncryptForIdentityTests.h"
   45.23 +
   45.24 +using namespace std;
   45.25 +
   45.26 +EncryptForIdentityTests::EncryptForIdentityTests(string suitename, string test_home_dir) :
   45.27 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   45.28 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EncryptForIdentityTests::check_encrypt_for_identity"),
   45.29 +                                                                      static_cast<Func>(&EncryptForIdentityTests::check_encrypt_for_identity)));
   45.30 +}
   45.31 +
   45.32 +void EncryptForIdentityTests::check_encrypt_for_identity() {
   45.33 +
   45.34 +    // message_api test code
   45.35 +
   45.36 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   45.37 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   45.38 +    const string gabrielle_pub_key = slurp("test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc");
   45.39 +    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");    
   45.40 +
   45.41 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   45.42 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   45.43 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   45.44 +    TEST_ASSERT(statuspriv == PEP_STATUS_OK);
   45.45 +    
   45.46 +    statuspub = import_key(session, gabrielle_pub_key.c_str(), gabrielle_pub_key.length(), NULL);
   45.47 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   45.48 +    statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
   45.49 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   45.50 +
   45.51 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   45.52 +    const char* gabrielle_fpr = "906C9B8349954E82C5623C3C8C541BD4E203586C";
   45.53 +    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
   45.54 +    const char* nobody_fpr = "1111111111111111111111111111111111111111";
   45.55 +
   45.56 +    cout << "creating message…\n";
   45.57 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Test");
   45.58 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
   45.59 +    
   45.60 +    alice->me = true;
   45.61 +
   45.62 +    PEP_STATUS mystatus = set_own_key(session, alice, alice_fpr);
   45.63 +    TEST_ASSERT(mystatus == PEP_STATUS_OK);
   45.64 +
   45.65 +    identity_list* to_list = new_identity_list(bob); // to bob
   45.66 +    message* outgoing_message = new_message(PEP_dir_outgoing);
   45.67 +    TEST_ASSERT(outgoing_message);
   45.68 +    outgoing_message->from = alice;
   45.69 +    outgoing_message->to = to_list;
   45.70 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
   45.71 +    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   45.72 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   45.73 +    cout << "message created.\n";
   45.74 +
   45.75 +    char* encoded_text = nullptr;
   45.76 +    PEP_STATUS status = mime_encode_message(outgoing_message, false, &encoded_text);
   45.77 +    TEST_ASSERT(status == PEP_STATUS_OK);
   45.78 +    TEST_ASSERT(encoded_text);
   45.79 +
   45.80 +    cout << "decrypted:\n\n";
   45.81 +    cout << encoded_text << "\n";
   45.82 +
   45.83 +    free(encoded_text);
   45.84 +
   45.85 +    message* encrypted_msg = nullptr;
   45.86 +    cout << "calling encrypt_message_for_identity()\n";
   45.87 +    status = encrypt_message_for_self(session, alice, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
   45.88 +    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
   45.89 +    TEST_ASSERT(status == PEP_STATUS_OK);
   45.90 +    TEST_ASSERT(encrypted_msg);
   45.91 +    cout << "message encrypted.\n";
   45.92 +    
   45.93 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
   45.94 +    TEST_ASSERT(status == PEP_STATUS_OK);
   45.95 +    TEST_ASSERT(encoded_text);
   45.96 +
   45.97 +    cout << "encrypted:\n\n";
   45.98 +    cout << encoded_text << "\n";
   45.99 +
  45.100 +    message* decoded_msg = nullptr;
  45.101 +    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
  45.102 +    TEST_ASSERT(status == PEP_STATUS_OK);
  45.103 +    const string string3 = encoded_text;
  45.104 +
  45.105 +    unlink("msg_encrypt_for_self.asc");
  45.106 +    ofstream outFile3("msg_encrypt_for_self.asc");
  45.107 +    outFile3.write(string3.c_str(), string3.size());
  45.108 +    outFile3.close();
  45.109 +
  45.110 +    message* decrypted_msg = nullptr;
  45.111 +    stringlist_t* keylist_used = nullptr;
  45.112 +
  45.113 +    PEP_rating rating;
  45.114 +    PEP_decrypt_flags_t flags;
  45.115 +
  45.116 +    flags = 0;
  45.117 +    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  45.118 +    TEST_ASSERT(decrypted_msg);
  45.119 +    TEST_ASSERT(keylist_used);
  45.120 +    TEST_ASSERT(rating);
  45.121 +    TEST_ASSERT(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
  45.122 +    PEP_comm_type ct = encrypted_msg->from->comm_type;
  45.123 +    TEST_ASSERT(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
  45.124 +
  45.125 +    cout << "keys used:\n";
  45.126 +
  45.127 +    int i = 0;
  45.128 +
  45.129 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
  45.130 +    {
  45.131 +        if (i == 0) {
  45.132 +            TEST_ASSERT(strcasecmp("",kl4->value) == 0);
  45.133 +        }
  45.134 +        else {
  45.135 +            cout << "\t " << kl4->value << endl;
  45.136 +            TEST_ASSERT(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
  45.137 +            cout << "Encrypted for Alice! Yay! It worked!" << endl;
  45.138 +        }
  45.139 +        TEST_ASSERT(i < 2);
  45.140 +    }
  45.141 +    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
  45.142 + 
  45.143 +    cout << "freeing messages…\n";
  45.144 +    free_message(encrypted_msg);
  45.145 +    free_message(decrypted_msg);
  45.146 +    free_stringlist (keylist_used);
  45.147 +    cout << "done.\n";
  45.148 +
  45.149 +    cout << "Now encrypt for self with extra keys." << endl;
  45.150 +    stringlist_t* extra_keys = new_stringlist(gabrielle_fpr);
  45.151 +    stringlist_add(extra_keys, bella_fpr);
  45.152 +    encrypted_msg = NULL;
  45.153 +    decrypted_msg = NULL;
  45.154 +    keylist_used = NULL;
  45.155 +
  45.156 +    cout << "calling encrypt_message_for_identity()\n";
  45.157 +    status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
  45.158 +    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
  45.159 +    TEST_ASSERT(status == PEP_STATUS_OK);
  45.160 +    TEST_ASSERT(encrypted_msg);
  45.161 +    cout << "message encrypted.\n";
  45.162 +    
  45.163 +    flags = 0;
  45.164 +    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  45.165 +    TEST_ASSERT(decrypted_msg);
  45.166 +    TEST_ASSERT(keylist_used);
  45.167 +    TEST_ASSERT(rating);
  45.168 +    TEST_ASSERT(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
  45.169 +    ct = encrypted_msg->from->comm_type;
  45.170 +    TEST_ASSERT(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
  45.171 +
  45.172 +    cout << "keys used:\n";
  45.173 +
  45.174 +    for (stringlist_t* incoming_kl = extra_keys; incoming_kl && incoming_kl->value; incoming_kl = incoming_kl->next) {
  45.175 +        bool found = false;
  45.176 +        cout << "Encrypted for: ";
  45.177 +        for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++) {
  45.178 +            if (strcasecmp(incoming_kl->value, kl4->value) == 0) {
  45.179 +                cout << "\t " << kl4->value;
  45.180 +                found = true;
  45.181 +                break;
  45.182 +            }
  45.183 +        }
  45.184 +        cout << endl;
  45.185 +        TEST_ASSERT(found);
  45.186 +    }
  45.187 +    cout << "Encrypted for all the extra keys!" << endl;
  45.188 +
  45.189 +    bool found = false;
  45.190 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
  45.191 +    {
  45.192 +        if (strcasecmp(alice_fpr, kl4->value) == 0) {
  45.193 +            found = true;
  45.194 +            cout << "Encrypted also for Alice! Yay!" << endl;
  45.195 +            break;
  45.196 +        }
  45.197 +    }
  45.198 +    TEST_ASSERT(found);
  45.199 +
  45.200 +    free_message(encrypted_msg);
  45.201 +    encrypted_msg = NULL;
  45.202 +    free_message(decrypted_msg);
  45.203 +    decrypted_msg = NULL;
  45.204 +    free_stringlist(keylist_used);
  45.205 +    keylist_used = NULL;
  45.206 +
  45.207 +    cout << "Now add a bad fpr." << endl;
  45.208 +    
  45.209 +    stringlist_add(extra_keys, nobody_fpr);
  45.210 +    
  45.211 +    cout << "calling encrypt_message_for_identity()\n";
  45.212 +    status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
  45.213 +    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
  45.214 +    TEST_ASSERT(status != PEP_STATUS_OK);
  45.215 +
  45.216 +    free_message(outgoing_message);
  45.217 +    outgoing_message = NULL;
  45.218 +    free_message(encrypted_msg);
  45.219 +    encrypted_msg = NULL;
  45.220 +    free_message(decrypted_msg);
  45.221 +    decrypted_msg = NULL;
  45.222 +    free_stringlist(keylist_used);
  45.223 +    keylist_used = NULL;
  45.224 +
  45.225 +
  45.226 +    cout << "*** Now testing MIME_encrypt_for_self ***" << endl;
  45.227 +
  45.228 +    alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
  45.229 +    bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
  45.230 +
  45.231 +    cout << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl;
  45.232 +    
  45.233 +    const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
  45.234 +
  45.235 +    cout << "Text read:" << endl;
  45.236 +    cout << mimetext.c_str() << endl;
  45.237 +    char* encrypted_mimetext = nullptr;
  45.238 +    
  45.239 +    cout << "Calling MIME_encrypt_message_for_self" << endl;
  45.240 +    status = MIME_encrypt_message_for_self(session, alice, mimetext.c_str(),
  45.241 +                                           mimetext.size(), 
  45.242 +                                           NULL,
  45.243 +                                           &encrypted_mimetext, 
  45.244 +                                           PEP_enc_PGP_MIME, 
  45.245 +                                           PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
  45.246 +    
  45.247 +    cout << "Encrypted message:" << endl;
  45.248 +    cout << encrypted_mimetext << endl;
  45.249 +
  45.250 +    cout << "Calling MIME_decrypt_message" << endl;
  45.251 +    
  45.252 +    char* decrypted_mimetext = nullptr;
  45.253 +    free_stringlist(keylist_used);
  45.254 +    keylist_used = nullptr;
  45.255 +    PEP_decrypt_flags_t mimeflags;
  45.256 +    PEP_rating mimerating;
  45.257 +    char* modified_src = NULL;
  45.258 +
  45.259 +    mimeflags = 0;
  45.260 +    status = MIME_decrypt_message(session,
  45.261 +                                  encrypted_mimetext,
  45.262 +                                  strlen(encrypted_mimetext),
  45.263 +                                  &decrypted_mimetext,
  45.264 +                                  &keylist_used,
  45.265 +                                  &mimerating,
  45.266 +                                  &mimeflags,
  45.267 +				  &modified_src);
  45.268 +
  45.269 +    TEST_ASSERT(decrypted_mimetext);
  45.270 +    TEST_ASSERT(keylist_used);
  45.271 +    TEST_ASSERT(mimerating);
  45.272 +                             
  45.273 +    TEST_ASSERT(status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable);
  45.274 +
  45.275 +    cout << "Decrypted message:" << endl;
  45.276 +    cout << decrypted_mimetext << endl;
  45.277 +
  45.278 +    cout << "keys used:\n";
  45.279 +
  45.280 +    i = 0;
  45.281 +
  45.282 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
  45.283 +    {
  45.284 +        if (i == 0) {
  45.285 +            TEST_ASSERT(strcasecmp("",kl4->value) == 0);
  45.286 +        }
  45.287 +        else {
  45.288 +            cout << "\t " << kl4->value << endl;
  45.289 +            TEST_ASSERT(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
  45.290 +            cout << "Encrypted for Alice! Yay! It worked!" << endl;
  45.291 +        }
  45.292 +        TEST_ASSERT(i < 2);
  45.293 +    }
  45.294 +    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
  45.295 +}