From 322a8c4719e54e637533593faaa9a82cd92a6f40 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 5 Nov 2007 23:41:41 +0000 Subject: Use lstat() instead of stat() to check whether a file exists. Thanks to Hans-Joachim Baader for reporting this problem. (http://lists.warhead.org.uk/pipermail/boxbackup/2007-November/003958.html) Add a test that symlinks are not followed during restore. --- test/bbackupd/testbbackupd.cpp | 91 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 4 deletions(-) (limited to 'test/bbackupd') diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 0e0e949c..4b00d3f4 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -1058,14 +1058,11 @@ int test_bbackupd() } #endif // PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE - printf("\n==== Testing that redundant locations are deleted on time\n"); - std::string cmd = BBACKUPD + bbackupd_args + " testfiles/bbackupd-temploc.conf"; - bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); + bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0); - ::safe_sleep(1); TEST_THAT(ServerIsAlive(bbackupd_pid)); @@ -1073,6 +1070,92 @@ int test_bbackupd() if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; + printf("\n==== Testing that absolute symlinks are not followed " + "during restore\n"); + + { + #define SYM_DIR "testfiles" DIRECTORY_SEPARATOR "TestDir1" \ + DIRECTORY_SEPARATOR "symlink_test" + + TEST_THAT(::mkdir(SYM_DIR, 0777) == 0); + TEST_THAT(::mkdir(SYM_DIR DIRECTORY_SEPARATOR "a", 0777) == 0); + TEST_THAT(::mkdir(SYM_DIR DIRECTORY_SEPARATOR "a" + DIRECTORY_SEPARATOR "subdir", 0777) == 0); + TEST_THAT(::mkdir(SYM_DIR DIRECTORY_SEPARATOR "b", 0777) == 0); + + FILE* fp = fopen(SYM_DIR DIRECTORY_SEPARATOR "a" + DIRECTORY_SEPARATOR "subdir" + DIRECTORY_SEPARATOR "content", "w"); + TEST_THAT(fp != NULL); + fputs("before\n", fp); + fclose(fp); + + char buf[PATH_MAX]; + TEST_THAT(getcwd(buf, sizeof(buf)) != NULL); + std::string path = buf; + path += DIRECTORY_SEPARATOR SYM_DIR + DIRECTORY_SEPARATOR "a" + DIRECTORY_SEPARATOR "subdir"; + TEST_THAT(symlink(path.c_str(), SYM_DIR + DIRECTORY_SEPARATOR "b" + DIRECTORY_SEPARATOR "link") == 0); + + ::wait_for_operation(4); + ::sync_and_wait(); + + // Check that the backup was successful, i.e. no differences + int compareReturnValue = ::system(BBACKUPQUERY " -q " + "-c testfiles/bbackupd.conf " + "-l testfiles/query1.log " + "\"compare -acQ\" quit"); + TEST_RETURN(compareReturnValue, 1); + TestRemoteProcessMemLeaks("bbackupquery.memleaks"); + + // now stop bbackupd and update the test file, + // make the original directory unreadable + terminate_bbackupd(bbackupd_pid); + + fp = fopen(SYM_DIR DIRECTORY_SEPARATOR "a" + DIRECTORY_SEPARATOR "subdir" + DIRECTORY_SEPARATOR "content", "w"); + TEST_THAT(fp != NULL); + fputs("after\n", fp); + fclose(fp); + + TEST_THAT(chmod(SYM_DIR, 0) == 0); + + // check that we can restore it + compareReturnValue = ::system(BBACKUPQUERY " " + "-c testfiles/bbackupd.conf " + "-q \"restore Test1 testfiles/restore-symlink\" " + "quit"); + TEST_RETURN(compareReturnValue, 0); + + // make it accessible again + TEST_THAT(chmod(SYM_DIR, 0755) == 0); + + // check that the original file was not overwritten + FileStream fs(SYM_DIR "/a/subdir/content"); + IOStreamGetLine gl(fs); + std::string line; + TEST_THAT(gl.GetLine(line)); + TEST_THAT(line != "before"); + TEST_THAT(line == "after"); + + #undef SYM_DIR + + bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); + TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0); + ::safe_sleep(1); + + TEST_THAT(ServerIsAlive(bbackupd_pid)); + TEST_THAT(ServerIsAlive(bbstored_pid)); + if (!ServerIsAlive(bbackupd_pid)) return 1; + if (!ServerIsAlive(bbstored_pid)) return 1; + } + + printf("\n==== Testing that redundant locations are deleted on time\n"); + { std::auto_ptr client = Connect( context, -- cgit v1.2.3