Example #1
0
    def test_iterate_over_archive_with_invalid_size(self):
        data = elf_reader.ARCHIVE_MAGIC + _archive_file(b'$' * 3210)
        file = io.BytesIO(data)

        # Iterate over the file normally.
        for size in elf_reader.files_in_archive(file):
            self.assertEqual(b'$' * 3210, file.read(size))

        # Replace the size with a hex number, which is not valid.
        with self.assertRaises(elf_reader.FileDecodeError):
            for _ in elf_reader.files_in_archive(
                    io.BytesIO(data.replace(b'3210', b'0x99'))):
                pass
Example #2
0
    def test_extra_newline_after_entry_is_ignored(self):
        archive = io.BytesIO(elf_reader.ARCHIVE_MAGIC +
                             _archive_file(self._elf_data) + b'\n' +
                             _archive_file(self._elf_data))

        for size in elf_reader.files_in_archive(archive):
            self.assertEqual(self._elf_data, archive.read(size))
Example #3
0
    def test_two_extra_newlines_parsing_fails(self):
        archive = io.BytesIO(elf_reader.ARCHIVE_MAGIC +
                             _archive_file(self._elf_data) + b'\n\n' +
                             _archive_file(self._elf_data))

        with self.assertRaises(elf_reader.FileDecodeError):
            for size in elf_reader.files_in_archive(archive):
                self.assertEqual(self._elf_data, archive.read(size))
Example #4
0
 def test_iterate_over_invalid_archive(self):
     with self.assertRaises(elf_reader.FileDecodeError):
         for _ in elf_reader.files_in_archive(
                 io.BytesIO(b'!<arch>blah blahblah')):
             pass
Example #5
0
 def test_iterate_over_empty_archive(self):
     with self.assertRaises(StopIteration):
         next(iter(elf_reader.files_in_archive(io.BytesIO(b'!<arch>\n'))))
Example #6
0
 def test_iterate_over_files(self):
     for expected, size in zip(self._archive_entries,
                               elf_reader.files_in_archive(self._archive)):
         self.assertEqual(expected, self._archive.read(size))