rdiff-backup-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Rdiff-backup-commits] rdiff-backup ./CHANGELOG testing/regresstest.py..


From: Ben Escoto
Subject: [Rdiff-backup-commits] rdiff-backup ./CHANGELOG testing/regresstest.py... [r1-0]
Date: Mon, 16 Jan 2006 04:09:50 +0000

CVSROOT:        /sources/rdiff-backup
Module name:    rdiff-backup
Branch:         r1-0
Changes by:     Ben Escoto <address@hidden>     06/01/16 04:09:50

Modified files:
        .              : CHANGELOG 
        testing        : regresstest.py roottest.py securitytest.py 

Log message:
        Final changes for 1.0.4

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff-backup/CHANGELOG.diff?only_with_tag=r1-0&tr1=1.147.2.14&tr2=1.147.2.15&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff-backup/testing/regresstest.py.diff?only_with_tag=r1-0&tr1=1.5&tr2=1.5.2.1&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff-backup/testing/roottest.py.diff?only_with_tag=r1-0&tr1=1.18&tr2=1.18.2.1&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff-backup/testing/securitytest.py.diff?only_with_tag=r1-0&tr1=1.9&tr2=1.9.2.1&r1=text&r2=text

Patches:
Index: rdiff-backup/CHANGELOG
diff -u rdiff-backup/CHANGELOG:1.147.2.14 rdiff-backup/CHANGELOG:1.147.2.15
--- rdiff-backup/CHANGELOG:1.147.2.14   Sat Jan 14 03:58:41 2006
+++ rdiff-backup/CHANGELOG      Mon Jan 16 04:09:50 2006
@@ -1,4 +1,4 @@
-New in v1.0.4 (????/??/??)
+New in v1.0.4 (2006/01/15)
 --------------------------
 
 Files with ACLs will not be unnecessarily marked as changed (bug
@@ -12,7 +12,7 @@
 were used.  Bug reported by Toni Price.
 
 Bug #15436 reported by Remy Blank: rdiff-backup would sometimes crash
-if ACLs and uname did not exist on destination.
+on ACLs if the owning uname did not exist on destination.
 
 
 New in v1.0.3 (2005/11/25)
Index: rdiff-backup/testing/regresstest.py
diff -u /dev/null rdiff-backup/testing/regresstest.py:1.5.2.1
--- /dev/null   Mon Jan 16 04:09:50 2006
+++ rdiff-backup/testing/regresstest.py Mon Jan 16 04:09:50 2006
@@ -0,0 +1,141 @@
+"""regresstest - test the regress module.
+
+Not to be confused with the regression tests.
+
+"""
+
+import unittest
+from commontest import *
+from rdiff_backup import regress, Time
+
+Log.setverbosity(3)
+
+class RegressTest(unittest.TestCase):
+       output_rp = rpath.RPath(Globals.local_connection, "testfiles/output")
+       output_rbdir_rp = output_rp.append_path("rdiff-backup-data")
+       inc1_rp = rpath.RPath(Globals.local_connection, "testfiles/increment1")
+       inc2_rp = rpath.RPath(Globals.local_connection, "testfiles/increment2")
+       inc3_rp = rpath.RPath(Globals.local_connection, "testfiles/increment3")
+       inc4_rp = rpath.RPath(Globals.local_connection, "testfiles/increment4")
+
+       def runtest(self, regress_function):
+               """Test regressing a full directory to older state
+
+               Make two directories, one with one more backup in it.  Then
+               regress the bigger one, and then make sure they compare the
+               same.
+
+               Regress_function takes a time and should regress
+               self.output_rp back to that time.
+
+               """
+               self.output_rp.setdata()
+               if self.output_rp.lstat(): Myrm(self.output_rp.path)
+
+               rdiff_backup(1, 1, self.inc1_rp.path, self.output_rp.path,
+                                        current_time = 10000)
+               assert CompareRecursive(self.inc1_rp, self.output_rp)
+
+               rdiff_backup(1, 1, self.inc2_rp.path, self.output_rp.path,
+                                        current_time = 20000)
+               assert CompareRecursive(self.inc2_rp, self.output_rp)
+
+               rdiff_backup(1, 1, self.inc3_rp.path, self.output_rp.path,
+                                        current_time = 30000)
+               assert CompareRecursive(self.inc3_rp, self.output_rp)
+
+               rdiff_backup(1, 1, self.inc4_rp.path, self.output_rp.path,
+                                        current_time = 40000)
+               assert CompareRecursive(self.inc4_rp, self.output_rp)
+
+               Globals.rbdir = self.output_rbdir_rp
+
+               regress_function(30000)
+               assert CompareRecursive(self.inc3_rp, self.output_rp,
+                                                               
compare_hardlinks = 0)
+               regress_function(20000)
+               assert CompareRecursive(self.inc2_rp, self.output_rp,
+                                                               
compare_hardlinks = 0)
+               regress_function(10000)
+               assert CompareRecursive(self.inc1_rp, self.output_rp,
+                                                               
compare_hardlinks = 0)
+
+       def regress_to_time_local(self, time):
+               """Regress self.output_rp to time by running regress locally"""
+               self.output_rp.setdata()
+               self.output_rbdir_rp.setdata()
+               self.add_current_mirror(time)
+               regress.Regress(self.output_rp)
+                       
+       def add_current_mirror(self, time):
+               """Add current_mirror marker at given time"""
+               cur_mirror_rp = self.output_rbdir_rp.append(
+                       "current_mirror.%s.data" % (Time.timetostring(time),))
+               cur_mirror_rp.touch()
+
+       def regress_to_time_remote(self, time):
+               """Like test_full above, but run regress remotely"""
+               self.output_rp.setdata()
+               self.output_rbdir_rp.setdata()
+               self.add_current_mirror(time)
+               cmdline = (SourceDir +
+                                  "/../rdiff-backup -v3 
--check-destination-dir "
+                                  "--remote-schema './chdir-wrapper2 %s' "
+                                  "test1::../" + self.output_rp.path)
+               print "Running:", cmdline
+               assert not os.system(cmdline)
+
+       def test_local(self):
+               """Run regress test locally"""
+               self.runtest(self.regress_to_time_local)
+
+       def test_remote(self):
+               """Run regress test remotely"""
+               self.runtest(self.regress_to_time_remote)
+
+       def test_unreadable(self):
+               """Run regress test when regular file is unreadable"""
+               self.output_rp.setdata()
+               if self.output_rp.lstat(): Myrm(self.output_rp.path)
+               unreadable_rp = self.make_unreadable()
+
+               rdiff_backup(1, 1, unreadable_rp.path, self.output_rp.path,
+                                        current_time = 1)
+               rbdir = self.output_rp.append('rdiff-backup-data')
+               marker = 
rbdir.append('current_mirror.2000-12-31T21:33:20-07:00.data')
+               marker.touch()
+               self.change_unreadable()
+
+               cmd = "../rdiff-backup --check-destination-dir " + 
self.output_rp.path
+               print "Executing:", cmd
+               assert not os.system(cmd)
+
+       def make_unreadable(self):
+               """Make unreadable input directory
+
+               The directory needs to be readable initially (otherwise it
+               just won't get backed up, and then later we will turn it
+               unreadable.
+
+               """
+               rp = rpath.RPath(Globals.local_connection, "testfiles/regress")
+               if rp.lstat(): Myrm(rp.path)
+               rp.setdata()
+               rp.mkdir()
+               rp1 = rp.append('unreadable_dir')
+               rp1.mkdir()
+               rp1_1 = rp1.append('to_be_unreadable')
+               rp1_1.write_string('aensuthaoeustnahoeu')
+               return rp
+
+       def change_unreadable(self):
+               """Change attributes in directory, so regress will request fp"""
+               subdir = self.output_rp.append('unreadable_dir')
+               assert subdir.lstat()
+               rp1_1 = subdir.append('to_be_unreadable')
+               rp1_1.chmod(0)
+               subdir.chmod(0)
+               
+
+if __name__ == "__main__": unittest.main()
+
Index: rdiff-backup/testing/roottest.py
diff -u /dev/null rdiff-backup/testing/roottest.py:1.18.2.1
--- /dev/null   Mon Jan 16 04:09:50 2006
+++ rdiff-backup/testing/roottest.py    Mon Jan 16 04:09:50 2006
@@ -0,0 +1,331 @@
+import unittest, os
+from commontest import *
+from rdiff_backup import Globals, log
+
+"""Root tests - contain tests which need to be run as root.
+
+Some of the quoting here may not work with csh (works on bash).  Also,
+if you aren't me, check out the 'user' global variable.
+
+"""
+
+Globals.set('change_source_perms', None)
+Globals.counter = 0
+verbosity = 5
+log.Log.setverbosity(verbosity)
+user = 'ben' # Non-root user to su to
+userid = 500 # id of user above
+assert os.getuid() == 0, "Run this test as root!"
+
+def Run(cmd):
+       print "Running: ", cmd
+       assert not os.system(cmd)
+
+class RootTest(unittest.TestCase):
+       dirlist1 = ["testfiles/root", "testfiles/various_file_types",
+                               "testfiles/increment4"]
+       dirlist2 = ["testfiles/increment4", "testfiles/root",
+                               "testfiles/increment1"]
+       def testLocal1(self):
+               BackupRestoreSeries(1, 1, self.dirlist1, compare_ownership = 1)
+       def testLocal2(self):
+               BackupRestoreSeries(1, 1, self.dirlist2, compare_ownership = 1)
+       def testRemote(self):
+               BackupRestoreSeries(None, None, self.dirlist1, 
compare_ownership = 1)
+
+       def test_ownership(self):
+               """Test backing up and restoring directory with different uids
+
+               This checks for a bug in 0.13.4 where uids and gids would not
+               be restored correctly.
+
+               Also test to make sure symlinks get the right ownership.
+               (Earlier symlink ownership was not preserved.)
+
+               """
+               dirrp = rpath.RPath(Globals.local_connection, 
"testfiles/root_owner")
+               def make_dir():
+                       re_init_dir(dirrp)
+                       rp1 = dirrp.append('file1')
+                       rp2 = dirrp.append('file2')
+                       rp3 = dirrp.append('file3')
+                       rp4 = dirrp.append('file4')
+                       rp5 = dirrp.append('symlink')
+                       rp1.touch()
+                       rp2.touch()
+                       rp3.touch()
+                       rp4.touch()
+                       rp5.symlink('foobar')
+                       rp1.chown(2000, 2000)
+                       rp2.chown(2001, 2001)
+                       rp3.chown(2002, 2002)
+                       rp4.chown(2003, 2003)
+                       rp5.chown(2004, 2004)
+               make_dir()
+               BackupRestoreSeries(1, 1, ['testfiles/root_owner', 
'testfiles/empty',
+                                                                  
'testfiles/root_owner'],
+                                                       compare_ownership = 1)
+               symrp = rpath.RPath(Globals.local_connection,
+                                                       
'testfiles/output/symlink')
+               assert symrp.issym(), symrp
+               assert symrp.getuidgid() == (2004, 2004), symrp.getuidgid()
+
+       def test_ownership_mapping(self):
+               """Test --user-mapping-file and --group-mapping-file options"""
+               def write_ownership_dir():
+                       """Write the directory testfiles/root_mapping"""
+                       rp = rpath.RPath(Globals.local_connection,
+                                                        
"testfiles/root_mapping")
+                       re_init_dir(rp)
+                       rp1 = rp.append('1')
+                       rp1.touch()
+                       rp2 = rp.append('2')
+                       rp2.touch()
+                       rp2.chown(userid, 1) # use groupid 1, usually bin
+                       return rp
+
+               def write_mapping_files(dir_rp):
+                       """Write user and group mapping files, return paths"""
+                       user_map_rp = dir_rp.append('user_map')
+                       group_map_rp = dir_rp.append('group_map')
+                       user_map_rp.write_string('root:%s\n%s:root' % (user, 
user))
+                       group_map_rp.write_string('0:1')
+                       return user_map_rp.path, group_map_rp.path
+
+               def get_ownership(dir_rp):
+                       """Return pair (ids of dir_rp/1, ids of dir_rp2) of 
ids"""
+                       rp1, rp2 = map(dir_rp.append, ('1', '2'))
+                       assert rp1.isreg() and rp2.isreg(), (rp1.isreg(), 
rp2.isreg())
+                       return (rp1.getuidgid(), rp2.getuidgid())
+
+               in_rp = write_ownership_dir()
+               user_map, group_map = write_mapping_files(in_rp)
+               out_rp = rpath.RPath(Globals.local_connection, 
'testfiles/output')
+               if out_rp.lstat(): Myrm(out_rp.path)
+
+               assert get_ownership(in_rp) == ((0,0), (userid, 1)), \
+                          get_ownership(in_rp)
+               rdiff_backup(1, 0, in_rp.path, out_rp.path,
+                                        extra_options = ("--user-mapping-file 
%s "
+                                                                         
"--group-mapping-file %s" %
+                                                                         
(user_map, group_map)))
+               assert get_ownership(out_rp) == ((userid, 1), (0, 1)), \
+                          get_ownership(in_rp)
+
+
+class HalfRoot(unittest.TestCase):
+       """Backing up files where origin is root and destination is non-root"""
+       def make_dirs(self):
+               """Make source directories, return rpaths
+
+               These make a directory with a changing file that is not
+               self-readable.  (Caused problems earlier.)
+
+               """
+               rp1 = rpath.RPath(Globals.local_connection, 
"testfiles/root_half1")
+               re_init_dir(rp1)
+               rp1_1 = rp1.append('foo')
+               rp1_1.write_string('hello')
+               rp1_1.chmod(0)
+               rp1_2 = rp1.append('to be deleted')
+               rp1_2.write_string('aosetuhaosetnuhontu')
+               rp1_2.chmod(0)
+               rp1_3 = rp1.append('unreadable_dir')
+               rp1_3.mkdir()
+               rp1_3_1 = rp1_3.append('file_inside')
+               rp1_3_1.write_string('blah')
+               rp1_3_1.chmod(0)
+               rp1_3_2 = rp1_3.append('subdir_inside')
+               rp1_3_2.mkdir()
+               rp1_3_2_1 = rp1_3_2.append('foo')
+               rp1_3_2_1.write_string('saotnhu')
+               rp1_3_2_1.chmod(0)
+               rp1_3_2.chmod(0)
+               rp1_3.chmod(0)
+
+               rp2 = rpath.RPath(Globals.local_connection, 
"testfiles/root_half2")
+               re_init_dir(rp2)
+               rp2_1 = rp2.append('foo')
+               rp2_1.write_string('goodbye')
+               rp2_1.chmod(0)
+               rp2_3 = rp2.append('unreadable_dir')
+               rp2_3.mkdir()
+               rp2_3_1 = rp2_3.append('file_inside')
+               rp2_3_1.write_string('new string')
+               rp2_3_1.chmod(0)
+               rp2_3_2 = rp2_3.append('subdir_inside')
+               rp2_3_2.mkdir()
+               rp2_3_2_1 = rp2_3_2.append('foo')
+               rp2_3_2_1.write_string('asoetn;oet')
+               rp2_3_2_1.chmod(0)
+               rp2_3_2.chmod(0)
+               rp2_3_3 = rp2_3.append('file2')
+               rp2_3_3.touch()
+               rp2_3.chmod(0)
+               # The rp_2_4 below test for a perm error, also tested in
+               # regressiontest.py testConfig1
+               rp2_4 = rp2.append('test2')
+               rp2_4.mkdir()
+               rp2_4_1 = rp2_4.append('1-dir')
+               rp2_4_1.mkdir()
+               reg2_4_1_1 = rp2_4_1.append('reg')
+               reg2_4_1_1.touch()
+               reg2_4_1_1.chmod(0)
+               rp2_4_1.chmod(0)
+               reg2_4_2 = rp2_4.append('2-reg')
+               reg2_4_2.touch()
+               reg2_4_2.chmod(0)
+               rp2_4.chmod(0)
+
+               return rp1, rp2
+
+       def cause_regress(self, rp):
+               """Change some of the above to trigger regress"""
+               rp1_1 = rp.append('foo')
+               rp1_1.chmod(04)
+               rp_new = rp.append('lala')
+               rp_new.write_string('asoentuh')
+               rp_new.chmod(0)
+               assert not os.system('chown %s %s' % (user, rp_new.path))
+               rp1_3 = rp.append('unreadable_dir')
+               rp1_3.chmod(0700)
+               rp1_3_1 = rp1_3.append('file_inside')
+               rp1_3_1.chmod(01)
+               rp1_3.chmod(0)
+               
+               rbdir = rp.append('rdiff-backup-data')
+               
rbdir.append('current_mirror.2000-12-31T21:33:20-07:00.data').touch()
+
+       def test_backup(self):
+               """Test back up, simple restores"""
+               in_rp1, in_rp2 = self.make_dirs()
+               outrp = rpath.RPath(Globals.local_connection, 
"testfiles/output")
+               if outrp.lstat(): outrp.delete()
+               remote_schema = 'su -c "../rdiff-backup --server" %s' % (user,)
+               cmd_schema = ("../rdiff-backup -v" + str(verbosity) +
+                                         " --current-time %s --remote-schema 
'%%s' %s '%s'::%s")
+
+               cmd1 = cmd_schema % (10000, in_rp1.path, remote_schema, 
outrp.path)
+               print "Executing: ", cmd1
+               assert not os.system(cmd1)
+               in_rp1.setdata()
+               outrp.setdata()
+               assert CompareRecursive(in_rp1, outrp)
+
+               cmd2 = cmd_schema % (20000, in_rp2.path, remote_schema, 
outrp.path)
+               print "Executing: ", cmd2
+               assert not os.system(cmd2)
+               in_rp2.setdata()
+               outrp.setdata()
+               assert CompareRecursive(in_rp2, outrp)
+
+               rout_rp = rpath.RPath(Globals.local_connection,
+                                                         
"testfiles/restore_out")
+               restore_schema = ("../rdiff-backup -v" + str(verbosity) +
+                                                 " -r %s --remote-schema '%%s' 
'%s'::%s %s")
+               Myrm(rout_rp.path)
+               cmd3 = restore_schema % (10000, remote_schema, outrp.path,
+                                                                rout_rp.path)
+               print "Executing restore: ", cmd3
+               assert not os.system(cmd3)
+               rout_perms = rout_rp.append('unreadable_dir').getperms()
+               outrp_perms = outrp.append('unreadable_dir').getperms()
+               assert rout_perms == 0, rout_perms
+               assert outrp_perms == 0, outrp_perms
+
+               Myrm(rout_rp.path)
+               cmd4 = restore_schema % ("now", remote_schema, outrp.path,
+                                                                rout_rp.path)
+               print "Executing restore: ", cmd4
+               assert not os.system(cmd4)
+               rout_perms = rout_rp.append('unreadable_dir').getperms()
+               outrp_perms = outrp.append('unreadable_dir').getperms()
+               assert rout_perms == 0, rout_perms
+               assert outrp_perms == 0, outrp_perms
+
+               self.cause_regress(outrp)
+               cmd5 = ('su -c "../rdiff-backup --check-destination-dir %s" %s' 
%
+                               (outrp.path, user))
+               print "Executing regress: ", cmd5
+               assert not os.system(cmd5)
+               
+
+class NonRoot(unittest.TestCase):
+       """Test backing up as non-root user
+
+       Test backing up a directory with files of different userids and
+       with device files in it, as a non-root user.  When restoring as
+       root, everything should be restored normally.
+
+       """
+       def make_root_dirs(self):
+               """Make directory createable only by root"""
+               rp = rpath.RPath(Globals.local_connection, 
"testfiles/root_out1")
+               re_init_dir(rp)
+               rp1 = rp.append("1")
+               rp1.touch()
+               rp2 = rp.append("2")
+               rp2.touch()
+               rp2.chown(1, 1)
+               rp3 = rp.append("3")
+               rp3.touch()
+               rp3.chown(2, 2)
+               rp4 = rp.append("dev")
+               rp4.makedev('c', 4, 28)
+
+               sp = rpath.RPath(Globals.local_connection, 
"testfiles/root_out2")
+               if sp.lstat(): Myrm(sp.path)
+               Run("cp -a %s %s" % (rp.path, sp.path))
+               rp2 = sp.append("2")
+               rp2.chown(2, 2)
+               rp3 = sp.append("3")
+               rp3.chown(1, 1)
+               assert not CompareRecursive(rp, sp, compare_ownership = 1)
+
+               return rp, sp
+
+       def backup(self, input_rp, output_rp, time):
+               global user
+               backup_cmd = ("../rdiff-backup --no-compare-inode "
+                                         "--current-time %s %s %s" %
+                                         (time, input_rp.path, output_rp.path))
+               Run("su %s -c '%s'" % (user, backup_cmd))
+
+       def restore(self, dest_rp, restore_rp, time = None):
+               assert restore_rp.path == "testfiles/rest_out"
+               Myrm(restore_rp.path)
+               if time is None: time = "now"
+               restore_cmd = "../rdiff-backup -r %s %s %s" % (time, 
dest_rp.path,
+                                                                               
                           restore_rp.path,)
+               Run(restore_cmd)                
+
+       def test_non_root(self):
+               """Main non-root -> root test"""
+               Myrm("testfiles/output")
+               input_rp1, input_rp2 = self.make_root_dirs()
+               Globals.change_ownership = 1
+               output_rp = rpath.RPath(Globals.local_connection, 
"testfiles/output")
+               restore_rp = rpath.RPath(Globals.local_connection,
+                                                                
"testfiles/rest_out")
+               empty_rp = rpath.RPath(Globals.local_connection, 
"testfiles/empty")
+
+               self.backup(input_rp1, output_rp, 1000000)
+               self.restore(output_rp, restore_rp)
+               assert CompareRecursive(input_rp1, restore_rp, 
compare_ownership = 1)
+
+               self.backup(input_rp2, output_rp, 2000000)
+               self.restore(output_rp, restore_rp)
+               assert CompareRecursive(input_rp2, restore_rp, 
compare_ownership = 1)
+
+               self.backup(empty_rp, output_rp, 3000000)
+               self.restore(output_rp, restore_rp)
+               assert CompareRecursive(empty_rp, restore_rp, compare_ownership 
= 1)
+
+               self.restore(output_rp, restore_rp, 1000000)
+               assert CompareRecursive(input_rp1, restore_rp, 
compare_ownership = 1)
+
+               self.restore(output_rp, restore_rp, 2000000)
+               assert CompareRecursive(input_rp2, restore_rp, 
compare_ownership = 1)
+
+
+if __name__ == "__main__": unittest.main()
Index: rdiff-backup/testing/securitytest.py
diff -u /dev/null rdiff-backup/testing/securitytest.py:1.9.2.1
--- /dev/null   Mon Jan 16 04:09:50 2006
+++ rdiff-backup/testing/securitytest.py        Mon Jan 16 04:09:50 2006
@@ -0,0 +1,212 @@
+import os, unittest, time, traceback, sys
+from commontest import *
+import rdiff_backup.Security as 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.
+
+               """
+               if not isinstance(exc, Security.Violation):
+                       type, value, tb = sys.exc_info()
+                       print "".join(traceback.format_tb(tb))
+                       raise exc
+               #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 path in ["foobar", "/usr/local", "foo/../bar"]:
+                       try:
+                               rp = rpath.RPath(conn, path)
+                               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()
+
+       def test_vet_rpath_root(self):
+               """Test vetting when restricted to root"""
+               remote_cmd = "../rdiff-backup --server --restrict-update-only /"
+               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
+               SetConnections.CloseConnections()
+
+       def secure_rdiff_backup(self, in_dir, out_dir, in_local, restrict_args,
+                                                       extra_args = "", 
success = 1, current_time = None):
+               """Run rdiff-backup locally, with given restrict settings"""
+               if not current_time: current_time = int(time.time())
+               prefix = ('../rdiff-backup --current-time %s ' % 
(current_time,) +
+                                 '--remote-schema %s ')
+
+               if in_local: out_dir = ("'../rdiff-backup %s --server'::%s" %
+                                                               (restrict_args, 
out_dir))
+               else: in_dir = ("'../rdiff-backup %s --server'::%s" %
+                                               (restrict_args, in_dir))
+
+               cmdline = "%s %s %s %s" % (prefix, extra_args, in_dir, out_dir)
+               print "Executing:", cmdline
+               exit_val = os.system(cmdline)
+               if success: assert not exit_val
+               else: assert exit_val, "Success when wanted failure"
+
+       def test_restrict_positive(self):
+               """Test that --restrict switch doesn't get in the way
+
+               This makes sure that basic backups with the restrict operator
+               work, (initial backup, incremental, restore).
+
+               """
+               Myrm("testfiles/output")
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 1,
+                                                                '--restrict 
testfiles/output',
+                                                                current_time = 
10000)
+               # Note the backslash below -- test for bug in path normalization
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 1,
+                                                                '--restrict 
testfiles/output/')
+
+               Myrm("testfiles/restore_out")
+               self.secure_rdiff_backup('testfiles/output',
+                                                                
'testfiles/restore_out', 1,
+                                                                '--restrict 
testfiles/restore_out',
+                                                                extra_args = 
'-r now')
+
+       def test_restrict_negative(self):
+               """Test that --restrict switch denies certain operations"""
+               # Backup to wrong directory
+               Myrm("testfiles/output testfiles/output2")
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output2', 1,
+                                                                '--restrict 
testfiles/output',
+                                                                success = 0)
+
+               # Restore to wrong directory
+               Myrm("testfiles/output testfiles/restore_out")
+               rdiff_backup(1, 1, 'testfiles/various_file_types',
+                                        'testfiles/output')
+               self.secure_rdiff_backup('testfiles/output',
+                                                                
'testfiles/restore_out', 1,
+                                                                '--restrict 
testfiles/output2',
+                                                                extra_args = 
'-r now',
+                                                                success = 0)
+
+               # Backup from wrong directory
+               Myrm("testfiles/output")
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 0,
+                                                                '--restrict 
testfiles/foobar',
+                                                                success = 0)
+
+       def test_restrict_readonly_positive(self):
+               """Test that --restrict-read-only switch doesn't impair normal 
ops"""
+               Myrm("testfiles/output testfiles/restore_out")
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 0,
+                                                  '--restrict-read-only 
testfiles/various_file_types')
+                                                                
+               self.secure_rdiff_backup('testfiles/output',
+                                                                
'testfiles/restore_out', 0,
+                                                                
'--restrict-read-only testfiles/output',
+                                                                extra_args = 
'-r now')
+
+       def test_restrict_readonly_negative(self):
+               """Test that --restrict-read-only doesn't allow too much"""
+               # Backup to restricted directory
+               Myrm('testfiles/output')
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 1,
+                                                                
'--restrict-read-only testfiles/output',
+                                                                success = 0)
+
+               # Restore to restricted directory
+               Myrm('testfiles/output testfiles/restore_out')
+               rdiff_backup(1, 1, 'testfiles/various_file_types', 
'testfiles/output')
+               self.secure_rdiff_backup('testfiles/output',
+                                                                
'testfiles/restore_out', 1,
+                                                                
'--restrict-read-only testfiles/restore_out',
+                                                                extra_args = 
'-r now',
+                                                                success = 0)
+
+       def test_restrict_updateonly_positive(self):
+               """Test that --restrict-update-only allows intended use"""
+               Myrm('testfiles/output')
+               rdiff_backup(1, 1, 'testfiles/various_file_types', 
'testfiles/output',
+                                        current_time = 10000)
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 1,
+                                                                
'--restrict-update-only testfiles/output')
+
+       def test_restrict_updateonly_negative(self):
+               """Test that --restrict-update-only impairs unintended"""
+               Myrm('testfiles/output')
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 1,
+                                                                
'--restrict-update-only testfiles/output',
+                                                                success = 0)
+
+               Myrm('testfiles/output testfiles/restore_out')
+               rdiff_backup(1, 1, 'testfiles/various_file_types', 
'testfiles/output')
+               self.secure_rdiff_backup('testfiles/output',
+                                                                
'testfiles/restore_out', 1,
+                                                          
'--restrict-update-only testfiles/restore_out',
+                                                                extra_args = 
'-r now',
+                                                                success = 0)
+
+       def test_restrict_bug(self):
+               """Test for bug 14209 --- mkdir outside --restrict arg"""
+               Myrm('testfiles/output')
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 1,
+                                                                '--restrict 
foobar', success = 0)
+               output = rpath.RPath(Globals.local_connection, 
'testfiles/output')
+               assert not output.lstat()
+
+       def test_quoting_bug(self):
+               """Test for bug 14545 --- quoting causes bad violation"""
+               Myrm('testfiles/output')
+               self.secure_rdiff_backup('testfiles/various_file_types',
+                                                                
'testfiles/output', 1, '',
+                                                                extra_args = 
'--override-chars-to-quote e')
+
+
+if __name__ == "__main__": unittest.main()
+               




reply via email to

[Prev in Thread] Current Thread [Next in Thread]