Fixed pathlength problems for MacOS tests: sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 14 Jan 2019 13:00:09 +0100
branchsync
changeset 321803a18842da11
parent 3214 79dacdb24a4b
child 3219 96ff8b710a0b
child 3220 d7b4ac90ce77
Fixed pathlength problems for MacOS tests:
test/include/EngineTestSuite.h
test/include/pEpTestStatic.h
test/src/EngineTestSuite.cc
test/src/TestDriver.cc
test/src/engine_tests/EncryptAttachPrivateKeyTests.cc
test/src/engine_tests/LeastCommonDenomColorTests.cc
test/src/pEpTestStatic.cc
     1.1 --- a/test/include/EngineTestSuite.h	Thu Jan 10 18:57:53 2019 +0100
     1.2 +++ b/test/include/EngineTestSuite.h	Mon Jan 14 13:00:09 2019 +0100
     1.3 @@ -59,6 +59,5 @@
     1.4          void add_file_to_gpg_dir_queue(std::string copy_from, std::string dst_fname);    
     1.5          void add_file_to_home_dir_queue(std::string copy_from, std::string dst_fname);
     1.6          void process_file_queue(std::string dirname, std::vector<std::pair<std::string, std::string>> file_queue);
     1.7 -
     1.8  };
     1.9  #endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/include/pEpTestStatic.h	Mon Jan 14 13:00:09 2019 +0100
     2.3 @@ -0,0 +1,25 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#ifndef PEP_TEST_STATIC_H
     2.8 +#define PEP_TEST_STATIC_H
     2.9 +
    2.10 +#include <string>
    2.11 +
    2.12 +using namespace std;
    2.13 +
    2.14 +class pEpTestStatic {
    2.15 +    public:
    2.16 +        static size_t getMaxPathSize();
    2.17 +        static size_t sun_path_size;
    2.18 +        static size_t getAvailablePathChars(string keypath_str);
    2.19 +        static size_t available_path_chars;
    2.20 +        static const size_t classname_chars;
    2.21 +        static const size_t testnum_path_chars;
    2.22 +        static const size_t max_test_num;
    2.23 +
    2.24 +    private:
    2.25 +        pEpTestStatic() {};
    2.26 +};
    2.27 +
    2.28 +#endif
     3.1 --- a/test/src/EngineTestSuite.cc	Thu Jan 10 18:57:53 2019 +0100
     3.2 +++ b/test/src/EngineTestSuite.cc	Mon Jan 14 13:00:09 2019 +0100
     3.3 @@ -18,6 +18,8 @@
     3.4  
     3.5  #include "test_util.h"
     3.6  #include "EngineTestSuite.h"
     3.7 +#include "pEpTestStatic.h"
     3.8 +#include <algorithm>
     3.9  
    3.10  using namespace std;
    3.11  
    3.12 @@ -98,11 +100,11 @@
    3.13      
    3.14      set_my_name();
    3.15  
    3.16 +// FIXME
    3.17  #ifndef USE_NETPGP
    3.18      success = system("gpgconf --kill all");
    3.19      if (success != 0)
    3.20          throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");
    3.21 - //   sleep(1); // hopefully enough time for the system to recognise that it is dead. *sigh*    
    3.22  #endif
    3.23  
    3.24      if (stat(test_home.c_str(), &dirchk) == 0) {
    3.25 @@ -122,6 +124,16 @@
    3.26              throw std::runtime_error("Error creating a test directory.");
    3.27      }
    3.28  
    3.29 +    if (my_name.size() > pEpTestStatic::classname_chars)
    3.30 +        my_name.resize(pEpTestStatic::classname_chars);
    3.31 +
    3.32 +    if (on_test_number > pEpTestStatic::max_test_num) {
    3.33 +        cerr << "Warning - there are at least " << pEpTestStatic::max_test_num << " tests in this suite. While this probably won't cause "
    3.34 +             << endl << "problems, there is an obscure possibility that if your test path is REALLY REALLY LONG, tests will fail because gpg-agent "
    3.35 +             << endl << "won't start with huge paths. In general, however, we stop well before these limits, and pEpTestStatic::testnum_path_chars "
    3.36 +             << endl << "is overly conservative, so you probably don't need to worry." << endl;
    3.37 +    }    
    3.38 +
    3.39      temp_test_home = test_home + "/" + my_name;
    3.40      
    3.41      int errchk = mkdir(temp_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    3.42 @@ -134,7 +146,6 @@
    3.43      if (errchk != 0)
    3.44          throw std::runtime_error("Error creating a test directory.");
    3.45  
    3.46 -
    3.47      // TODO: This is *nix specific, which the current testing env is anyway,
    3.48      // but it needn't remain so forever and always
    3.49  
    3.50 @@ -205,6 +216,8 @@
    3.51      
    3.52  //    cout << "calling init()\n";
    3.53      PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
    3.54 +    system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
    3.55 +
    3.56      assert(status == PEP_STATUS_OK);
    3.57      assert(session);
    3.58  //    cout << "init() completed.\n";
     4.1 --- a/test/src/TestDriver.cc	Thu Jan 10 18:57:53 2019 +0100
     4.2 +++ b/test/src/TestDriver.cc	Mon Jan 14 13:00:09 2019 +0100
     4.3 @@ -15,6 +15,7 @@
     4.4  #include "EngineTestIndividualSuite.h"
     4.5  #include "EngineTestSessionSuite.h"
     4.6  #include "SuiteMaker.h"
     4.7 +#include "pEpTestStatic.h"
     4.8  
     4.9  using namespace std;
    4.10  
    4.11 @@ -38,7 +39,21 @@
    4.12          throw std::runtime_error("Error grabbing current working directory"); 
    4.13  
    4.14      common_test_home = curr_wd + "/pEp_test_home";    
    4.15 +
    4.16 +    // Note: THIS IS BRITTLE. If you're trying on a new platform and it fails, it's because C++ names may be mangled differently
    4.17 +    // and other platforms may have other requirements. Start by checking maximum socket path lengths...
    4.18 +    // We need at least size for 3 chars of unique class dir, 3 chars of test number, 5 chars for "gnupg", for "S.gpg-agent", plus
    4.19 +    // slashes. This is really just because gpg-agent fails on MacOS because of a shorter sun_path max.
    4.20      
    4.21 +    // fixme = "gnupg" needs to be made central
    4.22 +    string keypath_str = "gnupg";
    4.23 +
    4.24 +    if (common_test_home.size() > pEpTestStatic::getAvailablePathChars(keypath_str)) {
    4.25 +        cerr << "Test home path size too long. Please notify the devs that this finally broke." 
    4.26 +             << " In the meantime, try modifying common_test_home here in TestDriver.cc and hope nothing breaks" << endl;
    4.27 +        throw -127;
    4.28 +    }     
    4.29 +
    4.30      EngineTestSuite* test_runner = new EngineTestSuite("MainTestDriver", common_test_home);
    4.31  
    4.32      std::vector<Test::Suite*> suites_to_run;
     5.1 --- a/test/src/engine_tests/EncryptAttachPrivateKeyTests.cc	Thu Jan 10 18:57:53 2019 +0100
     5.2 +++ b/test/src/engine_tests/EncryptAttachPrivateKeyTests.cc	Mon Jan 14 13:00:09 2019 +0100
     5.3 @@ -56,42 +56,42 @@
     5.4      // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
     5.5      input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
     5.6      status = import_key(session, input_key.c_str(), input_key.length(), NULL);
     5.7 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
     5.8 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
     5.9  
    5.10      input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0x3276D2E5_priv.asc");
    5.11      status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.12 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.13 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.14          
    5.15      // key with same address and user_id (initially untrusted, then trusted)
    5.16      // 359DD8AC87D1F5E4304D08338D7185F180C8CD87
    5.17      input_key = slurp("test_keys/pub/priv-key-import-test-main_1-0x80C8CD87_pub.asc");
    5.18      status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.19 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.20 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.21  
    5.22      // key with same address and to have different (non-aliased) user_id (initially untrusted, then trusted)
    5.23      // B044B83639E292283A3F6E14C2E64B520B74809C
    5.24      input_key = slurp("test_keys/pub/priv-key-import-test-main_2-0x0B74809C_pub.asc");
    5.25      status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.26 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.27 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.28  
    5.29      // key with different address to have same user_id (initially untrusted, then trusted)
    5.30      // C52911EBA0D34B0F549594A15A7A363BD11252C9
    5.31      input_key = slurp("test_keys/pub/priv-key-import-test-other_0-0xD11252C9_pub.asc");
    5.32      status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.33 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.34 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.35          
    5.36      // key with different address to have different user_id (initially untrusted, then trusted)
    5.37      // 567212EFB8A3A76B1D32B9565F45BEA9C785F20A
    5.38      input_key = slurp("test_keys/pub/priv-key-import-test-other_1-0xC785F20A_pub.asc");
    5.39      status = import_key(session, input_key.c_str(), input_key.length(), NULL);
    5.40 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.41 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.42      cout << "Done!" << endl << endl;
    5.43      
    5.44      cout << "Setting up own identity with default key " << fpr_main_me << endl;
    5.45      // Own identity with default key etc
    5.46      main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
    5.47      status = set_own_key(session, main_me, fpr_main_me);
    5.48 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.49 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.50  
    5.51      TEST_ASSERT_MSG((strcmp(main_me->fpr, fpr_main_me) == 0), "strcmp(main_me->fpr, fpr_main_me) == 0");
    5.52      cout << "Done!" << endl << endl;
    5.53 @@ -163,7 +163,7 @@
    5.54      cout << "Case 2: Same address, same user_id, trusted" << endl;
    5.55      status = trust_personal_key(session, same_addr_same_uid);
    5.56      cout << "Trust personal key for " << same_addr_same_uid << " gives status " << tl_status_string(status) << " (" << status << ")" << endl;
    5.57 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.58 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.59      message* enc_same_addr_same_uid_trusted = NULL;
    5.60      status = encrypt_message_and_add_priv_key(session,
    5.61                                                msg_same_addr_same_uid,
    5.62 @@ -173,7 +173,7 @@
    5.63                                                0);
    5.64  
    5.65      cout << "Case 2 Status: " << tl_status_string(status) << endl;
    5.66 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.67 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.68      cout << "PASS!" << endl;
    5.69  
    5.70      // Case 3:
    5.71 @@ -198,7 +198,7 @@
    5.72      // Different address, same user_id, trusted
    5.73      cout << "Case 4: Different address, same user_id, trusted" << endl;
    5.74      status = trust_personal_key(session, diff_addr_same_uid);
    5.75 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.76 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.77      message* enc_diff_addr_same_uid_trusted = NULL;
    5.78      status = encrypt_message_and_add_priv_key(session,
    5.79                                                msg_diff_addr_same_uid,
    5.80 @@ -233,7 +233,7 @@
    5.81      // Same address, different user_id, trusted
    5.82      cout << "Case 6: Same address, different user_id, trusted" << endl;        
    5.83      status = trust_personal_key(session, same_addr_diff_uid);
    5.84 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.85 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.86      message* enc_same_addr_diff_uid_trusted = NULL;
    5.87      status = encrypt_message_and_add_priv_key(session,
    5.88                                                msg_same_addr_diff_uid,
    5.89 @@ -268,7 +268,7 @@
    5.90      // Different address, different user_id, trusted
    5.91      cout << "Case 8: Different address, different user_id, trusted" << endl;    
    5.92      status = trust_personal_key(session, diff_addr_diff_uid);
    5.93 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    5.94 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    5.95      message* enc_diff_addr_diff_uid_trusted = NULL;
    5.96      status = encrypt_message_and_add_priv_key(session,
    5.97                                                msg_diff_addr_diff_uid,
     6.1 --- a/test/src/engine_tests/LeastCommonDenomColorTests.cc	Thu Jan 10 18:57:53 2019 +0100
     6.2 +++ b/test/src/engine_tests/LeastCommonDenomColorTests.cc	Mon Jan 14 13:00:09 2019 +0100
     6.3 @@ -68,12 +68,12 @@
     6.4      PEP_decrypt_flags_t flags;
     6.5      
     6.6      status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
     6.7 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
     6.8 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
     6.9      TEST_ASSERT_MSG((msg_ptr), "msg_ptr");
    6.10  
    6.11      flags = 0;
    6.12      status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    6.13 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    6.14 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    6.15      TEST_ASSERT_MSG((dest_msg), "dest_msg");
    6.16      /* message is signed and no recip is mistrusted... */
    6.17      TEST_ASSERT_MSG((color_from_rating(rating) == PEP_color_yellow), "color_from_rating(rating) == PEP_color_yellow");
    6.18 @@ -86,12 +86,12 @@
    6.19      
    6.20      /* re-evaluate rating, counting on optional fields */
    6.21      status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
    6.22 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    6.23 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    6.24      TEST_ASSERT_MSG((color_from_rating(rating) == PEP_color_yellow), "color_from_rating(rating) == PEP_color_yellow");
    6.25  
    6.26      /* re-evaluate rating, without optional fields */
    6.27      status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
    6.28 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    6.29 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    6.30      TEST_ASSERT_MSG((color_from_rating(rating) == PEP_color_yellow), "color_from_rating(rating) == PEP_color_yellow");
    6.31  
    6.32      /* Ok, now mistrust one recip */
    6.33 @@ -99,12 +99,12 @@
    6.34  
    6.35      /* re-evaluate rating, counting on optional fields */
    6.36      status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
    6.37 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    6.38 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    6.39      TEST_ASSERT_MSG((color_from_rating(rating) == PEP_color_red), "color_from_rating(rating) == PEP_color_red");
    6.40  
    6.41      /* re-evaluate rating, without optional fields */
    6.42      status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
    6.43 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    6.44 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    6.45      TEST_ASSERT_MSG((color_from_rating(rating) == PEP_color_red), "color_from_rating(rating) == PEP_color_red");
    6.46  
    6.47      free_message(dest_msg);
    6.48 @@ -117,7 +117,7 @@
    6.49      rating = PEP_rating_unreliable;
    6.50  
    6.51      status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    6.52 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    6.53 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    6.54      TEST_ASSERT_MSG((msg_ptr), "msg_ptr");
    6.55      flags = 0;
    6.56      status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    6.57 @@ -137,4 +137,6 @@
    6.58      dest_msg = nullptr;
    6.59      keylist = nullptr;
    6.60      rating = PEP_rating_unreliable;
    6.61 +
    6.62 +    TEST_ASSERT(true);
    6.63  }
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/src/pEpTestStatic.cc	Mon Jan 14 13:00:09 2019 +0100
     7.3 @@ -0,0 +1,30 @@
     7.4 +#include <stdlib.h>
     7.5 +#include <sys/un.h>
     7.6 +
     7.7 +#include "pEpTestStatic.h"
     7.8 +#include <math.h>
     7.9 +#include <string>
    7.10 +
    7.11 +using namespace std;
    7.12 +
    7.13 +size_t pEpTestStatic::sun_path_size = 0;
    7.14 +size_t pEpTestStatic::available_path_chars = 0;
    7.15 +
    7.16 +const size_t pEpTestStatic::classname_chars = 6;
    7.17 +const size_t pEpTestStatic::testnum_path_chars = 4;
    7.18 +const size_t pEpTestStatic::max_test_num = pow(10, pEpTestStatic::testnum_path_chars) - 1;
    7.19 +
    7.20 +size_t pEpTestStatic::getMaxPathSize() {
    7.21 +    if (pEpTestStatic::sun_path_size == 0) {
    7.22 +        struct sockaddr_un s;
    7.23 +        pEpTestStatic::sun_path_size = sizeof(s.sun_path);
    7.24 +    }
    7.25 +    return pEpTestStatic::sun_path_size;
    7.26 +}
    7.27 +
    7.28 +size_t pEpTestStatic::getAvailablePathChars(string keypath_str) {
    7.29 +    if (pEpTestStatic::available_path_chars == 0) {
    7.30 +        available_path_chars = pEpTestStatic::getMaxPathSize() - classname_chars - testnum_path_chars - keypath_str.size() - 4; // slashes
    7.31 +    }
    7.32 +    return pEpTestStatic::available_path_chars;
    7.33 +}