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

Remove directory from disposition header #3515

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions lib/pbench/server/api/resources/datasets_inventory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from http import HTTPStatus
from pathlib import Path
from urllib.request import Request

from flask import current_app, send_file
Expand Down Expand Up @@ -84,10 +85,9 @@ def _get(
# We link a callback to close the file stream and TarFile object on
# completion.
webbnh marked this conversation as resolved.
Show resolved Hide resolved
stream = file_info["stream"]
name = Path(file_info["name"]).name
try:
resp = send_file(
stream, as_attachment=target is None, download_name=file_info["name"]
)
resp = send_file(stream, as_attachment=target is None, download_name=name)
except Exception as e:
if stream:
stream.close()
Expand Down
9 changes: 9 additions & 0 deletions lib/pbench/test/functional/server/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,15 @@ def read_metadata(response: Response) -> JSONOBJECT:
API.DATASETS_INVENTORY,
{"dataset": dataset.resource_id, "target": "metadata.log"},
)

# Note that Werkzeug doesn't understand anything special about the
# ".log" filetype, but will apply a better content-type header for
# file types it understands like ".json".
assert response.headers["content-type"] == "application/octet-stream"
assert (
response.headers["content-disposition"]
== "inline; filename=metadata.log"
)
assert (
response.ok
), f"INVENTORY {dataset.name} failed {response.status_code}:{response.json()['message']}"
Expand Down
17 changes: 17 additions & 0 deletions lib/pbench/test/unit/server/test_datasets_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,20 @@ def mock_send_file(path_or_file, *args, **kwargs):

query_get_as("fio_2", "f1.json", HTTPStatus.INTERNAL_SERVER_ERROR)
assert mock_close

def test_get_inventory(self, query_get_as, monkeypatch):
exp_stream = io.BytesIO(b"file_as_a_byte_stream")

def mock_get_inventory(_s, _d: str, _t: str):
return {
"name": "f1.json",
"type": CacheType.FILE,
"stream": Inventory(exp_stream, None),
}

monkeypatch.setattr(CacheManager, "get_inventory", mock_get_inventory)
response = query_get_as("fio_2", "f1.json", HTTPStatus.OK)
assert response.status_code == HTTPStatus.OK
assert response.text == "file_as_a_byte_stream"
assert response.headers["content-type"] == "application/json"
assert response.headers["content-disposition"] == "inline; filename=f1.json"