Skip to content

Commit

Permalink
Merge pull request #557 from oda-hub/preserve-args-redirection
Browse files Browse the repository at this point in the history
preserve args before redirection if those are presents
  • Loading branch information
burnout87 authored Jul 18, 2023
2 parents bcae281 + 0ca0be5 commit 7d50f36
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cdci_data_analysis/flask_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def run_api_instr_list():

if app.config['conf'].products_url is not None and validators.url(app.config['conf'].products_url):
redirection_url = os.path.join(app.config['conf'].products_url, 'dispatch-data/instr-list')
if request.args:
args_request = urlencode(request.args)
redirection_url = f'{redirection_url}?{args_request}'

else:
parsed_request_url = urlparse(request.url)
path_request_url = parsed_request_url.path.replace('/api', '')
Expand Down
29 changes: 24 additions & 5 deletions tests/test_server_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,34 +472,53 @@ def test_query_restricted_instrument(dispatcher_live_fixture):


@pytest.mark.fast
@pytest.mark.parametrize("include_args", [True, False])
def test_instrument_list_redirection_external_products_url(dispatcher_live_fixture_with_external_products_url,
dispatcher_test_conf_with_external_products_url):
dispatcher_test_conf_with_external_products_url,
include_args):
server = dispatcher_live_fixture_with_external_products_url

logger.info("constructed server: %s", server)

c = requests.get(os.path.join(server, "api/instr-list"), allow_redirects=False)
url_request = os.path.join(server, "api/instr-list")

if include_args:
url_request += '?a=4566&token=aaaaaaaaaa'

c = requests.get(url_request, allow_redirects=False)

assert c.status_code == 302
redirection_header_location_url = c.headers["Location"]
redirection_url = os.path.join(dispatcher_test_conf_with_external_products_url['products_url'], 'dispatch-data/instr-list')
if include_args:
redirection_url += '?a=4566&token=aaaaaaaaaa'
assert redirection_url == redirection_header_location_url


@pytest.mark.fast
@pytest.mark.parametrize("allow_redirect", [True, False])
@pytest.mark.parametrize("include_args", [True, False])
def test_instrument_list_redirection_no_custom_products_url(dispatcher_live_fixture_no_products_url,
allow_redirect):
allow_redirect, include_args):
server = dispatcher_live_fixture_no_products_url

logger.info("constructed server: %s", server)

c = requests.get(os.path.join(server, "api/instr-list"), allow_redirects=allow_redirect)
url_request = os.path.join(server, "api/instr-list")

encoded_token = jwt.encode(default_token_payload, secret_key, algorithm='HS256')
if include_args:
url_request += '?a=4566&token=' + encoded_token

c = requests.get(url_request, allow_redirects=allow_redirect)

if not allow_redirect:
assert c.status_code == 302
redirection_header_location_url = c.headers["Location"]
assert redirection_header_location_url == os.path.join(server, 'instr-list')
redirection_url = os.path.join(server, 'instr-list')
if include_args:
redirection_url += '?a=4566&token=' + encoded_token
assert redirection_header_location_url == redirection_url
else:
assert c.status_code == 200

Expand Down

0 comments on commit 7d50f36

Please sign in to comment.