test/src/EngineTestSuite.cc
branchsync
changeset 3335 09af2cf0ac74
parent 3315 4d8f93b6cdcb
child 3336 bea05d3b250e
     1.1 --- a/test/src/EngineTestSuite.cc	Sat Mar 09 11:50:11 2019 +0100
     1.2 +++ b/test/src/EngineTestSuite.cc	Fri Mar 15 12:43:56 2019 +0100
     1.3 @@ -13,11 +13,10 @@
     1.4  #include <string>
     1.5  #include <vector>
     1.6  #include <utility>
     1.7 -#include <cpptest.h>
     1.8  
     1.9  #include "platform_unix.h"
    1.10  
    1.11 -#include "TestUtils.h"
    1.12 +#include "test_util.h"
    1.13  #include "EngineTestSuite.h"
    1.14  #include "pEpTestStatic.h"
    1.15  #include <algorithm>
    1.16 @@ -26,18 +25,15 @@
    1.17  using namespace std;
    1.18  
    1.19  // Constructor
    1.20 -EngineTestSuite::EngineTestSuite(string suitename, 
    1.21 -                                 string test_home_dir,
    1.22 -                                 bool make_default_device) {
    1.23 +EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
    1.24      // FIXME: deal with base
    1.25      test_home = test_home_dir;
    1.26              
    1.27      number_of_tests = 0;
    1.28      on_test_number = 0;
    1.29      real_home = getenv("HOME");
    1.30 -    session = NULL;
    1.31 -    device = NULL;
    1.32 -    make_device = make_default_device;
    1.33 +    cached_messageToSend = NULL;
    1.34 +    cached_inject_sync_event = NULL;
    1.35  }
    1.36  
    1.37  EngineTestSuite::~EngineTestSuite() {}
    1.38 @@ -105,12 +101,12 @@
    1.39      
    1.40      set_my_name();
    1.41  
    1.42 -// // FIXME
    1.43 -// #ifndef USE_NETPGP
    1.44 -//     success = system("gpgconf --kill all");
    1.45 -//     if (success != 0)
    1.46 -//         throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
    1.47 -// #endif
    1.48 +// FIXME
    1.49 +#ifndef USE_NETPGP
    1.50 +    success = system("gpgconf --kill all");
    1.51 +    if (success != 0)
    1.52 +        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
    1.53 +#endif
    1.54  
    1.55      if (stat(test_home.c_str(), &dirchk) == 0) {
    1.56          if (!S_ISDIR(dirchk.st_mode))
    1.57 @@ -170,92 +166,84 @@
    1.58      
    1.59      assert(temp_test_home.compare(home) != 0);
    1.60      assert(temp_test_home.compare(home + "/") != 0);
    1.61 -    // assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
    1.62 -    // assert(temp_test_home.compare(home + ".gnupg") != 0);
    1.63 -    // assert(temp_test_home.compare(home + "/gnupg") != 0);
    1.64 -    // assert(temp_test_home.compare(home + "gnupg") != 0);
    1.65 -    // assert(temp_test_home.compare(prev_pgp_home) != 0);
    1.66 -    // assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
    1.67 -    // assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
    1.68 -    // assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
    1.69 -    // assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
    1.70 +    assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
    1.71 +    assert(temp_test_home.compare(home + ".gnupg") != 0);
    1.72 +    assert(temp_test_home.compare(home + "/gnupg") != 0);
    1.73 +    assert(temp_test_home.compare(home + "gnupg") != 0);
    1.74 +    assert(temp_test_home.compare(prev_pgp_home) != 0);
    1.75 +    assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
    1.76 +    assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
    1.77 +    assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
    1.78 +    assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
    1.79  
    1.80      if (temp_test_home.compare(home) == 0 || temp_test_home.compare(home + "/") == 0 ||
    1.81          temp_test_home.compare(home + "/gnupg") == 0 || temp_test_home.compare(home + "gnupg") == 0 ||
    1.82 -        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0)
    1.83 -        // temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
    1.84 -        // temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
    1.85 -        // temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
    1.86 +        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0 ||
    1.87 +        temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
    1.88 +        temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
    1.89 +        temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
    1.90          throw std::runtime_error("SETUP: new pgp homedir threatens to mess up user pgp homedir (and delete all their keys). NO DICE.");
    1.91      
    1.92  //    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;
    1.93      cout << "Test home directory is " << temp_test_home << endl;
    1.94      
    1.95      struct stat buf;
    1.96 -    // 
    1.97 -    // success = setenv("GNUPGHOME", (temp_test_home + "/gnupg").c_str(), 1);
    1.98 -    // if (success != 0)
    1.99 -    //     throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
   1.100 -    // 
   1.101 -    // cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
   1.102 +    
   1.103 +    success = setenv("GNUPGHOME", (temp_test_home + "/gnupg").c_str(), 1);
   1.104 +    if (success != 0)
   1.105 +        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
   1.106 +
   1.107 +    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
   1.108      
   1.109      success = setenv("HOME", temp_test_home.c_str(), 1);
   1.110      if (success != 0)
   1.111          throw std::runtime_error("SETUP: Cannot set test_home for init.");
   1.112  
   1.113 -    // string tmp_gpg_dir = temp_test_home + "/.gnupg";
   1.114 +    string tmp_gpg_dir = temp_test_home + "/.gnupg";
   1.115  
   1.116 -    // process_file_queue(tmp_gpg_dir, gpgdir_fileadd_queue);
   1.117 -    // process_file_queue(temp_test_home, homedir_fileadd_queue);
   1.118 +    process_file_queue(tmp_gpg_dir, gpgdir_fileadd_queue);
   1.119 +    process_file_queue(temp_test_home, homedir_fileadd_queue);
   1.120  
   1.121 -    // if (gpg_conf_copy_path)
   1.122 -    //     copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
   1.123 -    // if (gpg_agent_conf_file_copy_path)        
   1.124 -    //     copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
   1.125 -    // if (db_conf_file_copy_path)
   1.126 -    //     copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
   1.127 +    if (gpg_conf_copy_path)
   1.128 +        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
   1.129 +    if (gpg_agent_conf_file_copy_path)        
   1.130 +        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
   1.131 +    if (db_conf_file_copy_path)
   1.132 +        copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
   1.133          
   1.134 -    // unix_local_db(true);
   1.135 -    // gpg_conf(true);
   1.136 -    // gpg_agent_conf(true);
   1.137 +    unix_local_db(true);
   1.138 +    gpg_conf(true);
   1.139 +    gpg_agent_conf(true);
   1.140      
   1.141  //    cout << "calling init()\n";
   1.142 -//     PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
   1.143 -// #ifndef USE_NETPGP            
   1.144 -//     success = system("gpgconf --create-socketdir");
   1.145 -//     if (success != 0)
   1.146 -//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
   1.147 -//     system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
   1.148 -// #endif
   1.149 +    PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
   1.150 +#ifndef USE_NETPGP            
   1.151 +    success = system("gpgconf --create-socketdir");
   1.152 +    if (success != 0)
   1.153 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
   1.154 +    system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
   1.155 +#endif
   1.156  
   1.157 -//    assert(status == PEP_STATUS_OK);
   1.158 -//    assert(session);
   1.159 +    assert(status == PEP_STATUS_OK);
   1.160 +    assert(session);
   1.161  //    cout << "init() completed.\n";
   1.162 -    if (make_device) {
   1.163 -        device = new pEpTestDevice(temp_test_home, "DefaultDevice");
   1.164 -        session = device->session;
   1.165 -    }
   1.166 +
   1.167  }
   1.168  
   1.169  void EngineTestSuite::restore_full_env() {
   1.170 -//    release(session);
   1.171 -//    session = NULL;
   1.172 -    if (make_device) {
   1.173 -        delete(device);
   1.174 -        device = NULL;
   1.175 -        session = NULL;
   1.176 -    }
   1.177 +    release(session);
   1.178 +    session = NULL;
   1.179          
   1.180      int success = 0;    
   1.181  
   1.182 -// #ifndef USE_NETPGP        
   1.183 -//     success = system("gpgconf --kill all");
   1.184 -//     if (success != 0)
   1.185 -//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
   1.186 -//     success = system("gpgconf --remove-socketdir");            
   1.187 -//     if (success != 0)
   1.188 -//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
   1.189 -// #endif
   1.190 +#ifndef USE_NETPGP        
   1.191 +    success = system("gpgconf --kill all");
   1.192 +    if (success != 0)
   1.193 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
   1.194 +    success = system("gpgconf --remove-socketdir");            
   1.195 +    if (success != 0)
   1.196 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
   1.197 +#endif
   1.198  
   1.199      success = setenv("GNUPGHOME", prev_pgp_home.c_str(), 1);
   1.200      if (success != 0)
   1.201 @@ -268,9 +256,9 @@
   1.202          throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");
   1.203      // else
   1.204      //     cout << "RESTORE: HOME is now " << getenv("HOME") << endl;
   1.205 -    // unix_local_db(true);
   1.206 -    // gpg_conf(true);
   1.207 -    // gpg_agent_conf(true);
   1.208 +    unix_local_db(true);
   1.209 +    gpg_conf(true);
   1.210 +    gpg_agent_conf(true);
   1.211  
   1.212  }
   1.213