зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1566627 support classification in proxy.onRequest r=zombie
Add trackingClassification to the details object for proxy.onRequest. Differential Revision: https://phabricator.services.mozilla.com/D36803 --HG-- rename : toolkit/components/extensions/test/mochitest/test_ext_webrequest_urlClassification.html => toolkit/components/extensions/test/mochitest/test_ext_request_urlClassification.html extra : moz-landing-system : lando
This commit is contained in:
Родитель
010f500b2d
Коммит
6cc768b0c5
|
@ -418,6 +418,16 @@ class ProxyChannelFilter {
|
|||
if (this.extraInfoSpec.includes("requestHeaders")) {
|
||||
data.requestHeaders = channel.getRequestHeaders();
|
||||
}
|
||||
if (this.extension.isPrivileged) {
|
||||
data.urlClassification = {
|
||||
firstParty: channel.urlClassification.firstParty.filter(
|
||||
c => !c.startsWith("socialtracking")
|
||||
),
|
||||
thirdParty: channel.urlClassification.thirdParty.filter(
|
||||
c => !c.startsWith("socialtracking")
|
||||
),
|
||||
};
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,8 @@
|
|||
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
|
||||
"ip": {"type": "string", "optional": true, "description": "The server IP address that the request was actually sent to. Note that it may be a literal IPv6 address."},
|
||||
"fromCache": {"type": "boolean", "description": "Indicates if this response was fetched from disk cache."},
|
||||
"requestHeaders": {"$ref": "webRequest.HttpHeaders", "optional": true, "description": "The HTTP request headers that are going to be sent out with this request."}
|
||||
"requestHeaders": {"$ref": "webRequest.HttpHeaders", "optional": true, "description": "The HTTP request headers that are going to be sent out with this request."},
|
||||
"urlClassification": {"$ref": "webRequest.UrlClassification", "description": "Url classification if the request has been classified."}
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
@ -112,6 +112,7 @@ skip-if = fission || (verify && debug && (os == 'linux' || os == 'mac'))
|
|||
skip-if = (toolkit == 'android') # bug 1342577
|
||||
[test_ext_redirect_jar.html]
|
||||
skip-if = os == 'win' && (debug || asan) # Bug 1563440
|
||||
[test_ext_request_urlClassification.html]
|
||||
[test_ext_runtime_connect.html]
|
||||
[test_ext_runtime_connect_twoway.html]
|
||||
[test_ext_runtime_connect2.html]
|
||||
|
@ -160,6 +161,5 @@ skip-if = fission
|
|||
[test_ext_webrequest_upload.html]
|
||||
skip-if = os == 'android' # Currently fails in emulator tests
|
||||
[test_ext_webrequest_redirect_data_uri.html]
|
||||
[test_ext_webrequest_urlClassification.html]
|
||||
[test_ext_window_postMessage.html]
|
||||
[test_ext_webrequest_redirect_bypass_cors.html]
|
||||
|
|
|
@ -26,11 +26,11 @@ add_task(async function setup() {
|
|||
chromeScript.destroy();
|
||||
});
|
||||
|
||||
add_task(async function test_webrequest_tracking() {
|
||||
add_task(async function test_urlClassification() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
applications: {gecko: {id: "classification@mochi.test"}},
|
||||
permissions: ["webRequest", "webRequestBlocking", "<all_urls>"],
|
||||
permissions: ["webRequest", "webRequestBlocking", "proxy", "<all_urls>"],
|
||||
},
|
||||
isPrivileged: true,
|
||||
background() {
|
||||
|
@ -39,8 +39,7 @@ add_task(async function test_webrequest_tracking() {
|
|||
"http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_third_party.html": {},
|
||||
"http://tracking.example.org/tests/toolkit/components/extensions/test/mochitest/file_image_bad.png": {third: "tracking"},
|
||||
};
|
||||
browser.webRequest.onBeforeRequest.addListener(async (details) => {
|
||||
browser.test.log(`request ${JSON.stringify(details)}`);
|
||||
function testRequest(details) {
|
||||
let expect = expected[details.url];
|
||||
if (expect) {
|
||||
if (expect.first) {
|
||||
|
@ -53,9 +52,25 @@ add_task(async function test_webrequest_tracking() {
|
|||
} else {
|
||||
browser.test.assertEq(details.urlClassification.thirdParty.length, 0, "not tracking thirdParty");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
browser.proxy.onRequest.addListener(details => {
|
||||
browser.test.log(`proxy.onRequest ${JSON.stringify(details)}`);
|
||||
testRequest(details);
|
||||
}, {urls: ["http://mochi.test/tests/*", "http://tracking.example.org/*"]});
|
||||
browser.webRequest.onBeforeRequest.addListener(async (details) => {
|
||||
browser.test.log(`webRequest.onBeforeRequest ${JSON.stringify(details)}`);
|
||||
testRequest(details);
|
||||
}, {urls: ["http://mochi.test/tests/*", "http://tracking.example.org/*"]}, ["blocking"]);
|
||||
browser.webRequest.onCompleted.addListener(async (details) => {
|
||||
browser.test.log(`webRequest.onCompleted ${JSON.stringify(details)}`);
|
||||
if (testRequest(details)) {
|
||||
browser.test.sendMessage("classification", details.url);
|
||||
}
|
||||
}, {urls: ["<all_urls>"]}, ["blocking"]);
|
||||
}, {urls: ["http://mochi.test/tests/*", "http://tracking.example.org/*"]});
|
||||
},
|
||||
});
|
||||
await extension.startup();
|
||||
|
@ -63,13 +78,15 @@ add_task(async function test_webrequest_tracking() {
|
|||
// Test first party tracking classification.
|
||||
let url = "http://tracking.example.org/";
|
||||
let win = window.open(url);
|
||||
is(await extension.awaitMessage("classification"), url);
|
||||
is(await extension.awaitMessage("classification"), url, "request completed");
|
||||
win.close();
|
||||
// Test third party tracking classification, expecting two results.
|
||||
url = "http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_third_party.html";
|
||||
win = window.open(url);
|
||||
is(await extension.awaitMessage("classification"), url);
|
||||
is(await extension.awaitMessage("classification"), "http://tracking.example.org/tests/toolkit/components/extensions/test/mochitest/file_image_bad.png");
|
||||
is(await extension.awaitMessage("classification"),
|
||||
"http://tracking.example.org/tests/toolkit/components/extensions/test/mochitest/file_image_bad.png",
|
||||
"request completed");
|
||||
win.close();
|
||||
|
||||
await extension.unload();
|
Загрузка…
Ссылка в новой задаче