@whotracksme/reporting 11.1.1 → 12.0.0
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 +17 -0
- package/package.json +1 -1
- package/reporting/README.md +13 -0
- package/reporting/example/README.md +4 -0
- package/reporting/example/e2e/README.md +263 -0
- package/reporting/example/e2e/console-capture.js +67 -0
- package/reporting/example/e2e/control.js +423 -0
- package/reporting/example/e2e/hub.mjs +380 -0
- package/reporting/example/e2e/launch.mjs +92 -0
- package/reporting/example/e2e/mock-extension.mjs +106 -0
- package/reporting/example/e2e/pages/private-fixture.html +16 -0
- package/reporting/example/e2e/run.mjs +187 -0
- package/reporting/example/e2e/scenarios/privacy-guards.json +26 -0
- package/reporting/example/e2e/scenarios/smoke.json +15 -0
- package/reporting/example/e2e/verify.mjs +159 -0
- package/reporting/example/index.js +55 -46
- package/reporting/example/manifests/chromium.json +1 -0
- package/reporting/example/storage.js +65 -0
- package/reporting/package.json +5 -1
- package/reporting/rollup.config.cjs +1 -1
- package/reporting/src/doublefetch-page-handler.js +24 -0
- package/reporting/src/doublefetch-unbreak.js +186 -0
- package/reporting/src/http.js +197 -19
- package/reporting/src/offscreen/doublefetch/capture.js +90 -0
- package/reporting/src/patterns.js +5 -2
- package/reporting/src/search-extractor.js +2 -0
- package/reporting/test/doublefetch-unbreak.spec.js +133 -0
- package/reporting/test/http.spec.js +113 -0
- package/reporting/test/index.js +1 -0
- package/reporting/test/patterns.spec.js +10 -0
|
@@ -0,0 +1,133 @@
|
|
|
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 { expect } from 'chai';
|
|
13
|
+
|
|
14
|
+
import { findSafeCookies } from '../src/doublefetch-unbreak.js';
|
|
15
|
+
|
|
16
|
+
const URL_ = 'https://www.example.test/search?q=foo';
|
|
17
|
+
|
|
18
|
+
describe('#findSafeCookies', function () {
|
|
19
|
+
let lookups;
|
|
20
|
+
let jar;
|
|
21
|
+
let originalCookies;
|
|
22
|
+
|
|
23
|
+
beforeEach(function () {
|
|
24
|
+
lookups = [];
|
|
25
|
+
jar = {};
|
|
26
|
+
originalCookies = chrome.cookies;
|
|
27
|
+
chrome.cookies = {
|
|
28
|
+
getAll: async (details) => {
|
|
29
|
+
lookups.push(details);
|
|
30
|
+
const value = jar[details.name];
|
|
31
|
+
return value === undefined ? [] : [{ name: details.name, value }];
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(function () {
|
|
37
|
+
chrome.cookies = originalCookies;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const collect = (template) =>
|
|
41
|
+
findSafeCookies(URL_, {
|
|
42
|
+
steps: [{ headers: { Cookie: template } }],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should not touch the cookie jar unless asked to', async function () {
|
|
46
|
+
const found = await collect('SOCS=fixed;X={{cookie:foo}}');
|
|
47
|
+
expect(found.size).to.eql(0);
|
|
48
|
+
expect(lookups).to.eql([]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should look up only what was asked for', async function () {
|
|
52
|
+
jar = { 'aws-waf-token': 'AWS', cf_clearance: 'CF' };
|
|
53
|
+
const found = await collect('t={{safecookie:aws-waf-token}}');
|
|
54
|
+
expect(lookups.map((x) => x.name)).to.eql(['aws-waf-token']);
|
|
55
|
+
expect(found.get('aws-waf-token')).to.eql('AWS');
|
|
56
|
+
expect(found.has('cf_clearance')).to.eql(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should refuse cookies that are not on the unbreaking list', async function () {
|
|
60
|
+
jar = { SID: 'secret', sessionid: 'secret' };
|
|
61
|
+
const found = await collect(
|
|
62
|
+
'a={{safecookie:SID}};b={{safecookie:sessionid}}',
|
|
63
|
+
);
|
|
64
|
+
expect(lookups).to.eql([]);
|
|
65
|
+
expect(found.size).to.eql(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should scope the lookup to the URL and to its own cookie store', async function () {
|
|
69
|
+
jar = { 'aws-waf-token': 'AWS' };
|
|
70
|
+
await collect('t={{safecookie:aws-waf-token}}');
|
|
71
|
+
expect(lookups).to.have.length(1);
|
|
72
|
+
expect(lookups[0].url).to.eql(URL_);
|
|
73
|
+
// no "storeId" means the extension's own store: not incognito, no container
|
|
74
|
+
expect(lookups[0]).to.not.have.property('storeId');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should skip a cookie that is not set, or that cannot be read', async function () {
|
|
78
|
+
const ask = () => collect('t={{safecookie:aws-waf-token}}');
|
|
79
|
+
expect((await ask()).size).to.eql(0);
|
|
80
|
+
|
|
81
|
+
chrome.cookies.getAll = async () => {
|
|
82
|
+
throw new Error('no permission');
|
|
83
|
+
};
|
|
84
|
+
expect((await ask()).size).to.eql(0);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should collect from the shared headers, every step and the rescue config', async function () {
|
|
88
|
+
jar = { 'aws-waf-token': 'AWS', cf_clearance: 'CF', __cf_bm: 'BM' };
|
|
89
|
+
const found = await findSafeCookies(URL_, {
|
|
90
|
+
headers: { Cookie: 'a={{safecookie:aws-waf-token}}' },
|
|
91
|
+
steps: [{}, { headers: { Cookie: 'b={{safecookie:cf_clearance}}' } }],
|
|
92
|
+
onError: { headers: { Cookie: 'c={{safecookie:__cf_bm}}' } },
|
|
93
|
+
});
|
|
94
|
+
expect([...found.keys()].sort()).to.eql([
|
|
95
|
+
'__cf_bm',
|
|
96
|
+
'aws-waf-token',
|
|
97
|
+
'cf_clearance',
|
|
98
|
+
]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should collect a cookie that a step only "requires"', async function () {
|
|
102
|
+
jar = { 'aws-waf-token': 'AWS' };
|
|
103
|
+
const found = await findSafeCookies(URL_, {
|
|
104
|
+
steps: [{ requires: ['{{safecookie:aws-waf-token}}'] }],
|
|
105
|
+
});
|
|
106
|
+
expect(found.get('aws-waf-token')).to.eql('AWS');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should refuse untrusted cookies in "requires" entries', async function () {
|
|
110
|
+
jar = { sessionid: 'secret' };
|
|
111
|
+
const found = await findSafeCookies(URL_, {
|
|
112
|
+
steps: [{ requires: ['{{safecookie:sessionid}}'] }],
|
|
113
|
+
});
|
|
114
|
+
expect(lookups).to.eql([]);
|
|
115
|
+
expect(found.size).to.eql(0);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should collect from "requires" inside the rescue config', async function () {
|
|
119
|
+
jar = { cf_clearance: 'CF' };
|
|
120
|
+
const found = await findSafeCookies(URL_, {
|
|
121
|
+
onError: { steps: [{ requires: ['{{safecookie:cf_clearance}}'] }] },
|
|
122
|
+
});
|
|
123
|
+
expect(found.get('cf_clearance')).to.eql('CF');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should support alternatives ("||")', async function () {
|
|
127
|
+
jar = { cf_clearance: 'CF' };
|
|
128
|
+
const found = await collect(
|
|
129
|
+
'x={{cookie:missing||safecookie:cf_clearance}}',
|
|
130
|
+
);
|
|
131
|
+
expect(found.get('cf_clearance')).to.eql('CF');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -117,6 +117,32 @@ describe('#replacePlaceholders', function () {
|
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
describe('#replacePlaceholders with borrowed cookies', function () {
|
|
121
|
+
const ctx = {
|
|
122
|
+
cookie: new Map(),
|
|
123
|
+
safecookie: new Map([['aws-waf-token', 'the-token']]),
|
|
124
|
+
};
|
|
125
|
+
const resolve = (template) => replacePlaceholders({ C: template }, ctx).C;
|
|
126
|
+
|
|
127
|
+
it('should resolve a borrowed cookie', function () {
|
|
128
|
+
expect(resolve('t={{safecookie:aws-waf-token}}')).to.eql('t=the-token');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should be empty if the cookie was not borrowed', function () {
|
|
132
|
+
expect(resolve('{{safecookie:cf_clearance}}')).to.eql('');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should take part in "||" alternatives', function () {
|
|
136
|
+
expect(resolve('{{cookie:absent||safecookie:aws-waf-token}}')).to.eql(
|
|
137
|
+
'the-token',
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should still reject an unsupported placeholder type', function () {
|
|
142
|
+
expect(() => resolve('{{cookies:x}}')).to.throw(/Unsupported expression/);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
120
146
|
describe('#findPlaceholders', function () {
|
|
121
147
|
it('should work with empty strings', function () {
|
|
122
148
|
expect(findPlaceholders('')).to.eql([]);
|
|
@@ -155,6 +181,93 @@ describe('#findPlaceholders', function () {
|
|
|
155
181
|
});
|
|
156
182
|
});
|
|
157
183
|
|
|
184
|
+
describe('#buildDependencyGraph with a prefilled context', function () {
|
|
185
|
+
const borrowed = { safecookie: new Map([['aws-waf-token', 'the-token']]) };
|
|
186
|
+
const nextStep = { headers: { Cookie: 't={{safecookie:aws-waf-token}}' } };
|
|
187
|
+
|
|
188
|
+
it('should not wait for a borrowed cookie', function () {
|
|
189
|
+
expect(buildDependencyGraph(nextStep, borrowed).allReady).to.eql(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should not wait for a value that an earlier step captured', function () {
|
|
193
|
+
const ctx = { cookie: new Map([['FOO', 'captured by an earlier step']]) };
|
|
194
|
+
expect(
|
|
195
|
+
buildDependencyGraph({ headers: { Cookie: '{{cookie:FOO}}' } }, ctx)
|
|
196
|
+
.allReady,
|
|
197
|
+
).to.eql(true);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('should not wait for a borrowed cookie that is absent', function () {
|
|
201
|
+
// it is fixed before the first request, so it will never arrive
|
|
202
|
+
expect(
|
|
203
|
+
buildDependencyGraph(nextStep, { safecookie: new Map() }).allReady,
|
|
204
|
+
).to.eql(true);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('should still wait if another source could provide it', function () {
|
|
208
|
+
const graph = buildDependencyGraph(
|
|
209
|
+
{ headers: { Cookie: 'x={{safecookie:absent||cookie:FOO}}' } },
|
|
210
|
+
{ safecookie: new Map() },
|
|
211
|
+
);
|
|
212
|
+
expect(graph.allReady).to.eql(false);
|
|
213
|
+
|
|
214
|
+
graph.onChange('cookie', 'FOO', 'arrived with the response');
|
|
215
|
+
expect(graph.allReady).to.eql(true);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('should still wait for the parts that are missing', function () {
|
|
219
|
+
const graph = buildDependencyGraph(
|
|
220
|
+
{
|
|
221
|
+
headers: {
|
|
222
|
+
Cookie: 't={{safecookie:aws-waf-token}};S={{param:from-response}}',
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
borrowed,
|
|
226
|
+
);
|
|
227
|
+
expect(graph.allReady).to.eql(false);
|
|
228
|
+
|
|
229
|
+
let onReadyCalled = 0;
|
|
230
|
+
graph.onReady = () => {
|
|
231
|
+
onReadyCalled += 1;
|
|
232
|
+
};
|
|
233
|
+
graph.onChange('param', 'from-response', 'dummy value');
|
|
234
|
+
expect(onReadyCalled).to.eql(1);
|
|
235
|
+
expect(graph.allReady).to.eql(true);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe('#buildDependencyGraph with "requires"', function () {
|
|
240
|
+
const noCookies = { safecookie: new Map() };
|
|
241
|
+
|
|
242
|
+
it('should wait for a required value that no header uses', function () {
|
|
243
|
+
const graph = buildDependencyGraph(
|
|
244
|
+
{ requires: ['{{param:from-response}}'], headers: { Cookie: 'x=1' } },
|
|
245
|
+
noCookies,
|
|
246
|
+
);
|
|
247
|
+
expect(graph.allReady).to.eql(false);
|
|
248
|
+
|
|
249
|
+
graph.onChange('param', 'from-response', 'arrived with the second request');
|
|
250
|
+
expect(graph.allReady).to.eql(true);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('should wait even if the step has no headers at all', function () {
|
|
254
|
+
expect(
|
|
255
|
+
buildDependencyGraph({ requires: ['{{param:never-seen}}'] }, noCookies)
|
|
256
|
+
.allReady,
|
|
257
|
+
).to.eql(false);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should not wait for a required borrowed cookie that is absent', function () {
|
|
261
|
+
// it can never arrive, so the step runs and fails on its own check
|
|
262
|
+
expect(
|
|
263
|
+
buildDependencyGraph(
|
|
264
|
+
{ requires: ['{{safecookie:cf_clearance}}'] },
|
|
265
|
+
noCookies,
|
|
266
|
+
).allReady,
|
|
267
|
+
).to.eql(true);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
158
271
|
describe('#buildDependencyGraph', function () {
|
|
159
272
|
it('should be immediately ready if there is no next step', function () {
|
|
160
273
|
expect(buildDependencyGraph(undefined).allReady).to.eql(true);
|
package/reporting/test/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import './patterns-updater.spec.js';
|
|
|
10
10
|
import './job-scheduler.spec.js';
|
|
11
11
|
import './country-provider.spec.js';
|
|
12
12
|
import './persisted-hashes.spec.js';
|
|
13
|
+
import './doublefetch-unbreak.spec.js';
|
|
13
14
|
import './url-analyzer.spec.js';
|
|
14
15
|
import './alive-check.spec.js';
|
|
15
16
|
import './alive-message-generator.spec.js';
|
|
@@ -1028,6 +1028,16 @@ describe('Patterns', function () {
|
|
|
1028
1028
|
});
|
|
1029
1029
|
});
|
|
1030
1030
|
|
|
1031
|
+
it('the render configuration of a dynamic step', function () {
|
|
1032
|
+
shouldForward({
|
|
1033
|
+
steps: [{ dynamic: true, waitFor: ['#results'], delay: 1000 }],
|
|
1034
|
+
});
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
it('timeout', function () {
|
|
1038
|
+
shouldForward({ timeout: 20000 });
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1031
1041
|
it('emptyHtml', function () {
|
|
1032
1042
|
shouldForward({ emptyHtml: true });
|
|
1033
1043
|
shouldForward({ emptyHtml: false });
|