Commit 5dfcaa90 authored by Nathan Bruer's avatar Nathan Bruer Committed by Commit Bot

[Devtools] Overriders now handles long urls properly

In the event that a url once encoded is more than 200 characters we will
do partial hashing to it in order to ensure it plays well with operating
systems like windows which only supports ~255 character total length
paths.

R=lushnikov
BUG=754371

Change-Id: I6120ad13bff71a4933dd38088b81ecf480771360
Reviewed-on: https://chromium-review.googlesource.com/777602
Commit-Queue: Blaise Bruer <allada@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517689}
parent e1b4ffdf
To make sure that filenames are encoded safely for Network Persistence.
www.example.com -> www.example.com
www.example.com/ -> www.example.com
www.example.com/ -> www.example.com/index.html
www.example.com/simple -> www.example.com/simple
www.example.com/hello/foo/bar -> www.example.com/hello/foo/bar
www.example.com/. -> www.example.com/%2e
......@@ -35,13 +34,15 @@ example.com/foo/?bar -> example.com/foo/%3fbar
example.com/foo/?bar -> example.com/foo/%3fbar
example.com/?foo/bar/3 -> example.com/%3ffoo%2fbar%2f3
example.com/?foo/bar/3#hello/bar -> example.com/%3ffoo%2fbar%2f3
example.com/#foo/bar/3hello/bar -> example.com
example.com/#foo/bar/3hello/bar -> example.com/index.html
example.com/foo/bar/?3hello/bar -> example.com/foo/bar/%3f3hello%2fbar
example.com/foo/bar/#?3hello/bar -> example.com/foo/bar
example.com/foo/bar/#?3hello/bar -> example.com/foo/bar/index.html
example.com/foo.js# -> example.com/foo.js
example.com/foo.js. -> example.com/foo.js%2e
example.com/foo.js -> example.com/foo.js%20
example.com/foo .js -> example.com/foo%20.js
example.com///foo.js -> example.com/foo.js
example.com/// -> example.com
example.com/// -> example.com/index.html
example.com/THIS/PATH/IS_MORE_THAN/200/Chars/THIS/PATH/IS_MORE_THAN/200/Chars/THIS/PATH/IS_MORE_THAN/200/Chars/THIS/PATH/IS_MORE_THAN/200/Chars/THIS/PATH/IS_MORE_THAN/200/Chars/THIS/PATH/IS_MORE_THAN/200/Chars/THIS/PATH/IS_MORE_THAN/200/Chars/THIS/PATH/IS_MORE_THAN/200/Chars -> example.com/longurls/Chars-141a715a
example.com/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars -> example.com/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars/THIS/PATH/IS_LESS_THAN/200/Chars
......@@ -5,12 +5,13 @@
(async function() {
TestRunner.addResult(`To make sure that filenames are encoded safely for Network Persistence.\n`);
await TestRunner.loadModule('persistence');
await TestRunner.loadModule('bindings_test_runner');
var project = await BindingsTestRunner.createOverrideProject('file:///tmp/');
Persistence.networkPersistenceManager.addFileSystemOverridesProject(Persistence.NetworkPersistenceManager.inspectedPageDomain(), project);
BindingsTestRunner.setOverridesEnabled(true);
var manager = new Persistence.NetworkPersistenceManager();
// Simple tests.
log('www.example.com');
log('www.example.com/');
log('www.example.com/simple');
log('www.example.com/hello/foo/bar');
......@@ -65,9 +66,14 @@
log('example.com/foo .js');
log('example.com///foo.js');
log('example.com///');
// Very long file names
log('example.com' + '/THIS/PATH/IS_MORE_THAN/200/Chars'.repeat(8));
log('example.com' + '/THIS/PATH/IS_LESS_THAN/200/Chars'.repeat(5));
TestRunner.completeTest();
function log(url) {
TestRunner.addResult(url + ' -> ' + manager._encodeUrlPathToLocalPath(url));
TestRunner.addResult(url + ' -> ' + Persistence.networkPersistenceManager._encodedPathFromUrl(url));
}
})();
Test to ensure the consistency of front-end patterns vs backend patterns for request interception.
Requesting: bar.js
Received: bar.js
Requesting: bar.js
Received File: (MASKED_URL_PATH)/bar.js
Pattern: (MASKED_URL_PATH)/bar.js
Received: bar.js
Requesting: bar.js
Received: bar.js
Requesting: bar.js
Received: bar.js
Requesting: bar.js
Received: bar.js
Requesting: bar.js
Received: bar.js
Requesting: bar.js
Received: bar.js
Requesting: bar.js
Received: bar.js
Requesting: bar.js
Received: bar.js
Setting Pattern: **bar.js
Requesting: (MASKED_URL_PATH)/bar.js
Intercepted Request: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: (MASKED_URL_PATH)/bar.js
Requesting: (MASKED_URL_PATH)/bar.js
Intercepted Request: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: *bar.js
Requesting: (MASKED_URL_PATH)/bar.js
Intercepted Request: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: bar.js
Requesting: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: *bar.js
Requesting: (MASKED_URL_PATH)/bar.js
Intercepted Request: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: *b*
Requesting: (MASKED_URL_PATH)/bar.js
Intercepted Request: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: *
Requesting: (MASKED_URL_PATH)/bar.js
Intercepted Request: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: *bar_js
Requesting: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
Setting Pattern: *bar?js
Requesting: (MASKED_URL_PATH)/bar.js
Intercepted Request: (MASKED_URL_PATH)/bar.js
Response Received: (MASKED_URL_PATH)/bar.js
......@@ -25,10 +25,11 @@
* @return {!Promise}
*/
async function checkPattern(pattern) {
TestRunner.addResult("Setting Pattern: " + cleanURLOrPattern(pattern));
await SDK.multitargetNetworkManager.setInterceptionHandlerForPatterns([pattern], interceptionHandler);
TestRunner.addResult("Requesting: bar.js");
TestRunner.addResult("Requesting: " + cleanURLOrPattern(resourceURL));
await TestRunner.evaluateInPageAsync(`fetch('` + resourceURL + `')`);
TestRunner.addResult("Received: bar.js");
TestRunner.addResult("Response Received: " + cleanURLOrPattern(resourceURL));
await SDK.multitargetNetworkManager.setInterceptionHandlerForPatterns([], interceptionHandler);
TestRunner.addResult("");
......@@ -37,8 +38,7 @@
* @return {!Promise}
*/
function interceptionHandler(interceptedRequest) {
TestRunner.addResult("Received File: " + cleanURL(interceptedRequest.request.url));
TestRunner.addResult("Pattern: " + cleanURL(pattern));
TestRunner.addResult("Intercepted Request: " + cleanURLOrPattern(interceptedRequest.request.url));
return Promise.resolve();
}
}
......@@ -47,8 +47,9 @@
* @param {string} url
* @return {string}
*/
function cleanURL(url) {
console.assert(url.startsWith(urlPrefix));
return '(MASKED_URL_PATH)' + url.substr(urlPrefix.length);
function cleanURLOrPattern(urlOrPattern) {
if (urlOrPattern.startsWith(urlPrefix))
return '(MASKED_URL_PATH)' + urlOrPattern.substr(urlPrefix.length);
return urlOrPattern;
}
})();
......@@ -798,8 +798,6 @@ SDK.MultitargetNetworkManager = class extends Common.Object {
this._effectiveBlockedURLs = [];
this._updateBlockedPatterns();
/** @type {!Multimap<string, !SDK.MultitargetNetworkManager.RequestInterceptor>} */
this._requestInterceptorMap = new Multimap();
/** @type {!Multimap<!SDK.MultitargetNetworkManager.RequestInterceptor, string>} */
this._urlsForRequestInterceptor = new Multimap();
......@@ -833,7 +831,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object {
networkAgent.setBlockedURLs(this._effectiveBlockedURLs);
if (this.isIntercepting()) {
networkAgent.setRequestInterception(
this._requestInterceptorMap.keysArray().map(pattern => ({urlPattern: pattern.replace(/([\\?*])/g, '\\$1')})));
this._urlsForRequestInterceptor.valuesArray().map(pattern => ({urlPattern: pattern})));
}
this._agents.add(networkAgent);
if (this.isThrottling())
......@@ -1005,7 +1003,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object {
* @return {boolean}
*/
isIntercepting() {
return !!this._requestInterceptorMap.size;
return !!this._urlsForRequestInterceptor.size;
}
/**
......@@ -1014,17 +1012,10 @@ SDK.MultitargetNetworkManager = class extends Common.Object {
* @return {!Promise}
*/
setInterceptionHandlerForPatterns(patterns, requestInterceptor) {
var oldPatterns = this._urlsForRequestInterceptor.get(requestInterceptor);
if (oldPatterns) {
for (var oldPattern of oldPatterns)
this._requestInterceptorMap.delete(oldPattern, requestInterceptor);
}
// Note: requestInterceptors may recieve interception requests for patterns they did not subscribe to.
this._urlsForRequestInterceptor.deleteAll(requestInterceptor);
for (var newPattern of patterns) {
for (var newPattern of patterns)
this._urlsForRequestInterceptor.set(requestInterceptor, newPattern);
this._requestInterceptorMap.set(newPattern, requestInterceptor);
}
return this._updateInterceptionPatternsOnNextTick();
}
......@@ -1048,8 +1039,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object {
var promises = /** @type {!Array<!Promise>} */ ([]);
for (var agent of this._agents) {
// We do not allow '?' as a single character wild card for now and do not support '*' either.
var patterns =
this._requestInterceptorMap.keysArray().map(pattern => ({urlPattern: pattern.replace(/([\\?*])/g, '\\$1')}));
var patterns = this._urlsForRequestInterceptor.valuesArray().map(pattern => ({urlPattern: pattern}));
promises.push(agent.setRequestInterception(this.isIntercepting() ? patterns : []));
}
this.dispatchEventToListeners(SDK.MultitargetNetworkManager.Events.InterceptorsChanged);
......@@ -1060,14 +1050,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object {
* @param {!SDK.MultitargetNetworkManager.InterceptedRequest} interceptedRequest
*/
async _requestIntercepted(interceptedRequest) {
var url = interceptedRequest.request.url;
var requestInterceptors = this._requestInterceptorMap.get(url);
if (!requestInterceptors)
return;
for (var requestInterceptor of requestInterceptors) {
// This might be a bit racy because we are awaiting, so we check again if it still exists in the map.
if (!this._requestInterceptorMap.hasValue(url, requestInterceptor))
continue;
for (var requestInterceptor of this._urlsForRequestInterceptor.keysArray()) {
await requestInterceptor(interceptedRequest);
if (interceptedRequest.hasResponded())
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment