From 8d5f38319bbb7fad2c1d9c8c30398912457360ea Mon Sep 17 00:00:00 2001 From: Sam Sneddon Date: Wed, 21 Oct 2026 15:21:39 +0100 Subject: [PATCH] Pass auth to bugs.webkit.org properly bugs.webkit.org only reads credentials from request parameters, not headers, so the `X-BUGZILLA-TOKEN` header was ignored and every request was made logged out. Logged-out responses now truncate email addresses (`ews-feeder` rather than `ews-feeder@webkit.org`), so the bot no longer recognised changes made by EWS or the commit queue and stopped approving WebKit export PRs. Send the API key as the `Bugzilla_api_key` query parameter instead, and redact it when logging. Also ask for `exclude_fields=update_token`, since authenticated responses otherwise include a per-user token. `create-secrets.js` returned the secret as `bugsWebkit` while `index.js` reads `bugsWebkitToken`, so the token was never set in production. Tests replay requests with a placeholder key. The real key is replaced with `REDACTED` both when saving fixtures and when matching them, so recording with a real key replays existing fixtures instead of duplicating them. The fixtures are re-recorded while authenticated. The "wrong bugzilla reference" test passed without asserting anything: bug 202311 loads fine when authenticated, so the rejection handler never ran. Point it at a nonexistent bug so it covers the error path again. --- README.md | 12 ++++-- create-secrets.js | 2 +- lib/bugs-webkit.js | 39 +++++++++++++++---- lib/metadata/webkit.js | 2 +- test/bugs-webkit.js | 39 +++++++++++++++++++ .../bugs.webkit.org-443/157512252738650000 | 26 +++++++------ .../bugs.webkit.org-443/157512252738650002 | 26 +++++++------ .../bugs.webkit.org-443/157667650677550000 | 29 +++++++------- test/get-metadata.js | 15 ++++--- test/setup.js | 38 ++++++++++++++++++ 10 files changed, 170 insertions(+), 58 deletions(-) create mode 100644 test/bugs-webkit.js diff --git a/README.md b/README.md index 899444b..e4690dc 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,15 @@ GitHub HTTP API. Contributors seeking to add new tests or modify existing tests will need to capture new request/response pairs. This can be achieved as follows: -1. Create a "personal access token" though GitHub.com (no particular access +1. Create a "personal access token" through GitHub.com (no particular access scopes are necessary) -2. Set the `GITHUB_TOKEN` environment variable to the value created above, set - the `REPLAY` environment variable to `record`, and run the tests. -3. If the tests pass, include the files that were generated by the previous +2. Set the `GITHUB_TOKEN` environment variable to the value created in the + previous step +3. Create an "API key" through bugs.webkit.org +4. Set the `WEBKIT_BUGZILLA_TOKEN` environment variable to the value created in + the previous step. +5. Set the `REPLAY` environment variable to `record`, and run the tests. +6. If the tests pass, include the files that were generated by the previous command in the patch. Development diff --git a/create-secrets.js b/create-secrets.js index f5e36d6..7987d16 100644 --- a/create-secrets.js +++ b/create-secrets.js @@ -27,7 +27,7 @@ async function loadSecrets() { const secrets = { webhookSecret: await fetchSecret('github-webhook-secret'), githubToken: await fetchSecret('wpt-pr-bot-github-token'), - bugsWebkit: await fetchSecret('wpt-pr-bot-bugswebkit-token'), + bugsWebkitToken: await fetchSecret('wpt-pr-bot-bugswebkit-token'), }; return secrets; } diff --git a/lib/bugs-webkit.js b/lib/bugs-webkit.js index 5b0aab3..19e1728 100644 --- a/lib/bugs-webkit.js +++ b/lib/bugs-webkit.js @@ -14,20 +14,43 @@ function errFrom(response, body) { function getHeaders() { return { "User-Agent": "ganesh", - "X-BUGZILLA-TOKEN": token, }; } +// Bugzilla 5.0 only reads credentials from request parameters, not headers. +function withAuth(url) { + if (!token) { + return url; + } + const authed = new URL(url); + authed.searchParams.set('Bugzilla_api_key', token); + return authed.href; +} + +// Redacts the API key from a URL, or from text containing URLs (e.g. error messages). +function redactAuth(text) { + return text.replace(/([?&]Bugzilla_api_key=)[^&#\s]*/g, '$1REDACTED'); +} + async function get(url, options) { url = replaceURL(baseURL(url), options); - var headers = getHeaders(); - logger.debug("GET", url); - const response = await fetch(url, { headers: headers }); - if (response.status < 200 || response.status >= 300) { - const bodyText = await response.text(); - throw errFrom(response, bodyText); + const headers = getHeaders(); + url = withAuth(url); + logger.debug("GET", redactAuth(url)); + try { + const response = await fetch(url, { headers: headers }); + if (response.status < 200 || response.status >= 300) { + const bodyText = await response.text(); + throw errFrom(response, bodyText); + } + return await response.json(); + } catch (err) { + // node-fetch includes the request URL, and so the API key, in its messages. + if (err instanceof fetch.FetchError) { + throw new fetch.FetchError(redactAuth(err.message), err.type, err); + } + throw err; } - return response.json(); } function baseURL(url) { diff --git a/lib/metadata/webkit.js b/lib/metadata/webkit.js index f1f8235..2738882 100644 --- a/lib/metadata/webkit.js +++ b/lib/metadata/webkit.js @@ -6,7 +6,7 @@ exports.related = function(title) { }; exports.verified = function(webkitIssue, wptPullRequestNumber) { - return bugsWebkit.get("/rest/bug/:id", { id: webkitIssue }).then(function (body) { + return bugsWebkit.get("/rest/bug/:id?exclude_fields=update_token", { id: webkitIssue }).then(function (body) { if (body && body.bugs && body.bugs.length > 0 && body.bugs[0].see_also) { return body.bugs[0].see_also.some(function(url) { return url == "https://github.com/web-platform-tests/wpt/pull/" + wptPullRequestNumber; diff --git a/test/bugs-webkit.js b/test/bugs-webkit.js new file mode 100644 index 0000000..5b3a166 --- /dev/null +++ b/test/bugs-webkit.js @@ -0,0 +1,39 @@ +'use strict'; + +const assert = require('chai').assert, + fetch = require('node-fetch'), + replay = require('replay'), + bugsWebkit = require('../lib/bugs-webkit'); + +suite('bugs-webkit', function() { + const token = 'fake-bugzilla-key-1234'; + + setup(function() { + // Relies on replay refusing requests that have no fixture. + if (replay.mode !== 'replay') { + this.skip(); + } + bugsWebkit.setToken(token); + }); + + teardown(function() { + // The placeholder that test/setup.js uses in replay mode. + bugsWebkit.setToken('REDACTED'); + }); + + test('redacts the API key from fetch errors', async function() { + let error; + try { + // There is no fixture for this bug, so the request fails. + await bugsWebkit.get('/rest/bug/:id', { id: 0 }); + } catch (e) { + error = e; + } + assert.instanceOf(error, fetch.FetchError); + assert.equal(error.type, 'system'); + assert.equal(error.code, 'ECONNREFUSED'); + assert.include(error.message, 'Bugzilla_api_key=REDACTED'); + assert.notInclude(error.message, token); + assert.notInclude(error.stack, token); + }); +}); diff --git a/test/fixtures/bugs.webkit.org-443/157512252738650000 b/test/fixtures/bugs.webkit.org-443/157512252738650000 index 0457639..6055cd8 100644 --- a/test/fixtures/bugs.webkit.org-443/157512252738650000 +++ b/test/fixtures/bugs.webkit.org-443/157512252738650000 @@ -1,20 +1,22 @@ -GET /rest/bug/201401 +GET /rest/bug/201401?exclude_fields=update_token&Bugzilla_api_key=REDACTED accept: */* accept-encoding: gzip,deflate HTTP/1.1 200 OK -date: Sat, 30 Nov 2019 14:02:07 GMT -server: Apache/2.4 -x-xss-protection: 1; mode=block +date: Wed, 21 Oct 2026 14:35:56 GMT +content-type: application/json; charset=UTF-8 access-control-allow-headers: origin, content-type, accept, x-requested-with -access-control-allow-origin: *, * -x-frame-options: SAMEORIGIN +access-control-allow-origin: * x-content-type-options: nosniff -set-cookie: Bugzilla_login_request_cookie=209DFljFZh; path=/; secure; HttpOnly -etag: jXilBcff1nXfTXVGCwb65w -strict-transport-security: max-age=7776000 -connection: close +x-frame-options: SAMEORIGIN +x-xss-protection: 1; mode=block +etag: 5N+/698Y31SVc6MFm5NmaA +strict-transport-security: max-age=31536000; includeSubDomains +age: 1 transfer-encoding: chunked -content-type: application/json; charset=UTF-8 +connection: keep-alive +via: https/1.1 uklon5-edge-fx-034.ts.apple.com (acdn/25.17695) +x-cache: skipped +cdnuuid: 36f1ad84-7295-4737-a38f-62aa087b4c56-1237697011 -{"bugs":[{"priority":"P2","assigned_to_detail":{"email":"aboya@igalia.com","real_name":"Alicia Boya García","name":"aboya@igalia.com","id":26809},"blocks":[],"creator":"mcatanzaro@gnome.org","last_change_time":"2019-10-24T16:40:06Z","is_cc_accessible":true,"keywords":["InRadar"],"creator_detail":{"email":"mcatanzaro@gnome.org","real_name":"Michael Catanzaro","name":"mcatanzaro@gnome.org","id":21676},"cc":["aboya@igalia.com","bugs-noreply@webkitgtk.org","calvaris@igalia.com","cgarcia@igalia.com","commit-queue@webkit.org","eric.carlson@apple.com","ews@webkit.org","glenn@skynav.com","gns@gnome.org","jer.noble@apple.com","mario@webkit.org","mcatanzaro@gnome.org","menard@kde.org","philipj@opera.com","pnormand@igalia.com","sergio@correia.cc","vjaquez@igalia.com","webkit-bug-importer@group.apple.com"],"url":"","assigned_to":"aboya@igalia.com","groups":[],"see_also":["https://github.com/web-platform-tests/wpt/pull/19538"],"id":201401,"whiteboard":"","creation_time":"2019-09-02T14:42:47Z","qa_contact":"","depends_on":[],"dupe_of":null,"resolution":"FIXED","classification":"Unclassified","alias":[],"op_sys":"Linux","status":"RESOLVED","cc_detail":[{"email":"aboya@igalia.com","real_name":"Alicia Boya García","name":"aboya@igalia.com","id":26809},{"email":"bugs-noreply@webkitgtk.org","real_name":"WebKitGTK+ bugs","name":"bugs-noreply@webkitgtk.org","id":24100},{"email":"calvaris@igalia.com","real_name":"Xabier Rodríguez Calvar","name":"calvaris@igalia.com","id":18338},{"email":"cgarcia@igalia.com","real_name":"Carlos Garcia Campos","name":"cgarcia@igalia.com","id":10421},{"email":"commit-queue@webkit.org","real_name":"WebKit Commit Bot","name":"commit-queue@webkit.org","id":10616},{"email":"eric.carlson@apple.com","real_name":"Eric Carlson","name":"eric.carlson@apple.com","id":2769},{"email":"ews@webkit.org","real_name":"Build Bot","name":"ews@webkit.org","id":26490},{"email":"glenn@skynav.com","real_name":"Glenn Adams","name":"glenn@skynav.com","id":14926},{"email":"gns@gnome.org","real_name":"Gustavo Noronha (kov)","name":"gns@gnome.org","id":7052},{"email":"jer.noble@apple.com","real_name":"Jer Noble","name":"jer.noble@apple.com","id":12084},{"email":"mario@webkit.org","real_name":"Mario Sanchez Prada","name":"mario@webkit.org","id":10290},{"email":"mcatanzaro@gnome.org","real_name":"Michael Catanzaro","name":"mcatanzaro@gnome.org","id":21676},{"email":"menard@kde.org","real_name":"Alexis Menard (darktears)","name":"menard@kde.org","id":12077},{"email":"philipj@opera.com","real_name":"Philip Jägenstedt","name":"philipj@opera.com","id":10312},{"email":"pnormand@igalia.com","real_name":"Philippe Normand","name":"pnormand@igalia.com","id":10698},{"email":"sergio@correia.cc","real_name":"Sergio Correia (qrwteyrutiyoup)","name":"sergio@correia.cc","id":20230},{"email":"vjaquez@igalia.com","real_name":"Víctor M. Jáquez L.","name":"vjaquez@igalia.com","id":14649},{"email":"webkit-bug-importer@group.apple.com","real_name":"Radar WebKit Bug Importer","name":"webkit-bug-importer@group.apple.com","id":15060}],"summary":"[GStreamer] cnn.com videos don't work","is_open":false,"platform":"PC","severity":"Normal","flags":[],"version":"WebKit Nightly Build","deadline":null,"component":"Media","is_creator_accessible":true,"product":"WebKit","is_confirmed":true,"target_milestone":"---"}],"faults":[]} +{"faults":[],"bugs":[{"deadline":null,"url":"","blocks":[],"qa_contact":"","dupe_of":null,"keywords":["InRadar"],"last_change_time":"2021-11-06T11:31:47Z","severity":"Normal","depends_on":[],"product":"WebKit","summary":"[GStreamer] cnn.com videos don't work","creator":"mcatanzaro@gnome.org","id":201401,"op_sys":"Linux","see_also":["https://github.com/web-platform-tests/wpt/pull/19538"],"flags":[],"creator_detail":{"email":"mcatanzaro@gnome.org","id":21676,"name":"mcatanzaro@gnome.org","real_name":"Michael Catanzaro"},"resolution":"FIXED","alias":[],"assigned_to":"aboya@igalia.com","component":"Media","is_creator_accessible":true,"version":"WebKit Nightly Build","classification":"Unclassified","status":"RESOLVED","cc":["aboya@igalia.com","bugs-noreply@webkitgtk.org","calvaris@igalia.com","cgarcia@igalia.com","commit-queue@webkit.org","eric.carlson@apple.com","ews-watchlist@webkit.org","glenn@skynav.com","gustavo@noronha.dev.br","jer.noble@apple.com","mario@igalia.com","mcatanzaro@gnome.org","menard@kde.org","ntim@apple.com","philipj@opera.com","pnormand@igalia.com","sergio@correia.cc","vjaquez@igalia.com","webkit-bug-importer@group.apple.com"],"is_confirmed":true,"assigned_to_detail":{"real_name":"Alicia Boya García","name":"aboya@igalia.com","id":26809,"email":"aboya@igalia.com"},"whiteboard":"","platform":"PC","priority":"P2","target_milestone":"---","groups":[],"is_open":false,"cc_detail":[{"id":26809,"real_name":"Alicia Boya García","name":"aboya@igalia.com","email":"aboya@igalia.com"},{"email":"bugs-noreply@webkitgtk.org","real_name":"WebKitGTK+ bugs","name":"bugs-noreply@webkitgtk.org","id":24100},{"email":"calvaris@igalia.com","name":"calvaris@igalia.com","real_name":"Xabier Rodríguez Calvar","id":18338},{"id":10421,"real_name":"Carlos Garcia Campos","name":"cgarcia@igalia.com","email":"cgarcia@igalia.com"},{"real_name":"WebKit Commit Bot","name":"commit-queue@webkit.org","id":10616,"email":"commit-queue@webkit.org"},{"email":"eric.carlson@apple.com","id":2769,"name":"eric.carlson@apple.com","real_name":"Eric Carlson"},{"real_name":"EWS Watchlist","name":"ews-watchlist@webkit.org","id":26490,"email":"ews-watchlist@webkit.org"},{"id":14926,"name":"glenn@skynav.com","real_name":"Glenn Adams","email":"glenn@skynav.com"},{"email":"gustavo@noronha.dev.br","id":7052,"name":"gustavo@noronha.dev.br","real_name":"Gustavo Noronha (kov)"},{"real_name":"Jer Noble","name":"jer.noble@apple.com","id":12084,"email":"jer.noble@apple.com"},{"real_name":"Mario Sanchez Prada","name":"mario@igalia.com","id":10290,"email":"mario@igalia.com"},{"email":"mcatanzaro@gnome.org","name":"mcatanzaro@gnome.org","real_name":"Michael Catanzaro","id":21676},{"email":"menard@kde.org","real_name":"Alexis Menard (darktears)","name":"menard@kde.org","id":12077},{"id":34428,"real_name":"Tim Nguyen (:ntim)","name":"ntim@apple.com","email":"ntim@apple.com"},{"email":"philipj@opera.com","name":"philipj@opera.com","real_name":"Philip Jägenstedt","id":10312},{"real_name":"Philippe Normand","name":"pnormand@igalia.com","id":10698,"email":"pnormand@igalia.com"},{"real_name":"Sergio Correia (qrwteyrutiyoup)","name":"sergio@correia.cc","id":20230,"email":"sergio@correia.cc"},{"email":"vjaquez@igalia.com","name":"vjaquez@igalia.com","real_name":"Víctor M. Jáquez L.","id":14649},{"name":"webkit-bug-importer@group.apple.com","real_name":"Radar WebKit Bug Importer","id":15060,"email":"webkit-bug-importer@group.apple.com"}],"creation_time":"2019-09-02T14:42:47Z","is_cc_accessible":true}]} \ No newline at end of file diff --git a/test/fixtures/bugs.webkit.org-443/157512252738650002 b/test/fixtures/bugs.webkit.org-443/157512252738650002 index cb0627b..f35caa1 100644 --- a/test/fixtures/bugs.webkit.org-443/157512252738650002 +++ b/test/fixtures/bugs.webkit.org-443/157512252738650002 @@ -1,20 +1,22 @@ -GET /rest/bug/201401/history +GET /rest/bug/201401/history?Bugzilla_api_key=REDACTED accept: */* accept-encoding: gzip,deflate HTTP/1.1 200 OK -date: Sat, 30 Nov 2019 14:02:07 GMT -server: Apache/2.4 -x-xss-protection: 1; mode=block +date: Wed, 21 Oct 2026 14:35:56 GMT +content-type: application/json; charset=UTF-8 access-control-allow-headers: origin, content-type, accept, x-requested-with -access-control-allow-origin: *, * -x-frame-options: SAMEORIGIN +access-control-allow-origin: * x-content-type-options: nosniff -set-cookie: Bugzilla_login_request_cookie=209DFljFZh; path=/; secure; HttpOnly -etag: jXilBcff1nXfTXVGCwb65w -strict-transport-security: max-age=7776000 -connection: close +x-frame-options: SAMEORIGIN +x-xss-protection: 1; mode=block +etag: ctH3gJgDL4/pj0DxvsWvsw +strict-transport-security: max-age=31536000; includeSubDomains +age: 0 transfer-encoding: chunked -content-type: application/json; charset=UTF-8 +connection: keep-alive +via: https/1.1 uklon5-edge-fx-034.ts.apple.com (acdn/25.17695) +x-cache: skipped +cdnuuid: 36f1ad84-7295-4737-a38f-62aa087b4c56-1237704224 -{"bugs":[{"history":[{"when":"2019-09-02T14:42:56Z","who":"mcatanzaro@gnome.org","changes":[{"removed":"","added":"bugs-noreply@webkitgtk.org, mcatanzaro@gnome.org","field_name":"cc"}]},{"when":"2019-09-03T09:36:57Z","who":"pnormand@igalia.com","changes":[{"removed":"","added":"aboya@igalia.com, pnormand@igalia.com","field_name":"cc"}]},{"when":"2019-09-06T14:58:53Z","who":"mcatanzaro@gnome.org","changes":[{"removed":"","added":"mario@webkit.org","field_name":"cc"}]},{"when":"2019-09-07T10:23:33Z","who":"aboya@igalia.com","changes":[{"removed":"webkit-unassigned@lists.webkit.org","added":"aboya@igalia.com","field_name":"assigned_to"}]},{"when":"2019-09-07T10:23:36Z","who":"aboya@igalia.com","changes":[{"attachment_id":378288,"removed":"","added":"review?","field_name":"flagtypes.name"}]},{"when":"2019-09-09T08:53:21Z","who":"calvaris@igalia.com","changes":[{"attachment_id":378288,"removed":"review?","added":"review-","field_name":"flagtypes.name"},{"removed":"","added":"calvaris@igalia.com","field_name":"cc"}]},{"when":"2019-10-06T16:48:41Z","who":"aboya@igalia.com","changes":[{"attachment_id":378288,"removed":"0","added":"1","field_name":"attachments.isobsolete"},{"attachment_id":378288,"removed":"review-","added":"","field_name":"flagtypes.name"}]},{"when":"2019-10-06T16:48:46Z","who":"aboya@igalia.com","changes":[{"attachment_id":380299,"removed":"","added":"review?","field_name":"flagtypes.name"}]},{"when":"2019-10-06T16:49:56Z","who":"ews@webkit.org","changes":[{"removed":"","added":"cgarcia@igalia.com, eric.carlson@apple.com, ews@webkit.org, glenn@skynav.com, gns@gnome.org, jer.noble@apple.com, menard@kde.org, philipj@opera.com, sergio@correia.cc, vjaquez@igalia.com","field_name":"cc"}]},{"when":"2019-10-06T17:03:06Z","who":"aboya@igalia.com","changes":[{"attachment_id":380299,"removed":"0","added":"1","field_name":"attachments.isobsolete"},{"attachment_id":380299,"removed":"review?","added":"","field_name":"flagtypes.name"}]},{"when":"2019-10-06T17:03:11Z","who":"aboya@igalia.com","changes":[{"attachment_id":380300,"removed":"","added":"review?","field_name":"flagtypes.name"}]},{"when":"2019-10-07T08:53:38Z","who":"calvaris@igalia.com","changes":[{"attachment_id":380300,"removed":"review?","added":"review+","field_name":"flagtypes.name"}]},{"when":"2019-10-07T12:11:20Z","who":"aboya@igalia.com","changes":[{"attachment_id":380300,"removed":"0","added":"1","field_name":"attachments.isobsolete"},{"attachment_id":380300,"removed":"review+","added":"","field_name":"flagtypes.name"}]},{"when":"2019-10-07T17:18:01Z","who":"aboya@igalia.com","changes":[{"attachment_id":380314,"removed":"0","added":"1","field_name":"attachments.isobsolete"}]},{"when":"2019-10-09T14:59:43Z","who":"aboya@igalia.com","changes":[{"attachment_id":380336,"removed":"0","added":"1","field_name":"attachments.isobsolete"}]},{"when":"2019-10-09T18:39:22Z","who":"aboya@igalia.com","changes":[{"attachment_id":380535,"removed":"","added":"commit-queue+","field_name":"flagtypes.name"}]},{"when":"2019-10-09T19:24:06Z","who":"commit-queue@webkit.org","changes":[{"removed":"","added":"commit-queue@webkit.org","field_name":"cc"}]},{"when":"2019-10-09T19:40:12Z","who":"commit-queue@webkit.org","changes":[{"attachment_id":380535,"removed":"commit-queue+","added":"","field_name":"flagtypes.name"}]},{"when":"2019-10-09T19:40:14Z","who":"commit-queue@webkit.org","changes":[{"removed":"","added":"FIXED","field_name":"resolution"},{"removed":"NEW","added":"RESOLVED","field_name":"status"}]},{"when":"2019-10-09T19:41:03Z","who":"webkit-bug-importer@group.apple.com","changes":[{"removed":"","added":"webkit-bug-importer@group.apple.com","field_name":"cc"}]},{"when":"2019-10-09T19:41:17Z","who":"webkit-bug-importer@group.apple.com","changes":[{"removed":"","added":"InRadar","field_name":"keywords"}]},{"when":"2019-10-24T14:40:51Z","who":"aboya@igalia.com","changes":[{"removed":"FIXED","added":"","field_name":"resolution"},{"removed":"RESOLVED","added":"REOPENED","field_name":"status"}]},{"when":"2019-10-24T15:05:38Z","who":"aboya@igalia.com","changes":[{"attachment_id":380535,"removed":"0","added":"1","field_name":"attachments.isobsolete"}]},{"when":"2019-10-24T15:05:45Z","who":"aboya@igalia.com","changes":[{"attachment_id":381810,"removed":"","added":"review?","field_name":"flagtypes.name"}]},{"when":"2019-10-24T15:37:18Z","who":"pnormand@igalia.com","changes":[{"attachment_id":381810,"removed":"review?","added":"review+","field_name":"flagtypes.name"}]},{"when":"2019-10-24T16:08:41Z","who":"aboya@igalia.com","changes":[{"attachment_id":381810,"removed":"","added":"commit-queue+","field_name":"flagtypes.name"}]},{"when":"2019-10-24T16:40:04Z","who":"commit-queue@webkit.org","changes":[{"attachment_id":381810,"removed":"review+, commit-queue+","added":"","field_name":"flagtypes.name"}]},{"when":"2019-10-24T16:40:06Z","who":"commit-queue@webkit.org","changes":[{"removed":"REOPENED","added":"RESOLVED","field_name":"status"},{"removed":"","added":"FIXED","field_name":"resolution"}]}],"id":201401,"alias":[]}]} +{"bugs":[{"history":[{"changes":[{"added":"bugs-noreply@webkitgtk.org, mcatanzaro@gnome.org","removed":"","field_name":"cc"}],"who":"mcatanzaro@gnome.org","when":"2019-09-02T14:42:56Z"},{"when":"2019-09-03T09:36:57Z","who":"pnormand@igalia.com","changes":[{"field_name":"cc","added":"aboya@igalia.com, pnormand@igalia.com","removed":""}]},{"changes":[{"field_name":"cc","removed":"","added":"mario@webkit.org"}],"who":"mcatanzaro@gnome.org","when":"2019-09-06T14:58:53Z"},{"who":"aboya@igalia.com","changes":[{"field_name":"assigned_to","added":"aboya@igalia.com","removed":"webkit-unassigned@lists.webkit.org"}],"when":"2019-09-07T10:23:33Z"},{"changes":[{"field_name":"flagtypes.name","attachment_id":378288,"added":"review?","removed":""}],"who":"aboya@igalia.com","when":"2019-09-07T10:23:36Z"},{"changes":[{"field_name":"flagtypes.name","removed":"review?","added":"review-","attachment_id":378288},{"field_name":"cc","added":"calvaris@igalia.com","removed":""}],"who":"calvaris@igalia.com","when":"2019-09-09T08:53:21Z"},{"when":"2019-10-06T16:48:41Z","who":"aboya@igalia.com","changes":[{"field_name":"flagtypes.name","added":"","removed":"review-","attachment_id":378288},{"field_name":"attachments.isobsolete","removed":"0","added":"1","attachment_id":378288}]},{"changes":[{"removed":"","added":"review?","attachment_id":380299,"field_name":"flagtypes.name"}],"who":"aboya@igalia.com","when":"2019-10-06T16:48:46Z"},{"when":"2019-10-06T16:49:56Z","changes":[{"field_name":"cc","removed":"","added":"cgarcia@igalia.com, eric.carlson@apple.com, ews@webkit.org, glenn@skynav.com, gns@gnome.org, jer.noble@apple.com, menard@kde.org, philipj@opera.com, sergio@correia.cc, vjaquez@igalia.com"}],"who":"ews-watchlist@webkit.org"},{"changes":[{"field_name":"flagtypes.name","attachment_id":380299,"removed":"review?","added":""},{"added":"1","removed":"0","attachment_id":380299,"field_name":"attachments.isobsolete"}],"who":"aboya@igalia.com","when":"2019-10-06T17:03:06Z"},{"changes":[{"removed":"","added":"review?","attachment_id":380300,"field_name":"flagtypes.name"}],"who":"aboya@igalia.com","when":"2019-10-06T17:03:11Z"},{"changes":[{"attachment_id":380300,"removed":"review?","added":"review+","field_name":"flagtypes.name"}],"who":"calvaris@igalia.com","when":"2019-10-07T08:53:38Z"},{"when":"2019-10-07T12:11:20Z","who":"aboya@igalia.com","changes":[{"removed":"review+","added":"","attachment_id":380300,"field_name":"flagtypes.name"},{"added":"1","removed":"0","attachment_id":380300,"field_name":"attachments.isobsolete"}]},{"when":"2019-10-07T17:18:01Z","changes":[{"added":"1","removed":"0","attachment_id":380314,"field_name":"attachments.isobsolete"}],"who":"aboya@igalia.com"},{"changes":[{"attachment_id":380336,"removed":"0","added":"1","field_name":"attachments.isobsolete"}],"who":"aboya@igalia.com","when":"2019-10-09T14:59:43Z"},{"when":"2019-10-09T18:39:22Z","changes":[{"field_name":"flagtypes.name","attachment_id":380535,"added":"commit-queue+","removed":""}],"who":"aboya@igalia.com"},{"who":"commit-queue@webkit.org","changes":[{"field_name":"cc","removed":"","added":"commit-queue@webkit.org"}],"when":"2019-10-09T19:24:06Z"},{"when":"2019-10-09T19:40:12Z","who":"commit-queue@webkit.org","changes":[{"field_name":"flagtypes.name","attachment_id":380535,"added":"","removed":"commit-queue+"}]},{"when":"2019-10-09T19:40:14Z","who":"commit-queue@webkit.org","changes":[{"removed":"","added":"FIXED","field_name":"resolution"},{"field_name":"status","removed":"NEW","added":"RESOLVED"}]},{"when":"2019-10-09T19:41:03Z","who":"webkit-bug-importer@group.apple.com","changes":[{"field_name":"cc","removed":"","added":"webkit-bug-importer@group.apple.com"}]},{"who":"webkit-bug-importer@group.apple.com","changes":[{"field_name":"keywords","removed":"","added":"InRadar"}],"when":"2019-10-09T19:41:17Z"},{"who":"aboya@igalia.com","changes":[{"removed":"FIXED","added":"","field_name":"resolution"},{"removed":"RESOLVED","added":"REOPENED","field_name":"status"}],"when":"2019-10-24T14:40:51Z"},{"who":"aboya@igalia.com","changes":[{"field_name":"attachments.isobsolete","attachment_id":380535,"removed":"0","added":"1"}],"when":"2019-10-24T15:05:38Z"},{"who":"aboya@igalia.com","changes":[{"field_name":"flagtypes.name","added":"review?","removed":"","attachment_id":381810}],"when":"2019-10-24T15:05:45Z"},{"when":"2019-10-24T15:37:18Z","changes":[{"removed":"review?","added":"review+","attachment_id":381810,"field_name":"flagtypes.name"}],"who":"pnormand@igalia.com"},{"when":"2019-10-24T16:08:41Z","changes":[{"field_name":"flagtypes.name","attachment_id":381810,"added":"commit-queue+","removed":""}],"who":"aboya@igalia.com"},{"who":"commit-queue@webkit.org","changes":[{"field_name":"flagtypes.name","attachment_id":381810,"added":"","removed":"review+, commit-queue+"}],"when":"2019-10-24T16:40:04Z"},{"changes":[{"added":"FIXED","removed":"","field_name":"resolution"},{"added":"RESOLVED","removed":"REOPENED","field_name":"status"}],"who":"commit-queue@webkit.org","when":"2019-10-24T16:40:06Z"},{"who":"ntim@apple.com","changes":[{"field_name":"see_also","removed":"","added":"https://github.com/web-platform-tests/wpt/pull/19538"},{"field_name":"cc","added":"ntim@apple.com","removed":""}],"when":"2021-11-06T11:31:47Z"}],"alias":[],"id":201401}]} \ No newline at end of file diff --git a/test/fixtures/bugs.webkit.org-443/157667650677550000 b/test/fixtures/bugs.webkit.org-443/157667650677550000 index 7f98e02..3cb63c9 100644 --- a/test/fixtures/bugs.webkit.org-443/157667650677550000 +++ b/test/fixtures/bugs.webkit.org-443/157667650677550000 @@ -1,21 +1,22 @@ -GET /rest/bug/202311 +GET /rest/bug/999999?exclude_fields=update_token&Bugzilla_api_key=REDACTED accept: */* accept-encoding: gzip,deflate -HTTP/1.1 400 Bad request -date: Wed, 18 Dec 2019 13:41:46 GMT -server: Apache/2.4 -x-xss-protection: 1; mode=block +HTTP/1.1 404 Not Found +date: Wed, 21 Oct 2026 15:16:20 GMT +content-type: application/json; charset=UTF-8 access-control-allow-headers: origin, content-type, accept, x-requested-with -access-control-allow-origin: *, * -x-frame-options: SAMEORIGIN +access-control-allow-origin: * x-content-type-options: nosniff -set-cookie: Bugzilla_login_request_cookie=7X8Z1kQTXQ; path=/; secure; HttpOnly -etag: wxMcU4mrz8kBlP4Ex1DNAw -strict-transport-security: max-age=7776000 -connection: close +x-frame-options: SAMEORIGIN +x-xss-protection: 1; mode=block +etag: jpzbEf4+t15jc7gp1DVG9g +strict-transport-security: max-age=31536000; includeSubDomains +age: 2 transfer-encoding: chunked -content-type: application/json; charset=UTF-8 - +connection: keep-alive +via: https/1.1 uklon5-edge-fx-042.ts.apple.com (acdn/25.17695) +x-cache: skipped +cdnuuid: ecd7f82e-01d6-42c2-9883-4f28fe7ab909-1331366575 -{"documentation":"https://bugzilla.readthedocs.org/en/5.0/api/","error":true,"code":100,"message":"'202311' is not a valid bug number nor an alias to a bug."} +{"error":true,"code":101,"documentation":"https://bugzilla.readthedocs.org/en/5.0/api/","message":"Bug #999999 does not exist."} \ No newline at end of file diff --git a/test/get-metadata.js b/test/get-metadata.js index f0b9f80..55377f8 100644 --- a/test/get-metadata.js +++ b/test/get-metadata.js @@ -441,12 +441,15 @@ suite('getMetadata', function() { expected.title = 'WebKit export of http://bugs.webkit.org/show_bug.cgi?id=201401'; assert.deepEqual(expected, actual); }); - test('retrieval and formatting of metadata for a WebKit related pull request with wrong bugzilla reference', function() { - var expected = "'202311' is not a valid bug number nor an alias to a bug."; - return getMetadata(19381, 'rwlbuis', 'WebKit export of https://bugs.webkit.org/show_bug.cgi?id=202311', '') - .then(function() {}, function(actual) { - assert.deepEqual(expected, actual.message); - }); + test('retrieval and formatting of metadata for a WebKit related pull request with wrong bugzilla reference', async function() { + let error; + try { + await getMetadata(19381, 'rwlbuis', 'WebKit export of https://bugs.webkit.org/show_bug.cgi?id=999999', ''); + } catch (e) { + error = e; + } + assert.isDefined(error, 'expected getMetadata to reject'); + assert.equal(error.message, 'Bug #999999 does not exist.'); }); test('limiting labels for pull requests that modify many files', function() { var expected = ['infra', 'very-large']; diff --git a/test/setup.js b/test/setup.js index 86177b3..9ba4453 100644 --- a/test/setup.js +++ b/test/setup.js @@ -10,3 +10,41 @@ replay.fixtures = path.join(__dirname, 'fixtures'); replay.headers = replay.headers.filter(function(pattern) { return !pattern.test('authorization'); }); + +// The WebKit Bugzilla API key is sent as a query parameter. Fixtures only ever +// contain a placeholder key: the real key is replaced with it before a +// fixture is written to disk, and before a request is matched against +// fixtures. Tests in `replay` mode send the placeholder itself. +var API_KEY_PARAM = /([?&]Bugzilla_api_key=)[^&]*/; +var PLACEHOLDER_API_KEY = 'REDACTED'; + +if (replay.mode === 'replay') { + require('../lib/bugs-webkit').setToken(PLACEHOLDER_API_KEY); +} + +function redactRequest(request) { + var redact = function(s) { + return s && s.replace(API_KEY_PARAM, '$1' + PLACEHOLDER_API_KEY); + }; + var url = Object.assign(Object.create(Object.getPrototypeOf(request.url)), request.url, { + path: redact(request.url.path), + href: redact(request.url.href), + search: redact(request.url.search) + }); + return Object.assign(Object.create(Object.getPrototypeOf(request)), request, { url: url }); +} + +var find = replay.catalog.find; +replay.catalog.find = function(host) { + var matchers = find.call(this, host); + return matchers && matchers.map(function(matcher) { + return function(request) { + return matcher(redactRequest(request)); + }; + }); +}; + +var save = replay.catalog.save; +replay.catalog.save = function(host, request, response, callback) { + return save.call(this, host, redactRequest(request), response, callback); +};