diff options
Diffstat (limited to 'test/backupstore/testbackupstore.cpp')
-rw-r--r-- | test/backupstore/testbackupstore.cpp | 148 |
1 files changed, 126 insertions, 22 deletions
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index 593ae121..46c74bd0 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -1,4 +1,4 @@ -// distribution boxbackup-0.10 (svn version: 494) +// distribution boxbackup-0.11rc1 (svn version: 2023_2024) // // Copyright (c) 2003 - 2006 // Ben Summers and contributors. All rights reserved. @@ -71,6 +71,7 @@ #include "MemBlockStream.h" #include "BackupClientFileAttributes.h" #include "BackupClientCryptoKeys.h" +#include "ServerControl.h" #include "MemLeakFindOn.h" @@ -463,7 +464,8 @@ void test_test_file(int t, IOStream &rStream) } free(data); - unlink("testfiles/test_download"); + in.Close(); + TEST_THAT(unlink("testfiles/test_download") == 0); } void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) @@ -968,6 +970,7 @@ int test_server(const char *hostname) // Check marker is 0 TEST_THAT(loginConf->GetClientStoreMarker() == 0); +#ifndef WIN32 // Check that we can't open a new connection which requests write permissions { SocketStreamTLS conn; @@ -979,10 +982,12 @@ int test_server(const char *hostname) ConnectionException, Conn_Protocol_UnexpectedReply); protocol.QueryFinished(); } +#endif // Set the client store marker protocol.QuerySetClientStoreMarker(0x8732523ab23aLL); +#ifndef WIN32 // Open a new connection which is read only SocketStreamTLS connReadOnly; connReadOnly.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); @@ -1001,10 +1006,12 @@ int test_server(const char *hostname) // Check client store marker TEST_THAT(loginConf->GetClientStoreMarker() == 0x8732523ab23aLL); } +#else // WIN32 + BackupProtocolClient& protocolReadOnly(protocol); +#endif test_server_1(protocol, protocolReadOnly); - // Create and upload some test files int64_t maxID = 0; for(int t = 0; t < UPLOAD_NUM; ++t) @@ -1242,6 +1249,7 @@ int test_server(const char *hostname) StreamableMemBlock attr(attr1, sizeof(attr1)); TEST_THAT(dir.GetAttributes() == attr); } + // Check that we don't get attributes if we don't ask for them { // Command @@ -1255,6 +1263,10 @@ int test_server(const char *hostname) dir.ReadFromStream(*dirstream, IOStream::TimeOutInfinite); TEST_THAT(!dir.HasAttributes()); } + + // sleep to ensure that the timestamp on the file will change + ::safe_sleep(1); + // Change attributes on the directory { MemBlockStream attrnew(attr2, sizeof(attr2)); @@ -1293,6 +1305,7 @@ int test_server(const char *hostname) subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName)); TEST_THAT(rep->GetObjectID() == uploads[UPLOAD_FILE_TO_MOVE].allocated_objid); } + // Try some dodgy renames { BackupStoreFilenameClear newName("moved-files"); @@ -1305,6 +1318,10 @@ int test_server(const char *hostname) subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName), ConnectionException, Conn_Protocol_UnexpectedReply); } + + // sleep to ensure that the timestamp on the file will change + ::safe_sleep(1); + // Rename within a directory { BackupStoreFilenameClear newName("moved-files-x"); @@ -1312,6 +1329,7 @@ int test_server(const char *hostname) subdirid, subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName); } + // Check it's all gone from the root directory... { // Command @@ -1331,6 +1349,7 @@ int test_server(const char *hostname) TEST_THAT(en->GetName() != uploads[UPLOAD_FILE_TO_MOVE].name); } } + // Check the old and new versions are in the other directory { BackupStoreFilenameClear lookFor("moved-files-x"); @@ -1360,6 +1379,7 @@ int test_server(const char *hostname) TEST_THAT(foundCurrent); TEST_THAT(foundOld); } + // make a little bit more of a thing to look at int64_t subsubdirid = 0; int64_t subsubfileid = 0; @@ -1383,6 +1403,7 @@ int test_server(const char *hostname) upload)); subsubfileid = stored->GetObjectID(); } + // Query names -- test that invalid stuff returns not found OK { std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(3248972347823478927LL, subsubdirid)); @@ -1400,6 +1421,7 @@ int test_server(const char *hostname) std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL)); TEST_THAT(nameRep->GetNumNameElements() == 0); } + // Query names... first, get info for the file { std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(subsubfileid, subsubdirid)); @@ -1417,6 +1439,7 @@ int test_server(const char *hostname) TEST_THAT(fn.GetClearFilename() == testnames[l]); } } + // Query names... secondly, for the directory { std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, subsubdirid)); @@ -1476,11 +1499,15 @@ int test_server(const char *hostname) } // Finish the connections +#ifndef WIN32 protocolReadOnly.QueryFinished(); +#endif protocol.QueryFinished(); // Close logs +#ifndef WIN32 ::fclose(protocolReadOnlyLog); +#endif ::fclose(protocolLog); } @@ -1639,6 +1666,7 @@ int test3(int argc, const char *argv[]) TEST_THAT(decoded->GetNumBlocks() == 3); } +#ifndef WIN32 // no symlinks on Win32 // Try out doing this on a symlink { TEST_THAT(::symlink("does/not/exist", "testfiles/testsymlink") == 0); @@ -1652,6 +1680,7 @@ int test3(int argc, const char *argv[]) // Decode it BackupStoreFile::DecodeFile(b, "testfiles/testsymlink_2", IOStream::TimeOutInfinite); } +#endif } // Store info @@ -1709,7 +1738,11 @@ int test3(int argc, const char *argv[]) "testfiles/clientTrustedCAs.pem"); // First, try logging in without an account having been created... just make sure login fails. - int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); + + std::string cmd = BBSTORED " " + bbstored_args + + " testfiles/bbstored.conf"; + int pid = LaunchServer(cmd.c_str(), "testfiles/bbstored.pid"); + TEST_THAT(pid != -1 && pid != 0); if(pid > 0) { @@ -1738,12 +1771,17 @@ int test3(int argc, const char *argv[]) } // Create an account for the test client - TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0); + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf create 01234567 0 " + "10000B 20000B") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + TEST_THAT(TestDirExists("testfiles/0_0/backup/01234567")); TEST_THAT(TestDirExists("testfiles/0_1/backup/01234567")); TEST_THAT(TestDirExists("testfiles/0_2/backup/01234567")); - TEST_THAT(TestGetFileSize("testfiles/accounts.txt") > 8); // make sure something is written to it + TEST_THAT(TestGetFileSize("testfiles/accounts.txt") > 8); + // make sure something is written to it TEST_THAT(ServerIsAlive(pid)); @@ -1763,15 +1801,22 @@ int test3(int argc, const char *argv[]) TEST_THAT(KillServer(pid)); ::sleep(1); TEST_THAT(!ServerIsAlive(pid)); +#ifndef WIN32 TestRemoteProcessMemLeaks("bbstored.memleaks"); +#endif - // Set a new limit on the account -- leave the hard limit high to make sure the target for - // freeing space is the soft limit. - TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20000B") == 0); + // Set a new limit on the account -- leave the hard limit + // high to make sure the target for freeing space is the + // soft limit. + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf setlimit 01234567 " + "10B 20000B") == 0); TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); // Start things up - pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); + pid = LaunchServer(BBSTORED " testfiles/bbstored.conf", + "testfiles/bbstored.pid"); + ::sleep(1); TEST_THAT(ServerIsAlive(pid)); @@ -1787,8 +1832,9 @@ int test3(int argc, const char *argv[]) // Count the objects again recursive_count_objects_results after = {0,0,0}; - recursive_count_objects("localhost", BackupProtocolClientListDirectory::RootDirectory, after); -printf("after.objectsNotDel=%i, deleted=%i, old=%i\n",after.objectsNotDel, after.deleted, after.old); + recursive_count_objects("localhost", + BackupProtocolClientListDirectory::RootDirectory, + after); // If these tests fail then try increasing the timeout above TEST_THAT(after.objectsNotDel == before.objectsNotDel); @@ -1796,7 +1842,9 @@ printf("after.objectsNotDel=%i, deleted=%i, old=%i\n",after.objectsNotDel, after TEST_THAT(after.old == 0); // Set a really small hard limit - TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20B") == 0); + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf setlimit 01234567 " + "10B 20B") == 0); TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); // Try to upload a file and create a directory, and check an error is generated @@ -1846,7 +1894,10 @@ printf("after.objectsNotDel=%i, deleted=%i, old=%i\n",after.objectsNotDel, after TEST_THAT(KillServer(pid)); ::sleep(1); TEST_THAT(!ServerIsAlive(pid)); + +#ifndef WIN32 TestRemoteProcessMemLeaks("bbstored.memleaks"); +#endif } return 0; @@ -1857,11 +1908,16 @@ int multi_server() printf("Starting server for connection from remote machines...\n"); // Create an account for the test client - TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 30000B 40000B") == 0); + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf create 01234567 0 " + "30000B 40000B") == 0); TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); // First, try logging in without an account having been created... just make sure login fails. - int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored_multi.conf", "testfiles/bbstored.pid"); + + int pid = LaunchServer(BBSTORED " testfiles/bbstored_multi.conf", + "testfiles/bbstored.pid"); + TEST_THAT(pid != -1 && pid != 0); if(pid > 0) { @@ -1878,15 +1934,58 @@ int multi_server() TEST_THAT(KillServer(pid)); ::sleep(1); TEST_THAT(!ServerIsAlive(pid)); +#ifndef WIN32 TestRemoteProcessMemLeaks("bbstored.memleaks"); +#endif } return 0; } +#ifdef WIN32 +WCHAR* ConvertUtf8ToWideString(const char* pString); +std::string ConvertPathToAbsoluteUnicode(const char *pFileName); +#endif + int test(int argc, const char *argv[]) { +#ifdef WIN32 + // this had better work, or bbstored will die when combining diffs + char* file = "foo"; + std::string abs = ConvertPathToAbsoluteUnicode(file); + WCHAR* wfile = ConvertUtf8ToWideString(abs.c_str()); + + DWORD accessRights = FILE_READ_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_READ_EA | FILE_WRITE_ATTRIBUTES | + FILE_WRITE_DATA | FILE_WRITE_EA /*| FILE_ALL_ACCESS*/; + DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + + HANDLE h1 = CreateFileW(wfile, accessRights, shareMode, + NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); + assert(h1 != INVALID_HANDLE_VALUE); + TEST_THAT(h1 != INVALID_HANDLE_VALUE); + + accessRights = FILE_READ_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_READ_EA; + + HANDLE h2 = CreateFileW(wfile, accessRights, shareMode, + NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + assert(h2 != INVALID_HANDLE_VALUE); + TEST_THAT(h2 != INVALID_HANDLE_VALUE); + + CloseHandle(h2); + CloseHandle(h1); + delete [] wfile; + + h1 = openfile("foo", O_CREAT | O_RDWR, 0); + TEST_THAT(h1 != INVALID_HANDLE_VALUE); + h2 = openfile("foo", O_RDWR, 0); + TEST_THAT(h2 != INVALID_HANDLE_VALUE); + CloseHandle(h2); + CloseHandle(h1); +#endif + // SSL library SSLLib::Initialise(); @@ -1905,14 +2004,19 @@ int test(int argc, const char *argv[]) // for seeing what's going on. BackupClientCryptoKeys_Setup("testfiles/bbackupd.keys"); - // encode in some filenames -- can't do static initialisation because the key won't be set up when these are initialised - for(unsigned int l = 0; l < sizeof(ens_filenames) / sizeof(ens_filenames[0]); ++l) + // encode in some filenames -- can't do static initialisation + // because the key won't be set up when these are initialised { - ens[l].fn = BackupStoreFilenameClear(ens_filenames[l]); - } - for(unsigned int l = 0; l < sizeof(uploads_filenames) / sizeof(uploads_filenames[0]); ++l) - { - uploads[l].name = BackupStoreFilenameClear(uploads_filenames[l]); + MEMLEAKFINDER_NO_LEAKS + + for(unsigned int l = 0; l < sizeof(ens_filenames) / sizeof(ens_filenames[0]); ++l) + { + ens[l].fn = BackupStoreFilenameClear(ens_filenames[l]); + } + for(unsigned int l = 0; l < sizeof(uploads_filenames) / sizeof(uploads_filenames[0]); ++l) + { + uploads[l].name = BackupStoreFilenameClear(uploads_filenames[l]); + } } // Trace errors out |