Working toward multi 'device' tests sync_test_refactor
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 12 Feb 2019 19:37:34 +0100
branchsync_test_refactor
changeset 3299f15bf275c50f
parent 3296 fe7cbfc8e84f
child 3300 835802e96172
Working toward multi 'device' tests
test/include/EngineTestIndividualSuite.h
test/include/pEpTestDevice.h
test/src/EngineTestIndividualSuite.cc
test/src/EngineTestSuite.cc
test/src/SuiteMaker.cc
test/src/pEpTestDevice.cc
     1.1 --- a/test/include/EngineTestIndividualSuite.h	Tue Feb 12 14:55:17 2019 +0100
     1.2 +++ b/test/include/EngineTestIndividualSuite.h	Tue Feb 12 19:37:34 2019 +0100
     1.3 @@ -12,7 +12,8 @@
     1.4  
     1.5  class EngineTestIndividualSuite : public EngineTestSuite {
     1.6      public:
     1.7 -        EngineTestIndividualSuite(string suitename, string test_home_dir);
     1.8 +        EngineTestIndividualSuite(string suitename, string test_home_dir,
     1.9 +                                  bool make_default_device = true);
    1.10          virtual ~EngineTestIndividualSuite();
    1.11      protected:
    1.12          virtual void setup();
     2.1 --- a/test/include/pEpTestDevice.h	Tue Feb 12 14:55:17 2019 +0100
     2.2 +++ b/test/include/pEpTestDevice.h	Tue Feb 12 19:37:34 2019 +0100
     2.3 @@ -17,21 +17,23 @@
     2.4                        inject_sync_event_t inject_sync_ev_func = NULL);        
     2.5                        
     2.6          virtual ~pEpTestDevice();
     2.7 +        void set_mailbox_dir(string mbox_dirname);
     2.8 +
     2.9 +        void set_device_environment();
    2.10 +        void unset_device_environment();
    2.11 +        void grab_context(pEpTestDevice* victim);
    2.12 +
    2.13          string device_name;
    2.14          PEP_SESSION session;
    2.15 +        string device_dir;        
    2.16 +        string root_test_dir;
    2.17 +        string mbox_dir;
    2.18  
    2.19          messageToSend_t device_messageToSend;
    2.20          inject_sync_event_t device_inject_sync_event;
    2.21          
    2.22 -    protected:
    2.23 -        string device_dir;        
    2.24 -        string root_test_dir;
    2.25 -        
    2.26 +//    protected:        
    2.27  //        string current_test_name;
    2.28 -
    2.29 -        void set_device_environment();
    2.30 -        void teardown_device_environment();
    2.31 -        void grab_context();
    2.32          
    2.33  //        void set_full_env();
    2.34  //        void set_full_env(const char* gpg_conf_copy_path, const char* gpg_agent_conf_file_copy_path, const char* db_conf_file_copy_path);
     3.1 --- a/test/src/EngineTestIndividualSuite.cc	Tue Feb 12 14:55:17 2019 +0100
     3.2 +++ b/test/src/EngineTestIndividualSuite.cc	Tue Feb 12 19:37:34 2019 +0100
     3.3 @@ -12,8 +12,10 @@
     3.4  using namespace std;
     3.5  
     3.6  // Constructor
     3.7 -EngineTestIndividualSuite::EngineTestIndividualSuite(string suitename, string test_home_dir) 
     3.8 -    : EngineTestSuite(suitename, test_home_dir) { 
     3.9 +EngineTestIndividualSuite::EngineTestIndividualSuite(string suitename, 
    3.10 +                                                     string test_home_dir,
    3.11 +                                                     bool make_default_device) 
    3.12 +    : EngineTestSuite(suitename, test_home_dir, make_default_device) { 
    3.13  }
    3.14  
    3.15  EngineTestIndividualSuite::~EngineTestIndividualSuite() {
     4.1 --- a/test/src/EngineTestSuite.cc	Tue Feb 12 14:55:17 2019 +0100
     4.2 +++ b/test/src/EngineTestSuite.cc	Tue Feb 12 19:37:34 2019 +0100
     4.3 @@ -214,9 +214,9 @@
     4.4      // if (db_conf_file_copy_path)
     4.5      //     copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
     4.6          
     4.7 -    unix_local_db(true);
     4.8 -    gpg_conf(true);
     4.9 -    gpg_agent_conf(true);
    4.10 +    // unix_local_db(true);
    4.11 +    // gpg_conf(true);
    4.12 +    // gpg_agent_conf(true);
    4.13      
    4.14  //    cout << "calling init()\n";
    4.15  //     PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
    4.16 @@ -267,9 +267,9 @@
    4.17          throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");
    4.18      // else
    4.19      //     cout << "RESTORE: HOME is now " << getenv("HOME") << endl;
    4.20 -    unix_local_db(true);
    4.21 -    gpg_conf(true);
    4.22 -    gpg_agent_conf(true);
    4.23 +    // unix_local_db(true);
    4.24 +    // gpg_conf(true);
    4.25 +    // gpg_agent_conf(true);
    4.26  
    4.27  }
    4.28  
     5.1 --- a/test/src/SuiteMaker.cc	Tue Feb 12 14:55:17 2019 +0100
     5.2 +++ b/test/src/SuiteMaker.cc	Tue Feb 12 19:37:34 2019 +0100
     5.3 @@ -48,6 +48,7 @@
     5.4  #include "CheckRenewedExpiredKeyTrustStatusTests.h"
     5.5  #include "TrustwordsTests.h"
     5.6  #include "SimpleBodyNotAltTests.h"
     5.7 +#include "DeviceModelTests.h"
     5.8  #include "ReencryptPlusExtraKeysTests.h"
     5.9  #include "MapAsn1Tests.h"
    5.10  #include "DecorateTests.h"
    5.11 @@ -99,6 +100,7 @@
    5.12      "CheckRenewedExpiredKeyTrustStatusTests",
    5.13      "TrustwordsTests",
    5.14      "SimpleBodyNotAltTests",
    5.15 +    "DeviceModelTests",
    5.16      "ReencryptPlusExtraKeysTests",
    5.17      "MapAsn1Tests",
    5.18      "DecorateTests",
    5.19 @@ -114,7 +116,7 @@
    5.20  };
    5.21  
    5.22  // This file is generated, so magic constants are ok.
    5.23 -int SuiteMaker::num_suites = 48;
    5.24 +int SuiteMaker::num_suites = 49;
    5.25  
    5.26  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    5.27      if (strcmp(test_class_name, "MimeTests") == 0)
    5.28 @@ -189,6 +191,8 @@
    5.29          *test_suite = new TrustwordsTests(test_class_name, test_home);
    5.30      else if (strcmp(test_class_name, "SimpleBodyNotAltTests") == 0)
    5.31          *test_suite = new SimpleBodyNotAltTests(test_class_name, test_home);
    5.32 +    else if (strcmp(test_class_name, "DeviceModelTests") == 0)
    5.33 +        *test_suite = new DeviceModelTests(test_class_name, test_home);
    5.34      else if (strcmp(test_class_name, "ReencryptPlusExtraKeysTests") == 0)
    5.35          *test_suite = new ReencryptPlusExtraKeysTests(test_class_name, test_home);
    5.36      else if (strcmp(test_class_name, "MapAsn1Tests") == 0)
     6.1 --- a/test/src/pEpTestDevice.cc	Tue Feb 12 14:55:17 2019 +0100
     6.2 +++ b/test/src/pEpTestDevice.cc	Tue Feb 12 19:37:34 2019 +0100
     6.3 @@ -1,14 +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  #include <fstream>
    6.12  #include <iostream>
    6.13  #include <sys/types.h>
    6.14 -#include <sys/stat.h>
    6.15  
    6.16  #include <string>
    6.17  #include <vector>
    6.18 @@ -39,7 +37,9 @@
    6.19  }
    6.20  
    6.21  pEpTestDevice::~pEpTestDevice() {
    6.22 -    teardown_device_environment();
    6.23 +    unset_device_environment();
    6.24 +    // FIXME: Remove homedir
    6.25 +    nftw((device_dir).c_str(), util_delete_filepath, 100, FTW_DEPTH);
    6.26  }
    6.27  
    6.28  void pEpTestDevice::set_device_environment() {
    6.29 @@ -102,37 +102,41 @@
    6.30      assert(session);
    6.31  }
    6.32  
    6.33 -void pEpTestDevice::grab_context() {
    6.34 -    int success = system("gpgconf --kill all");
    6.35 -    if (success != 0)
    6.36 -        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
    6.37 -    struct stat buf;
    6.38 -
    6.39 -    success = system("gpgconf --remove-socketdir");            
    6.40 -    if (success != 0)
    6.41 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
    6.42 -        
    6.43 -    success = setenv("GNUPGHOME", (device_dir + "/gnupg").c_str(), 1);
    6.44 -
    6.45 -    if (success != 0)
    6.46 -        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
    6.47 -
    6.48 -    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
    6.49 -
    6.50 -    success = setenv("HOME", device_dir.c_str(), 1);
    6.51 -    if (success != 0)
    6.52 -        throw std::runtime_error("SETUP: Cannot set device_dir for init.");
    6.53 -            
    6.54 -#ifndef USE_NETPGP            
    6.55 -    success = system("gpgconf --create-socketdir");
    6.56 -    if (success != 0)
    6.57 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
    6.58 -    system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
    6.59 -#endif
    6.60 +void pEpTestDevice::grab_context(pEpTestDevice* victim) {
    6.61 +    victim->unset_device_environment();
    6.62 +    set_device_environment();
    6.63 +// 
    6.64 +//     int success = system("gpgconf --kill all");
    6.65 +//     if (success != 0)
    6.66 +//         throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
    6.67 +//     struct stat buf;
    6.68 +// 
    6.69 +//     success = system("gpgconf --remove-socketdir");            
    6.70 +//     if (success != 0)
    6.71 +//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
    6.72 +// 
    6.73 +//     success = setenv("GNUPGHOME", (device_dir + "/gnupg").c_str(), 1);
    6.74 +// 
    6.75 +//     if (success != 0)
    6.76 +//         throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
    6.77 +// 
    6.78 +//     cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
    6.79 +// 
    6.80 +//     success = setenv("HOME", device_dir.c_str(), 1);
    6.81 +//     if (success != 0)
    6.82 +//         throw std::runtime_error("SETUP: Cannot set device_dir for init.");
    6.83 +// 
    6.84 +// w#ifndef USE_NETPGP            
    6.85 +//     success = system("gpgconf --create-socketdir");
    6.86 +//     if (success != 0)
    6.87 +//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
    6.88 +//     system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
    6.89 +// #endif
    6.90  }
    6.91  
    6.92 -void pEpTestDevice::teardown_device_environment() {
    6.93 -    release(session);
    6.94 +void pEpTestDevice::unset_device_environment() {
    6.95 +    if (session)
    6.96 +        release(session);
    6.97      session = NULL;
    6.98          
    6.99      int success = 0;    
   6.100 @@ -146,8 +150,23 @@
   6.101          throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
   6.102  #endif
   6.103  
   6.104 -    // FIXME: Remove homedir
   6.105      unix_local_db(true);
   6.106      gpg_conf(true);
   6.107      gpg_agent_conf(true);
   6.108  }
   6.109 +
   6.110 +void pEpTestDevice::set_mailbox_dir(string mbox_dirname) {
   6.111 +    mbox_dir = mbox_dirname;
   6.112 +    struct stat dirchk;
   6.113 +    
   6.114 +    if (stat(mbox_dir.c_str(), &dirchk) == 0) {
   6.115 +        if (!S_ISDIR(dirchk.st_mode))
   6.116 +            throw std::runtime_error(("The mbox directory, " + device_dir + "exists, but is not a directory.").c_str());                     
   6.117 +    }
   6.118 +    else {
   6.119 +        int errchk = mkdir(mbox_dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
   6.120 +        cout << errchk << endl;
   6.121 +        if (errchk != 0)
   6.122 +            throw std::runtime_error("Error creating an mbox directory.");
   6.123 +    }    
   6.124 +}