From 07ca8d63876b1c95080a7ccf7edfa6b3032814f2 Mon Sep 17 00:00:00 2001 From: Daisie Huang Date: Mon, 17 Apr 2023 23:22:01 -0700 Subject: [PATCH] don't deal with non-absolute local file paths --- htsget_server/drs_operations.py | 7 ++++++- htsget_server/htsget_operations.py | 2 +- tests/test_htsget_server.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/htsget_server/drs_operations.py b/htsget_server/drs_operations.py index 7f556939..985c1970 100644 --- a/htsget_server/drs_operations.py +++ b/htsget_server/drs_operations.py @@ -2,6 +2,7 @@ import database from flask import request, Flask import os +import os.path import re import authz from markupsafe import escape @@ -231,9 +232,13 @@ def _get_file_path(drs_file_obj_id): url_pieces = urlparse(method["access_url"]["url"]) if url_pieces.scheme == "file": if url_pieces.netloc == "" or url_pieces.netloc == "localhost": - result["path"] = url_pieces.path.lstrip("/") + result["path"] = os.path.abspath(url_pieces.path) + if not os.path.exists(result["path"]): + result['message'] = f"No file exists at {result['path']} on the server." + result['status_code'] = 404 if result['path'] is None: result['message'] = f"No file was found for drs_obj {drs_file_obj_id}: {url}" + result['status_code'] = 404 result.pop('path') return result diff --git a/htsget_server/htsget_operations.py b/htsget_server/htsget_operations.py index c3317b62..6772d0ce 100644 --- a/htsget_server/htsget_operations.py +++ b/htsget_server/htsget_operations.py @@ -338,7 +338,7 @@ def _get_data(id_, reference_name=None, start=None, end=None, class_=None, forma gen_obj = drs_operations._get_genomic_obj(id_) if gen_obj is not None: if "message" in gen_obj: - return gen_obj['message'], gen_obj['status_code'] + return {"message": gen_obj['message']}, gen_obj['status_code'] file_in = gen_obj["file"] ntf = tempfile.NamedTemporaryFile(prefix='htsget', suffix=format_, mode='wb', delete=False) diff --git a/tests/test_htsget_server.py b/tests/test_htsget_server.py index 43afb651..fdd9c094 100644 --- a/tests/test_htsget_server.py +++ b/tests/test_htsget_server.py @@ -126,7 +126,7 @@ def test_post_update(): obj = response.json() url = f"{HOST}/ga4gh/drs/v1/objects" - access_url = f"file:///./data/files/NA18537.vcf.gz" # this is local within the htsget server container, not from where we're running pytest + access_url = f"file:////app/htsget_server/data/files/NA18537.vcf.gz" # this is local within the htsget server container, not from where we're running pytest obj["access_methods"] = [ { "type": "file",