|
| 1 | +import hashlib |
1 | 2 | import json |
2 | 3 | import re |
3 | 4 | import tarfile |
@@ -128,3 +129,53 @@ def test_process_tarball_with_tarball_url_v6(tmp_path: Path) -> None: |
128 | 129 | url_idx_file = store_dir / url_dir_name / 'integrity.json' |
129 | 130 |
|
130 | 131 | assert url_idx_file.exists() |
| 132 | + |
| 133 | + |
| 134 | +def test_process_tarball_with_uppercase_path(tmp_path: Path) -> None: |
| 135 | + tar_path = tmp_path / 'pkg.tgz' |
| 136 | + store_dir = tmp_path / 'store' |
| 137 | + tarball_url = 'https://example.com/PKG.tgz' |
| 138 | + |
| 139 | + _create_tarball(tar_path, {'package/index.js': "console.log('hello');"}) |
| 140 | + |
| 141 | + _process_tarball( |
| 142 | + tarball_path=str(tar_path), |
| 143 | + pkg_name='pkg', |
| 144 | + pkg_version='1.0.0', |
| 145 | + integrity_hex='a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2', |
| 146 | + store=str(store_dir), |
| 147 | + now=1234567890, |
| 148 | + tarball_url=tarball_url, |
| 149 | + store_version='v6', |
| 150 | + ) |
| 151 | + |
| 152 | + sanitized_tarball_url = re.sub(r'[:/]', '+', tarball_url) |
| 153 | + normalized_tarball_url = f'{sanitized_tarball_url}_{hashlib.sha256(sanitized_tarball_url.encode()).hexdigest()[:32]}' |
| 154 | + url_idx_file = store_dir / normalized_tarball_url / 'integrity.json' |
| 155 | + |
| 156 | + assert url_idx_file.exists() |
| 157 | + |
| 158 | + |
| 159 | +def test_process_tarball_with_long_path(tmp_path: Path) -> None: |
| 160 | + tar_path = tmp_path / 'pkg.tgz' |
| 161 | + store_dir = tmp_path / 'store' |
| 162 | + tarball_url = f'https://example.com{"pkg" * 50}.tgz' |
| 163 | + |
| 164 | + _create_tarball(tar_path, {'package/index.js': "console.log('hello');"}) |
| 165 | + |
| 166 | + _process_tarball( |
| 167 | + tarball_path=str(tar_path), |
| 168 | + pkg_name='pkg', |
| 169 | + pkg_version='1.0.0', |
| 170 | + integrity_hex='a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2', |
| 171 | + store=str(store_dir), |
| 172 | + now=1234567890, |
| 173 | + tarball_url=tarball_url, |
| 174 | + store_version='v6', |
| 175 | + ) |
| 176 | + |
| 177 | + sanitized_tarball_url = re.sub(r'[:/]', '+', tarball_url) |
| 178 | + normalized_tarball_url = f'{sanitized_tarball_url[:87]}_{hashlib.sha256(sanitized_tarball_url.encode()).hexdigest()[:32]}' |
| 179 | + url_idx_file = store_dir / normalized_tarball_url / 'integrity.json' |
| 180 | + |
| 181 | + assert url_idx_file.exists() |
0 commit comments