Skip to content

gh-95675 filter uid/guid in test_add_dir_getmember #96505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,30 @@ def test_issue14160(self):
self._test_fileobj_link("symtype2", "ustar/regtype")

def test_add_dir_getmember(self):
def reset(tarinfo):
tarinfo.uid = tarinfo.gid = 1000
return tarinfo

# bpo-21987
self.add_dir_and_getmember('bar')
self.add_dir_and_getmember('a'*101)
self.add_dir_and_getmember('bar', reset)
self.add_dir_and_getmember('a'*101, reset)

def test_add_dir_getmember_throw_exception_invalid_uid_gid(self):
def reset(tarinfo):
tarinfo.uid = tarinfo.gid = 16777216
return tarinfo

with self.assertRaises(ValueError) as context:
self.add_dir_and_getmember('bar', reset)
self.add_dir_and_getmember('a'*101, reset)

def add_dir_and_getmember(self, name):
def add_dir_and_getmember(self, name, filter):
with os_helper.temp_cwd():
with tarfile.open(tmpname, 'w') as tar:
tar.format = tarfile.USTAR_FORMAT
try:
os.mkdir(name)
tar.add(name)
tar.add(name,filter=filter)
finally:
os.rmdir(name)
with tarfile.open(tmpname) as tar:
Expand Down