Commiting so I can merge sync_test_refactor
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 12 Feb 2019 12:14:29 +0100
branchsync_test_refactor
changeset 32947b95c642c491
parent 3292 673b8c6da681
child 3295 1a12a24ff0e6
Commiting so I can merge
test/include/EngineTestSuite.h
test/src/EngineTestSuite.cc
test/src/SuiteMaker.cc
     1.1 --- a/test/include/EngineTestSuite.h	Mon Feb 11 08:35:27 2019 +0100
     1.2 +++ b/test/include/EngineTestSuite.h	Tue Feb 12 12:14:29 2019 +0100
     1.3 @@ -7,12 +7,16 @@
     1.4  #include <vector>
     1.5  #include <utility>
     1.6  #include "pEpEngine.h"
     1.7 +#include "pEpTestDevice.h"
     1.8  
     1.9  using namespace std;
    1.10  
    1.11  class EngineTestSuite : public Test::Suite {
    1.12      public:
    1.13 -        EngineTestSuite(string suitename, string test_home_dir);
    1.14 +        EngineTestSuite(string suitename, 
    1.15 +                        string test_home_dir, 
    1.16 +                        bool make_default_device = true);   
    1.17 +                             
    1.18          virtual ~EngineTestSuite();
    1.19          
    1.20          void add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()> test_func);
    1.21 @@ -21,6 +25,9 @@
    1.22  
    1.23      protected:
    1.24          PEP_SESSION session;
    1.25 +        bool make_device;
    1.26 +        pEpTestDevice* device;
    1.27 +        
    1.28          string test_home;
    1.29          string real_home;
    1.30          string prev_pgp_home;
     2.1 --- a/test/src/EngineTestSuite.cc	Mon Feb 11 08:35:27 2019 +0100
     2.2 +++ b/test/src/EngineTestSuite.cc	Tue Feb 12 12:14:29 2019 +0100
     2.3 @@ -25,7 +25,9 @@
     2.4  using namespace std;
     2.5  
     2.6  // Constructor
     2.7 -EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
     2.8 +EngineTestSuite::EngineTestSuite(string suitename, 
     2.9 +                                 string test_home_dir,
    2.10 +                                 bool make_default_device) {
    2.11      // FIXME: deal with base
    2.12      test_home = test_home_dir;
    2.13              
    2.14 @@ -34,6 +36,9 @@
    2.15      real_home = getenv("HOME");
    2.16      cached_messageToSend = NULL;
    2.17      cached_inject_sync_event = NULL;
    2.18 +    session = NULL;
    2.19 +    device = NULL;
    2.20 +    make_device = make_default_device;
    2.21  }
    2.22  
    2.23  EngineTestSuite::~EngineTestSuite() {}
    2.24 @@ -101,12 +106,12 @@
    2.25      
    2.26      set_my_name();
    2.27  
    2.28 -// FIXME
    2.29 -#ifndef USE_NETPGP
    2.30 -    success = system("gpgconf --kill all");
    2.31 -    if (success != 0)
    2.32 -        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
    2.33 -#endif
    2.34 +// // FIXME
    2.35 +// #ifndef USE_NETPGP
    2.36 +//     success = system("gpgconf --kill all");
    2.37 +//     if (success != 0)
    2.38 +//         throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
    2.39 +// #endif
    2.40  
    2.41      if (stat(test_home.c_str(), &dirchk) == 0) {
    2.42          if (!S_ISDIR(dirchk.st_mode))
    2.43 @@ -166,84 +171,92 @@
    2.44      
    2.45      assert(temp_test_home.compare(home) != 0);
    2.46      assert(temp_test_home.compare(home + "/") != 0);
    2.47 -    assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
    2.48 -    assert(temp_test_home.compare(home + ".gnupg") != 0);
    2.49 -    assert(temp_test_home.compare(home + "/gnupg") != 0);
    2.50 -    assert(temp_test_home.compare(home + "gnupg") != 0);
    2.51 -    assert(temp_test_home.compare(prev_pgp_home) != 0);
    2.52 -    assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
    2.53 -    assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
    2.54 -    assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
    2.55 -    assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
    2.56 +    // assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
    2.57 +    // assert(temp_test_home.compare(home + ".gnupg") != 0);
    2.58 +    // assert(temp_test_home.compare(home + "/gnupg") != 0);
    2.59 +    // assert(temp_test_home.compare(home + "gnupg") != 0);
    2.60 +    // assert(temp_test_home.compare(prev_pgp_home) != 0);
    2.61 +    // assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
    2.62 +    // assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
    2.63 +    // assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
    2.64 +    // assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
    2.65  
    2.66      if (temp_test_home.compare(home) == 0 || temp_test_home.compare(home + "/") == 0 ||
    2.67          temp_test_home.compare(home + "/gnupg") == 0 || temp_test_home.compare(home + "gnupg") == 0 ||
    2.68 -        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0 ||
    2.69 -        temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
    2.70 -        temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
    2.71 -        temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
    2.72 +        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0)
    2.73 +        // temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
    2.74 +        // temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
    2.75 +        // temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
    2.76          throw std::runtime_error("SETUP: new pgp homedir threatens to mess up user pgp homedir (and delete all their keys). NO DICE.");
    2.77      
    2.78  //    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;
    2.79      cout << "Test home directory is " << temp_test_home << endl;
    2.80      
    2.81      struct stat buf;
    2.82 -    
    2.83 -    success = setenv("GNUPGHOME", (temp_test_home + "/gnupg").c_str(), 1);
    2.84 -    if (success != 0)
    2.85 -        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
    2.86 -
    2.87 -    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
    2.88 +    // 
    2.89 +    // success = setenv("GNUPGHOME", (temp_test_home + "/gnupg").c_str(), 1);
    2.90 +    // if (success != 0)
    2.91 +    //     throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
    2.92 +    // 
    2.93 +    // cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
    2.94      
    2.95      success = setenv("HOME", temp_test_home.c_str(), 1);
    2.96      if (success != 0)
    2.97          throw std::runtime_error("SETUP: Cannot set test_home for init.");
    2.98  
    2.99 -    string tmp_gpg_dir = temp_test_home + "/.gnupg";
   2.100 +    // string tmp_gpg_dir = temp_test_home + "/.gnupg";
   2.101  
   2.102 -    process_file_queue(tmp_gpg_dir, gpgdir_fileadd_queue);
   2.103 -    process_file_queue(temp_test_home, homedir_fileadd_queue);
   2.104 +    // process_file_queue(tmp_gpg_dir, gpgdir_fileadd_queue);
   2.105 +    // process_file_queue(temp_test_home, homedir_fileadd_queue);
   2.106  
   2.107 -    if (gpg_conf_copy_path)
   2.108 -        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
   2.109 -    if (gpg_agent_conf_file_copy_path)        
   2.110 -        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
   2.111 -    if (db_conf_file_copy_path)
   2.112 -        copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
   2.113 +    // if (gpg_conf_copy_path)
   2.114 +    //     copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
   2.115 +    // if (gpg_agent_conf_file_copy_path)        
   2.116 +    //     copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
   2.117 +    // if (db_conf_file_copy_path)
   2.118 +    //     copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
   2.119          
   2.120      unix_local_db(true);
   2.121      gpg_conf(true);
   2.122      gpg_agent_conf(true);
   2.123      
   2.124  //    cout << "calling init()\n";
   2.125 -    PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
   2.126 -#ifndef USE_NETPGP            
   2.127 -    success = system("gpgconf --create-socketdir");
   2.128 -    if (success != 0)
   2.129 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
   2.130 -    system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
   2.131 -#endif
   2.132 +//     PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
   2.133 +// #ifndef USE_NETPGP            
   2.134 +//     success = system("gpgconf --create-socketdir");
   2.135 +//     if (success != 0)
   2.136 +//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
   2.137 +//     system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
   2.138 +// #endif
   2.139  
   2.140 -    assert(status == PEP_STATUS_OK);
   2.141 -    assert(session);
   2.142 +//    assert(status == PEP_STATUS_OK);
   2.143 +//    assert(session);
   2.144  //    cout << "init() completed.\n";
   2.145 -
   2.146 +    if (make_device) {
   2.147 +        device = new pEpTestDevice(temp_test_home, "DefaultDevice");
   2.148 +        session = device->session;
   2.149 +    }
   2.150  }
   2.151  
   2.152  void EngineTestSuite::restore_full_env() {
   2.153 -    release(session);
   2.154 -    session = NULL;
   2.155 +//    release(session);
   2.156 +//    session = NULL;
   2.157 +    if (make_device) {
   2.158 +        delete(device);
   2.159 +        device = NULL;
   2.160 +        session = NULL;
   2.161 +    }
   2.162          
   2.163      int success = 0;    
   2.164  
   2.165 -#ifndef USE_NETPGP        
   2.166 -    success = system("gpgconf --kill all");
   2.167 -    if (success != 0)
   2.168 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
   2.169 -    success = system("gpgconf --remove-socketdir");            
   2.170 -    if (success != 0)
   2.171 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
   2.172 -#endif
   2.173 +// #ifndef USE_NETPGP        
   2.174 +//     success = system("gpgconf --kill all");
   2.175 +//     if (success != 0)
   2.176 +//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
   2.177 +//     success = system("gpgconf --remove-socketdir");            
   2.178 +//     if (success != 0)
   2.179 +//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
   2.180 +// #endif
   2.181  
   2.182      success = setenv("GNUPGHOME", prev_pgp_home.c_str(), 1);
   2.183      if (success != 0)
     3.1 --- a/test/src/SuiteMaker.cc	Mon Feb 11 08:35:27 2019 +0100
     3.2 +++ b/test/src/SuiteMaker.cc	Tue Feb 12 12:14:29 2019 +0100
     3.3 @@ -35,7 +35,6 @@
     3.4  #include "Engine358Tests.h"
     3.5  #include "BlacklistAcceptNewKeyTests.h"
     3.6  #include "DecryptAttachPrivateKeyUntrustedTests.h"
     3.7 -#include "ReturnMistrustFprTests.h"
     3.8  #include "BlacklistTests.h"
     3.9  #include "RevokeRegenAttachTests.h"
    3.10  #include "PepSubjectReceivedTests.h"
    3.11 @@ -87,7 +86,6 @@
    3.12      "Engine358Tests",
    3.13      "BlacklistAcceptNewKeyTests",
    3.14      "DecryptAttachPrivateKeyUntrustedTests",
    3.15 -    "ReturnMistrustFprTests",
    3.16      "BlacklistTests",
    3.17      "RevokeRegenAttachTests",
    3.18      "PepSubjectReceivedTests",
    3.19 @@ -116,7 +114,7 @@
    3.20  };
    3.21  
    3.22  // This file is generated, so magic constants are ok.
    3.23 -int SuiteMaker::num_suites = 49;
    3.24 +int SuiteMaker::num_suites = 48;
    3.25  
    3.26  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    3.27      if (strcmp(test_class_name, "MimeTests") == 0)
    3.28 @@ -165,8 +163,6 @@
    3.29          *test_suite = new BlacklistAcceptNewKeyTests(test_class_name, test_home);
    3.30      else if (strcmp(test_class_name, "DecryptAttachPrivateKeyUntrustedTests") == 0)
    3.31          *test_suite = new DecryptAttachPrivateKeyUntrustedTests(test_class_name, test_home);
    3.32 -    else if (strcmp(test_class_name, "ReturnMistrustFprTests") == 0)
    3.33 -        *test_suite = new ReturnMistrustFprTests(test_class_name, test_home);
    3.34      else if (strcmp(test_class_name, "BlacklistTests") == 0)
    3.35          *test_suite = new BlacklistTests(test_class_name, test_home);
    3.36      else if (strcmp(test_class_name, "RevokeRegenAttachTests") == 0)