feat: cleanup on library dir creation and upload endpoints (#3069)
This commit is contained in:
parent
bafb4ddf75
commit
1323a2005b
10 changed files with 208 additions and 111 deletions
42
tests/unit/test_upload_file_path.py
Normal file
42
tests/unit/test_upload_file_path.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from lnbits.helpers import safe_upload_file_path
|
||||
from lnbits.settings import settings
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"filepath",
|
||||
[
|
||||
"test.txt",
|
||||
"test/test.txt",
|
||||
"test/test/test.txt",
|
||||
"test/../test.txt",
|
||||
"*/test.txt",
|
||||
"test/**/test.txt",
|
||||
"./test.txt",
|
||||
],
|
||||
)
|
||||
def test_safe_upload_file_path(filepath: str):
|
||||
safe_path = safe_upload_file_path(filepath)
|
||||
assert safe_path.name == "test.txt"
|
||||
|
||||
# check if subdirectories got removed
|
||||
images_folder = Path(settings.lnbits_data_folder) / "images"
|
||||
assert images_folder.resolve() / "test.txt" == safe_path
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"filepath",
|
||||
[
|
||||
"../test.txt",
|
||||
"test/../../test.txt",
|
||||
"../../test.txt",
|
||||
"test/../../../test.txt",
|
||||
"../../../test.txt",
|
||||
],
|
||||
)
|
||||
def test_unsafe_upload_file_path(filepath: str):
|
||||
with pytest.raises(ValueError):
|
||||
safe_upload_file_path(filepath)
|
||||
Loading…
Add table
Add a link
Reference in a new issue