def test_apply_to_path_restricted_access(): if is_superuser() or detect_fakeroot(): return if sys.platform.startswith("cygwin"): return # chmod 000 isn't effective. tmpdir = tempfile.mkdtemp(prefix="bup-tmetadata-") try: parent = tmpdir + "/foo" path = parent + "/bar" os.mkdir(parent) os.mkdir(path) clear_errors() m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(parent, 000) m.apply_to_path(path) print >>sys.stderr, helpers.saved_errors expected_errors = ["utime: "] if m.linux_attr and _linux_attr_supported(tmpdir): expected_errors.append("Linux chattr: ") if metadata.xattr and m.linux_xattr: expected_errors.append("xattr.set: ") WVPASS(len(helpers.saved_errors) == len(expected_errors)) for i in xrange(len(expected_errors)): WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i])) clear_errors() finally: subprocess.call(["chmod", "-R", "u+rwX", tmpdir]) subprocess.call(["rm", "-rf", tmpdir])
def test_restore_restricted_user_group(): if is_superuser() or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' os.mkdir(path) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) WVPASSEQ(m.apply_to_path(path), None) orig_uid = m.uid m.uid = 0; m.apply_to_path(path, restore_numeric_ids=True) WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith('lchown: ')) clear_errors() m.uid = orig_uid m.gid = 0; m.apply_to_path(path, restore_numeric_ids=True) WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith('lchown: ') or os.stat(path).st_gid == m.gid) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_handling_of_incorrect_existing_linux_xattrs(): if not is_superuser() or detect_fakeroot(): WVMSG("skipping test -- not superuser") return setup_testfs() for f in glob.glob("testfs/*"): ex("rm", "-rf", f) path = "testfs/foo" open(path, "w").close() xattr.set(path, "foo", "bar", namespace=xattr.NS_USER) m = metadata.from_path(path, archive_path=path, save_symlinks=True) xattr.set(path, "baz", "bax", namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ["user.foo"]) WVPASSEQ(xattr.get(path, "user.foo"), "bar") xattr.set(path, "foo", "baz", namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ["user.foo"]) WVPASSEQ(xattr.get(path, "user.foo"), "bar") xattr.remove(path, "foo", namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ["user.foo"]) WVPASSEQ(xattr.get(path, "user.foo"), "bar") os.chdir(start_dir) cleanup_testfs()
def test_handling_of_incorrect_existing_linux_xattrs(): if not is_superuser() or detect_fakeroot(): pytest.skip('skipping test -- not superuser') return if not setup_testfs(): pytest.skip('unable to load loop module; skipping dependent tests') return for f in glob.glob(b'testfs/*'): ex(b'rm', b'-rf', f) path = b'testfs/foo' open(path, 'w').close() xattr.set(path, b'foo', b'bar', namespace=xattr.NS_USER) m = metadata.from_path(path, archive_path=path, save_symlinks=True) xattr.set(path, b'baz', b'bax', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(remove_selinux(xattr.list(path)), [b'user.foo']) WVPASSEQ(xattr.get(path, b'user.foo'), b'bar') xattr.set(path, b'foo', b'baz', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(remove_selinux(xattr.list(path)), [b'user.foo']) WVPASSEQ(xattr.get(path, b'user.foo'), b'bar') xattr.remove(path, b'foo', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(remove_selinux(xattr.list(path)), [b'user.foo']) WVPASSEQ(xattr.get(path, b'user.foo'), b'bar') cleanup_testfs()
def test_apply_to_path_restricted_access(tmpdir): if is_superuser() or detect_fakeroot(): return if sys.platform.startswith('cygwin'): return # chmod 000 isn't effective. try: parent = tmpdir + b'/foo' path = parent + b'/bar' os.mkdir(parent) os.mkdir(path) clear_errors() if metadata.xattr: try: metadata.xattr.set(path, b'user.buptest', b'bup') except: print("failed to set test xattr") # ignore any failures here - maybe FS cannot do it pass m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(parent, 0o000) m.apply_to_path(path) print(b'saved_errors:', helpers.saved_errors, file=sys.stderr) expected_errors = ['utime: '] if m.linux_attr and _linux_attr_supported(tmpdir): expected_errors.append('Linux chattr: ') if metadata.xattr and m.linux_xattr: expected_errors.append("xattr.set ") WVPASS(len(helpers.saved_errors) == len(expected_errors)) for i in range(len(expected_errors)): assert str(helpers.saved_errors[i]).startswith(expected_errors[i]) finally: clear_errors()
def test_apply_to_path_restricted_access(): initial_failures = wvfailure_count() if is_superuser() or detect_fakeroot(): return if sys.platform.startswith('cygwin'): return # chmod 000 isn't effective. tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-') parent = tmpdir + '/foo' path = parent + '/bar' os.mkdir(parent) os.mkdir(path) clear_errors() m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(parent, 000) m.apply_to_path(path) print >> sys.stderr, helpers.saved_errors expected_errors = ['utime: '] if m.linux_attr and _linux_attr_supported(tmpdir): expected_errors.append('Linux chattr: ') if metadata.xattr and m.linux_xattr: expected_errors.append('xattr.set: ') WVPASS(len(helpers.saved_errors) == len(expected_errors)) for i in xrange(len(expected_errors)): WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i])) clear_errors() if wvfailure_count() == initial_failures: subprocess.call(['chmod', '-R', 'u+rwX', tmpdir]) subprocess.call(['rm', '-rf', tmpdir])
def test_apply_to_path_restricted_access(): initial_failures = wvfailure_count() if is_superuser() or detect_fakeroot(): return if sys.platform.startswith('cygwin'): return # chmod 000 isn't effective. tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-') parent = tmpdir + '/foo' path = parent + '/bar' os.mkdir(parent) os.mkdir(path) clear_errors() m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(parent, 000) m.apply_to_path(path) print >> sys.stderr, helpers.saved_errors expected_errors = ['utime: '] if m.linux_attr and _linux_attr_supported(tmpdir): expected_errors.append('Linux chattr: ') if metadata.xattr and m.linux_xattr: expected_errors.append("xattr.set '") WVPASS(len(helpers.saved_errors) == len(expected_errors)) for i in xrange(len(expected_errors)): WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i])) clear_errors() if wvfailure_count() == initial_failures: subprocess.call(['chmod', '-R', 'u+rwX', tmpdir]) subprocess.call(['rm', '-rf', tmpdir])
def test_handling_of_incorrect_existing_linux_xattrs(): if not is_superuser() or detect_fakeroot(): WVMSG('skipping test -- not superuser') return setup_testfs() for f in glob.glob('testfs/*'): ex('rm', '-rf', f) path = 'testfs/foo' open(path, 'w').close() xattr.set(path, 'foo', 'bar', namespace=xattr.NS_USER) m = metadata.from_path(path, archive_path=path, save_symlinks=True) xattr.set(path, 'baz', 'bax', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ['user.foo']) WVPASSEQ(xattr.get(path, 'user.foo'), 'bar') xattr.set(path, 'foo', 'baz', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ['user.foo']) WVPASSEQ(xattr.get(path, 'user.foo'), 'bar') xattr.remove(path, 'foo', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ['user.foo']) WVPASSEQ(xattr.get(path, 'user.foo'), 'bar') os.chdir(start_dir) cleanup_testfs()
def test_apply_to_path_restricted_access(): if is_superuser() or detect_fakeroot(): return if sys.platform.startswith('cygwin'): return # chmod 000 isn't effective. with no_lingering_errors(), test_tempdir('bup-tmetadata-') as tmpdir: parent = tmpdir + '/foo' path = parent + '/bar' os.mkdir(parent) os.mkdir(path) clear_errors() m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(parent, 000) m.apply_to_path(path) print >> sys.stderr, 'saved_errors:', helpers.saved_errors expected_errors = ['utime: '] if m.linux_attr and _linux_attr_supported(tmpdir): expected_errors.append('Linux chattr: ') if metadata.xattr and m.linux_xattr: expected_errors.append("xattr.set '") WVPASS(len(helpers.saved_errors) == len(expected_errors)) for i in xrange(len(expected_errors)): WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i])) clear_errors()
def test_from_path_error(tmpdir): if is_superuser() or detect_fakeroot(): return path = tmpdir + b'/foo' os.mkdir(path) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(path, 0o000) metadata.from_path(path, archive_path=path, save_symlinks=True) if metadata.get_linux_file_attr: print('saved_errors:', helpers.saved_errors, file=sys.stderr) WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith('read Linux attr')) clear_errors()
def test_from_path_error(): if os.geteuid() == 0 or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' subprocess.call(['mkdir', path]) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) subprocess.call(['chmod', '000', path]) metadata.from_path(path, archive_path=path, save_symlinks=True) errmsg = helpers.saved_errors[0] if helpers.saved_errors else '' WVPASS(errmsg.startswith('read Linux attr')) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_from_path_error(): if is_superuser() or detect_fakeroot(): return with no_lingering_errors(), test_tempdir('bup-tmetadata-') as tmpdir: path = tmpdir + '/foo' os.mkdir(path) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(path, 000) metadata.from_path(path, archive_path=path, save_symlinks=True) if metadata.get_linux_file_attr: print >> sys.stderr, 'saved_errors:', helpers.saved_errors WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith('read Linux attr')) clear_errors()
def test_apply_to_path_restricted_access(): if is_superuser() or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' os.mkdir(path) clear_errors() m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(tmpdir, 000) m.apply_to_path(path) errmsg = _first_err() WVPASS(errmsg.startswith('utime: ')) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_from_path_error(): if os.geteuid() == 0 or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' os.mkdir(path) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(path, 000) metadata.from_path(path, archive_path=path, save_symlinks=True) if metadata.get_linux_file_attr: errmsg = _first_err() WVPASS(errmsg.startswith('read Linux attr')) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_from_path_error(): if is_superuser() or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' os.mkdir(path) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(path, 000) metadata.from_path(path, archive_path=path, save_symlinks=True) if metadata.get_linux_file_attr: errmsg = _first_err() WVPASS(errmsg.startswith('read Linux attr')) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_apply_to_path_restricted_access(): if os.geteuid() == 0 or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' os.mkdir(path) clear_errors() m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(tmpdir, 000) m.apply_to_path(path) errmsg = _first_err() WVPASS(errmsg.startswith('utime: ')) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_from_path_error(): initial_failures = wvfailure_count() if is_superuser() or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-') path = tmpdir + '/foo' os.mkdir(path) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(path, 000) metadata.from_path(path, archive_path=path, save_symlinks=True) if metadata.get_linux_file_attr: WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith('read Linux attr')) clear_errors() if wvfailure_count() == initial_failures: subprocess.call(['chmod', '-R', 'u+rwX', tmpdir]) subprocess.call(['rm', '-rf', tmpdir])
def test_from_path_error(): if is_superuser() or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix="bup-tmetadata-") try: path = tmpdir + "/foo" os.mkdir(path) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(path, 000) metadata.from_path(path, archive_path=path, save_symlinks=True) if metadata.get_linux_file_attr: WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith("read Linux attr")) clear_errors() finally: subprocess.call(["chmod", "-R", "u+rwX", tmpdir]) subprocess.call(["rm", "-rf", tmpdir])
def test_apply_to_path_restricted_access(): if is_superuser() or detect_fakeroot(): return if sys.platform.startswith('cygwin'): return # chmod 000 isn't effective. tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' os.mkdir(path) clear_errors() m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) os.chmod(tmpdir, 000) m.apply_to_path(path) WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith('utime: ')) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_handling_of_incorrect_existing_linux_xattrs(): if os.geteuid() != 0 or detect_fakeroot(): return setup_testfs() subprocess.check_call('rm -rf testfs/*', shell=True) path = 'testfs/foo' open(path, 'w').close() xattr.set(path, 'foo', 'bar', namespace=xattr.NS_USER) m = metadata.from_path(path, archive_path=path, save_symlinks=True) xattr.set(path, 'baz', 'bax', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ['user.foo']) WVPASSEQ(xattr.get(path, 'user.foo'), 'bar') xattr.set(path, 'foo', 'baz', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ['user.foo']) WVPASSEQ(xattr.get(path, 'user.foo'), 'bar') xattr.remove(path, 'foo', namespace=xattr.NS_USER) m.apply_to_path(path, restore_numeric_ids=False) WVPASSEQ(xattr.list(path), ['user.foo']) WVPASSEQ(xattr.get(path, 'user.foo'), 'bar') os.chdir(top_dir) cleanup_testfs()
def test_restore_restricted_user_group(): if os.geteuid() == 0 or detect_fakeroot(): return tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: path = tmpdir + '/foo' subprocess.call(['mkdir', path]) m = metadata.from_path(path, archive_path=path, save_symlinks=True) WVPASSEQ(m.path, path) WVPASSEQ(m.apply_to_path(path), None) orig_uid = m.uid m.uid = 0; m.apply_to_path(path, restore_numeric_ids=True) errmsg = str(helpers.saved_errors[0]) if helpers.saved_errors else '' WVPASS(errmsg.startswith('lchown: ')) clear_errors() m.uid = orig_uid m.gid = 0; m.apply_to_path(path, restore_numeric_ids=True) errmsg = str(helpers.saved_errors[0]) if helpers.saved_errors else '' WVPASS(errmsg.startswith('lchown: ')) clear_errors() finally: subprocess.call(['rm', '-rf', tmpdir])
def test_detect_fakeroot(): if os.getenv('FAKEROOTKEY'): WVPASS(detect_fakeroot()) else: WVPASS(not detect_fakeroot())
def test_detect_fakeroot(): if b'FAKEROOTKEY' in environ: WVPASS(detect_fakeroot()) else: WVPASS(not detect_fakeroot())
def test_detect_fakeroot(): with no_lingering_errors(): if os.getenv('FAKEROOTKEY'): WVPASS(detect_fakeroot()) else: WVPASS(not detect_fakeroot())
def test_detect_fakeroot(): with no_lingering_errors(): if b'FAKEROOTKEY' in environ: WVPASS(detect_fakeroot()) else: WVPASS(not detect_fakeroot())