ENGINE-129: modified test cases on blacklist a bit. ENGINE-129
authorKrista Grothoff <krista@pep-project.org>
Thu, 27 Oct 2016 21:56:46 +0200
branchENGINE-129
changeset 134359f014327d4a
parent 1342 89f45a5a9ae2
child 1344 bdde3e670d9d
ENGINE-129: modified test cases on blacklist a bit.
test/blacklist_accept_new_key_test.cc
test/blacklist_test.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/blacklist_accept_new_key_test.cc	Thu Oct 27 21:56:46 2016 +0200
     1.3 @@ -0,0 +1,102 @@
     1.4 +#include <iostream>
     1.5 +#include <iostream>
     1.6 +#include <fstream>
     1.7 +#include <string>
     1.8 +#include <cstring> // for strcmp()
     1.9 +#include <assert.h>
    1.10 +#include "blacklist.h"
    1.11 +#include "keymanagement.h"
    1.12 +#include "message_api.h"
    1.13 +#include "mime.h"
    1.14 +
    1.15 +using namespace std;
    1.16 +
    1.17 +int main() {
    1.18 +    cout << "\n*** blacklist_test ***\n\n";
    1.19 +
    1.20 +    PEP_SESSION session;
    1.21 +    
    1.22 +    cout << "calling init()\n";
    1.23 +    PEP_STATUS status1 = init(&session);   
    1.24 +    assert(status1 == PEP_STATUS_OK);
    1.25 +    assert(session);
    1.26 +    cout << "init() completed.\n";
    1.27 +
    1.28 +    // blacklist test code
    1.29 +
    1.30 +    cout << "blacklist only key for identity / add key / check which key is used" << endl;
    1.31 +    
    1.32 +    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    1.33 +
    1.34 +    /* read the key into memory */
    1.35 +    ifstream infile("blacklisted_pub.asc");
    1.36 +    string keytext;
    1.37 +    while (!infile.eof()) {
    1.38 +        static string line;
    1.39 +        getline(infile, line);
    1.40 +        keytext += line + "\n";
    1.41 +    }
    1.42 +    infile.close(); 
    1.43 +    
    1.44 +    /* import it into pep */
    1.45 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    1.46 +    
    1.47 +    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
    1.48 +    bool is_blacklisted = false;
    1.49 +    
    1.50 +    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
    1.51 +                                                      bl_fpr_1,
    1.52 +                                                      NULL,
    1.53 +                                                      "Blacklist Keypair");
    1.54 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
    1.55 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    1.56 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    1.57 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
    1.58 +
    1.59 +    /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
    1.60 +    
    1.61 +    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";    
    1.62 +    
    1.63 +    ifstream infile2("test_mails/blacklist_new_key_attached.eml");
    1.64 +    string mailtext;
    1.65 +    while (!infile2.eof()) {
    1.66 +        static string line;
    1.67 +        getline(infile2, line);
    1.68 +        mailtext += line + "\n";
    1.69 +    }
    1.70 +    infile2.close(); 
    1.71 +
    1.72 +    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    1.73 +
    1.74 +    PEP_STATUS status = update_identity(session, me1);
    1.75 +    message* msg_ptr = nullptr;
    1.76 +    message* dest_msg = nullptr;
    1.77 +    stringlist_t* keylist = nullptr;
    1.78 +    PEP_rating rating;
    1.79 +    PEP_decrypt_flags_t flags;
    1.80 +    
    1.81 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    1.82 +    assert(status == PEP_STATUS_OK);
    1.83 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    1.84 +
    1.85 +    PEP_STATUS status12 = update_identity(session, blacklisted_identity);
    1.86 +
    1.87 +    assert(strcasecmp(blacklisted_identity->fpr, new_key) == 0);
    1.88 +
    1.89 +    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
    1.90 +    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
    1.91 +
    1.92 +    status = delete_keypair(session, bl_fpr_1);
    1.93 +    update_identity(session, blacklisted_identity);
    1.94 +    status = delete_keypair(session, new_key);
    1.95 +    update_identity(session, blacklisted_identity);
    1.96 +    
    1.97 +    free_message(msg_ptr);
    1.98 +    free_message(dest_msg);
    1.99 +    free_stringlist(keylist);
   1.100 +    
   1.101 +    cout << "calling release()\n";
   1.102 +    release(session);
   1.103 +    return 0;
   1.104 +}
   1.105 +
     2.1 --- a/test/blacklist_test.cc	Thu Oct 27 21:43:59 2016 +0200
     2.2 +++ b/test/blacklist_test.cc	Thu Oct 27 21:56:46 2016 +0200
     2.3 @@ -111,12 +111,15 @@
     2.4      PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
     2.5      PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
     2.6      PEP_STATUS status13 = update_identity(session, blacklisted_identity);
     2.7 -    
     2.8 -    /* FIXME: remove both keys again from everywhere and clean up identities */
     2.9 +            
    2.10 +    PEP_STATUS status16 = delete_keypair(session, bl_fpr_1);
    2.11 +    update_identity(session, blacklisted_identity);
    2.12 +    PEP_STATUS status17 = delete_keypair(session, bl_fpr_2);
    2.13 +    update_identity(session, blacklisted_identity2);
    2.14 +        
    2.15      free_identity(blacklisted_identity);
    2.16      free_identity(blacklisted_identity2);
    2.17      
    2.18 -    
    2.19      cout << "calling release()\n";
    2.20      release(session);
    2.21      return 0;