Skip to content
Snippets Groups Projects
Commit 64cfc42b authored by Florian Bruhin's avatar Florian Bruhin
Browse files

Reject invalid zip files

Closes #7
parent 2a698fd5
No related branches found
No related tags found
No related merge requests found
import datetime
import sys
import time
import zipfile
from pathlib import Path
import httpx
......@@ -86,6 +87,10 @@ def check_project_file(path: Path, force: bool) -> None:
else:
console.print("Continuing submission since --force has been given.\n")
if not zipfile.is_zipfile(path):
console.print(f"[red]{path.name} is not a valid .zip file.[/]")
raise typer.Exit(1)
@app.command()
def upload_file(
......
......@@ -4,6 +4,7 @@ import os
import io
import pathlib
import datetime
import zipfile
import rich.console
import rich.panel
......@@ -260,7 +261,8 @@ def test_project(
time_machine.move_to(FROZEN_TIME)
project_path = tmp_path / "project.zip"
project_path.touch()
with zipfile.ZipFile(project_path, "w"):
pass
result = runner.run("--project", str(project_path))
......@@ -298,9 +300,8 @@ def test_project_size_limit(
file_size_mb = 2 if hard_limit else 1
project_path = tmp_path / "project.zip"
with project_path.open("wb") as f:
f.seek(file_size_mb * 1024 * 1024)
f.write(b"\x00")
with zipfile.ZipFile(project_path, "w") as zf:
zf.writestr("data.bin", "\x00" * file_size_mb * 1024 * 1024)
flags = ["--project"]
if force:
......@@ -311,6 +312,17 @@ def test_project_size_limit(
assert result.stdout == golden_special.out["output"]
def test_project_invalid_zip(
runner: Runner,
tmp_path: pathlib.Path,
):
project_path = tmp_path / "project.zip"
project_path.touch()
result = runner.run("--project", str(project_path))
assert result.exit_code == 1
assert result.stdout == "project.zip is not a valid .zip file.\n"
def test_version(
runner: Runner,
httpx_mock: HTTPXMock,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment