Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_new_eltorito_multi_hidden():
# Create a new ISO.
iso = pycdlib.PyCdlib()
iso.new(interchange_level=4)
bootstr = b"boot\n"
iso.add_fp(BytesIO(bootstr), len(bootstr), "/boot")
iso.add_eltorito("/boot", "/boot.cat")
boot2str = b"boot2\n"
iso.add_fp(BytesIO(boot2str), len(boot2str), "/boot2")
iso.add_eltorito("/boot2", "/boot.cat")
iso.rm_hard_link(iso_path="/boot2")
do_a_test(iso, check_eltorito_multi_hidden)
iso.close()
def do_a_test(tmpdir, outfile, check_func):
testout = tmpdir.join("writetest.iso")
# Now open up the ISO with pycdlib and check some things out.
iso = pycdlib.PyCdlib()
iso.open(str(outfile))
check_func(iso, os.stat(str(outfile)).st_size)
iso.write(str(testout))
iso.close()
# Now round-trip through write.
iso2 = pycdlib.PyCdlib()
iso2.open(str(testout))
check_func(iso2, os.stat(str(outfile)).st_size)
iso2.close()
def test_facade_iso9660_add_directory():
iso = pycdlib.PyCdlib()
iso.new()
facade = iso.get_iso9660_facade()
facade.add_directory('/DIR1')
rec = facade.get_record('/DIR1')
assert(rec.file_identifier() == b'DIR1')
iso.close()
def test_new_get_record_iso_path():
iso = pycdlib.PyCdlib()
iso.new()
iso.add_directory("/DIR1")
rec = iso.get_record(iso_path="/DIR1")
assert(rec.file_identifier() == b'DIR1')
assert(len(rec.children) == 2)
iso.close()
def test_parse_list_dir(tmpdir):
# First set things up, and generate the ISO with genisoimage.
indir = tmpdir.mkdir("twofile")
outfile = str(indir)+".iso"
dir1 = indir.mkdir("dir1")
with open(os.path.join(str(dir1), "bar"), 'w') as outfp:
outfp.write("bar\n")
subprocess.call(["genisoimage", "-v", "-v", "-iso-level", "1", "-no-pad",
"-o", str(outfile), str(indir)])
# Now open up the ISO with pycdlib and check some things out.
iso = pycdlib.PyCdlib()
iso.open(str(outfile))
for children in iso.list_dir("/DIR1"):
pass
iso.close()
def test_facade_iso9660_open_file_from_iso():
iso = pycdlib.PyCdlib()
iso.new()
facade = iso.get_iso9660_facade()
foostr = b'foo\n'
facade.add_fp(BytesIO(foostr), len(foostr), '/FOO.;1')
with facade.open_file_from_iso('/FOO.;1') as infp:
assert(infp.read() == b'foo\n')
assert(infp.tell() == 4)
iso.close()
def test_parse_open_invalid_pvd_unused1(tmpdir):
# First set things up, and generate the ISO with genisoimage.
indir = tmpdir.mkdir('modifyinplaceisolevel4onefile')
outfile = str(indir)+'.iso'
subprocess.call(['genisoimage', '-v', '-v', '-iso-level', '4', '-no-pad',
'-o', str(outfile), str(indir)])
# Now that we've made a valid ISO, we open it up and perturb the first
# byte. This should be enough to make an invalid ISO.
with open(str(outfile), 'r+b') as fp:
fp.seek((16*2048)+7)
fp.write(b'\x02')
iso = pycdlib.PyCdlib()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
iso.open(str(outfile))
assert(str(excinfo.value) == 'PVD flags field is not zero')
def open_and_check(outfile, checkfunc):
iso = pycdlib.PyCdlib()
iso.open(str(outfile))
checkfunc(iso, os.stat(str(outfile)).st_size)
iso.close()
def test_parse_open_invalid_pvd_unused4(tmpdir):
# First set things up, and generate the ISO with genisoimage.
indir = tmpdir.mkdir("modifyinplaceisolevel4onefile")
outfile = str(indir)+".iso"
subprocess.call(["genisoimage", "-v", "-v", "-iso-level", "4", "-no-pad",
"-o", str(outfile), str(indir)])
# Now that we've made a valid ISO, we open it up and perturb the first
# byte. This should be enough to make an invalid ISO.
with open(str(outfile), 'r+b') as fp:
fp.seek((16*2048)+882)
fp.write('\x02')
iso = pycdlib.PyCdlib()
with pytest.raises(pycdlib.PyCdlibException):
iso.open(str(outfile))
def test_facade_joliet_add_directory():
iso = pycdlib.PyCdlib()
iso.new(joliet=3)
facade = iso.get_joliet_facade()
facade.add_directory('/dir1')
rec = facade.get_record('/dir1')
assert(rec.file_identifier() == bytes('dir1'.encode('utf-16_be')))
iso.close()