diff options
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/BoxException.h | 3 | ||||
-rw-r--r-- | lib/common/BoxPortsAndFiles.h.in | 4 | ||||
-rw-r--r-- | lib/common/Configuration.cpp | 15 | ||||
-rw-r--r-- | lib/common/Configuration.h | 1 | ||||
-rw-r--r-- | lib/common/FileStream.h | 1 | ||||
-rw-r--r-- | lib/common/Test.cpp | 138 | ||||
-rw-r--r-- | lib/common/Test.h | 10 |
7 files changed, 35 insertions, 137 deletions
diff --git a/lib/common/BoxException.h b/lib/common/BoxException.h index 361f04e8..e3a2268a 100644 --- a/lib/common/BoxException.h +++ b/lib/common/BoxException.h @@ -34,6 +34,9 @@ public: private: }; +#define EXCEPTION_IS_TYPE(exception_obj, type, subtype) \ + (exception_obj.GetType() == type::ExceptionType && \ + exception_obj.GetSubType() == type::subtype) #endif // BOXEXCEPTION__H diff --git a/lib/common/BoxPortsAndFiles.h.in b/lib/common/BoxPortsAndFiles.h.in index 047a828f..f63e614b 100644 --- a/lib/common/BoxPortsAndFiles.h.in +++ b/lib/common/BoxPortsAndFiles.h.in @@ -20,6 +20,10 @@ // directory within the RAIDFILE root for the backup store daemon #define BOX_RAIDFILE_ROOT_BBSTORED "backup" +// default security level if SSLSecurityLevel is not specified: see +// https://github.com/boxbackup/boxbackup/wiki/WeakSSLCertificates +const int BOX_DEFAULT_SSL_SECURITY_LEVEL = -1; + // configuration file paths #ifdef WIN32 // no default config file path, use these macros to call diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp index 8ce8d389..9860864a 100644 --- a/lib/common/Configuration.cpp +++ b/lib/common/Configuration.cpp @@ -470,6 +470,16 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const } +int Configuration::GetKeyValueInt(const std::string& rKeyName, int default_value) const +{ + if(!KeyExists(rKeyName)) + { + return default_value; + } + return GetKeyValueInt(rKeyName); +} + + // -------------------------------------------------------------------------- // // Function @@ -778,8 +788,7 @@ bool Configuration::Verify(const ConfigurationVerify &rVerify, } else if(pvkey->HasDefaultValue()) { - mKeys[pvkey->Name()] = - pvkey->DefaultValue(); + mKeys[pvkey->Name()] = pvkey->DefaultValue(); } } @@ -922,5 +931,3 @@ bool Configuration::Verify(const ConfigurationVerify &rVerify, return ok; } - - diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h index e6498e80..f9b5eb77 100644 --- a/lib/common/Configuration.h +++ b/lib/common/Configuration.h @@ -122,6 +122,7 @@ public: bool KeyExists(const std::string& rKeyName) const; const std::string &GetKeyValue(const std::string& rKeyName) const; int GetKeyValueInt(const std::string& rKeyName) const; + int GetKeyValueInt(const std::string& rKeyName, int default_value) const; uint32_t GetKeyValueUint32(const std::string& rKeyName) const; bool GetKeyValueBool(const std::string& rKeyName) const; std::vector<std::string> GetKeyNames() const; diff --git a/lib/common/FileStream.h b/lib/common/FileStream.h index 1426d8a2..26442212 100644 --- a/lib/common/FileStream.h +++ b/lib/common/FileStream.h @@ -42,6 +42,7 @@ public: virtual pos_type BytesLeftToRead(); virtual void Write(const void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite); + using IOStream::Write; virtual pos_type GetPosition() const; virtual void Seek(IOStream::pos_type Offset, int SeekType); virtual void Close(); diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index 2c51cd61..3d1620a1 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -28,7 +28,7 @@ int num_tests_selected = 0; int num_failures = 0; -int old_failure_count = 0; +static int old_failure_count = 0; // do not expose! int first_fail_line; std::string original_working_dir; std::string first_fail_file; @@ -97,6 +97,8 @@ bool setUp(const char* function_name) if(StartsWith("TestDir", filename) || StartsWith("0_", filename) || filename == "accounts.txt" || + filename == "bbackupd-data" || + filename == "ca" || StartsWith("file", filename) || StartsWith("notifyran", filename) || StartsWith("notifyscript.tag", filename) || @@ -105,7 +107,9 @@ bool setUp(const char* function_name) filename == "syncallowscript.control" || StartsWith("syncallowscript.notifyran.", filename) || filename == "test2.downloaded" || - EndsWith("testfile", filename)) + EndsWith("testfile", filename) || + filename == "tmp" || + EndsWith(".qdbm", filename)) { std::string filepath = std::string("testfiles\\") + filename; @@ -201,7 +205,8 @@ bool setUp(const char* function_name) "testfiles/restore* testfiles/bbackupd-data " "testfiles/syncallowscript.control " "testfiles/syncallowscript.notifyran.* " - "testfiles/test2.downloaded" + "testfiles/test2.downloaded " + "testfiles/tmp " ) == 0); TEST_THAT_THROWONFAIL(system("touch testfiles/accounts.txt") == 0); #endif @@ -382,133 +387,6 @@ int ReadPidFile(const char *pidFile) return pid; } -int LaunchServer(const std::string& rCommandLine, const char *pidFile) -{ - BOX_INFO("Starting server: " << rCommandLine); - -#ifdef WIN32 - - PROCESS_INFORMATION procInfo; - - STARTUPINFO startInfo; - startInfo.cb = sizeof(startInfo); - startInfo.lpReserved = NULL; - startInfo.lpDesktop = NULL; - startInfo.lpTitle = NULL; - startInfo.dwFlags = 0; - startInfo.cbReserved2 = 0; - startInfo.lpReserved2 = NULL; - - std::string cmd = ConvertPaths(rCommandLine); - CHAR* tempCmd = strdup(cmd.c_str()); - - DWORD result = CreateProcess - ( - NULL, // lpApplicationName, naughty! - tempCmd, // lpCommandLine - NULL, // lpProcessAttributes - NULL, // lpThreadAttributes - false, // bInheritHandles - 0, // dwCreationFlags - NULL, // lpEnvironment - NULL, // lpCurrentDirectory - &startInfo, // lpStartupInfo - &procInfo // lpProcessInformation - ); - - free(tempCmd); - - TEST_THAT_OR(result != 0, - BOX_LOG_WIN_ERROR("Launch failed: " << rCommandLine); - return -1; - ); - - CloseHandle(procInfo.hProcess); - CloseHandle(procInfo.hThread); - - return WaitForServerStartup(pidFile, (int)procInfo.dwProcessId); - -#else // !WIN32 - - TEST_THAT_OR(RunCommand(rCommandLine) == 0, - TEST_FAIL_WITH_MESSAGE("Failed to start server: " << rCommandLine); - return -1; - ) - - return WaitForServerStartup(pidFile, 0); - -#endif // WIN32 -} - -int WaitForServerStartup(const char *pidFile, int pidIfKnown) -{ - #ifdef WIN32 - if (pidFile == NULL) - { - return pidIfKnown; - } - #else - // on other platforms there is no other way to get - // the PID, so a NULL pidFile doesn't make sense. - ASSERT(pidFile != NULL); - #endif - - // time for it to start up - BOX_TRACE("Waiting for server to start"); - - for (int i = 0; i < 15; i++) - { - if (TestFileNotEmpty(pidFile)) - { - break; - } - - if (pidIfKnown && !ServerIsAlive(pidIfKnown)) - { - break; - } - - ::sleep(1); - } - - // on Win32 we can check whether the process is alive - // without even checking the PID file - - if (pidIfKnown && !ServerIsAlive(pidIfKnown)) - { - TEST_FAIL_WITH_MESSAGE("Server died!"); - return -1; - } - - if (!TestFileNotEmpty(pidFile)) - { - TEST_FAIL_WITH_MESSAGE("Server didn't save PID file"); - return -1; - } - - BOX_TRACE("Server started"); - - // wait a second for the pid to be written to the file - ::sleep(1); - - // read pid file - int pid = ReadPidFile(pidFile); - - // On Win32 we can check whether the PID in the pidFile matches - // the one returned by the system, which it always should. - - if (pidIfKnown && pid != pidIfKnown) - { - BOX_ERROR("Server wrote wrong pid to file (" << pidFile << - "): expected " << pidIfKnown << " but found " << - pid); - TEST_FAIL_WITH_MESSAGE("Server wrote wrong pid to file"); - return -1; - } - - return pid; -} - void TestRemoteProcessMemLeaksFunc(const char *filename, const char* file, int line) { diff --git a/lib/common/Test.h b/lib/common/Test.h index 4b5cef61..35443c29 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -23,6 +23,7 @@ #define BBACKUPQUERY "..\\..\\bin\\bbackupquery\\bbackupquery.exe" #define BBSTOREACCOUNTS "..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts.exe" #define TEST_RETURN(actual, expected) TEST_EQUAL(expected, actual); +#define TEST_RETURN_COMMAND(actual, expected, command) TEST_EQUAL_LINE(expected, actual, command); #else #define BBACKUPCTL "../../bin/bbackupctl/bbackupctl" #define BBACKUPD "../../bin/bbackupd/bbackupd" @@ -30,12 +31,16 @@ #define BBACKUPQUERY "../../bin/bbackupquery/bbackupquery" #define BBSTOREACCOUNTS "../../bin/bbstoreaccounts/bbstoreaccounts" #define TEST_RETURN(actual, expected) TEST_EQUAL((expected << 8), actual); +#define TEST_RETURN_COMMAND(actual, expected, command) TEST_EQUAL_LINE((expected << 8), actual, command); #endif +#define DEFAULT_BBSTORED_CONFIG_FILE "testfiles/bbstored.conf" +#define DEFAULT_BBACKUPD_CONFIG_FILE "testfiles/bbackupd.conf" +#define DEFAULT_S3_CACHE_DIR "testfiles/bbackupd-cache" + extern int num_failures; extern int first_fail_line; extern int num_tests_selected; -extern int old_failure_count; extern std::string first_fail_file; extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args; extern std::list<std::string> run_only_named_tests; @@ -215,6 +220,7 @@ int finish_test_suite(); bool TestFileExists(const char *Filename); bool TestDirExists(const char *Filename); +bool TestFileNotEmpty(const char *Filename); // -1 if doesn't exist int TestGetFileSize(const std::string& Filename); @@ -222,8 +228,6 @@ std::string ConvertPaths(const std::string& rOriginal); int RunCommand(const std::string& rCommandLine); bool ServerIsAlive(int pid); int ReadPidFile(const char *pidFile); -int LaunchServer(const std::string& rCommandLine, const char *pidFile); -int WaitForServerStartup(const char *pidFile, int pidIfKnown); #define TestRemoteProcessMemLeaks(filename) \ TestRemoteProcessMemLeaksFunc(filename, __FILE__, __LINE__) |