Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite FileResponse Content-Type with application/octet-stream for all files in /store #1064

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion asu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from asu.config import settings
from asu.routers import api
from asu.util import get_redis_client, parse_feeds_conf, parse_packages_file
from asu.fastapi.StaticFiles import StaticFiles as AsuStaticFiles
from asu.fastapi.staticfiles import StaticFiles as AsuStaticFiles

logging.basicConfig(encoding="utf-8", level=settings.log_level)

Expand Down
36 changes: 36 additions & 0 deletions tests/test_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from asu.config import settings
from asu.fastapi.staticfiles import FileResponse

store_path = settings.public_path / "store"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ugly.

But conftest.py overwrites settings.public_path, unfortunately the main.py/app has already been constructed, with the previous old public_path.
Thus the conftest.py app()-setting of public_path to a temp-path doesn't work here.


def test_store_content_type_img(client):
store_path.mkdir(parents=True, exist_ok=True)
with open(store_path / "test_store_content_type.img", "w+b"):
pass
response = client.head("/store/test_store_content_type.img")

assert response.status_code == 200

headers = response.headers
assert headers["Content-Type"] == "application/octet-stream"


def test_store_content_type_imggz(client):
store_path.mkdir(parents=True, exist_ok=True)
with open(store_path / "test_store_content_type.img.gz", "w+b"):
pass
response = client.head("/store/test_store_content_type.img.gz")

assert response.status_code == 200

headers = response.headers
assert headers["Content-Type"] == "application/octet-stream"


def test_store_file_missing(client):
response = client.head("/store/test_store_file_missing.bin")

assert response.status_code == 404

headers = response.headers
assert headers["Content-Type"] != "application/octet-stream"