Bug 1855149 - [bidi] Add authChallenges to response data in network events r=webdriver-reviewers,whimboo

Depends on D190072

Differential Revision: https://phabricator.services.mozilla.com/D190073
This commit is contained in:
Julian Descottes 2023-10-17 11:10:41 +00:00
parent 220803a19e
commit dd422fdd4b
2 changed files with 73 additions and 23 deletions

View File

@ -231,6 +231,29 @@ export class NetworkEventRecord {
*/
addServerTimings(serverTimings) {}
/**
* Convert the provided request timing to a timing relative to the beginning
* of the request. All timings are numbers representing high definition
* timestamps.
*
* @param {number} timing
* High definition timestamp for a request timing relative from the time
* origin.
* @param {number} requestTime
* High definition timestamp for the request start time relative from the
* time origin.
* @returns {number}
* High definition timestamp for the request timing relative to the start
* time of the request, or 0 if the provided timing was 0.
*/
#convertTimestamp(timing, requestTime) {
if (timing == 0) {
return 0;
}
return timing - requestTime;
}
#emitBeforeRequestSent() {
this.#updateDataFromTimedChannel();
@ -274,29 +297,6 @@ export class NetworkEventRecord {
});
}
/**
* Convert the provided request timing to a timing relative to the beginning
* of the request. All timings are numbers representing high definition
* timestamps.
*
* @param {number} timing
* High definition timestamp for a request timing relative from the time
* origin.
* @param {number} requestTime
* High definition timestamp for the request start time relative from the
* time origin.
* @returns {number}
* High definition timestamp for the request timing relative to the start
* time of the request, or 0 if the provided timing was 0.
*/
#convertTimestamp(timing, requestTime) {
if (timing == 0) {
return 0;
}
return timing - requestTime;
}
#getBrowsingContext() {
const id = lazy.NetworkUtils.getChannelBrowsingContextID(
this.#requestChannel

View File

@ -16,6 +16,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
"chrome://remote/content/shared/NavigationManager.sys.mjs",
NetworkListener:
"chrome://remote/content/shared/listeners/NetworkListener.sys.mjs",
parseChallengeHeader:
"chrome://remote/content/shared/ChallengeHeaderParser.sys.mjs",
parseURLPattern:
"chrome://remote/content/shared/webdriver/URLPattern.sys.mjs",
TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
@ -23,6 +25,12 @@ ChromeUtils.defineESModuleGetters(lazy, {
"chrome://remote/content/shared/messagehandler/WindowGlobalMessageHandler.sys.mjs",
});
/**
* @typedef {object} AuthChallenge
* @property {string} scheme
* @property {string} realm
*/
/**
* @typedef {object} BaseParameters
* @property {string=} context
@ -184,6 +192,7 @@ const InterceptPhase = {
* @property {number|null} bodySize
* Defaults to null.
* @property {ResponseContent} content
* @property {Array<AuthChallenge>=} authChallenges
*/
/**
@ -367,6 +376,42 @@ class NetworkModule extends Module {
this.#interceptMap.delete(intercept);
}
#extractChallenges(responseData) {
let headerName;
// Using case-insensitive match for header names, so we use the lowercase
// version of the "WWW-Authenticate" / "Proxy-Authenticate" strings.
if (responseData.status === 401) {
headerName = "www-authenticate";
} else if (responseData.status === 407) {
headerName = "proxy-authenticate";
} else {
return null;
}
const challenges = [];
for (const header of responseData.headers) {
if (header.name.toLowerCase() === headerName) {
// A single header can contain several challenges.
const headerChallenges = lazy.parseChallengeHeader(header.value);
for (const headerChallenge of headerChallenges) {
const realmParam = headerChallenge.params.find(
param => param.name == "realm"
);
const realm = realmParam ? realmParam.value : undefined;
const challenge = {
scheme: headerChallenge.scheme,
realm,
};
challenges.push(challenge);
}
}
}
return challenges;
}
#getContextInfo(browsingContext) {
return {
contextId: browsingContext.id,
@ -571,6 +616,11 @@ class NetworkModule extends Module {
response: responseData,
});
const authChallenges = this.#extractChallenges(responseData);
if (authChallenges !== null) {
responseEvent.response.authChallenges = authChallenges;
}
this.emitEvent(
protocolEventName,
responseEvent,