test/blacklist_test.cc
author Krista Grothoff <krista@pep-project.org>
Thu, 27 Oct 2016 21:56:46 +0200
branchENGINE-129
changeset 1343 59f014327d4a
parent 1341 a54396ccb460
child 1449 c4874b0a2501
permissions -rw-r--r--
ENGINE-129: modified test cases on blacklist a bit.
     1 #include <iostream>
     2 #include <iostream>
     3 #include <fstream>
     4 #include <string>
     5 #include <cstring> // for strcmp()
     6 #include <assert.h>
     7 #include "blacklist.h"
     8 #include "keymanagement.h"
     9 
    10 using namespace std;
    11 
    12 int main() {
    13     cout << "\n*** blacklist_test ***\n\n";
    14 
    15     PEP_SESSION session;
    16     
    17     cout << "calling init()\n";
    18     PEP_STATUS status1 = init(&session);   
    19     assert(status1 == PEP_STATUS_OK);
    20     assert(session);
    21     cout << "init() completed.\n";
    22 
    23     // blacklist test code
    24 
    25     cout << "adding 23 to blacklist\n";
    26     PEP_STATUS status2 = blacklist_add(session, "23");
    27     assert(status2 == PEP_STATUS_OK);
    28     cout << "added.\n";
    29 
    30     bool listed;
    31     PEP_STATUS status3 = blacklist_is_listed(session, "23", &listed);
    32     assert(status3 == PEP_STATUS_OK);
    33     assert(listed);
    34     cout << "23 is listed.\n";
    35 
    36     stringlist_t *blacklist;
    37     PEP_STATUS status6 = blacklist_retrieve(session, &blacklist);
    38     assert(status6 == PEP_STATUS_OK);
    39     assert(blacklist);
    40 
    41     bool in23 = false;
    42     cout << "the blacklist contains now: ";
    43     for (stringlist_t *bl = blacklist; bl && bl->value; bl = bl->next) {
    44         cout << bl->value << ", ";
    45         if (std::strcmp(bl->value, "23") == 0)
    46             in23 = true;
    47     }
    48     cout << "END\n";
    49     assert(in23);
    50     free_stringlist(blacklist);
    51 
    52     cout << "deleting 23 from blacklist\n";
    53     PEP_STATUS status4 = blacklist_delete(session, "23");
    54     assert(status4 == PEP_STATUS_OK);
    55     cout << "deleted.\n";
    56     
    57     PEP_STATUS status5 = blacklist_is_listed(session, "23", &listed);
    58     assert(status5 == PEP_STATUS_OK);
    59     assert(!listed);
    60     cout << "23 is not listed any more.\n";
    61 
    62     cout << "blacklist only key for identity / unblacklist key / add key" << endl;
    63     
    64     // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    65 
    66     /* read the key into memory */
    67     ifstream infile("blacklisted_pub.asc");
    68     string keytext;
    69     while (!infile.eof()) {
    70         static string line;
    71         getline(infile, line);
    72         keytext += line + "\n";
    73     }
    74     infile.close(); 
    75     
    76     /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
    77      *        fix in */
    78     /* import it into pep */
    79     PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    80     
    81     const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
    82     const char* bl_fpr_2 = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
    83     bool is_blacklisted = false;
    84     
    85     pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
    86                                                       bl_fpr_1,
    87                                                       NULL,
    88                                                       "Blacklist Keypair");
    89     PEP_STATUS status8 = update_identity(session, blacklisted_identity);
    90 
    91     PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    92     PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    93     PEP_STATUS status11 = update_identity(session, blacklisted_identity);
    94 
    95     /* read the key into memory */
    96     ifstream infile2("blacklisted_pub2.asc");
    97     string keytext2;
    98     while (!infile2.eof()) {
    99         static string line2;
   100         getline(infile2, line2);
   101         keytext2 += line2 + "\n";
   102     }
   103     infile2.close(); 
   104     
   105     PEP_STATUS status14 = import_key(session, keytext.c_str(), keytext.length(), NULL);
   106     
   107     pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
   108                                                        bl_fpr_2,
   109                                                         NULL,
   110                                                        "Blacklist Keypair");
   111     PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
   112     PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
   113     PEP_STATUS status13 = update_identity(session, blacklisted_identity);
   114             
   115     PEP_STATUS status16 = delete_keypair(session, bl_fpr_1);
   116     update_identity(session, blacklisted_identity);
   117     PEP_STATUS status17 = delete_keypair(session, bl_fpr_2);
   118     update_identity(session, blacklisted_identity2);
   119         
   120     free_identity(blacklisted_identity);
   121     free_identity(blacklisted_identity2);
   122     
   123     cout << "calling release()\n";
   124     release(session);
   125     return 0;
   126 }
   127