def test_extract(tmpdir, bundlepath, ensure_directory_contents): """test extracting a zipfile"""
dest = tmpdir.mkdir("dest").strpath
mozfile.extract(bundlepath, dest)
ensure_directory_contents(dest)
def test_extract_zipfile_missing_file_attributes(tmpdir): """if files do not have attributes set the default permissions have to be inherited."""
_zipfile = os.path.join(
os.path.dirname(__file__), "files", "missing_file_attributes.zip"
) assert os.path.exists(_zipfile)
dest = tmpdir.mkdir("dest").strpath
# Get the default file permissions for the user
fname = os.path.join(dest, "foo") with open(fname, "w"): pass
default_stmode = os.stat(fname).st_mode
files = mozfile.extract_zip(_zipfile, dest) for filename in files: assert os.stat(os.path.join(dest, filename)).st_mode == default_stmode
def test_extract_non_archive(tarpath, zippath): """test the generalized extract function""" # test extracting some non-archive; this should fail
fd, filename = tempfile.mkstemp()
os.write(fd, b"This is not a zipfile or tarball")
os.close(fd)
exception = None
try:
dest = tempfile.mkdtemp()
mozfile.extract(filename, dest) except Exception as exc:
exception = exc finally:
os.remove(filename)
os.rmdir(dest)
def test_tarball_escape(tmpdir): """Ensures that extracting a tarball can't write outside of the intended
destination directory. """
workdir = tmpdir.mkdir("workdir")
os.chdir(workdir)
# Generate a "malicious" bundle. with open("bad.txt", "w") as fh:
fh.write("pwned!")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.