|
1 | | -"""Tests that verify which S3 bucket each build type is stored in. |
| 1 | +"""Tests that verify which S3 bucket each build type is stored in, and that |
| 2 | +the /builds/ endpoint routes to the correct backend depending on User-Agent |
| 3 | +and HTTP method. |
2 | 4 |
|
3 | | -Artifacts routes uploads to one of three buckets based on the build name: |
| 5 | +Bucket routing based on build name: |
4 | 6 | *:staging-* → artifacts-staging |
5 | 7 | *:promoted-* → artifacts-promoted |
6 | 8 | anything else → artifacts-prolonged |
7 | 9 |
|
8 | 10 | Uploads via the artifacts API only accept staging build names (nginx regex |
9 | 11 | enforces this). For promoted/prolonged builds we insert objects directly via |
10 | 12 | the S3 client and verify the artifacts download API can still retrieve them. |
| 13 | +
|
| 14 | +/builds/ backend routing: |
| 15 | + GET + non-Mozilla UA → /redirect/ → 302 presigned S3 URL |
| 16 | + GET + Mozilla UA → /download/ → 200 proxied |
| 17 | + HEAD + any UA → /download/ → 200 proxied (HEAD is always direct) |
11 | 18 | """ |
12 | 19 |
|
13 | 20 | import pytest |
@@ -67,6 +74,39 @@ def test_prolonged_build_downloadable_from_prolonged_bucket( |
67 | 74 | assert resp.content == b'notes' |
68 | 75 |
|
69 | 76 |
|
| 77 | +def test_builds_cli_ua_redirects_to_presigned_url(upload_file, session, artifacts_url): |
| 78 | + """GET /builds/ with a non-Mozilla UA is rewritten to /redirect/ → 302.""" |
| 79 | + upload_file(STAGING_BUILD, 'file.txt') |
| 80 | + resp = session.get( |
| 81 | + f'{artifacts_url}/builds/{STAGING_BUILD}/file.txt', |
| 82 | + headers={'User-Agent': 'curl/7.83.1'}, |
| 83 | + allow_redirects=False, |
| 84 | + ) |
| 85 | + assert resp.status_code == 302 |
| 86 | + |
| 87 | + |
| 88 | +def test_builds_browser_ua_proxied_directly(upload_file, session, artifacts_url): |
| 89 | + """GET /builds/ with a Mozilla UA is rewritten to /download/ → 200 proxied.""" |
| 90 | + upload_file(STAGING_BUILD, 'file.txt') |
| 91 | + resp = session.get( |
| 92 | + f'{artifacts_url}/builds/{STAGING_BUILD}/file.txt', |
| 93 | + headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)'}, |
| 94 | + allow_redirects=False, |
| 95 | + ) |
| 96 | + assert resp.status_code == 200 |
| 97 | + |
| 98 | + |
| 99 | +def test_builds_head_always_proxied_regardless_of_ua(upload_file, session, artifacts_url): |
| 100 | + """HEAD /builds/ with a non-Mozilla UA is still rewritten to /download/ → 200.""" |
| 101 | + upload_file(STAGING_BUILD, 'file.txt') |
| 102 | + resp = session.head( |
| 103 | + f'{artifacts_url}/builds/{STAGING_BUILD}/file.txt', |
| 104 | + headers={'User-Agent': 'curl/7.83.1'}, |
| 105 | + allow_redirects=False, |
| 106 | + ) |
| 107 | + assert resp.status_code == 200 |
| 108 | + |
| 109 | + |
70 | 110 | def test_staging_build_not_visible_from_promoted_bucket( |
71 | 111 | session, artifacts_url, s3_client |
72 | 112 | ): |
|
0 commit comments