From 886dba8a2915252a008c4218627297d54eb1221a Mon Sep 17 00:00:00 2001 From: bescoto Date: Mon, 25 Aug 2003 06:58:33 +0000 Subject: ACL/EA parsing fixes, use new quoting style git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@403 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/testing/ctest.py | 8 +++ rdiff-backup/testing/eas_aclstest.py | 122 ++++++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 1 deletion(-) (limited to 'rdiff-backup/testing') diff --git a/rdiff-backup/testing/ctest.py b/rdiff-backup/testing/ctest.py index 16a7882..2f11b1f 100644 --- a/rdiff-backup/testing/ctest.py +++ b/rdiff-backup/testing/ctest.py @@ -41,5 +41,13 @@ class CTest(unittest.TestCase): """Test running C.sync""" C.sync() + def test_acl_quoting(self): + """Test the acl_quote and acl_unquote functions""" + assert C.acl_quote('foo') == 'foo', C.acl_quote('foo') + assert C.acl_quote('\n') == '\\012', C.acl_quote('\n') + assert C.acl_unquote('\\012') == '\n' + s = '\\\n\t\145\n\01==' + assert C.acl_unquote(C.acl_quote(s)) == s + if __name__ == "__main__": unittest.main() diff --git a/rdiff-backup/testing/eas_aclstest.py b/rdiff-backup/testing/eas_aclstest.py index ed1a5b4..54d9f05 100644 --- a/rdiff-backup/testing/eas_aclstest.py +++ b/rdiff-backup/testing/eas_aclstest.py @@ -1,9 +1,11 @@ -import unittest, os, time +import unittest, os, time, cStringIO from commontest import * from rdiff_backup.eas_acls import * from rdiff_backup import Globals, rpath, Time tempdir = rpath.RPath(Globals.local_connection, "testfiles/output") +restore_dir = rpath.RPath(Globals.local_connection, + "testfiles/restore_out") class EATest(unittest.TestCase): """Test extended attributes""" @@ -27,6 +29,7 @@ class EATest(unittest.TestCase): """Make temp directory testfiles/output""" if tempdir.lstat(): tempdir.delete() tempdir.mkdir() + if restore_dir.lstat(): restore_dir.delete() def testBasic(self): """Test basic writing and reading of extended attributes""" @@ -61,6 +64,41 @@ class EATest(unittest.TestCase): (self.sample_ea.index, new_ea.index) assert 0, "We shouldn't have gotten this far" + def testExtractor(self): + """Test seeking inside a record list""" + record_list = """# file: 0foo +user.multiline=0sVGhpcyBpcyBhIGZhaXJseSBsb25nIGV4dGVuZGVkIGF0dHJpYnV0ZS4KCQkJIEVuY29kaW5nIGl0IHdpbGwgcmVxdWlyZSBzZXZlcmFsIGxpbmVzIG9mCgkJCSBiYXNlNjQusbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGx +user.third=0saGVsbG8= +user.not_empty=0sZm9vYmFy +user.binary=0sAAECjC89Ig== +user.empty +# file: 1foo/bar/baz +user.multiline=0sVGhpcyBpcyBhIGZhaXJseSBsb25nIGV4dGVuZGVkIGF0dHJpYnV0ZS4KCQkJIEVuY29kaW5nIGl0IHdpbGwgcmVxdWlyZSBzZXZlcmFsIGxpbmVzIG9mCgkJCSBiYXNlNjQusbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGx +user.third=0saGVsbG8= +user.binary=0sAAECjC89Ig== +user.empty +# file: 2foo/\\012 +user.empty +""" + extractor = EAExtractor(cStringIO.StringIO(record_list)) + ea_iter = extractor.iterate_starting_with(()) + first = ea_iter.next() + assert first.index == ('0foo',), first + second = ea_iter.next() + assert second.index == ('1foo', 'bar', 'baz'), second + third = ea_iter.next() # Test quoted filenames + assert third.index == ('2foo', '\n'), third.index + try: ea_iter.next() + except StopIteration: pass + else: assert 0, "Too many elements in iterator" + + extractor = EAExtractor(cStringIO.StringIO(record_list)) + ea_iter = extractor.iterate_starting_with(('1foo', 'bar')) + assert ea_iter.next().index == ('1foo', 'bar', 'baz') + try: ea_iter.next() + except StopIteration: pass + else: assert 0, "Too many elements in iterator" + def make_backup_dirs(self): """Create testfiles/ea_test[12] directories @@ -137,6 +175,21 @@ class EATest(unittest.TestCase): 'testfiles/empty', 'testfiles/ea_test1'] BackupRestoreSeries(None, None, dirlist, compare_eas = 1) + def test_final_local(self): + """Test backing up and restoring using 'rdiff-backup' script""" + self.make_backup_dirs() + self.make_temp() + rdiff_backup(1, 1, self.ea_testdir1.path, tempdir.path, + current_time = 10000) + assert CompareRecursive(self.ea_testdir1, tempdir, compare_eas = 1) + + rdiff_backup(1, 1, self.ea_testdir2.path, tempdir.path, + current_time = 20000) + assert CompareRecursive(self.ea_testdir2, tempdir, compare_eas = 1) + + rdiff_backup(1, 1, tempdir.path, restore_dir.path, + extra_options = '-r 10000') + assert CompareRecursive(self.ea_testdir1, restore_dir, compare_eas = 1) class ACLTest(unittest.TestCase): @@ -181,6 +234,7 @@ other::---""") """Make temp directory testfile/output""" if tempdir.lstat(): tempdir.delete() tempdir.mkdir() + if restore_dir.lstat(): restore_dir.delete() def testBasic(self): """Test basic writing and reading of ACLs""" @@ -227,6 +281,49 @@ other::---""") assert new_acl2.eq_verbose(self.dir_acl) assert 0 + def testExtractor(self): + """Test seeking inside a record list""" + record_list = """# file: 0foo +user::r-- +user:ben:--- +group::--- +group:root:--- +mask::--- +other::--- +# file: 1foo/bar/baz +user::r-- +user:ben:--- +group::--- +group:root:--- +mask::--- +other::--- +# file: 2foo/\\012 +user::r-- +user:ben:--- +group::--- +group:root:--- +mask::--- +other::--- +""" + extractor = ACLExtractor(cStringIO.StringIO(record_list)) + acl_iter = extractor.iterate_starting_with(()) + first = acl_iter.next() + assert first.index == ('0foo',), first + second = acl_iter.next() + assert second.index == ('1foo', 'bar', 'baz'), second + third = acl_iter.next() # Test quoted filenames + assert third.index == ('2foo', '\n'), third.index + try: acl_iter.next() + except StopIteration: pass + else: assert 0, "Too many elements in iterator" + + extractor = ACLExtractor(cStringIO.StringIO(record_list)) + acl_iter = extractor.iterate_starting_with(('1foo', 'bar')) + assert acl_iter.next().index == ('1foo', 'bar', 'baz') + try: acl_iter.next() + except StopIteration: pass + else: assert 0, "Too many elements in iterator" + def make_backup_dirs(self): """Create testfiles/acl_test[12] directories""" if self.acl_testdir1.lstat(): self.acl_testdir1.delete() @@ -295,6 +392,29 @@ other::---""") 'testfiles/empty', 'testfiles/acl_test1'] BackupRestoreSeries(None, None, dirlist, compare_acls = 1) + def test_final_local(self): + """Test backing up and restoring using 'rdiff-backup' script""" + self.make_backup_dirs() + self.make_temp() + rdiff_backup(1, 1, self.acl_testdir1.path, tempdir.path, + current_time = 10000) + assert CompareRecursive(self.acl_testdir1, tempdir, compare_acls = 1) + + rdiff_backup(1, 1, self.acl_testdir2.path, tempdir.path, + current_time = 20000) + assert CompareRecursive(self.acl_testdir2, tempdir, compare_acls = 1) + + rdiff_backup(1, 1, tempdir.path, restore_dir.path, + extra_options = '-r 10000') + assert CompareRecursive(self.acl_testdir1, restore_dir, + compare_acls = 1) + + restore_dir.delete() + rdiff_backup(1, 1, tempdir.path, restore_dir.path, + extra_options = '-r now') + assert CompareRecursive(self.acl_testdir2, restore_dir, + compare_acls = 1) + class CombinedTest(unittest.TestCase): """Test backing up and restoring directories with both EAs and ACLs""" -- cgit v1.2.1