# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import hashlib import os import shutil import stat import tarfile import tempfile import unittest
import pytest from mozunit import main
from mozpack.archive import (
DEFAULT_MTIME,
create_tar_bz2_from_files,
create_tar_from_files,
create_tar_gz_from_files,
) from mozpack.files import GeneratedFile
def file_hash(path):
h = hashlib.sha1() with open(path, "rb") as fh: whileTrue:
data = fh.read(8192) ifnot data: break
h.update(data)
return h.hexdigest()
class TestArchive(unittest.TestCase): def _create_files(self, root):
files = {} for i in range(10):
p = os.path.join(root, "file%02d" % i) with open(p, "wb") as fh:
fh.write(b"file%02d" % i) # Need to set permissions or umask may influence testing.
os.chmod(p, MODE_STANDARD)
files["file%02d" % i] = p
for i in range(10):
files["file%02d" % (i + 10)] = GeneratedFile(b"file%02d" % (i + 10))
names = ["file%02d" % i for i in range(20)]
self.assertEqual(tf.getnames(), names)
for ti in tf.getmembers():
self.assertEqual(ti.uid, 0)
self.assertEqual(ti.gid, 0)
self.assertEqual(ti.uname, "")
self.assertEqual(ti.gname, "")
self.assertEqual(ti.mode, MODE_STANDARD)
self.assertEqual(ti.mtime, DEFAULT_MTIME)
@pytest.mark.xfail(
reason="ValueError is not thrown despite being provided directory."
) def test_dirs_refused(self):
d = tempfile.mkdtemp() try:
tp = os.path.join(d, "test.tar") with open(tp, "wb") as fh: with self.assertRaisesRegex(ValueError, "not a regular"):
create_tar_from_files(fh, {"test": d}) finally:
shutil.rmtree(d)
@pytest.mark.xfail(reason="ValueError is not thrown despite uid/gid being set.") def test_setuid_setgid_refused(self):
d = tempfile.mkdtemp() try:
uid = os.path.join(d, "setuid")
gid = os.path.join(d, "setgid") with open(uid, "a"): pass with open(gid, "a"): pass
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 ist noch experimentell.