diff --git a/conf/nginx.conf.template b/conf/nginx.conf.template index b935943..89e6ad5 100644 --- a/conf/nginx.conf.template +++ b/conf/nginx.conf.template @@ -271,7 +271,9 @@ http { # Directory listings (trailing slash) always go to /download/. # $builds_backend is set by the map directive in the http block above. # - rewrite ^/builds/([^/]+/.+[^/])$ $builds_backend$1 last; + if ($builds_backend = /redirect/) { + rewrite ^/builds/([^/]+/.+[^/])$ /redirect/$1 last; + } rewrite ^/builds/(.*)$ /download/$1 last; # Handle subdir listing under "/redirect/" diff --git a/tests/end2end/test_routing.py b/tests/end2end/test_routing.py index 36aa252..f56e63b 100644 --- a/tests/end2end/test_routing.py +++ b/tests/end2end/test_routing.py @@ -86,14 +86,19 @@ def test_builds_cli_ua_redirects_to_presigned_url(upload_file, session, artifact def test_builds_browser_ua_proxied_directly(upload_file, session, artifacts_url): - """GET /builds/ with a Mozilla UA is rewritten to /download/ → 200 proxied.""" - upload_file(STAGING_BUILD, 'file.txt') + """GET /builds/ with a Mozilla UA is rewritten to /download/ → 200 proxied. + + The response body must be the file content, not an HTML directory listing. + """ + data = b'browser-proxied content' + upload_file(STAGING_BUILD, 'file.txt', data=data) resp = session.get( f'{artifacts_url}/builds/{STAGING_BUILD}/file.txt', headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)'}, allow_redirects=False, ) assert resp.status_code == 200 + assert resp.content == data def test_builds_head_always_proxied_regardless_of_ua(upload_file, session, artifacts_url):