test/blacklist_test.cc
branchENGINE-112
changeset 1275 39dfd55d21ee
parent 526 b8b302ec9330
child 1341 a54396ccb460
     1.1 --- a/test/blacklist_test.cc	Wed Oct 12 23:08:45 2016 +0200
     1.2 +++ b/test/blacklist_test.cc	Thu Oct 13 16:22:09 2016 +0200
     1.3 @@ -1,8 +1,11 @@
     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  
    1.13  using namespace std;
    1.14  
    1.15 @@ -56,6 +59,61 @@
    1.16      assert(!listed);
    1.17      cout << "23 is not listed any more.\n";
    1.18  
    1.19 +    cout << "blacklist only key for identity / unblacklist key / add key" << endl;
    1.20 +    
    1.21 +    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    1.22 +
    1.23 +    /* read the key into memory */
    1.24 +    ifstream infile("blacklisted_pub.asc");
    1.25 +    string keytext;
    1.26 +    while (!infile.eof()) {
    1.27 +        static string line;
    1.28 +        getline(infile, line);
    1.29 +        keytext += line + "\n";
    1.30 +    }
    1.31 +    infile.close(); 
    1.32 +    
    1.33 +    /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
    1.34 +     *        fix in */
    1.35 +    /* import it into pep */
    1.36 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    1.37 +    
    1.38 +    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
    1.39 +    const char* bl_fpr_2 = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
    1.40 +    bool is_blacklisted = false;
    1.41 +    
    1.42 +    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
    1.43 +                                                      bl_fpr_1,
    1.44 +                                                      NULL,
    1.45 +                                                      "Blacklist Keypair");
    1.46 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
    1.47 +
    1.48 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    1.49 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    1.50 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
    1.51 +
    1.52 +    /* read the key into memory */
    1.53 +    ifstream infile2("blacklisted_pub2.asc");
    1.54 +    string keytext2;
    1.55 +    while (!infile2.eof()) {
    1.56 +        static string line2;
    1.57 +        getline(infile2, line2);
    1.58 +        keytext2 += line2 + "\n";
    1.59 +    }
    1.60 +    infile2.close(); 
    1.61 +    
    1.62 +    PEP_STATUS status14 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    1.63 +    
    1.64 +    pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
    1.65 +                                                       bl_fpr_2,
    1.66 +                                                        NULL,
    1.67 +                                                       "Blacklist Keypair");
    1.68 +    PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
    1.69 +    PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
    1.70 +    PEP_STATUS status13 = update_identity(session, blacklisted_identity);
    1.71 +    
    1.72 +    /* FIXME: remove both keys again from everywhere and clean up identities */
    1.73 +    
    1.74      cout << "calling release()\n";
    1.75      release(session);
    1.76      return 0;