Skip to content

Commit

Permalink
Merge pull request #94 from oda-hub/build-download-file-url
Browse files Browse the repository at this point in the history
Validate filename in the download url in run_query
  • Loading branch information
burnout87 authored Jun 3, 2024
2 parents 5c65e1c + ff9aa7f commit 3026a0a
Show file tree
Hide file tree
Showing 5 changed files with 306 additions and 8 deletions.
9 changes: 4 additions & 5 deletions dispatcher_plugin_nb2workflow/dataserver_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from . import exposer
from urllib.parse import urlsplit, parse_qs, urlencode
import os
from glob import glob
import logging

logger = logging.getLogger()
Expand Down Expand Up @@ -53,7 +52,7 @@ def backend_options(self, max_trial=5, sleep_seconds=5):
time.sleep(sleep_seconds)
if not backend_available:
return {}

self._backend_options = options_dict
return options_dict

Expand Down Expand Up @@ -195,8 +194,8 @@ def run_query(self,
task=self.task

if param_dict is None:
param_dict=self.param_dict
param_dict=self.param_dict

if run_asynch:
param_dict['_async_request_callback'] = call_back_url
param_dict['_async_request'] = "yes"
Expand All @@ -217,7 +216,7 @@ def run_query(self,
message='Backend failed. ' + except_message,
job_status='failed')
return res, query_out

comment_name = self.get_backend_comment(task.strip('/'))
comment_value = ''
if comment_name:
Expand Down
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from cdci_data_analysis.pytest_fixtures import (
dispatcher_debug,
dispatcher_test_conf_fn,
dispatcher_live_fixture
dispatcher_test_conf_with_external_products_url_fn,
dispatcher_test_conf_with_default_route_products_url_fn,
dispatcher_test_conf,
dispatcher_test_conf_with_external_products_url,
dispatcher_test_conf_with_default_route_products_url,
dispatcher_live_fixture,
dispatcher_live_fixture_with_external_products_url,
dispatcher_live_fixture_with_default_route_products_url,
gunicorn_dispatcher,
gunicorn_dispatcher_live_fixture,
)
import pytest
import json
Expand Down Expand Up @@ -168,7 +177,9 @@ class Starter(ProcessStarter):
timeout = 30
max_read_lines = 10000
terminate_on_interrupt = True
args = ['nb2service', '--port', '9393', os.path.join(wd, 'tests', 'example_nb')]
responses_path = os.path.join(os.path.dirname(__file__), 'example_nb')
args = ['nb2service', '--port', '9393', responses_path]
# args = ['nb2service', '--port', '9393', os.path.join(wd, 'tests', 'example_nb')]
def startup_check(self):
try:
res = requests.get('http://localhost:9393/')
Expand All @@ -179,6 +190,7 @@ def startup_check(self):
return res.json()['message'] == 'all is ok!'
try:
logfile = xprocess.ensure("nb2service", Starter)

except Exception as e:
xprocess.getinfo("nb2service").terminate()
raise e
Expand Down
80 changes: 80 additions & 0 deletions tests/example_nb/file_download.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"dummy_file = \"test.fits\" # oda:POSIXPath\n",
"RA = 0. \n",
"DEC = 0. \n",
"T1 = 50000. \n",
"T2 = 50005. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"output_file_download = 'file not downloaded'\n",
"print(f\"dummy_file: {dummy_file}\")\n",
"if os.path.exists(dummy_file) is True:\n",
" print(\"file exists!\")\n",
" output_file_download = 'file downloaded successfully'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"outputs"
]
},
"outputs": [],
"source": [
"output_file_download"
]
}
],
"metadata": {
"interpreter": {
"hash": "767d51c1340bd893661ea55ea3124f6de3c7a262a8b4abca0554b478b1e2ff90"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
25 changes: 25 additions & 0 deletions tests/responses/options.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
{
"file_download": {
"output": {
"result": {
"comment": " http://odahub.io/ontology#Image",
"name": "result",
"owl_type": "http://odahub.io/ontology#Image",
"python_type": {
"type_object": "<class 'str'>"
},
"value": " astroim.encode() "
}
},
"parameters": {
"dummy_file": {
"comment": "",
"default_value": "",
"name": "dummy_file",
"owl_type": "http://odahub.io/ontology#POSIXPath",
"python_type": {
"type_object": "<class 'str'>"
},
"value": ""
}
}
},
"dummy_echo": {
"output": {
"result": {
Expand Down
Loading

0 comments on commit 3026a0a

Please sign in to comment.