shelving changes to add graftable fix ENGINE-434
authorKrista Bennett <krista@pep-project.org>
Tue, 22 May 2018 09:33:43 +0200
branchENGINE-434
changeset 2679567462e5b11a
parent 2678 610a608c410d
child 2680 b6f5a8fb2219
shelving changes to add graftable fix
src/pgp_gpg.c
test/include/EngineTestSuite.h
test/include/IntegrityTests.h
test/include/test_util.h
test/src/EngineTestIndividualSuite.cc
test/src/EngineTestSuite.cc
test/src/TestDriver.cc
test/src/engine_tests/IntegrityTests.cc
test/src/util/test_util.cc
     1.1 --- a/src/pgp_gpg.c	Fri May 18 10:20:08 2018 +0200
     1.2 +++ b/src/pgp_gpg.c	Tue May 22 09:33:43 2018 +0200
     1.3 @@ -1831,6 +1831,7 @@
     1.4  }
     1.5  
     1.6  
     1.7 +
     1.8  static PEP_STATUS _pgp_search_keys(PEP_SESSION session, const char* pattern,
     1.9                              stringlist_t** keylist,
    1.10                              int private_only) {
     2.1 --- a/test/include/EngineTestSuite.h	Fri May 18 10:20:08 2018 +0200
     2.2 +++ b/test/include/EngineTestSuite.h	Tue May 22 09:33:43 2018 +0200
     2.3 @@ -18,6 +18,7 @@
     2.4      protected:
     2.5          PEP_SESSION session;
     2.6          string test_home;
     2.7 +        string real_home;
     2.8          string prev_gpg_home;
     2.9          string name;
    2.10          
    2.11 @@ -37,6 +38,5 @@
    2.12          void set_full_env();
    2.13          void restore_full_env();
    2.14          void initialise_test_home();
    2.15 -        
    2.16  };
    2.17  #endif
     3.1 --- a/test/include/IntegrityTests.h	Fri May 18 10:20:08 2018 +0200
     3.2 +++ b/test/include/IntegrityTests.h	Tue May 22 09:33:43 2018 +0200
     3.3 @@ -41,6 +41,11 @@
     3.4          void check_unknown_signed_PGP_MIME_attached_key();
     3.5          void check_unsigned_PGP_MIME_corrupted();
     3.6          void check_signed_PGP_MIME_corrupted();
     3.7 +        void check_unsigned_2_0();
     3.8 +        void check_unknown_signed_2_0_no_key();
     3.9 +        void check_unknown_signed_2_0_no_key_known_signer();
    3.10 +        void check_unknown_signed_2_0_key_attached();
    3.11 +
    3.12          void check_integrity();
    3.13          
    3.14  
     4.1 --- a/test/include/test_util.h	Fri May 18 10:20:08 2018 +0200
     4.2 +++ b/test/include/test_util.h	Tue May 22 09:33:43 2018 +0200
     4.3 @@ -2,6 +2,10 @@
     4.4  #define PEP_TEST_UTILS_H
     4.5  
     4.6  #include <string>
     4.7 +#include <stdlib.h>
     4.8 +#include <sys/stat.h>
     4.9 +#include <ftw.h>
    4.10 +
    4.11  #include "pEpEngine.h"
    4.12  #include "message_api.h"
    4.13  
    4.14 @@ -33,4 +37,9 @@
    4.15  
    4.16  bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename);
    4.17  
    4.18 +int util_delete_filepath(const char *filepath, 
    4.19 +                         const struct stat *file_stat, 
    4.20 +                         int ftw_info, 
    4.21 +                         struct FTW * ftw_struct);
    4.22 +        
    4.23  #endif
     5.1 --- a/test/src/EngineTestIndividualSuite.cc	Fri May 18 10:20:08 2018 +0200
     5.2 +++ b/test/src/EngineTestIndividualSuite.cc	Tue May 22 09:33:43 2018 +0200
     5.3 @@ -20,10 +20,12 @@
     5.4  }
     5.5  
     5.6  void EngineTestIndividualSuite::setup() {
     5.7 +    EngineTestSuite::setup();
     5.8      set_full_env(); // This will be called by default before every test
     5.9  }
    5.10  
    5.11  void EngineTestIndividualSuite::tear_down() {
    5.12      release(session);
    5.13      restore_full_env();
    5.14 +    EngineTestSuite::tear_down();
    5.15  }
     6.1 --- a/test/src/EngineTestSuite.cc	Fri May 18 10:20:08 2018 +0200
     6.2 +++ b/test/src/EngineTestSuite.cc	Tue May 22 09:33:43 2018 +0200
     6.3 @@ -1,7 +1,12 @@
     6.4 +#include <stdlib.h>
     6.5 +#include <sys/stat.h>
     6.6 +#include <errno.h>
     6.7  #include <stdlib.h>
     6.8  #include <unistd.h>
     6.9  #include <ftw.h>
    6.10 +#include <assert.h>
    6.11  
    6.12 +#include "test_util.h"
    6.13  #include "EngineTestSuite.h"
    6.14  using namespace std;
    6.15  
    6.16 @@ -9,13 +14,7 @@
    6.17  EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
    6.18      // FIXME: deal with base
    6.19      test_home = test_home_dir;
    6.20 -    
    6.21 -    // TODO: This is *nix specific, which the current testing env is anyway,
    6.22 -    // but it needn't remain so forever and always
    6.23 -    char* tmp = getenv("GNUPGHOME");
    6.24 -    if (tmp)
    6.25 -        prev_gpg_home = getenv("GNUPGHOME");
    6.26 -        
    6.27 +            
    6.28      number_of_tests = 0;
    6.29      on_test_number = 0;
    6.30  }
    6.31 @@ -29,45 +28,80 @@
    6.32  }
    6.33  
    6.34  void EngineTestSuite::set_full_env() {
    6.35 +    int success = 0;
    6.36 +    struct stat dirchk;
    6.37 +    if (stat(test_home.c_str(), &dirchk) == 0) {
    6.38 +        if (!S_ISDIR(dirchk.st_mode))
    6.39 +            throw std::runtime_error(("The test directory, " + test_home + "exists, but is not a directory.").c_str()); 
    6.40 +                    
    6.41 +        struct stat buf;
    6.42  
    6.43 -    if (test_home.empty())
    6.44 +        if (stat(test_home.c_str(), &buf) == 0) {
    6.45 +            cout << test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
    6.46 +            int success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
    6.47 +        }
    6.48 +    }
    6.49 +    else {
    6.50 +        int errchk = mkdir(test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    6.51 +        cout << errchk << endl;
    6.52 +        if (errchk != 0)
    6.53 +            throw std::runtime_error("Error creating a test directory.");
    6.54 +    }
    6.55 +
    6.56 +    string temp_test_home = test_home + "/" + to_string(on_test_number);
    6.57 +    
    6.58 +    int errchk = mkdir(temp_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    6.59 +    cout << errchk << endl;
    6.60 +    if (errchk != 0)
    6.61 +        throw std::runtime_error("Error creating a test directory.");
    6.62 +
    6.63 +    // TODO: This is *nix specific, which the current testing env is anyway,
    6.64 +    // but it needn't remain so forever and always
    6.65 +    char* tmp = getenv("GNUPGHOME");
    6.66 +    if (tmp)
    6.67 +        prev_gpg_home = getenv("GNUPGHOME");
    6.68 +        
    6.69 +    if (temp_test_home.empty())
    6.70          throw std::runtime_error("SETUP: BAD INITIALISATION. No test home.");
    6.71      
    6.72 -    int success = system("gpgconf --kill all");
    6.73 -    if (success != 0)
    6.74 -        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");
    6.75      
    6.76      string home = getenv("HOME");
    6.77 -    if (test_home.compare(home) == 0 || test_home.compare(home + "/") == 0 ||
    6.78 -        test_home.compare(home + "/.gnupg") == 0 || test_home.compare(home + ".gnupg") == 0 ||
    6.79 -        test_home.compare(prev_gpg_home) == 0 || test_home.compare(prev_gpg_home + "/.gnupg") == 0 ||
    6.80 -        test_home.compare(prev_gpg_home + ".gnupg") == 0)
    6.81 +    if (temp_test_home.compare(home) == 0 || temp_test_home.compare(home + "/") == 0 ||
    6.82 +        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0 ||
    6.83 +        temp_test_home.compare(prev_gpg_home) == 0 || temp_test_home.compare(prev_gpg_home + "/.gnupg") == 0 ||
    6.84 +        temp_test_home.compare(prev_gpg_home + ".gnupg") == 0)
    6.85          throw std::runtime_error("SETUP: new GNUPGHOME threatens to mess up user GNUPGHOME (and delete all their keys). NO DICE.");
    6.86      
    6.87  //    cout << "Ok - checked if new test home will be safe. We'll try and make the directory, deleting it if it has already exists." << endl;
    6.88      
    6.89      struct stat buf;
    6.90      
    6.91 -    success = setenv("GNUPGHOME", (test_home + "/.gnupg").c_str(), 1);
    6.92 +    success = setenv("GNUPGHOME", (temp_test_home + "/.gnupg").c_str(), 1);
    6.93      if (success != 0)
    6.94          throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
    6.95  
    6.96 -    success = setenv("HOME", test_home.c_str(), 1);
    6.97 +    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl;
    6.98 +    
    6.99 +    success = system("gpgconf --kill all");
   6.100 +    if (success != 0)
   6.101 +        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");
   6.102 +    sleep(1); // hopefully enough time for the system to recognise that it is dead. *sigh*
   6.103 +
   6.104 +    
   6.105 +    success = setenv("HOME", temp_test_home.c_str(), 1);
   6.106      if (success != 0)
   6.107          throw std::runtime_error("SETUP: Cannot set test_home for init.");
   6.108      
   6.109  //    cout << "calling init()\n";
   6.110      PEP_STATUS status = init(&session);
   6.111      // assert(status == PEP_STATUS_OK);
   6.112 -    // assert(session);
   6.113 +    assert(session);
   6.114  //    cout << "init() completed.\n";
   6.115  
   6.116 -    success = setenv("HOME", home.c_str(), 1);
   6.117 -    if (success != 0)
   6.118 -        throw std::runtime_error("SETUP: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");    
   6.119  }
   6.120  
   6.121  void EngineTestSuite::restore_full_env() {
   6.122 +            
   6.123      int success = system("gpgconf --kill all");
   6.124      if (success != 0)
   6.125          throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
   6.126 @@ -75,6 +109,13 @@
   6.127      success = setenv("GNUPGHOME", prev_gpg_home.c_str(), 1);
   6.128      if (success != 0)
   6.129          throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
   6.130 +                
   6.131 +    success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
   6.132 +    
   6.133 +    success = setenv("HOME", real_home.c_str(), 1);
   6.134 +    if (success != 0)
   6.135 +        throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");    
   6.136 +
   6.137  }
   6.138  
   6.139  void EngineTestSuite::setup() {
     7.1 --- a/test/src/TestDriver.cc	Fri May 18 10:20:08 2018 +0200
     7.2 +++ b/test/src/TestDriver.cc	Tue May 22 09:33:43 2018 +0200
     7.3 @@ -16,57 +16,27 @@
     7.4  
     7.5  using namespace std;
     7.6  
     7.7 -string common_test_home = "./pEp_test_home";
     7.8 +string common_test_home;
     7.9  
    7.10  void usage() {
    7.11      throw std::runtime_error("Bad usage. Fix me, you loser developer.");
    7.12  }
    7.13  
    7.14 -int util_delete_filepath(const char *filepath, 
    7.15 -                         const struct stat *file_stat, 
    7.16 -                         int ftw_info, 
    7.17 -                         struct FTW * ftw_struct) {
    7.18 -    int retval = 0;
    7.19 -    switch (ftw_info) {
    7.20 -        case FTW_DP:
    7.21 -            retval = rmdir(filepath);
    7.22 -            break;
    7.23 -        case FTW_F:
    7.24 -        case FTW_SLN:
    7.25 -            retval = unlink(filepath);
    7.26 -            break;    
    7.27 -        default:
    7.28 -            retval = -1;
    7.29 -    }
    7.30 -    
    7.31 -    return retval;
    7.32 -}
    7.33 -
    7.34 -
    7.35  int main(int argc, const char** argv) {
    7.36      const int MIN_ARGC = 1;
    7.37      if (argc < MIN_ARGC)
    7.38          usage();
    7.39      
    7.40 -    struct stat dirchk;
    7.41 -    if (stat(common_test_home.c_str(), &dirchk) == 0) {
    7.42 -        if (!S_ISDIR(dirchk.st_mode))
    7.43 -            throw std::runtime_error(("The test directory, " + common_test_home + "exists, but is not a directory.").c_str()); 
    7.44 -                    
    7.45 -        struct stat buf;
    7.46 +    size_t BUF_MAX_PATHLEN = 4097; 
    7.47 +    char buf[BUF_MAX_PATHLEN];// Linux max path size...
    7.48 +                          
    7.49 +    string curr_wd = getcwd(buf, BUF_MAX_PATHLEN);
    7.50 +    
    7.51 +    if (curr_wd.empty())
    7.52 +        throw std::runtime_error("Error grabbing current working directory"); 
    7.53  
    7.54 -        if (stat(common_test_home.c_str(), &buf) == 0) {
    7.55 -            cout << common_test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
    7.56 -            int success = nftw((common_test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
    7.57 -        }
    7.58 -    }
    7.59 -    else {
    7.60 -        int errchk = mkdir(common_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    7.61 -        cout << errchk << endl;
    7.62 -        if (errchk != 0)
    7.63 -            throw std::runtime_error("Error creating a test directory.");
    7.64 -    }
    7.65 -                    
    7.66 +    common_test_home = curr_wd + "/pEp_test_home";    
    7.67 +    
    7.68      EngineTestSuite* test_runner = new EngineTestSuite("MainTestDriver", common_test_home);
    7.69  
    7.70      std::vector<Test::Suite*> suites_to_run;
     8.1 --- a/test/src/engine_tests/IntegrityTests.cc	Fri May 18 10:20:08 2018 +0200
     8.2 +++ b/test/src/engine_tests/IntegrityTests.cc	Tue May 22 09:33:43 2018 +0200
     8.3 @@ -4,6 +4,7 @@
     8.4  #include <stdlib.h>
     8.5  #include <string>
     8.6  #include <assert.h>
     8.7 +#include <unistd.h>
     8.8  
     8.9  #include "pEpEngine.h"
    8.10  #include "message_api.h"
    8.11 @@ -36,6 +37,14 @@
    8.12                                                                        static_cast<Func>(&IntegrityTests::check_unsigned_PGP_MIME_corrupted)));
    8.13      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("IntegrityTests::check_signed_PGP_MIME_corrupted"),
    8.14                                                                        static_cast<Func>(&IntegrityTests::check_signed_PGP_MIME_corrupted)));
    8.15 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("IntegrityTests::check_unsigned_2_0"),
    8.16 +                                                                      static_cast<Func>(&IntegrityTests::check_unsigned_2_0)));
    8.17 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("IntegrityTests::check_unknown_signed_2_0_no_key"),
    8.18 +                                                                      static_cast<Func>(&IntegrityTests::check_unknown_signed_2_0_no_key)));
    8.19 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("IntegrityTests::check_unknown_signed_2_0_no_key_known_signer"),
    8.20 +                                                                      static_cast<Func>(&IntegrityTests::check_unknown_signed_2_0_no_key_known_signer)));                                                                                                                                        
    8.21 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("IntegrityTests::check_unknown_signed_2_0_key_attached"),
    8.22 +                                                                      static_cast<Func>(&IntegrityTests::check_unknown_signed_2_0_key_attached)));  
    8.23      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("IntegrityTests::check_integrity"),
    8.24                                                                        static_cast<Func>(&IntegrityTests::check_integrity)));
    8.25  }
    8.26 @@ -45,9 +54,16 @@
    8.27      string recip_key = slurp("test_keys/pub/integrity_test_recip_0-0xF390A40D_pub.asc");
    8.28      PEP_STATUS status = import_key(session, recip_key.c_str(), recip_key.size(), NULL);
    8.29      assert(status == PEP_STATUS_OK);
    8.30 -    recip_key = slurp("test_keys/priv/integrity_test_recip_0-0xF390A40D_priv.asc");
    8.31 -    status = import_key(session, recip_key.c_str(), recip_key.size(), NULL);
    8.32 +    recip_key = "";
    8.33 +    string priv_key = slurp("test_keys/priv/integrity_test_recip_0-0xF390A40D_priv.asc");
    8.34 +    cout << priv_key << endl;
    8.35 +    cout << "GNUPGHOME is " << getenv("GNUPGHOME") << endl;
    8.36 +    status = import_key(session, priv_key.c_str(), priv_key.size(), NULL);
    8.37      assert(status == PEP_STATUS_OK);
    8.38 +    stringlist_t* debug_keylist = NULL;
    8.39 +    status = find_private_keys(session, recip_fpr, &debug_keylist);
    8.40 +    assert(debug_keylist);
    8.41 +    
    8.42      pEp_identity* me = new_identity("integrity_test_recip@darthmama.org", recip_fpr, PEP_OWN_USERID, "Integrity Test Recipient");
    8.43      assert(me != NULL);
    8.44      status = set_own_key(session, me, recip_fpr);
    8.45 @@ -204,6 +220,60 @@
    8.46      TEST_ASSERT(decrypted_msg == NULL);
    8.47  }
    8.48  
    8.49 +void IntegrityTests::check_unsigned_2_0() {
    8.50 +    TEST_ASSERT(slurp_message_and_import_key(session, "test_mails/fake_2.0_unsigned.eml", message,
    8.51 +                                             NULL));
    8.52 +    decrypt_status = MIME_decrypt_message(session, message.c_str(), message.size(), &decrypted_msg, &keylist,
    8.53 +                                          &rating, &flags, &dummy_ignore);
    8.54 +
    8.55 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Decrypt status == %s, should be PEP_DECRYPT_MODIFICATION_DETECTED", tl_status_string(decrypt_status));
    8.56 +    TEST_ASSERT_MSG(decrypt_status == PEP_DECRYPT_MODIFICATION_DETECTED, failed_msg_buf);
    8.57 +    TEST_ASSERT(decrypted_msg == NULL);
    8.58 +    TEST_ASSERT(rating == PEP_rating_under_attack);
    8.59 +}
    8.60 +
    8.61 +void IntegrityTests::check_unknown_signed_2_0_no_key() {
    8.62 +    TEST_ASSERT(slurp_message_and_import_key(session, "test_mails/fake_2.0_signed_no_key_attached.eml", message,
    8.63 +                                             NULL));
    8.64 +    decrypt_status = MIME_decrypt_message(session, message.c_str(), message.size(), &decrypted_msg, &keylist,
    8.65 +                                          &rating, &flags, &dummy_ignore);
    8.66 +
    8.67 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Decrypt status == %s, should be PEP_DECRYPT_MODIFICATION_DETECTED", tl_status_string(decrypt_status));
    8.68 +    TEST_ASSERT_MSG(decrypt_status == PEP_DECRYPT_MODIFICATION_DETECTED, failed_msg_buf);
    8.69 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Decrypted msg should have been NULL, but starts with %s", decrypted_msg);
    8.70 +    TEST_ASSERT_MSG(decrypted_msg == NULL, failed_msg_buf);
    8.71 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Rating == %s, should be PEP_rating_under_attack", tl_rating_string(rating));
    8.72 +    TEST_ASSERT_MSG(rating == PEP_rating_under_attack, failed_msg_buf);
    8.73 +}
    8.74 +
    8.75 +void IntegrityTests::check_unknown_signed_2_0_no_key_known_signer() {
    8.76 +    TEST_ASSERT(slurp_message_and_import_key(session, "test_mails/fake_2.0_signed_no_key_attached.eml", message,
    8.77 +                                             "test_keys/pub/integrity_test_signer_0-0xFF26631A_pub.asc"));
    8.78 +    decrypt_status = MIME_decrypt_message(session, message.c_str(), message.size(), &decrypted_msg, &keylist,
    8.79 +                                          &rating, &flags, &dummy_ignore);
    8.80 +
    8.81 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Decrypt status == %s, should be PEP_DECRYPT_MODIFICATION_DETECTED", tl_status_string(decrypt_status));
    8.82 +    TEST_ASSERT_MSG(decrypt_status == PEP_DECRYPT_MODIFICATION_DETECTED, failed_msg_buf);
    8.83 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Decrypted msg should have been NULL, but starts with %s", decrypted_msg);
    8.84 +    TEST_ASSERT_MSG(decrypted_msg == NULL, failed_msg_buf);
    8.85 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Rating == %s, should be PEP_rating_under_attack", tl_rating_string(rating));
    8.86 +    TEST_ASSERT_MSG(rating == PEP_rating_under_attack, failed_msg_buf);
    8.87 +}
    8.88 +
    8.89 +
    8.90 +void IntegrityTests::check_unknown_signed_2_0_key_attached() {
    8.91 +    TEST_ASSERT(slurp_message_and_import_key(session, "test_mails/fake_2.0_good.eml", message,
    8.92 +                                             NULL));
    8.93 +    decrypt_status = MIME_decrypt_message(session, message.c_str(), message.size(), &decrypted_msg, &keylist,
    8.94 +                                          &rating, &flags, &dummy_ignore);
    8.95 +
    8.96 +    snprintf(failed_msg_buf, TEST_FAILED_MESSAGE_BUFSIZE, "Decrypt status == %s, should be PEP_STATUS_OK", tl_status_string(decrypt_status));
    8.97 +    TEST_ASSERT_MSG(decrypt_status == PEP_STATUS_OK, failed_msg_buf);
    8.98 +    TEST_ASSERT(decrypted_msg != NULL);
    8.99 +    TEST_ASSERT(rating == PEP_rating_reliable);
   8.100 +}
   8.101 +
   8.102 +
   8.103  void IntegrityTests::check_integrity() {
   8.104      TEST_ASSERT(true);
   8.105  }
     9.1 --- a/test/src/util/test_util.cc	Fri May 18 10:20:08 2018 +0200
     9.2 +++ b/test/src/util/test_util.cc	Tue May 22 09:33:43 2018 +0200
     9.3 @@ -2,9 +2,16 @@
     9.4  #include "pEpEngine.h"
     9.5  #include "pEp_internal.h"
     9.6  #include "message_api.h"
     9.7 +
     9.8  #include <fstream>
     9.9  #include <sstream>
    9.10  #include <stdexcept>
    9.11 +#include <stdlib.h>
    9.12 +#include <sys/stat.h>
    9.13 +#include <errno.h>
    9.14 +#include <stdlib.h>
    9.15 +#include <unistd.h>
    9.16 +#include <ftw.h>
    9.17  
    9.18  char* str_to_lower(const char* str) {
    9.19      if (!str)
    9.20 @@ -333,3 +340,26 @@
    9.21      }
    9.22      return true;
    9.23  }
    9.24 +
    9.25 +
    9.26 +
    9.27 +int util_delete_filepath(const char *filepath, 
    9.28 +                         const struct stat *file_stat, 
    9.29 +                         int ftw_info, 
    9.30 +                         struct FTW * ftw_struct) {
    9.31 +    int retval = 0;
    9.32 +    switch (ftw_info) {
    9.33 +        case FTW_DP:
    9.34 +            retval = rmdir(filepath);
    9.35 +            break;
    9.36 +        case FTW_F:
    9.37 +        case FTW_SLN:
    9.38 +            retval = unlink(filepath);
    9.39 +            break;    
    9.40 +        default:
    9.41 +            retval = -1;
    9.42 +    }
    9.43 +    
    9.44 +    return retval;
    9.45 +}
    9.46 +