ENGINE-427: tests in, but aren't quite passing yet, so need to see if tests or code are broken ENGINE-427
authorKrista Bennett <krista@pep-project.org>
Thu, 28 Jun 2018 11:10:07 +0200
branchENGINE-427
changeset 27825be6494a85ae
parent 2781 50318bebf6ef
child 2783 83dafb06379c
ENGINE-427: tests in, but aren't quite passing yet, so need to see if tests or code are broken
test/include/EngineTestSuite.h
test/include/GPGConfFixTests.h
test/src/EngineTestSuite.cc
test/src/SuiteMaker.cc
test/src/engine_tests/GPGConfFixTests.cc
test/test_files/427_fixed_gpg_conf_0
test/test_files/427_fixed_gpg_conf_1
test/test_files/427_fixed_gpg_conf_2
test/test_files/427_fixed_gpg_conf_3
test/test_files/427_fixed_gpg_conf_4
test/test_files/427_fixed_gpg_conf_5
test/test_files/427_fixed_gpg_conf_6
     1.1 --- a/test/include/EngineTestSuite.h	Thu Jun 28 08:20:18 2018 +0200
     1.2 +++ b/test/include/EngineTestSuite.h	Thu Jun 28 11:10:07 2018 +0200
     1.3 @@ -34,15 +34,17 @@
     1.4          unsigned int number_of_tests;
     1.5          unsigned int on_test_number;
     1.6          
     1.7 +        string temp_test_home;
     1.8 +        
     1.9          virtual void setup();
    1.10          virtual void tear_down();
    1.11          
    1.12          void set_full_env();
    1.13 -	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);
    1.14 +	    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);
    1.15          void restore_full_env();
    1.16          void initialise_test_home();
    1.17          void set_my_name();    
    1.18  	
    1.19 -	void copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name);
    1.20 +	    void copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name);
    1.21  };
    1.22  #endif
     2.1 --- a/test/include/GPGConfFixTests.h	Thu Jun 28 08:20:18 2018 +0200
     2.2 +++ b/test/include/GPGConfFixTests.h	Thu Jun 28 11:10:07 2018 +0200
     2.3 @@ -17,7 +17,13 @@
     2.4  	void setup();
     2.5  
     2.6      private:
     2.7 -        void check_g_p_g_conf_fix();
     2.8 +        void check_conf_fix_broken_conf_old_db_0();
     2.9 +        void check_conf_fix_broken_conf_old_db_1();
    2.10 +        void check_conf_fix_broken_conf_old_db_2();
    2.11 +        void check_conf_fix_broken_conf_old_db_3();
    2.12 +        void check_conf_fix_broken_conf_old_db_4();
    2.13 +        void check_conf_fix_broken_conf_old_db_5();
    2.14 +        void check_conf_fix_broken_conf_old_db_6();        
    2.15  };
    2.16  
    2.17  #endif
     3.1 --- a/test/src/EngineTestSuite.cc	Thu Jun 28 08:20:18 2018 +0200
     3.2 +++ b/test/src/EngineTestSuite.cc	Thu Jun 28 11:10:07 2018 +0200
     3.3 @@ -7,6 +7,8 @@
     3.4  #include <assert.h>
     3.5  #include <fstream>
     3.6  #include <iostream>
     3.7 +#include <sys/types.h>
     3.8 +#include <sys/stat.h>
     3.9  
    3.10  #include "platform_unix.h"
    3.11  
    3.12 @@ -33,14 +35,28 @@
    3.13  }
    3.14  
    3.15  void EngineTestSuite::copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name) {
    3.16 -    string conf_dest_path = dest_path + "/" + conf_dest_name;
    3.17 +    string conf_dest_path = dest_path;
    3.18 +    
    3.19 +    struct stat pathinfo;
    3.20 +
    3.21 +    if(stat(conf_dest_path.c_str(), &pathinfo) != 0) {
    3.22 +        int errchk = mkdir(conf_dest_path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    3.23 +        if (errchk != 0)
    3.24 +            throw std::runtime_error("Error accessing conf file directory.");
    3.25 +    }
    3.26 +    
    3.27 +    conf_dest_path += "/";
    3.28 +    conf_dest_path += conf_dest_name;
    3.29 +    
    3.30      ifstream src(conf_orig_path);
    3.31 -    ofstream dst(conf_dest_path, ios::trunc);
    3.32 -    assert(src && dst);
    3.33 +    ofstream dst(conf_dest_path.c_str(), ios::trunc);
    3.34 +    
    3.35 +    assert(src);
    3.36 +    assert(dst);
    3.37      
    3.38      dst << src.rdbuf();
    3.39       
    3.40 -    src.close()
    3.41 +    src.close();
    3.42      dst.close();
    3.43  }
    3.44  
    3.45 @@ -77,7 +93,7 @@
    3.46              throw std::runtime_error("Error creating a test directory.");
    3.47      }
    3.48  
    3.49 -    string temp_test_home = test_home + "/" + my_name;
    3.50 +    temp_test_home = test_home + "/" + my_name;
    3.51      
    3.52      int errchk = mkdir(temp_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    3.53      if (errchk != 0)
    3.54 @@ -103,7 +119,7 @@
    3.55      cout << "home is " << home << endl;
    3.56      assert(temp_test_home.compare(home) != 0);
    3.57      assert(temp_test_home.compare(home + "/") != 0);
    3.58 -    assert(temp_test_home.compare(home + "/.gnupg") != 0);
    3.59 +    assert(temp_test_home.compare(home + "") != 0);
    3.60      assert(temp_test_home.compare(home + ".gnupg") != 0);
    3.61      assert(temp_test_home.compare(prev_gpg_home) != 0);
    3.62      assert(temp_test_home.compare(prev_gpg_home + "/.gnupg") != 0);
    3.63 @@ -130,11 +146,11 @@
    3.64          throw std::runtime_error("SETUP: Cannot set test_home for init.");
    3.65  
    3.66      if (gpg_conf_copy_path)
    3.67 -        copy_conf_file_to_test_dir(temp_test_home + "/.gnupg", gpg_conf_copy_path, "gpg.conf")
    3.68 +        copy_conf_file_to_test_dir((temp_test_home + "/.gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
    3.69      if (gpg_agent_conf_file_copy_path)        
    3.70 -        copy_conf_file_to_test_dir(temp_test_home + "/.gnupg", gpg_agent_conf_file_copy_path, "gpg-agent.conf")
    3.71 +        copy_conf_file_to_test_dir((temp_test_home + "/.gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
    3.72      if (db_conf_file_copy_path)
    3.73 -        copy copy_conf_file_to_test_dir(temp_test_home, db_conf_file_copy_path, ".pEp_management.db");
    3.74 +        copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
    3.75          
    3.76      unix_local_db(true);
    3.77      gpg_conf(true);
     4.1 --- a/test/src/SuiteMaker.cc	Thu Jun 28 08:20:18 2018 +0200
     4.2 +++ b/test/src/SuiteMaker.cc	Thu Jun 28 11:10:07 2018 +0200
     4.3 @@ -39,6 +39,7 @@
     4.4  #include "NewUpdateIdAndMyselfTests.h"
     4.5  #include "StringlistTests.h"
     4.6  #include "LeastColorGroupTests.h"
     4.7 +#include "GPGConfFixTests.h"
     4.8  #include "ExternalRevokeTests.h"
     4.9  #include "EncryptForIdentityTests.h"
    4.10  #include "TrustwordsTests.h"
    4.11 @@ -78,6 +79,7 @@
    4.12      "NewUpdateIdAndMyselfTests",
    4.13      "StringlistTests",
    4.14      "LeastColorGroupTests",
    4.15 +    "GPGConfFixTests",
    4.16      "ExternalRevokeTests",
    4.17      "EncryptForIdentityTests",
    4.18      "TrustwordsTests",
    4.19 @@ -90,7 +92,7 @@
    4.20  };
    4.21  
    4.22  // This file is generated, so magic constants are ok.
    4.23 -int SuiteMaker::num_suites = 36;
    4.24 +int SuiteMaker::num_suites = 37;
    4.25  
    4.26  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    4.27      if (strcmp(test_class_name, "MapAsn1Tests") == 0)
    4.28 @@ -147,6 +149,8 @@
    4.29          *test_suite = new StringlistTests(test_class_name, test_home);
    4.30      else if (strcmp(test_class_name, "LeastColorGroupTests") == 0)
    4.31          *test_suite = new LeastColorGroupTests(test_class_name, test_home);
    4.32 +    else if (strcmp(test_class_name, "GPGConfFixTests") == 0)
    4.33 +        *test_suite = new GPGConfFixTests(test_class_name, test_home);
    4.34      else if (strcmp(test_class_name, "ExternalRevokeTests") == 0)
    4.35          *test_suite = new ExternalRevokeTests(test_class_name, test_home);
    4.36      else if (strcmp(test_class_name, "EncryptForIdentityTests") == 0)
     5.1 --- a/test/src/engine_tests/GPGConfFixTests.cc	Thu Jun 28 08:20:18 2018 +0200
     5.2 +++ b/test/src/engine_tests/GPGConfFixTests.cc	Thu Jun 28 11:10:07 2018 +0200
     5.3 @@ -3,6 +3,8 @@
     5.4  
     5.5  #include <stdlib.h>
     5.6  #include <string>
     5.7 +#include <iostream>
     5.8 +#include <fstream>
     5.9  
    5.10  #include "pEpEngine.h"
    5.11  
    5.12 @@ -11,8 +13,8 @@
    5.13  
    5.14  using namespace std;
    5.15  
    5.16 -GPGConfFixTests::GPGConfFixTests(string suitename, string test_home_dir) :
    5.17 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    5.18 +GPGConfFixTests::GPGConfFixTests(string suitename, string temp_test_home_dir) :
    5.19 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, temp_test_home_dir) {
    5.20      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("GPGConfFixTests::check_conf_fix_broken_conf_old_db_0"),
    5.21                                                                        static_cast<Func>(&GPGConfFixTests::check_conf_fix_broken_conf_old_db_0)));
    5.22      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("GPGConfFixTests::check_conf_fix_broken_conf_old_db_1"),
    5.23 @@ -33,31 +35,61 @@
    5.24      EngineTestSuite::setup();
    5.25  }
    5.26  
    5.27 +static bool file_bytes_equal(const char* file_path_1, const char* file_path_2) {
    5.28 +    ifstream f1(file_path_1);
    5.29 +    ifstream f2(file_path_2);
    5.30 +
    5.31 +    char c1, c2;
    5.32 +    
    5.33 +    while (f1.get(c1)) {
    5.34 +        if (f2.get(c2)) {
    5.35 +            if (c1 != c2)
    5.36 +                return false;
    5.37 +        }
    5.38 +        else {
    5.39 +            return false;
    5.40 +        }        
    5.41 +    }
    5.42 +    if (f2.get(c2))
    5.43 +        return false;
    5.44 +    
    5.45 +    return true;
    5.46 +    
    5.47 +}
    5.48 +
    5.49  void GPGConfFixTests::check_conf_fix_broken_conf_old_db_0() {
    5.50      set_full_env("test_files/427_bad_gpg_conf_0", NULL, "test_files/427_old_db");
    5.51 +    TEST_ASSERT(file_bytes_equal("test_files/427_fixed_gpg_conf_0", (temp_test_home + "/.gnupg/gpg.conf").c_str()));
    5.52  }
    5.53  
    5.54  void GPGConfFixTests::check_conf_fix_broken_conf_old_db_1() {
    5.55      set_full_env("test_files/427_bad_gpg_conf_1", NULL, "test_files/427_old_db");    
    5.56 +    TEST_ASSERT(file_bytes_equal("test_files/427_fixed_gpg_conf_1", (temp_test_home + "/.gnupg/gpg.conf").c_str()));
    5.57 +    
    5.58  }
    5.59  
    5.60  void GPGConfFixTests::check_conf_fix_broken_conf_old_db_2() {
    5.61      set_full_env("test_files/427_bad_gpg_conf_2", NULL, "test_files/427_old_db");        
    5.62 +    TEST_ASSERT(file_bytes_equal("test_files/427_fixed_gpg_conf_2", (temp_test_home + "/.gnupg/gpg.conf").c_str()));    
    5.63  }
    5.64  
    5.65 -void GPGConfFixTests::check_conf_fix_broken_conf_old_db_3()() {
    5.66 +void GPGConfFixTests::check_conf_fix_broken_conf_old_db_3() {
    5.67      set_full_env("test_files/427_bad_gpg_conf_3", NULL, "test_files/427_old_db");    
    5.68 +    TEST_ASSERT(file_bytes_equal("test_files/427_fixed_gpg_conf_3", (temp_test_home + "/.gnupg/gpg.conf").c_str()));    
    5.69  }
    5.70  
    5.71  void GPGConfFixTests::check_conf_fix_broken_conf_old_db_4() {
    5.72      set_full_env("test_files/427_bad_gpg_conf_4", NULL, "test_files/427_old_db");        
    5.73 +    TEST_ASSERT(file_bytes_equal("test_files/427_fixed_gpg_conf_4", (temp_test_home + "/.gnupg/gpg.conf").c_str()));    
    5.74  }
    5.75  
    5.76  void GPGConfFixTests::check_conf_fix_broken_conf_old_db_5() {
    5.77      set_full_env("test_files/427_bad_gpg_conf_5", NULL, "test_files/427_old_db");        
    5.78 +    TEST_ASSERT(file_bytes_equal("test_files/427_fixed_gpg_conf_5", (temp_test_home + "/.gnupg/gpg.conf").c_str()));    
    5.79  }
    5.80  
    5.81  void GPGConfFixTests::check_conf_fix_broken_conf_old_db_6() {
    5.82      set_full_env("test_files/427_bad_gpg_conf_6", NULL, "test_files/427_old_db");        
    5.83 +    TEST_ASSERT(file_bytes_equal("test_files/427_fixed_gpg_conf_6", (temp_test_home + "/.gnupg/gpg.conf").c_str()));    
    5.84  }
    5.85  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/test_files/427_fixed_gpg_conf_0	Thu Jun 28 11:10:07 2018 +0200
     6.3 @@ -0,0 +1,2 @@
     6.4 +personal-cipher-preferences AES 
     6.5 +no-emit-version
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/test_files/427_fixed_gpg_conf_1	Thu Jun 28 11:10:07 2018 +0200
     7.3 @@ -0,0 +1,5 @@
     7.4 +comment No Comment
     7.5 +keyid-format 0xlong
     7.6 +ignore-time-conflict 
     7.7 +personal-cipher-preferences AES 
     7.8 +allow-freeform-uid
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/test_files/427_fixed_gpg_conf_2	Thu Jun 28 11:10:07 2018 +0200
     8.3 @@ -0,0 +1,5 @@
     8.4 +comment No Comment
     8.5 +allow-freeform-uid
     8.6 +keyid-format 0xlong
     8.7 +ignore-time-conflict 
     8.8 +personal-cipher-preferences AES 
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/test_files/427_fixed_gpg_conf_3	Thu Jun 28 11:10:07 2018 +0200
     9.3 @@ -0,0 +1,5 @@
     9.4 +comment No Comment
     9.5 +allow-freeform-uid
     9.6 +keyid-format 0xlong
     9.7 +ignore-time-conflict 
     9.8 +personal-cipher-preferences AES 
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/test_files/427_fixed_gpg_conf_4	Thu Jun 28 11:10:07 2018 +0200
    10.3 @@ -0,0 +1,6 @@
    10.4 +comment No Comment
    10.5 +allow-freeform-uid
    10.6 +default-cache-ttl ignore-time-conflict-butts
    10.7 +keyid-format 0xlong
    10.8 +ignore-time-conflict 
    10.9 +personal-cipher-preferences AES 
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/test_files/427_fixed_gpg_conf_5	Thu Jun 28 11:10:07 2018 +0200
    11.3 @@ -0,0 +1,5 @@
    11.4 +comment No Comment
    11.5 +allow-freeform-uid
    11.6 +keyid-format 0xlong
    11.7 +ignore-time-conflict 
    11.8 +personal-cipher-preferences AES 
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/test_files/427_fixed_gpg_conf_6	Thu Jun 28 11:10:07 2018 +0200
    12.3 @@ -0,0 +1,1 @@
    12.4 +allow-freeform-uid