Skip to content

Commit

Permalink
Raise 404 in check if a nonexistent file is requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
jarosenb committed Jan 12, 2022
1 parent 65d0d05 commit a52b8fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def walk_archive_paths(base_path: str, file_paths: List[str]) -> List[Archive]:
size = 0
for file in file_paths:
full_path = base / file.strip("/")
print(full_path)

if full_path.is_file():
zip_paths.append({"fs": str(full_path), "n": full_path.name})
Expand All @@ -78,6 +79,12 @@ def walk_archive_paths(base_path: str, file_paths: List[str]) -> List[Archive]:
)
size += file_path.stat().st_size
raise_for_size(size)
else:
# No file/folder exists at the requested path, so raise a 404.
raise HTTPException(
status_code=404,
detail="One or more of the requested files could not be found.",
)

return zip_paths

Expand Down
6 changes: 6 additions & 0 deletions server/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def test_walk_archive(tmp_path):
]


def test_walk_archive_404(tmp_path):
base = tmp_path
with pytest.raises(HTTPException):
walk_archive_paths(base, ["nonexistent_file.txt"])


@pytest.fixture
def mock_get_success(monkeypatch, request):
import requests
Expand Down

0 comments on commit a52b8fa

Please sign in to comment.