|
6 | 6 | import pytest |
7 | 7 |
|
8 | 8 | from launchpad.artifacts.providers.zip_provider import ( |
9 | | - COMPRESSION_ZSTD, |
10 | 9 | UnreasonableZipError, |
11 | 10 | UnsafePathError, |
12 | 11 | ZipProvider, |
@@ -89,37 +88,6 @@ def test_invalid_zip_file(self) -> None: |
89 | 88 | with pytest.raises(zipfile.BadZipFile): |
90 | 89 | provider.extract_to_temp_directory() |
91 | 90 |
|
92 | | - def test_detect_compression_methods(self, hackernews_xcarchive: Path) -> None: |
93 | | - provider = ZipProvider(hackernews_xcarchive) |
94 | | - methods = provider._detect_compression_methods(str(hackernews_xcarchive)) |
95 | | - |
96 | | - # Verify detection works and standard zips use deflate compression, not zstd |
97 | | - assert zipfile.ZIP_DEFLATED in methods |
98 | | - assert COMPRESSION_ZSTD not in methods |
99 | | - |
100 | | - def test_extract_zstd_zip(self) -> None: |
101 | | - """Test that zstd-compressed zips can be extracted when zipfile-zstd is available.""" |
102 | | - try: |
103 | | - import zipfile_zstd # noqa: F401 |
104 | | - except ImportError: |
105 | | - pytest.skip("zipfile-zstd not installed") |
106 | | - |
107 | | - with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as temp_file: |
108 | | - temp_path = Path(temp_file.name) |
109 | | - |
110 | | - with zipfile.ZipFile(temp_path, "w") as zf: |
111 | | - zf.writestr("test.txt", "content", compress_type=COMPRESSION_ZSTD) |
112 | | - |
113 | | - try: |
114 | | - provider = ZipProvider(temp_path) |
115 | | - temp_dir = provider.extract_to_temp_directory() |
116 | | - |
117 | | - assert temp_dir.exists() |
118 | | - assert (temp_dir / "test.txt").exists() |
119 | | - assert (temp_dir / "test.txt").read_text() == "content" |
120 | | - finally: |
121 | | - temp_path.unlink(missing_ok=True) |
122 | | - |
123 | 91 |
|
124 | 92 | class TestIsSafePath: |
125 | 93 | def test_valid_paths(self) -> None: |
@@ -157,3 +125,22 @@ def test_max_file_size(self, hackernews_xcarchive: Path) -> None: |
157 | 125 | # iOS fixture is ~32MB uncompressed, so limit of 10MB should fail |
158 | 126 | with pytest.raises(UnreasonableZipError, match="exceeding the limit of 10.0MB"): |
159 | 127 | check_reasonable_zip(zf, max_uncompressed_size=10 * 1024 * 1024) |
| 128 | + |
| 129 | + def test_extract_zstd_zip(self) -> None: |
| 130 | + """Test that zstd-compressed zips can be extracted.""" |
| 131 | + with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as temp_file: |
| 132 | + temp_path = Path(temp_file.name) |
| 133 | + |
| 134 | + # Create a zstd-compressed zip (compression method 93) |
| 135 | + with zipfile.ZipFile(temp_path, "w") as zf: |
| 136 | + zf.writestr("test.txt", "content", compress_type=93) |
| 137 | + |
| 138 | + try: |
| 139 | + provider = ZipProvider(temp_path) |
| 140 | + temp_dir = provider.extract_to_temp_directory() |
| 141 | + |
| 142 | + assert temp_dir.exists() |
| 143 | + assert (temp_dir / "test.txt").exists() |
| 144 | + assert (temp_dir / "test.txt").read_text() == "content" |
| 145 | + finally: |
| 146 | + temp_path.unlink(missing_ok=True) |
0 commit comments