|
22 | 22 | has_valid_characters, |
23 | 23 | has_valid_first_character, |
24 | 24 | check_filename, |
| 25 | + is_supported_extension, |
| 26 | + is_supported_type, |
25 | 27 | is_valid_path, |
26 | 28 | get_x_accel_uri, |
27 | 29 | wkb2wkt, |
28 | 30 | has_trailing_space, |
| 31 | + check_skip_validation, |
29 | 32 | ) |
30 | 33 | from ..auth.models import LoginHistory, User |
31 | 34 | from . import json_headers |
@@ -322,3 +325,46 @@ class TestSchema(Schema): |
322 | 325 | "size": "disk_usage", |
323 | 326 | } |
324 | 327 | assert schema_map == expected_map |
| 328 | + |
| 329 | + |
| 330 | +def test_check_skip_validation(): |
| 331 | + ALLOWED_FILES = ["script.js", "config/script.js"] |
| 332 | + |
| 333 | + # We patch the Configuration class attribute directly |
| 334 | + with patch("mergin.sync.utils.Configuration.UPLOAD_FILES_WHITELIST", ALLOWED_FILES): |
| 335 | + |
| 336 | + # Test allowed files |
| 337 | + for file_path in ALLOWED_FILES: |
| 338 | + assert check_skip_validation(file_path) |
| 339 | + |
| 340 | + # Test not allowed files |
| 341 | + assert not check_skip_validation("test.py") |
| 342 | + assert not check_skip_validation("/some/path/test.py") |
| 343 | + assert not check_skip_validation("image.png") |
| 344 | + |
| 345 | + |
| 346 | +def test_is_supported_extension(): |
| 347 | + ALLOWED_FILES = ["script.js", "config/script.js"] |
| 348 | + |
| 349 | + with patch("mergin.sync.utils.Configuration.UPLOAD_FILES_WHITELIST", ALLOWED_FILES): |
| 350 | + for file_path in ALLOWED_FILES: |
| 351 | + assert is_supported_extension(file_path) |
| 352 | + |
| 353 | + # Allowed normal file |
| 354 | + assert is_supported_extension("image.png") |
| 355 | + |
| 356 | + # Forbidden file |
| 357 | + assert not is_supported_extension("test.js") |
| 358 | + |
| 359 | + |
| 360 | +def test_mime_type_validation_skip(): |
| 361 | + ALLOWED_FILES = ["script.js", "config/script.js"] |
| 362 | + # Mocking get_mimetype to return forbidden mime type |
| 363 | + with patch( |
| 364 | + "mergin.sync.utils.get_mimetype", return_value="application/x-python-code" |
| 365 | + ), patch("mergin.sync.utils.Configuration.UPLOAD_FILES_WHITELIST", ALLOWED_FILES): |
| 366 | + for file_path in ALLOWED_FILES: |
| 367 | + assert is_supported_type(file_path) |
| 368 | + |
| 369 | + # Should be forbidden |
| 370 | + assert not is_supported_type("other.js") |
0 commit comments