@whotracksme/reporting 5.1.28 → 5.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/package.json +1 -1
- package/reporting/example/index.js +2 -12
- package/reporting/example/manifests/chromium.json +1 -0
- package/reporting/snapshots/0001/events.log.br +0 -0
- package/reporting/snapshots/0001/snapshot.json +4173 -0
- package/reporting/snapshots/0002/events.log.br +0 -0
- package/reporting/snapshots/0002/snapshot.json +2539 -0
- package/reporting/snapshots/0003/events.log.br +0 -0
- package/reporting/snapshots/0003/snapshot.json +855 -0
- package/reporting/snapshots/0004/events.log.br +0 -0
- package/reporting/snapshots/0004/snapshot.json +802 -0
- package/reporting/src/hash-detector.js +1 -1
- package/reporting/src/index.js +1 -2
- package/reporting/src/request/config.js +9 -4
- package/reporting/src/request/{hash.js → hash/index.js} +3 -3
- package/reporting/src/request/index.js +447 -496
- package/reporting/src/{webrequest-pipeline → request}/page-store.js +65 -75
- package/reporting/src/request/qs-whitelist2.js +0 -2
- package/reporting/src/request/steps/cookie-context.js +6 -5
- package/reporting/src/request/steps/oauth-detector.js +3 -24
- package/reporting/src/request/steps/page-logger.js +3 -4
- package/reporting/src/request/steps/token-checker/token-domain.js +1 -1
- package/reporting/src/request/steps/token-examiner.js +3 -4
- package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +55 -75
- package/reporting/src/request/steps/token-telemetry/index.js +86 -115
- package/reporting/src/request/steps/token-telemetry/key-pipeline.js +3 -2
- package/reporting/src/request/steps/token-telemetry/token-pipeline.js +3 -2
- package/reporting/src/request/utils/temp-set.js +2 -4
- package/reporting/src/request/{time.js → utils/time.js} +0 -5
- package/reporting/src/request/utils/tlds.js +1 -11
- package/reporting/src/request/{utils.js → utils/utils.js} +9 -0
- package/reporting/src/{webrequest-pipeline/webrequest-context.js → request/utils/webrequest.js} +84 -4
- package/reporting/src/utils/url.js +0 -25
- package/reporting/test/helpers/scenarios.js +76 -17
- package/reporting/test/index.js +3 -8
- package/reporting/test/request/database.test.js +96 -0
- package/reporting/test/request/{hash.spec.js → hash/index.spec.js} +2 -2
- package/reporting/test/request/index.spec.js +24 -46
- package/reporting/test/{request-reporter.test.js → request/index.test.js} +102 -46
- package/reporting/test/{webrequest-pipeline → request}/page-store.test.js +1 -1
- package/reporting/test/request/steps/oauth-detector.spec.js +15 -25
- package/reporting/test/request/{utils.spec.js → utils/utils.spec.js} +2 -2
- package/reporting/test/setup.unit.js +1 -0
- package/reporting/test/utils/url.spec.js +1 -26
- package/reporting/src/request/page-telemetry.js +0 -42
- package/reporting/src/request/steps/subdomain-check.js +0 -34
- package/reporting/src/request/utils/subject.js +0 -37
- package/reporting/src/request-reporter.js +0 -111
- package/reporting/src/utils/pacemaker.js +0 -279
- package/reporting/src/webrequest-pipeline/cname-uncloak.js +0 -110
- package/reporting/src/webrequest-pipeline/index.js +0 -286
- package/reporting/src/webrequest-pipeline/logger.js +0 -14
- package/reporting/src/webrequest-pipeline/pipeline.js +0 -249
- package/reporting/src/webrequest-pipeline/utils/webrequest.js +0 -119
- package/reporting/test/utils/pacemaker.spec.js +0 -222
- package/reporting/test/webrequest-pipeline/index.test.js +0 -160
- package/reporting/test/webrequest-pipeline/pipeline.spec.js +0 -251
- /package/reporting/src/request/{resources → hash}/prob.js +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhoTracks.Me
|
|
3
|
+
* https://whotracks.me/
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2017-present Ghostery GmbH. All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
8
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
9
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { IDBFactory } from 'fake-indexeddb';
|
|
13
|
+
import { expect } from 'chai';
|
|
14
|
+
import { deleteDB } from 'idb';
|
|
15
|
+
|
|
16
|
+
import Database from '../../src/request/database.js';
|
|
17
|
+
|
|
18
|
+
describe('request/database', function () {
|
|
19
|
+
let database;
|
|
20
|
+
|
|
21
|
+
beforeEach(async function () {
|
|
22
|
+
globalThis.indexedDB = new IDBFactory();
|
|
23
|
+
|
|
24
|
+
if (database) {
|
|
25
|
+
await database.unload();
|
|
26
|
+
await deleteDB(database.tableName);
|
|
27
|
+
}
|
|
28
|
+
database = new Database();
|
|
29
|
+
await database.init();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(function () {
|
|
33
|
+
delete globalThis.indexedDB;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('#tokens', function () {
|
|
37
|
+
it('#bulkPut', async function () {
|
|
38
|
+
const token = {
|
|
39
|
+
token: '8b72dcfadc69a786b66584b8b69d0512',
|
|
40
|
+
created: 10060,
|
|
41
|
+
safe: false,
|
|
42
|
+
lastSent: '',
|
|
43
|
+
sites: ['a10104ad75306d26', '6287472925cbc9b4'],
|
|
44
|
+
trackers: [
|
|
45
|
+
'e10f949fcaacdb19',
|
|
46
|
+
'e317a68e65ec3e72',
|
|
47
|
+
'14dd5266c70789bd',
|
|
48
|
+
'685c1532a4c8585c',
|
|
49
|
+
'b1d934463190cb39',
|
|
50
|
+
'9521166916c82eac',
|
|
51
|
+
'513d8f48d45a9708',
|
|
52
|
+
'aaaa9055e37b2c41',
|
|
53
|
+
'04e2599b3faf050b',
|
|
54
|
+
'2388a0be94d354c3',
|
|
55
|
+
'0fc2925edc331870',
|
|
56
|
+
'b8ea0ff0ff328509',
|
|
57
|
+
'a1da39e35b260336',
|
|
58
|
+
'dd9091206cde9290',
|
|
59
|
+
'dbb493430c36961e',
|
|
60
|
+
'7936b9e9fc6b1595',
|
|
61
|
+
'6dd56db607da346c',
|
|
62
|
+
'4b1f42f90487b5be',
|
|
63
|
+
'fe61a5b83c837c9f',
|
|
64
|
+
'1a3c9a8ebcc58dac',
|
|
65
|
+
'1d5920f4b44b27a8',
|
|
66
|
+
'78f46604122e0a47',
|
|
67
|
+
'2952759073d266f1',
|
|
68
|
+
'8ea58e416a21d5bb',
|
|
69
|
+
'2343ec78a04c6ea9',
|
|
70
|
+
'1df7e81cf5e2db18',
|
|
71
|
+
'f989f85475637850',
|
|
72
|
+
'dbbc49f14541867e',
|
|
73
|
+
'e244a3dd0980a641',
|
|
74
|
+
'421d522c51846d95',
|
|
75
|
+
'6660d08b6d1c5653',
|
|
76
|
+
'25ac106d69e67d6b',
|
|
77
|
+
'135b955866e31ce0',
|
|
78
|
+
'aef0ae912fccaca6',
|
|
79
|
+
'3a59fb0cba397714',
|
|
80
|
+
'b7961d2144027cc7',
|
|
81
|
+
'39e67d76e378a4d8',
|
|
82
|
+
'824a9c5b7b39d556',
|
|
83
|
+
'05d986b30d7eb849',
|
|
84
|
+
],
|
|
85
|
+
count: 1,
|
|
86
|
+
};
|
|
87
|
+
expect(await database.tokens.count()).to.equal(0);
|
|
88
|
+
await database.tokens.bulkPut([
|
|
89
|
+
token,
|
|
90
|
+
// add the same token with a different id
|
|
91
|
+
{ ...token, token: 1 },
|
|
92
|
+
]);
|
|
93
|
+
expect(await database.tokens.count()).to.equal(2);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
import * as chai from 'chai';
|
|
13
13
|
|
|
14
|
-
import probData from '
|
|
14
|
+
import probData from '../../../src/request/hash/prob.js';
|
|
15
15
|
import {
|
|
16
16
|
isMostlyNumeric,
|
|
17
17
|
HashProb,
|
|
18
18
|
shouldCheckToken,
|
|
19
|
-
} from '
|
|
19
|
+
} from '../../../src/request/hash/index.js';
|
|
20
20
|
|
|
21
21
|
const nonNumeric = ['', 'ithinkthereis1numberhere', '1240abcd'];
|
|
22
22
|
const mostlyNumeric = ['4902', '1024x768'];
|
|
@@ -21,10 +21,7 @@ import { createFetchMock } from '../helpers/fetch-mock';
|
|
|
21
21
|
|
|
22
22
|
import { truncatedHash, default as md5 } from '../../src/md5.js';
|
|
23
23
|
|
|
24
|
-
import
|
|
25
|
-
import Database from '../../src/request/database.js';
|
|
26
|
-
import RequestMonitor from '../../src/request/index.js';
|
|
27
|
-
import WebrequestPipeline from '../../src/webrequest-pipeline/index.js';
|
|
24
|
+
import RequestReporter from '../../src/request/index.js';
|
|
28
25
|
|
|
29
26
|
const THIRD_PARTY_HOST1 = '127.0.0.1:60508';
|
|
30
27
|
const THIRD_PARTY_HOST2 = 'cliqztest2.de:60508';
|
|
@@ -57,8 +54,6 @@ describe('request/index', function () {
|
|
|
57
54
|
let oldChromeStorageSession;
|
|
58
55
|
let oldChromeStorage;
|
|
59
56
|
|
|
60
|
-
let pipeline;
|
|
61
|
-
|
|
62
57
|
beforeEach(() => {
|
|
63
58
|
if (!chrome?.storage?.session) {
|
|
64
59
|
monkeyPatchedChromeStorage = true;
|
|
@@ -71,18 +66,14 @@ describe('request/index', function () {
|
|
|
71
66
|
// indicate that there are bugs in the implementation or in the tests.
|
|
72
67
|
chrome.storage.session = chrome.storage.local;
|
|
73
68
|
chrome.storage.session.get.yields({});
|
|
69
|
+
chrome.tabs.query.returns([]);
|
|
74
70
|
|
|
75
71
|
// to test against a real in-memory implementation:
|
|
76
72
|
// chrome.storage.session = new FakeSessionApi();
|
|
77
73
|
}
|
|
78
|
-
|
|
79
|
-
pipeline = new WebrequestPipeline();
|
|
80
|
-
pipeline.init();
|
|
81
74
|
});
|
|
82
75
|
|
|
83
76
|
afterEach(() => {
|
|
84
|
-
pipeline?.unload();
|
|
85
|
-
pipeline = null;
|
|
86
77
|
if (monkeyPatchedChromeStorage) {
|
|
87
78
|
chrome.storage.session = oldChromeStorageSession;
|
|
88
79
|
chrome.storage = oldChromeStorage;
|
|
@@ -90,7 +81,6 @@ describe('request/index', function () {
|
|
|
90
81
|
});
|
|
91
82
|
|
|
92
83
|
let attrack;
|
|
93
|
-
let config;
|
|
94
84
|
let fetchMock = createFetchMock();
|
|
95
85
|
|
|
96
86
|
beforeEach(async function () {
|
|
@@ -101,35 +91,24 @@ describe('request/index', function () {
|
|
|
101
91
|
return '';
|
|
102
92
|
},
|
|
103
93
|
};
|
|
104
|
-
|
|
105
|
-
await db.init();
|
|
106
|
-
config = new Config(
|
|
94
|
+
attrack = new RequestReporter(
|
|
107
95
|
{
|
|
108
96
|
configUrl: 'http://cdn',
|
|
109
97
|
remoteWhitelistUrl: 'http://cdn',
|
|
110
98
|
localWhitelistUrl: '/base/assets/request',
|
|
111
99
|
},
|
|
112
100
|
{
|
|
113
|
-
db,
|
|
114
|
-
trustedClock,
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
await config.init();
|
|
118
|
-
attrack = new RequestMonitor(
|
|
119
|
-
{},
|
|
120
|
-
{
|
|
121
|
-
db,
|
|
122
|
-
webRequestPipeline: pipeline,
|
|
123
101
|
countryProvider: {},
|
|
124
102
|
trustedClock,
|
|
125
103
|
communication: {},
|
|
104
|
+
getBrowserInfo: () => ({ name: 'xx' }),
|
|
126
105
|
},
|
|
127
106
|
);
|
|
128
|
-
await attrack.init(
|
|
107
|
+
await attrack.init();
|
|
129
108
|
await attrack.qs_whitelist.initPromise;
|
|
130
|
-
config.cookieEnabled = false;
|
|
131
|
-
config.qsEnabled = false;
|
|
132
|
-
config.placeHolder = '<removed>';
|
|
109
|
+
attrack.config.cookieEnabled = false;
|
|
110
|
+
attrack.config.qsEnabled = false;
|
|
111
|
+
attrack.config.placeHolder = '<removed>';
|
|
133
112
|
});
|
|
134
113
|
|
|
135
114
|
afterEach(() => {
|
|
@@ -142,18 +121,18 @@ describe('request/index', function () {
|
|
|
142
121
|
chrome.tabs.onCreated.dispatch(pageSpec.tab);
|
|
143
122
|
return {
|
|
144
123
|
onBeforeRequest: pageSpec.onBeforeRequest.map(function (reqData) {
|
|
145
|
-
const response =
|
|
124
|
+
const response = attrack.onBeforeRequest(reqData);
|
|
146
125
|
return { url: reqData.url, response };
|
|
147
126
|
}),
|
|
148
127
|
onBeforeSendHeaders: pageSpec.onBeforeSendHeaders.map(function (reqData) {
|
|
149
128
|
reqData.requestHeaders = mockRequestHeaders;
|
|
150
|
-
const response =
|
|
129
|
+
const response = attrack.onBeforeSendHeaders(reqData);
|
|
151
130
|
return { url: reqData.url, response };
|
|
152
131
|
}),
|
|
153
132
|
onHeadersReceived: pageSpec.onHeadersReceived.map(function (reqData) {
|
|
154
133
|
reqData.requestHeaders = mockRequestHeaders;
|
|
155
134
|
reqData.responseHeaders = mockResponseHeaders;
|
|
156
|
-
const response =
|
|
135
|
+
const response = attrack.onHeadersReceived(reqData);
|
|
157
136
|
return { url: reqData.url, response };
|
|
158
137
|
}),
|
|
159
138
|
};
|
|
@@ -166,7 +145,7 @@ describe('request/index', function () {
|
|
|
166
145
|
describe('cookie blocking', function () {
|
|
167
146
|
describe('cookie blocking disabled', function () {
|
|
168
147
|
beforeEach(function () {
|
|
169
|
-
config.cookieEnabled = false;
|
|
148
|
+
attrack.config.cookieEnabled = false;
|
|
170
149
|
});
|
|
171
150
|
|
|
172
151
|
it('allows all cookies', function () {
|
|
@@ -178,7 +157,7 @@ describe('request/index', function () {
|
|
|
178
157
|
|
|
179
158
|
describe('cookie blocking enabled', function () {
|
|
180
159
|
beforeEach(function () {
|
|
181
|
-
config.cookieEnabled = true;
|
|
160
|
+
attrack.config.cookieEnabled = true;
|
|
182
161
|
});
|
|
183
162
|
|
|
184
163
|
it('blocks third party cookies', function () {
|
|
@@ -198,7 +177,7 @@ describe('request/index', function () {
|
|
|
198
177
|
|
|
199
178
|
context('QS blocking', function () {
|
|
200
179
|
beforeEach(function () {
|
|
201
|
-
config.qsEnabled = true;
|
|
180
|
+
attrack.config.qsEnabled = true;
|
|
202
181
|
});
|
|
203
182
|
|
|
204
183
|
it('allows query strings on domains not in the tracker list', function () {
|
|
@@ -216,8 +195,8 @@ describe('request/index', function () {
|
|
|
216
195
|
key = md5('uid');
|
|
217
196
|
trackerHash = truncatedHash('127.0.0.1');
|
|
218
197
|
attrack.qs_whitelist.addSafeToken(trackerHash, '');
|
|
219
|
-
config.tokenDomainCountThreshold = 2;
|
|
220
|
-
attrack.
|
|
198
|
+
attrack.config.tokenDomainCountThreshold = 2;
|
|
199
|
+
attrack.tokenChecker.tokenDomain.clear();
|
|
221
200
|
});
|
|
222
201
|
|
|
223
202
|
it('allows QS first time on tracker', function () {
|
|
@@ -238,7 +217,7 @@ describe('request/index', function () {
|
|
|
238
217
|
}
|
|
239
218
|
|
|
240
219
|
beforeEach(function () {
|
|
241
|
-
config.tokenDomainCountThreshold = 0;
|
|
220
|
+
attrack.config.tokenDomainCountThreshold = 0;
|
|
242
221
|
});
|
|
243
222
|
|
|
244
223
|
it('blocks long tokens on tracker domain', function () {
|
|
@@ -279,14 +258,13 @@ describe('request/index', function () {
|
|
|
279
258
|
const uid = '04C2EAD03BAB7F5E-2E85855CF4C75134';
|
|
280
259
|
|
|
281
260
|
beforeEach(function () {
|
|
282
|
-
config.qsEnabled = true;
|
|
261
|
+
attrack.config.qsEnabled = true;
|
|
283
262
|
attrack.qs_whitelist.addSafeToken(truncatedHash('tracker.com'), '');
|
|
284
|
-
config.tokenDomainCountThreshold = 0; // block first time
|
|
285
|
-
return attrack.initPipeline();
|
|
263
|
+
attrack.config.tokenDomainCountThreshold = 0; // block first time
|
|
286
264
|
});
|
|
287
265
|
|
|
288
266
|
it('removes all occurances of uid in the request', function () {
|
|
289
|
-
const mainDoc =
|
|
267
|
+
const mainDoc = attrack.onBeforeRequest({
|
|
290
268
|
tabId: 34,
|
|
291
269
|
frameId: 0,
|
|
292
270
|
parentFrameId: -1,
|
|
@@ -298,7 +276,7 @@ describe('request/index', function () {
|
|
|
298
276
|
chai.expect(mainDoc).to.not.have.property('cancel');
|
|
299
277
|
chai.expect(mainDoc).to.not.have.property('redirectUrl');
|
|
300
278
|
chai.expect(mainDoc).to.not.have.property('requestHeaders');
|
|
301
|
-
const response =
|
|
279
|
+
const response = attrack.onBeforeRequest({
|
|
302
280
|
tabId: 34,
|
|
303
281
|
frameId: 0,
|
|
304
282
|
parentFrameId: -1,
|
|
@@ -317,7 +295,7 @@ describe('request/index', function () {
|
|
|
317
295
|
});
|
|
318
296
|
|
|
319
297
|
it('removes also after subsequent redirect with same uid', function () {
|
|
320
|
-
const mainDoc =
|
|
298
|
+
const mainDoc = attrack.onBeforeRequest({
|
|
321
299
|
tabId: 34,
|
|
322
300
|
frameId: 0,
|
|
323
301
|
parentFrameId: -1,
|
|
@@ -331,7 +309,7 @@ describe('request/index', function () {
|
|
|
331
309
|
chai.expect(mainDoc).to.not.have.property('cancel');
|
|
332
310
|
chai.expect(mainDoc).to.not.have.property('redirectUrl');
|
|
333
311
|
chai.expect(mainDoc).to.not.have.property('requestHeaders');
|
|
334
|
-
let response =
|
|
312
|
+
let response = attrack.onBeforeRequest({
|
|
335
313
|
tabId: 34,
|
|
336
314
|
frameId: 0,
|
|
337
315
|
parentFrameId: -1,
|
|
@@ -349,7 +327,7 @@ describe('request/index', function () {
|
|
|
349
327
|
chai.expect(response.redirectUrl).to.not.contain(uid);
|
|
350
328
|
chai.expect(response.redirectUrl).to.not.contain(encodeURIComponent(uid));
|
|
351
329
|
|
|
352
|
-
response =
|
|
330
|
+
response = attrack.onBeforeRequest({
|
|
353
331
|
tabId: 34,
|
|
354
332
|
frameId: 0,
|
|
355
333
|
parentFrameId: -1,
|
|
@@ -10,19 +10,22 @@
|
|
|
10
10
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import 'fake-indexeddb/auto';
|
|
14
|
-
import { IDBFactory } from 'fake-indexeddb';
|
|
15
13
|
import chrome from 'sinon-chrome';
|
|
16
14
|
import sinon from 'sinon';
|
|
17
15
|
import { expect } from 'chai';
|
|
18
16
|
import EventEmitter from 'node:events';
|
|
17
|
+
import { IDBFactory } from 'fake-indexeddb';
|
|
19
18
|
|
|
20
|
-
import {
|
|
21
|
-
|
|
19
|
+
import {
|
|
20
|
+
playScenario,
|
|
21
|
+
playSnapshotScenario,
|
|
22
|
+
recordSnapshot,
|
|
23
|
+
readSnapshot,
|
|
24
|
+
} from '../helpers/scenarios.js';
|
|
25
|
+
import { base64ToArrayBuffer } from '../helpers/fetch-mock.js';
|
|
22
26
|
|
|
23
|
-
import { setLogLevel } from '
|
|
24
|
-
import RequestReporter from '
|
|
25
|
-
import WebRequestPipeline from '../src/webrequest-pipeline/index.js';
|
|
27
|
+
import { setLogLevel } from '../../src/logger.js';
|
|
28
|
+
import RequestReporter from '../../src/request/index.js';
|
|
26
29
|
|
|
27
30
|
const config = {
|
|
28
31
|
configUrl: 'config',
|
|
@@ -59,7 +62,7 @@ describe('RequestReporter', function () {
|
|
|
59
62
|
async arrayBuffer() {
|
|
60
63
|
// empty bloom filter
|
|
61
64
|
return base64ToArrayBuffer('AAAAAgrdwUcnN1113w==');
|
|
62
|
-
}
|
|
65
|
+
},
|
|
63
66
|
});
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -70,6 +73,7 @@ describe('RequestReporter', function () {
|
|
|
70
73
|
beforeEach(function () {
|
|
71
74
|
chrome.flush();
|
|
72
75
|
chrome.storage.session.get.yields({});
|
|
76
|
+
chrome.tabs.query.returns([]);
|
|
73
77
|
});
|
|
74
78
|
|
|
75
79
|
after(function () {
|
|
@@ -98,29 +102,25 @@ describe('RequestReporter', function () {
|
|
|
98
102
|
communicationEmiter.removeAllListeners();
|
|
99
103
|
const communication = {
|
|
100
104
|
send(msg) {
|
|
101
|
-
communicationEmiter.emit('send', msg)
|
|
105
|
+
communicationEmiter.emit('send', msg);
|
|
102
106
|
},
|
|
103
107
|
sendInstant(msg) {
|
|
104
|
-
communicationEmiter.emit('sendInstant', msg)
|
|
108
|
+
communicationEmiter.emit('sendInstant', msg);
|
|
105
109
|
},
|
|
106
110
|
trustedClock,
|
|
107
111
|
};
|
|
108
|
-
const webRequestPipeline = new WebRequestPipeline();
|
|
109
|
-
await webRequestPipeline.init();
|
|
110
112
|
reporter = new RequestReporter(config, {
|
|
111
113
|
communication,
|
|
112
|
-
webRequestPipeline,
|
|
113
114
|
trustedClock,
|
|
114
115
|
getBrowserInfo: () => ({ name: 'xx' }),
|
|
115
116
|
countryProvider: { getSafeCountryCode: () => 'en' },
|
|
116
117
|
});
|
|
117
118
|
await reporter.init();
|
|
118
|
-
await reporter.
|
|
119
|
+
await reporter.qs_whitelist.initPromise;
|
|
119
120
|
});
|
|
120
121
|
|
|
121
122
|
afterEach(function () {
|
|
122
123
|
reporter.unload();
|
|
123
|
-
reporter.webRequestPipeline.unload();
|
|
124
124
|
reporter = undefined;
|
|
125
125
|
clock.restore();
|
|
126
126
|
delete globalThis.indexedDB;
|
|
@@ -134,11 +134,14 @@ describe('RequestReporter', function () {
|
|
|
134
134
|
});
|
|
135
135
|
await clock.runToLast();
|
|
136
136
|
expect(
|
|
137
|
-
reporter.
|
|
137
|
+
reporter.pageStore.checkIfEmpty(),
|
|
138
138
|
).to.be.false;
|
|
139
139
|
expect(seenTabIds).to.have.property('size', 1);
|
|
140
140
|
const tabId = seenTabIds.values().next().value;
|
|
141
|
-
const tab = reporter.
|
|
141
|
+
const tab = reporter.pageStore.getPageForRequest({
|
|
142
|
+
tabId,
|
|
143
|
+
frameId: 0,
|
|
144
|
+
});
|
|
142
145
|
expect(tab.requestStats).to.be.empty;
|
|
143
146
|
});
|
|
144
147
|
});
|
|
@@ -151,14 +154,15 @@ describe('RequestReporter', function () {
|
|
|
151
154
|
});
|
|
152
155
|
await clock.runToLast();
|
|
153
156
|
expect(
|
|
154
|
-
reporter.
|
|
157
|
+
reporter.pageStore.checkIfEmpty(),
|
|
155
158
|
).to.be.false;
|
|
156
159
|
expect(seenTabIds).to.have.property('size', 1);
|
|
157
160
|
const tabId = seenTabIds.values().next().value;
|
|
158
|
-
const tab = reporter.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
const tab = reporter.pageStore.getPageForRequest({
|
|
162
|
+
tabId,
|
|
163
|
+
frameId: 0,
|
|
164
|
+
});
|
|
165
|
+
expect(tab.requestStats).to.have.keys(['script.localhost']);
|
|
162
166
|
});
|
|
163
167
|
|
|
164
168
|
it('reports 3rd parties', async function () {
|
|
@@ -167,23 +171,25 @@ describe('RequestReporter', function () {
|
|
|
167
171
|
scenarioRelease: '2024-08-02',
|
|
168
172
|
});
|
|
169
173
|
await clock.runToLast();
|
|
170
|
-
const eventPromise = new Promise((resolve) =>
|
|
174
|
+
const eventPromise = new Promise((resolve) =>
|
|
175
|
+
communicationEmiter.once('send', resolve),
|
|
176
|
+
);
|
|
171
177
|
// force stage all pages
|
|
172
|
-
seenTabIds.forEach(tabId => chrome.tabs.onRemoved.dispatch(tabId));
|
|
178
|
+
seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
|
|
173
179
|
await clock.runToLast();
|
|
174
180
|
const event = await eventPromise;
|
|
175
181
|
expect(event).to.deep.include({
|
|
176
182
|
action: 'wtm.attrack.tp_events',
|
|
177
183
|
});
|
|
178
|
-
expect(event.payload.data[0].tps).to.have.keys([
|
|
179
|
-
'script.localhost',
|
|
180
|
-
])
|
|
184
|
+
expect(event.payload.data[0].tps).to.have.keys(['script.localhost']);
|
|
181
185
|
});
|
|
182
186
|
});
|
|
183
187
|
|
|
184
188
|
context('0004-ping', function () {
|
|
185
189
|
it('reports pings', async function () {
|
|
186
|
-
const eventPromise = new Promise((resolve) =>
|
|
190
|
+
const eventPromise = new Promise((resolve) =>
|
|
191
|
+
communicationEmiter.once('send', resolve),
|
|
192
|
+
);
|
|
187
193
|
await playScenario(chrome, {
|
|
188
194
|
scenarioName: this.test.parent.title,
|
|
189
195
|
scenarioRelease: '2024-08-02-1',
|
|
@@ -194,9 +200,7 @@ describe('RequestReporter', function () {
|
|
|
194
200
|
expect(event).to.deep.include({
|
|
195
201
|
action: 'wtm.attrack.tp_events',
|
|
196
202
|
});
|
|
197
|
-
expect(event.payload.data[0].tps).to.have.keys([
|
|
198
|
-
'ping.localhost',
|
|
199
|
-
])
|
|
203
|
+
expect(event.payload.data[0].tps).to.have.keys(['ping.localhost']);
|
|
200
204
|
});
|
|
201
205
|
});
|
|
202
206
|
|
|
@@ -207,23 +211,25 @@ describe('RequestReporter', function () {
|
|
|
207
211
|
scenarioRelease: '2024-08-02',
|
|
208
212
|
});
|
|
209
213
|
await clock.runToLast();
|
|
210
|
-
const eventPromise = new Promise((resolve) =>
|
|
214
|
+
const eventPromise = new Promise((resolve) =>
|
|
215
|
+
communicationEmiter.once('send', resolve),
|
|
216
|
+
);
|
|
211
217
|
// force stage all pages
|
|
212
|
-
seenTabIds.forEach(tabId => chrome.tabs.onRemoved.dispatch(tabId));
|
|
218
|
+
seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
|
|
213
219
|
await clock.runToLast();
|
|
214
220
|
const event = await eventPromise;
|
|
215
221
|
expect(event).to.deep.include({
|
|
216
222
|
action: 'wtm.attrack.tp_events',
|
|
217
223
|
});
|
|
218
|
-
expect(event.payload.data[0].tps).to.have.keys([
|
|
219
|
-
'preload.localhost',
|
|
220
|
-
]);
|
|
224
|
+
expect(event.payload.data[0].tps).to.have.keys(['preload.localhost']);
|
|
221
225
|
});
|
|
222
226
|
});
|
|
223
227
|
|
|
224
228
|
context('0008-navigation', function () {
|
|
225
229
|
it('reports 3rd parties', async function () {
|
|
226
|
-
const eventPromise1 = new Promise((resolve) =>
|
|
230
|
+
const eventPromise1 = new Promise((resolve) =>
|
|
231
|
+
communicationEmiter.once('send', resolve),
|
|
232
|
+
);
|
|
227
233
|
const { seenTabIds } = await playScenario(chrome, {
|
|
228
234
|
scenarioName: this.test.parent.title,
|
|
229
235
|
scenarioRelease: '2024-08-02-2',
|
|
@@ -233,23 +239,73 @@ describe('RequestReporter', function () {
|
|
|
233
239
|
expect(event1).to.deep.include({
|
|
234
240
|
action: 'wtm.attrack.tp_events',
|
|
235
241
|
});
|
|
236
|
-
expect(event1.payload.data[0].tps).to.have.keys([
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
242
|
+
expect(event1.payload.data[0].tps).to.have.keys(['script1.localhost']);
|
|
243
|
+
const eventPromise2 = new Promise((resolve) =>
|
|
244
|
+
communicationEmiter.once('send', resolve),
|
|
245
|
+
);
|
|
240
246
|
// force stage all pages
|
|
241
|
-
seenTabIds.forEach(tabId => chrome.tabs.onRemoved.dispatch(tabId));
|
|
247
|
+
seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
|
|
242
248
|
await clock.runToLast();
|
|
243
249
|
const event2 = await eventPromise2;
|
|
244
250
|
expect(event2).to.deep.include({
|
|
245
251
|
action: 'wtm.attrack.tp_events',
|
|
246
252
|
});
|
|
247
|
-
expect(event2.payload.data[0].tps).to.have.keys([
|
|
248
|
-
'script2.localhost',
|
|
249
|
-
]);
|
|
253
|
+
expect(event2.payload.data[0].tps).to.have.keys(['script2.localhost']);
|
|
250
254
|
// reports should belong to different pages
|
|
251
|
-
expect(event1.payload.data[0].hostname).to.not.be.equal(
|
|
255
|
+
expect(event1.payload.data[0].hostname).to.not.be.equal(
|
|
256
|
+
event2.payload.data[0].hostname,
|
|
257
|
+
);
|
|
252
258
|
});
|
|
253
259
|
});
|
|
260
|
+
|
|
261
|
+
context('snapshots', function () {
|
|
262
|
+
this.timeout(10000);
|
|
263
|
+
|
|
264
|
+
function cleanupMessage(message) {
|
|
265
|
+
delete message['anti-duplicates'];
|
|
266
|
+
return message;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function processRunloopUntil(timeout) {
|
|
270
|
+
const start = Date.now();
|
|
271
|
+
// eslint-disable-next-line no-constant-condition
|
|
272
|
+
while (true) {
|
|
273
|
+
const now = await clock.runToLast();
|
|
274
|
+
if (now - start > timeout) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
for (const snapshotName of ['0001', '0002', '0003', '0004']) {
|
|
281
|
+
it(snapshotName, async function () {
|
|
282
|
+
const messages = [];
|
|
283
|
+
communicationEmiter.addListener('send', (message) =>
|
|
284
|
+
messages.push(cleanupMessage(message)),
|
|
285
|
+
);
|
|
286
|
+
playSnapshotScenario(chrome, snapshotName);
|
|
287
|
+
|
|
288
|
+
// run twice to allow token telemetry to trigger
|
|
289
|
+
playSnapshotScenario(chrome, snapshotName, {
|
|
290
|
+
rewriteUrls: { 'onet.pl': 'wp.pl', 'soundcloud.com': 'google.com' },
|
|
291
|
+
});
|
|
292
|
+
await processRunloopUntil(
|
|
293
|
+
reporter.tokenTelemetry
|
|
294
|
+
.NEW_ENTRY_MIN_AGE,
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
// eslint-disable-next-line no-undef
|
|
298
|
+
if (process.argv.includes('--record-snapshot')) {
|
|
299
|
+
recordSnapshot(snapshotName, messages);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const snapshot = await readSnapshot(snapshotName);
|
|
303
|
+
expect(messages).to.have.lengthOf(snapshot.length);
|
|
304
|
+
messages.forEach((message, index) => {
|
|
305
|
+
expect(message).to.deep.equal(snapshot[index]);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
254
310
|
});
|
|
255
311
|
});
|
|
@@ -13,7 +13,7 @@ import chrome from 'sinon-chrome';
|
|
|
13
13
|
import { mock, match } from 'sinon';
|
|
14
14
|
import { expect } from 'chai';
|
|
15
15
|
|
|
16
|
-
import PageStore from '../../src/
|
|
16
|
+
import PageStore from '../../src/request/page-store.js';
|
|
17
17
|
|
|
18
18
|
describe('PageStore', function () {
|
|
19
19
|
before(function () {
|