Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion create-secrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this had been broken, @DanielRyanSmith, can you check this actually exists and works?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have confirmed the code here retrieves full emails back with this change

};
return secrets;
}
Expand Down
39 changes: 31 additions & 8 deletions lib/bugs-webkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/metadata/webkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 39 additions & 0 deletions test/bugs-webkit.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
26 changes: 14 additions & 12 deletions test/fixtures/bugs.webkit.org-443/157512252738650000
Original file line number Diff line number Diff line change
@@ -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}]}
Loading
Loading