diff options
author | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-07-16 05:16:42 +0000 |
---|---|---|
committer | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-07-16 05:16:42 +0000 |
commit | 4c8440ee71ba819c7327913870a615186ef8d386 (patch) | |
tree | 5d4d811680e1b3fd0a3393de3d49eb9cae116481 /rdiff-backup/testing | |
parent | 6efc3610e37994c38a70cf32266e1e495035fbd3 (diff) | |
download | rdiff-backup-4c8440ee71ba819c7327913870a615186ef8d386.tar.gz |
Various changes to 0.9.3, see CHANGELOG
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@157 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/testing')
-rw-r--r-- | rdiff-backup/testing/commontest.py | 16 | ||||
-rw-r--r-- | rdiff-backup/testing/connectiontest.py | 13 | ||||
-rw-r--r-- | rdiff-backup/testing/finaltest.py | 31 | ||||
-rw-r--r-- | rdiff-backup/testing/securitytest.py | 60 | ||||
-rw-r--r-- | rdiff-backup/testing/selectiontest.py | 12 | ||||
-rw-r--r-- | rdiff-backup/testing/statisticstest.py | 1 | ||||
-rw-r--r-- | rdiff-backup/testing/timetest.py | 26 |
7 files changed, 152 insertions, 7 deletions
diff --git a/rdiff-backup/testing/commontest.py b/rdiff-backup/testing/commontest.py index 24eb2cb..dd49394 100644 --- a/rdiff-backup/testing/commontest.py +++ b/rdiff-backup/testing/commontest.py @@ -54,6 +54,15 @@ def rdiff_backup(source_local, dest_local, src_dir, dest_dir, os.system(" ".join(cmdargs)) +def cmd_schemas2rps(schema_list, remote_schema): + """Input list of file descriptions and the remote schema, return rps + + File descriptions should be strings of the form 'hostname.net::foo' + + """ + return map(SetConnections.cmdpair2rp, + SetConnections.get_cmd_pairs(schema_list, remote_schema)) + def InternalBackup(source_local, dest_local, src_dir, dest_dir, current_time = None): """Backup src to dest internally @@ -75,7 +84,7 @@ def InternalBackup(source_local, dest_local, src_dir, dest_dir, dest_dir = "cd test2/tmp; python ../../server.py ../../%s::../../%s" \ % (SourceDir, dest_dir) - rpin, rpout = SetConnections.InitRPs([src_dir, dest_dir], remote_schema) + rpin, rpout = cmd_schemas2rps([src_dir, dest_dir], remote_schema) Main.misc_setup([rpin, rpout]) Main.Backup(rpin, rpout) Main.cleanup() @@ -92,7 +101,7 @@ def InternalMirror(source_local, dest_local, src_dir, dest_dir, dest_dir = "cd test2/tmp; python ../../server.py ../../%s::../../%s" \ % (SourceDir, dest_dir) - rpin, rpout = SetConnections.InitRPs([src_dir, dest_dir], remote_schema) + rpin, rpout = cmd_schemas2rps([src_dir, dest_dir], remote_schema) Main.misc_setup([rpin, rpout]) Main.backup_init_select(rpin, rpout) if not rpout.lstat(): rpout.mkdir() @@ -127,8 +136,7 @@ def InternalRestore(mirror_local, dest_local, mirror_dir, dest_dir, time): dest_dir = "cd test2/tmp; python ../../server.py ../../%s::../../%s" \ % (SourceDir, dest_dir) - mirror_rp, dest_rp = SetConnections.InitRPs([mirror_dir, dest_dir], - remote_schema) + mirror_rp, dest_rp = cmd_schemas2rps([mirror_dir, dest_dir], remote_schema) Time.setcurtime() inc = get_increment_rp(mirror_rp, time) if inc: Main.restore(get_increment_rp(mirror_rp, time), dest_rp) diff --git a/rdiff-backup/testing/connectiontest.py b/rdiff-backup/testing/connectiontest.py index 1deadbe..ab80256 100644 --- a/rdiff-backup/testing/connectiontest.py +++ b/rdiff-backup/testing/connectiontest.py @@ -168,13 +168,22 @@ class RedirectedConnectionTest(unittest.TestCase): def testBasic(self): """Test basic operations with redirection""" + self.conna.Globals.set("tmp_val", 1) + self.connb.Globals.set("tmp_val", 2) + assert self.conna.Globals.get("tmp_val") == 1 + assert self.connb.Globals.get("tmp_val") == 2 + self.conna.Globals.set("tmp_connb", self.connb) self.connb.Globals.set("tmp_conna", self.conna) assert self.conna.Globals.get("tmp_connb") is self.connb assert self.connb.Globals.get("tmp_conna") is self.conna - #self.conna.Test_SetConnGlobals(self.connb, "tmp_settest", 1) - #assert self.connb.Globals.get("tmp_settest") + val = self.conna.reval("Globals.get('tmp_connb').Globals.get", + "tmp_val") + assert val == 2, val + val = self.connb.reval("Globals.get('tmp_conna').Globals.get", + "tmp_val") + assert val == 1, val assert self.conna.reval("Globals.get('tmp_connb').pow", 2, 3) == 8 self.conna.reval("Globals.tmp_connb.reval", diff --git a/rdiff-backup/testing/finaltest.py b/rdiff-backup/testing/finaltest.py index 0a51485..43daef6 100644 --- a/rdiff-backup/testing/finaltest.py +++ b/rdiff-backup/testing/finaltest.py @@ -17,6 +17,7 @@ class Local: def get_local_rp(extension): return RPath(Globals.local_connection, "testfiles/" + extension) + vftrp = get_local_rp('various_file_types') inc1rp = get_local_rp('increment1') inc2rp = get_local_rp('increment2') inc3rp = get_local_rp('increment3') @@ -71,6 +72,19 @@ class PathSetter(unittest.TestCase): print "executing " + cmdstr assert not os.system(cmdstr) + def exec_rb_extra_args(self, time, extra_args, *args): + """Run rdiff-backup on given arguments""" + arglist = [] + if time: arglist.append("--current-time %s" % str(time)) + arglist.append(self.src_prefix + args[0]) + if len(args) > 1: + arglist.append(self.dest_prefix + args[1]) + assert len(args) == 2 + + cmdstr = "%s %s %s" % (self.rb_schema, extra_args, ' '.join(arglist)) + print "executing " + cmdstr + assert not os.system(cmdstr) + def exec_rb_restore(self, time, *args): """Restore using rdiff-backup's new syntax and given time""" arglist = [] @@ -174,6 +188,23 @@ class Final(PathSetter): self.set_connections("test1/", '../', 'test2/tmp/', '../../') self.runtest() + def testMirroringLocal(self): + """Run mirroring only everything remote""" + self.delete_tmpdirs() + self.set_connections(None, None, None, None) + self.exec_rb_extra_args(10000, "-m", + "testfiles/various_file_types", + "testfiles/output") + assert CompareRecursive(Local.vftrp, Local.rpout, exclude_rbdir = None) + + def testMirroringRemote(self): + """Run mirroring only everything remote""" + self.delete_tmpdirs() + self.set_connections("test1/", "../", "test2/tmp/", "../../") + self.exec_rb_extra_args(10000, "-m", + "testfiles/various_file_types", + "testfiles/output") + assert CompareRecursive(Local.vftrp, Local.rpout, exclude_rbdir = None) class FinalSelection(PathSetter): """Test selection options""" diff --git a/rdiff-backup/testing/securitytest.py b/rdiff-backup/testing/securitytest.py new file mode 100644 index 0000000..689544d --- /dev/null +++ b/rdiff-backup/testing/securitytest.py @@ -0,0 +1,60 @@ +import os, unittest +from commontest import * +import rdiff_backup.Security, Security + +#Log.setverbosity(5) + +class SecurityTest(unittest.TestCase): + def assert_exc_sec(self, exc): + """Fudge - make sure exception is a security violation + + This is necessary because of some kind of pickling/module + problem. + + """ + assert isinstance(exc, rdiff_backup.Security.Violation) + #assert str(exc).find("Security") >= 0, "%s\n%s" % (exc, repr(exc)) + + def test_vet_request_ro(self): + """Test vetting of ConnectionRequests on read-only server""" + remote_cmd = "rdiff-backup --server --restrict-read-only foo" + conn = SetConnections.init_connection(remote_cmd) + assert type(conn.os.getuid()) is type(5) + try: conn.os.remove("/tmp/foobar") + except Exception, e: self.assert_exc_sec(e) + else: assert 0, "No exception raised" + SetConnections.CloseConnections() + + def test_vet_request_minimal(self): + """Test vetting of ConnectionRequests on minimal server""" + remote_cmd = "rdiff-backup --server --restrict-update-only foo" + conn = SetConnections.init_connection(remote_cmd) + assert type(conn.os.getuid()) is type(5) + try: conn.os.remove("/tmp/foobar") + except Exception, e: self.assert_exc_sec(e) + else: assert 0, "No exception raised" + SetConnections.CloseConnections() + + def test_vet_rpath(self): + """Test to make sure rpaths not in restricted path will be rejected""" + remote_cmd = "rdiff-backup --server --restrict-update-only foo" + conn = SetConnections.init_connection(remote_cmd) + + for rp in [RPath(Globals.local_connection, "blahblah"), + RPath(conn, "foo/bar")]: + conn.Globals.set("TEST_var", rp) + assert conn.Globals.get("TEST_var").path == rp.path + + for rp in [RPath(conn, "foobar"), + RPath(conn, "/usr/local"), + RPath(conn, "foo/../bar")]: + try: conn.Globals.set("TEST_var", rp) + except Exception, e: + self.assert_exc_sec(e) + continue + assert 0, "No violation raised by rp %s" % (rp,) + + SetConnections.CloseConnections() + +if __name__ == "__main__": unittest.main() + diff --git a/rdiff-backup/testing/selectiontest.py b/rdiff-backup/testing/selectiontest.py index 76af96f..f512f12 100644 --- a/rdiff-backup/testing/selectiontest.py +++ b/rdiff-backup/testing/selectiontest.py @@ -221,6 +221,18 @@ testfiles/select/1/1 select.filelist_get_sf(StringIO.StringIO("/foo/bar"), 0, "test")(root) == None + def testOtherFilesystems(self): + """Test to see if --exclude-other-filesystems works correctly""" + root = DSRPath(1, Globals.local_connection, "/") + select = Select(root) + sf = select.other_filesystems_get_sf(0) + assert sf(root) is None + assert sf(RPath(Globals.local_connection, "/usr/bin")) is None, \ + "Assumption: /usr/bin is on the same filesystem as /" + assert sf(RPath(Globals.local_connection, "/proc")) == 0, \ + "Assumption: /proc is on a different filesystem" + assert sf(RPath(Globals.local_connection, "/boot")) == 0, \ + "Assumption: /boot is on a different filesystem" class ParseArgsTest(unittest.TestCase): """Test argument parsing""" diff --git a/rdiff-backup/testing/statisticstest.py b/rdiff-backup/testing/statisticstest.py index 819bb85..cc1f675 100644 --- a/rdiff-backup/testing/statisticstest.py +++ b/rdiff-backup/testing/statisticstest.py @@ -57,6 +57,7 @@ ChangedSourceSize 8 (8 bytes) ChangedMirrorSize 9 (9 bytes) IncrementFiles 15 IncrementFileSize 10 (10 bytes) +TotalDestinationSizeChange 7 (7 bytes) """, "'%s'" % stats_string def test_line_string(self): diff --git a/rdiff-backup/testing/timetest.py b/rdiff-backup/testing/timetest.py index 089ae0c..b6d545f 100644 --- a/rdiff-backup/testing/timetest.py +++ b/rdiff-backup/testing/timetest.py @@ -1,4 +1,4 @@ -import unittest +import unittest, time from commontest import * import Globals, Time @@ -108,5 +108,29 @@ class TimeTest(unittest.TestCase): self.assertRaises(Time.TimeException, g2t, "") self.assertRaises(Time.TimeException, g2t, "3q") + def testSleeping(self): + """Test sleep and sleep ratio""" + sleep_ratio = 0.5 + time1 = time.time() + Time.sleep(0) # set initial time + time.sleep(1) + time2 = time.time() + Time.sleep(sleep_ratio) + time3 = time.time() + time.sleep(0.5) + time4 = time.time() + Time.sleep(sleep_ratio) + time5 = time.time() + + sleep_ratio = 0.25 + time.sleep(0.75) + time6 = time.time() + Time.sleep(sleep_ratio) + time7 = time.time() + + assert 0.9 < time3 - time2 < 1.1, time3 - time2 + assert 0.4 < time5 - time4 < 0.6, time5 - time4 + assert 0.2 < time7 - time6 < 0.3, time7 - time6 + if __name__ == '__main__': unittest.main() |