|
9 | 9 |
|
10 | 10 | import pytest |
11 | 11 |
|
12 | | -from libarchive import ArchiveError, memory_reader, memory_writer |
| 12 | +from libarchive import ( |
| 13 | + ArchiveError, ffi, file_reader, file_writer, memory_reader, memory_writer, |
| 14 | +) |
13 | 15 | from libarchive.entry import ArchiveEntry, ConsumedArchiveEntry, PassedArchiveEntry |
14 | 16 |
|
15 | 17 | from . import data_dir, get_entries, get_tarinfos |
@@ -155,3 +157,26 @@ def test_non_ASCII_encoding_of_file_metadata(): |
155 | 157 | with memory_reader(buf, header_codec='cp037') as archive: |
156 | 158 | entry = next(iter(archive)) |
157 | 159 | assert entry.pathname == file_name |
| 160 | + |
| 161 | + |
| 162 | +@pytest.mark.xfail( |
| 163 | + condition=ffi.version_number() < 3008000, |
| 164 | + reason="libarchive < 3.8", |
| 165 | +) |
| 166 | +def test_writing_and_reading_entry_digests(tmpdir): |
| 167 | + fake_hashes = dict( |
| 168 | + md5=b'0000000000000000', |
| 169 | + rmd160=b'00000000000000000000', |
| 170 | + sha1=b'00000000000000000000', |
| 171 | + sha256=b'00000000000000000000000000000000', |
| 172 | + sha384=b'000000000000000000000000000000000000000000000000', |
| 173 | + sha512=b'0000000000000000000000000000000000000000000000000000000000000000', |
| 174 | + ) |
| 175 | + archive_path = str(tmpdir / 'mtree') |
| 176 | + with file_writer(archive_path, 'mtree') as archive: |
| 177 | + # Add an empty file, with fake hashes. |
| 178 | + archive.add_file_from_memory('empty.txt', 0, b'', **fake_hashes) |
| 179 | + with file_reader(archive_path) as archive: |
| 180 | + entry = next(iter(archive)) |
| 181 | + for key, value in fake_hashes.items(): |
| 182 | + assert getattr(entry, key) == value |
0 commit comments