|
13 | 13 | import pytest |
14 | 14 | from pycdlib import PyCdlib |
15 | 15 |
|
| 16 | +from ofrak import OFRAKContext |
16 | 17 | from ofrak.resource import Resource |
17 | 18 | from ofrak.core.iso9660 import ( |
18 | 19 | ISO9660Entry, |
@@ -167,3 +168,41 @@ def create_test_file(self, tmpdir): |
167 | 168 | ) |
168 | 169 | iso.write(os.path.join(tmpdir, self.TEST_ISO_NAME)) |
169 | 170 | self._test_file = os.path.join(tmpdir, self.TEST_ISO_NAME) |
| 171 | + |
| 172 | + |
| 173 | +@pytest.mark.skipif_missing_deps([ISO9660Unpacker]) |
| 174 | +class TestIso9660RootLevelFileUnpack: |
| 175 | + """ |
| 176 | + Test for an ISO that contains a file directly at the root (no enclosing directory). |
| 177 | + """ |
| 178 | + |
| 179 | + TEST_ISO_NAME = "root_file.iso" |
| 180 | + ROOT_FILE_NAME = "ROOTFILE.TXT" |
| 181 | + ROOT_FILE_DATA = b"hello at the root\n" |
| 182 | + |
| 183 | + @pytest.fixture |
| 184 | + def iso_with_root_level_file(self, tmpdir): |
| 185 | + iso = PyCdlib() |
| 186 | + iso.new(interchange_level=3) |
| 187 | + iso.add_fp( |
| 188 | + BytesIO(self.ROOT_FILE_DATA), |
| 189 | + len(self.ROOT_FILE_DATA), |
| 190 | + "/" + self.ROOT_FILE_NAME + ";1", |
| 191 | + ) |
| 192 | + path = os.path.join(tmpdir, self.TEST_ISO_NAME) |
| 193 | + iso.write(path) |
| 194 | + iso.close() |
| 195 | + return path |
| 196 | + |
| 197 | + async def test_unpack_iso_with_root_level_file( |
| 198 | + self, ofrak_context: OFRAKContext, iso_with_root_level_file |
| 199 | + ): |
| 200 | + root_resource = await ofrak_context.create_root_resource_from_file(iso_with_root_level_file) |
| 201 | + await root_resource.unpack() |
| 202 | + |
| 203 | + iso_resource = await root_resource.view_as(ISO9660Image) |
| 204 | + for descendant in await iso_resource.resource.get_descendants(): |
| 205 | + assert ISO9660Entry in descendant.get_tags(), ( |
| 206 | + f"Descendant {descendant.get_id().hex()} with tags {tags} is missing " |
| 207 | + f"ISO9660Entry" |
| 208 | + ) |
0 commit comments