Repository navigation
Fix WebKit export approval: verify landings against the WebKit repository #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| "use strict"; | ||
| const fetch = require('node-fetch'); | ||
|
|
||
| const BASE_URL = 'https://commits.webkit.org'; | ||
|
|
||
| // Only allow references to commits on WebKit's main branch, either as a | ||
| // canonical identifier (e.g. "324168@main") or as a legacy Subversion revision | ||
| // (e.g. "r266816"). References are parsed out of Bugzilla comments, so they | ||
| // are strictly validated before being used to build a URL. | ||
| const REF_PATTERN = /^(?:\d+@main|r\d+)$/; | ||
|
|
||
| /** | ||
| * Retrieves information about a commit in the WebKit repository. | ||
| * | ||
| * @param {string} ref A commit reference, e.g. "324168@main" or "r266816". | ||
| * @return {Promise<object|null>} The commit (with `hash`, `branch`, | ||
| * `identifier`, `revision` and `message` fields), or null if no such | ||
| * commit exists. | ||
| */ | ||
| async function get(ref) { | ||
| if (typeof ref !== 'string' || !REF_PATTERN.test(ref)) { | ||
| throw new Error(`Invalid WebKit commit reference: ${ref}`); | ||
| } | ||
| const response = await exports.fetch(`${BASE_URL}/${ref}/json`, { | ||
| headers: { "User-Agent": "wpt-pr-bot" }, | ||
| }); | ||
| if (response.status === 404) { | ||
| return null; | ||
| } | ||
| if (!response.ok) { | ||
| throw new Error(`Unexpected status ${response.status} from ${BASE_URL} for ${ref}`); | ||
| } | ||
| return response.json(); | ||
| } | ||
|
|
||
| exports.get = get; | ||
| // Exposed so that tests can stub out network access. | ||
| exports.fetch = fetch; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,38 @@ | ||||||||||||||||||||||||
| "use strict"; | ||||||||||||||||||||||||
| var bugsWebkit = require('../bugs-webkit'); | ||||||||||||||||||||||||
| var bugsWebkit = require('../bugs-webkit'), | ||||||||||||||||||||||||
| commitsWebkit = require('../commits-webkit'), | ||||||||||||||||||||||||
| logger = require('../logger'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Accounts that resolve a bug as FIXED when a reviewed patch lands in WebKit. | ||||||||||||||||||||||||
| const WEBKIT_LANDING_BOTS = ["ews-feeder", "commit-queue"]; | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's actually store these by their actual usernames, for when we actually fix authentication:
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Matches the comment left by WebKit's landing bots, e.g. | ||||||||||||||||||||||||
| // "Committed 324168@main (004e01c34435): <https://commits.webkit.org/324168@main>" | ||||||||||||||||||||||||
| // "Committed r266816: <https://trac.webkit.org/changeset/266816>" | ||||||||||||||||||||||||
| const LANDING_COMMENT_PATTERN = /Committed (\d+@main|r\d+)(?: \(([0-9a-f]{7,40})\))?/g; | ||||||||||||||||||||||||
|
Comment on lines
+9
to
+12
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an interesting inconsistency here, insofar as we allow any branch for SVN but only The history of comments is something like: https://bugs.webkit.org/show_bug.cgi?id=209237, commit-queue@webkit.org:
https://bugs.webkit.org/show_bug.cgi?id=208861, ews-feeder@webkit.org:
https://bugs.webkit.org/show_bug.cgi?id=223117, ews-feeder@webkit.org:
Eight bugs, including https://bugs.webkit.org/show_bug.cgi?id=230351, ews-feeder@webkit.org:
And https://bugs.webkit.org/show_bug.cgi?id=247043 contains two examples, ews-feeder@webkit.org:
Plus:
Though we can have things only on a branch on their own bug. I might be tempted to use a regex more like:
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // bugs.webkit.org historically reported user identities (e.g. the `who` field | ||||||||||||||||||||||||
| // of bug history) as full email addresses (e.g. "ews-feeder@webkit.org"), but | ||||||||||||||||||||||||
| // now applies Bugzilla's email filtering for logged-out users, which reports | ||||||||||||||||||||||||
| // only the local part of the address (e.g. "ews-feeder"). Accept either form. | ||||||||||||||||||||||||
| // | ||||||||||||||||||||||||
| // IMPORTANT: The local part alone is NOT a unique identity; anyone can register | ||||||||||||||||||||||||
| // an account such as "ews-feeder@example.com", which is reported as | ||||||||||||||||||||||||
| // "ews-feeder". This check is therefore only a cheap pre-filter, and a landing | ||||||||||||||||||||||||
| // must additionally be verified against the WebKit repository (see `landed`). | ||||||||||||||||||||||||
| function isWebKitLandingBot(who) { | ||||||||||||||||||||||||
| if (typeof who !== "string") { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| var at = who.indexOf("@"); | ||||||||||||||||||||||||
| if (at > -1) { | ||||||||||||||||||||||||
| if (who.slice(at + 1) !== "webkit.org") { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| who = who.slice(0, at); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return WEBKIT_LANDING_BOTS.includes(who); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| exports.related = function(title) { | ||||||||||||||||||||||||
| return title.indexOf("WebKit export of") > -1; | ||||||||||||||||||||||||
|
|
@@ -16,13 +49,81 @@ exports.verified = function(webkitIssue, wptPullRequestNumber) { | |||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Returns true if `commit` (as returned by commits-webkit) is a commit on | ||||||||||||||||||||||||
| // WebKit's main branch whose message references the given WebKit bug. | ||||||||||||||||||||||||
| function isLandedCommitForBug(commit, issue, abbreviatedHash) { | ||||||||||||||||||||||||
| if (!commit || commit.branch !== "main" || typeof commit.message !== "string") { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if (abbreviatedHash && (typeof commit.hash !== "string" || !commit.hash.startsWith(abbreviatedHash))) { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| // `issue` is always numeric (it is extracted with /\d+/ from the PR title), | ||||||||||||||||||||||||
| // so it is safe to embed in the pattern. The negative lookahead prevents | ||||||||||||||||||||||||
| // e.g. bug 12345 from matching a reference to bug 123456. | ||||||||||||||||||||||||
| var bugURLPattern = new RegExp( | ||||||||||||||||||||||||
| `(?:https?://bugs\\.webkit\\.org/show_bug\\.cgi\\?id=|https?://webkit\\.org/b/)${issue}(?!\\d)`); | ||||||||||||||||||||||||
|
Comment on lines
+64
to
+65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't change wpt-pr-bot/lib/metadata/index.js Line 114 in 784d204
https?://webkit\\.org/b/ alternation is pointless.
We also only have a single bug matching that, which suggests we might not need it: https://github.com/web-platform-tests/wpt/pulls?q=is%3Apr+webkit.org%2Fb%2F+in%3Atitle |
||||||||||||||||||||||||
| return bugURLPattern.test(commit.message); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Determines whether a change for the given WebKit bug has actually landed on | ||||||||||||||||||||||||
| // WebKit's main branch. | ||||||||||||||||||||||||
| // | ||||||||||||||||||||||||
| // Bugzilla identities cannot be trusted (see `isWebKitLandingBot`), and nor can | ||||||||||||||||||||||||
| // comment text, so this looks for the "Committed ..." comment left by the | ||||||||||||||||||||||||
| // landing bot and then confirms with the WebKit repository itself (via | ||||||||||||||||||||||||
| // commits.webkit.org) that the referenced commit exists on main and that its | ||||||||||||||||||||||||
| // message references this bug. Only WebKit committers can land on main, so | ||||||||||||||||||||||||
| // this cannot be spoofed by an arbitrary Bugzilla user. | ||||||||||||||||||||||||
| // | ||||||||||||||||||||||||
| // Errors talking to commits.webkit.org are logged and treated as "not landed"; | ||||||||||||||||||||||||
| // the pull request poller will try again later. | ||||||||||||||||||||||||
| exports.landed = async function(issue) { | ||||||||||||||||||||||||
| var body = await bugsWebkit.get("/rest/bug/:id/comment", { id: issue }); | ||||||||||||||||||||||||
| var bug = body && body.bugs && body.bugs[issue]; | ||||||||||||||||||||||||
| var comments = (bug && bug.comments) || []; | ||||||||||||||||||||||||
| for (var comment of comments) { | ||||||||||||||||||||||||
| if (!isWebKitLandingBot(comment.creator) || typeof comment.text !== "string") { | ||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| for (var match of comment.text.matchAll(LANDING_COMMENT_PATTERN)) { | ||||||||||||||||||||||||
| var ref = match[1], abbreviatedHash = match[2]; | ||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||
| var commit = await commitsWebkit.get(ref); | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to ensure the |
||||||||||||||||||||||||
| if (isLandedCommitForBug(commit, issue, abbreviatedHash)) { | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||
| logger.warn({ err: e, webkitIssue: issue, ref: ref }, | ||||||||||||||||||||||||
| `Unable to verify WebKit commit ${ref} for bug ${issue}`); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function isLandingResolution(history_item, change) { | ||||||||||||||||||||||||
| return change.field_name == "resolution" && | ||||||||||||||||||||||||
| change.added.includes("FIXED") && | ||||||||||||||||||||||||
| isWebKitLandingBot(history_item.who); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| exports.flags = function(issue) { | ||||||||||||||||||||||||
| var flags = { | ||||||||||||||||||||||||
| reviewed: false, | ||||||||||||||||||||||||
| inCommit: false | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| return bugsWebkit.get("/rest/bug/:id/history", { id: issue }).then(function (body) { | ||||||||||||||||||||||||
| body.bugs[0].history.forEach(function(history_item) { | ||||||||||||||||||||||||
| return bugsWebkit.get("/rest/bug/:id/history", { id: issue }).then(async function (body) { | ||||||||||||||||||||||||
| var history = body.bugs[0].history; | ||||||||||||||||||||||||
| // Only verify the landing (which requires additional network | ||||||||||||||||||||||||
| // requests) if the history claims that a landing bot fixed the bug. | ||||||||||||||||||||||||
| var claimsLanding = history.some(function(history_item) { | ||||||||||||||||||||||||
| return history_item.changes.some(function(change) { | ||||||||||||||||||||||||
| return isLandingResolution(history_item, change); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| var landed = claimsLanding && await exports.landed(issue); | ||||||||||||||||||||||||
| history.forEach(function(history_item) { | ||||||||||||||||||||||||
| history_item.changes.forEach(function(change) { | ||||||||||||||||||||||||
| if (change.field_name == "flagtypes.name") { | ||||||||||||||||||||||||
| if (change.removed.includes("review+")) { | ||||||||||||||||||||||||
|
|
@@ -40,11 +141,9 @@ exports.flags = function(issue) { | |||||||||||||||||||||||
| flags.inCommit = true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if (change.field_name == "resolution") { | ||||||||||||||||||||||||
| if (change.added.includes("FIXED") && ["ews-feeder@webkit.org", "commit-queue@webkit.org"].includes(history_item.who)) { | ||||||||||||||||||||||||
| flags.reviewed = true; | ||||||||||||||||||||||||
| flags.inCommit = true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if (landed && isLandingResolution(history_item, change)) { | ||||||||||||||||||||||||
| flags.reviewed = true; | ||||||||||||||||||||||||
| flags.inCommit = true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| 'use strict'; | ||
|
|
||
| var assert = require('chai').assert, | ||
| sinon = require('sinon'), | ||
| commitsWebkit = require('../lib/commits-webkit'); | ||
|
|
||
| suite('commits-webkit', function() { | ||
| var sandbox, fetch; | ||
|
|
||
| setup(function() { | ||
| sandbox = sinon.createSandbox(); | ||
| fetch = sandbox.stub(commitsWebkit, 'fetch'); | ||
| }); | ||
|
|
||
| teardown(function() { | ||
| sandbox.restore(); | ||
| }); | ||
|
|
||
| function respond(status, body) { | ||
| fetch.resolves({ | ||
| status: status, | ||
| ok: status >= 200 && status < 300, | ||
| json: async () => body, | ||
| }); | ||
| } | ||
|
|
||
| test('retrieves a commit by git identifier', async function() { | ||
| var commit = { hash: 'abc', branch: 'main', identifier: '324168@main' }; | ||
| respond(200, commit); | ||
| assert.deepEqual(await commitsWebkit.get('324168@main'), commit); | ||
| assert.equal(fetch.firstCall.args[0], 'https://commits.webkit.org/324168@main/json'); | ||
| }); | ||
|
|
||
| test('retrieves a commit by Subversion revision', async function() { | ||
| var commit = { hash: 'def', branch: 'main', revision: 266816 }; | ||
| respond(200, commit); | ||
| assert.deepEqual(await commitsWebkit.get('r266816'), commit); | ||
| assert.equal(fetch.firstCall.args[0], 'https://commits.webkit.org/r266816/json'); | ||
| }); | ||
|
|
||
| test('returns null for a commit that does not exist', async function() { | ||
| respond(404, { message: 'No commit with the specified reference could be found' }); | ||
| assert.isNull(await commitsWebkit.get('999999999@main')); | ||
| }); | ||
|
|
||
| test('throws on other errors', async function() { | ||
| respond(503, {}); | ||
| try { | ||
| await commitsWebkit.get('324168@main'); | ||
| assert.fail('expected an error'); | ||
| } catch (e) { | ||
| assert.include(e.message, '503'); | ||
| } | ||
| }); | ||
|
|
||
| [ | ||
| '324168@safari-7620-branch', | ||
| '../324168@main', | ||
| '324168@main/../../evil', | ||
| 'abcdef', | ||
| '', | ||
| undefined, | ||
| ].forEach(function(ref) { | ||
| test(`rejects invalid reference ${JSON.stringify(ref)}`, async function() { | ||
| try { | ||
| await commitsWebkit.get(ref); | ||
| assert.fail('expected an error'); | ||
| } catch (e) { | ||
| assert.include(e.message, 'Invalid WebKit commit reference'); | ||
| } | ||
| assert.isFalse(fetch.called); | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should match everything else:
wpt-pr-bot/lib/specref.js
Line 10 in 784d204
wpt-pr-bot/lib/bugs-webkit.js
Line 16 in 784d204
wpt-pr-bot/lib/github.js
Line 20 in 784d204