@whotracksme/reporting 5.1.29 → 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 +25 -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/snapshot.json +1 -1
- package/reporting/snapshots/0002/snapshot.json +2 -2
- 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 +445 -494
- 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 +52 -68
- package/reporting/src/request/steps/token-telemetry/index.js +86 -113
- 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 +1 -1
- package/reporting/test/index.js +3 -8
- package/reporting/test/request/{hash.spec.js → hash/index.spec.js} +2 -2
- package/reporting/test/request/index.spec.js +23 -46
- package/reporting/test/{request-reporter.test.js → request/index.test.js} +13 -17
- 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/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
|
@@ -1,222 +0,0 @@
|
|
|
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 * as chai from 'chai';
|
|
13
|
-
import sinon from 'sinon';
|
|
14
|
-
|
|
15
|
-
import { Pacemaker } from '../../src/utils/pacemaker';
|
|
16
|
-
|
|
17
|
-
const expect = chai.expect;
|
|
18
|
-
|
|
19
|
-
describe('core/services/pacemaker', function () {
|
|
20
|
-
describe('#pacemaker', () => {
|
|
21
|
-
let clock;
|
|
22
|
-
let pacemaker;
|
|
23
|
-
|
|
24
|
-
beforeEach(function () {
|
|
25
|
-
clock = sinon.useFakeTimers();
|
|
26
|
-
pacemaker = new Pacemaker();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(function () {
|
|
30
|
-
pacemaker.stop();
|
|
31
|
-
clock.restore();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('no timer when no task registered', () => {
|
|
35
|
-
expect(pacemaker.freq).to.be.null;
|
|
36
|
-
expect(pacemaker.timer).to.be.null;
|
|
37
|
-
expect(pacemaker.tasks.size).to.equal(0);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('adds one task', async () => {
|
|
41
|
-
const spy = sinon.spy(function callback() {});
|
|
42
|
-
pacemaker.register(spy, { timeout: 10 });
|
|
43
|
-
|
|
44
|
-
// Check state of pacemaker
|
|
45
|
-
expect(pacemaker.freq).to.equal(10);
|
|
46
|
-
expect(pacemaker.timer).not.to.be.null;
|
|
47
|
-
expect(pacemaker.tasks.size).to.equal(1);
|
|
48
|
-
expect(spy).not.to.have.been.called;
|
|
49
|
-
|
|
50
|
-
// Check state of task
|
|
51
|
-
const task = pacemaker.tasks.values().next().value;
|
|
52
|
-
expect(task.args).to.have.length(0);
|
|
53
|
-
expect(task.name).to.equal('callback');
|
|
54
|
-
expect(task.timeout).to.equal(10);
|
|
55
|
-
expect(task.once).to.be.false;
|
|
56
|
-
|
|
57
|
-
// Make sure spy was not called after tick
|
|
58
|
-
expect(spy).not.to.have.been.called;
|
|
59
|
-
|
|
60
|
-
// Run all timers and expect task to have been called
|
|
61
|
-
clock.next();
|
|
62
|
-
expect(spy).to.have.been.called;
|
|
63
|
-
|
|
64
|
-
// Run again and task should be called twice
|
|
65
|
-
clock.next();
|
|
66
|
-
expect(spy).to.have.been.calledTwice;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('adds two tasks + a timeout', async () => {
|
|
70
|
-
const tickSpy = sinon.spy(pacemaker, '_tick');
|
|
71
|
-
const adjustSpy = sinon.spy(pacemaker, '_adjustFrequency');
|
|
72
|
-
|
|
73
|
-
const spy1 = sinon.spy(function callback1() {});
|
|
74
|
-
pacemaker.register(spy1, { timeout: 20 });
|
|
75
|
-
expect(tickSpy).not.to.have.been.called;
|
|
76
|
-
expect(adjustSpy).to.have.been.calledOnce;
|
|
77
|
-
|
|
78
|
-
const spy2 = sinon.spy(function callback2() {});
|
|
79
|
-
pacemaker.register(spy2, { timeout: 10 });
|
|
80
|
-
expect(tickSpy).not.to.have.been.called;
|
|
81
|
-
expect(adjustSpy).to.have.been.calledTwice;
|
|
82
|
-
|
|
83
|
-
const spy3 = sinon.spy(function callback3() {});
|
|
84
|
-
const timeout = pacemaker.setTimeout(spy3, 30);
|
|
85
|
-
expect(tickSpy).not.to.have.been.called;
|
|
86
|
-
expect(adjustSpy).to.have.been.calledThrice;
|
|
87
|
-
|
|
88
|
-
// None of the tasks was triggered at this point
|
|
89
|
-
expect(spy1).not.to.have.been.called;
|
|
90
|
-
expect(spy2).not.to.have.been.called;
|
|
91
|
-
expect(spy3).not.to.have.been.called;
|
|
92
|
-
|
|
93
|
-
// Tick should call task2 but none of the others
|
|
94
|
-
clock.next();
|
|
95
|
-
expect(spy1).not.to.have.been.called; // tick=10 -> not triggered
|
|
96
|
-
expect(spy2).to.have.been.calledOnce; // tick=10 -> triggered
|
|
97
|
-
expect(spy3).not.to.have.been.called; // tick=10 -> not triggered
|
|
98
|
-
|
|
99
|
-
// Tick should call task1 + task2 but not task3 (yet)
|
|
100
|
-
clock.next();
|
|
101
|
-
expect(spy1).to.have.been.calledOnce; // tick=20 -> triggered
|
|
102
|
-
expect(spy2).to.have.been.calledTwice; // tick=20 -> triggered
|
|
103
|
-
expect(spy3).not.to.have.been.called; // tick=20 -> not triggered
|
|
104
|
-
|
|
105
|
-
// Tick should call task1 + task2 + task3
|
|
106
|
-
clock.next();
|
|
107
|
-
expect(spy1).to.have.been.calledOnce; // tick=30 -> not triggered
|
|
108
|
-
expect(spy2).to.have.been.calledThrice; // tick=30 -> triggered
|
|
109
|
-
expect(spy3).to.have.been.calledOnce; // tick=30 -> triggered
|
|
110
|
-
|
|
111
|
-
// At this point the setTimeout should have been removed
|
|
112
|
-
expect(pacemaker.tasks).not.to.include(timeout);
|
|
113
|
-
expect(pacemaker.tasks.size).to.equal(2);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('stops when no task', async () => {
|
|
117
|
-
// Initialize pacemaker with one setTimeout
|
|
118
|
-
const spy = sinon.spy(function callback() {});
|
|
119
|
-
pacemaker.setTimeout(spy, 30);
|
|
120
|
-
expect(pacemaker.tasks.size).to.equal(1);
|
|
121
|
-
|
|
122
|
-
// Call timeout
|
|
123
|
-
clock.next();
|
|
124
|
-
expect(spy).to.have.been.calledOnce;
|
|
125
|
-
|
|
126
|
-
// Make sure pacemaker stopped
|
|
127
|
-
expect(pacemaker.timer).to.be.null;
|
|
128
|
-
expect(pacemaker.freq).to.be.null;
|
|
129
|
-
expect(pacemaker.tasks.size).to.equal(0);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('adjusts frequency', async () => {
|
|
133
|
-
const tickSpy = sinon.spy(pacemaker, '_tick');
|
|
134
|
-
const adjustSpy = sinon.spy(pacemaker, '_adjustFrequency');
|
|
135
|
-
|
|
136
|
-
// Initial state, no freq and no timer
|
|
137
|
-
expect(pacemaker.freq).to.be.null;
|
|
138
|
-
expect(pacemaker.timer).to.be.null;
|
|
139
|
-
|
|
140
|
-
// Add one task with timeout 0
|
|
141
|
-
pacemaker.setTimeout(function callback() {}, 0);
|
|
142
|
-
expect(pacemaker.freq).to.equal(0);
|
|
143
|
-
expect(pacemaker.timer).not.to.be.null;
|
|
144
|
-
expect(adjustSpy).to.have.been.calledOnce;
|
|
145
|
-
expect(tickSpy).not.to.have.been.called;
|
|
146
|
-
|
|
147
|
-
// Trigger task
|
|
148
|
-
clock.next();
|
|
149
|
-
expect(tickSpy).to.have.been.calledOnce;
|
|
150
|
-
|
|
151
|
-
// Expect pacemaker to have stopped
|
|
152
|
-
expect(pacemaker.timer).to.be.null;
|
|
153
|
-
expect(pacemaker.freq).to.be.null;
|
|
154
|
-
expect(pacemaker.tasks.size).to.equal(0);
|
|
155
|
-
|
|
156
|
-
// Make sure freq is adjusted properly
|
|
157
|
-
const t1 = pacemaker.setTimeout(function callback() {}, 30);
|
|
158
|
-
expect(pacemaker.freq).to.equal(30);
|
|
159
|
-
|
|
160
|
-
const t2 = pacemaker.register(function callback() {}, { timeout: 29 });
|
|
161
|
-
expect(pacemaker.freq).to.equal(29);
|
|
162
|
-
|
|
163
|
-
const t3 = pacemaker.register(function callback() {}, { timeout: 31 });
|
|
164
|
-
expect(pacemaker.freq).to.equal(29);
|
|
165
|
-
|
|
166
|
-
const t4 = pacemaker.register(function callback() {}, { timeout: 32 });
|
|
167
|
-
expect(pacemaker.freq).to.equal(29);
|
|
168
|
-
|
|
169
|
-
t4.stop();
|
|
170
|
-
expect(pacemaker.freq).to.equal(29);
|
|
171
|
-
|
|
172
|
-
t2.stop();
|
|
173
|
-
expect(pacemaker.freq).to.equal(30);
|
|
174
|
-
|
|
175
|
-
t1.stop();
|
|
176
|
-
expect(pacemaker.freq).to.equal(31);
|
|
177
|
-
|
|
178
|
-
t3.stop();
|
|
179
|
-
expect(pacemaker.freq).to.be.null;
|
|
180
|
-
expect(pacemaker.timer).to.be.null;
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('adds instant task', async () => {
|
|
184
|
-
clock.tick(1);
|
|
185
|
-
const spy = sinon.spy(function callback() {});
|
|
186
|
-
pacemaker.register(spy, { timeout: 5, startImmediately: true });
|
|
187
|
-
|
|
188
|
-
// Trigger first on next tick (start immediately)
|
|
189
|
-
clock.next();
|
|
190
|
-
expect(spy).to.have.been.calledOnce;
|
|
191
|
-
expect(pacemaker.tasks.values().next().value.last).to.equal(1);
|
|
192
|
-
|
|
193
|
-
// Trigger next after `timeout` milliseconds
|
|
194
|
-
clock.next();
|
|
195
|
-
expect(spy).to.have.been.calledTwice;
|
|
196
|
-
expect(pacemaker.tasks.values().next().value.last).to.equal(6);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('throwing task does not stop pacemaker', () => {
|
|
200
|
-
const spy = sinon.spy(function callback() {
|
|
201
|
-
throw new Error('boom');
|
|
202
|
-
});
|
|
203
|
-
const task = pacemaker.register(spy, { timeout: 1 });
|
|
204
|
-
|
|
205
|
-
expect(spy).not.to.have.been.called;
|
|
206
|
-
|
|
207
|
-
clock.next();
|
|
208
|
-
expect(spy).to.have.been.calledOnce;
|
|
209
|
-
expect(spy).to.have.thrown;
|
|
210
|
-
|
|
211
|
-
clock.next();
|
|
212
|
-
expect(spy).to.have.been.calledTwice;
|
|
213
|
-
expect(spy).to.have.thrown;
|
|
214
|
-
|
|
215
|
-
clock.next();
|
|
216
|
-
expect(spy).to.have.been.calledThrice;
|
|
217
|
-
expect(spy).to.have.thrown;
|
|
218
|
-
|
|
219
|
-
task.stop();
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WhoTracks.Me
|
|
3
|
-
* https://ghostery.com/whotracksme
|
|
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 chrome from 'sinon-chrome';
|
|
13
|
-
import { expect } from 'chai';
|
|
14
|
-
|
|
15
|
-
import { playScenario } from '../helpers/scenarios.js';
|
|
16
|
-
|
|
17
|
-
import WebRequestPipeline from '../../src/webrequest-pipeline/index.js';
|
|
18
|
-
|
|
19
|
-
describe('WebRequestPipeline', function () {
|
|
20
|
-
before(function () {
|
|
21
|
-
chrome.storage.session = chrome.storage.local;
|
|
22
|
-
globalThis.chrome = chrome;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
beforeEach(function () {
|
|
26
|
-
chrome.flush();
|
|
27
|
-
chrome.storage.session.get.yields({});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
after(function () {
|
|
31
|
-
chrome.flush();
|
|
32
|
-
delete globalThis.chrome;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
context('PageStore', function () {
|
|
36
|
-
it('starts empty', function () {
|
|
37
|
-
const pipeline = new WebRequestPipeline();
|
|
38
|
-
pipeline.init();
|
|
39
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.true;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
context('on webRequest.onBeforeRequest', function () {
|
|
43
|
-
it('creates a page', function () {
|
|
44
|
-
const pipeline = new WebRequestPipeline();
|
|
45
|
-
pipeline.init();
|
|
46
|
-
pipeline.addPipelineStep('onBeforeRequest', {
|
|
47
|
-
name: 'test',
|
|
48
|
-
spec: 'annotate',
|
|
49
|
-
fn: () => {},
|
|
50
|
-
});
|
|
51
|
-
const details = {
|
|
52
|
-
tabId: 1,
|
|
53
|
-
frameId: 0,
|
|
54
|
-
url: 'https://example.com',
|
|
55
|
-
type: 'main_frame',
|
|
56
|
-
};
|
|
57
|
-
chrome.webRequest.onBeforeRequest.dispatch(details);
|
|
58
|
-
const tab = pipeline.pageStore.getPageForRequest(details);
|
|
59
|
-
expect(tab).to.deep.include({
|
|
60
|
-
url: details.url,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
context('with pre-recorded events', function () {
|
|
66
|
-
let pipeline;
|
|
67
|
-
|
|
68
|
-
beforeEach(function () {
|
|
69
|
-
pipeline = new WebRequestPipeline();
|
|
70
|
-
pipeline.init();
|
|
71
|
-
[
|
|
72
|
-
'onBeforeRequest',
|
|
73
|
-
'onBeforeSendHeaders',
|
|
74
|
-
'onHeadersReceived',
|
|
75
|
-
'onAuthRequired',
|
|
76
|
-
'onBeforeRedirect',
|
|
77
|
-
'onCompleted',
|
|
78
|
-
'onErrorOccurred',
|
|
79
|
-
].forEach((step) => {
|
|
80
|
-
pipeline.addPipelineStep(step, {
|
|
81
|
-
name: 'test',
|
|
82
|
-
spec: 'annotate',
|
|
83
|
-
fn: () => {},
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
afterEach(function () {
|
|
89
|
-
pipeline.unload();
|
|
90
|
-
pipeline = undefined;
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
context('0001-quick-close', function () {
|
|
94
|
-
it('runs without a crash', async function () {
|
|
95
|
-
const { seenTabIds } = await playScenario(chrome, {
|
|
96
|
-
scenarioName: '0001-quick-close',
|
|
97
|
-
scenarioRelease: '2024-09-27',
|
|
98
|
-
});
|
|
99
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.false;
|
|
100
|
-
expect(seenTabIds).to.have.property('size', 1);
|
|
101
|
-
const tabId = seenTabIds.values().next().value;
|
|
102
|
-
const tab = pipeline.pageStore.getPageForRequest({
|
|
103
|
-
tabId,
|
|
104
|
-
frameId: 0,
|
|
105
|
-
});
|
|
106
|
-
expect(tab).to.deep.include({
|
|
107
|
-
url: 'https://ghosterysearch.com/',
|
|
108
|
-
});
|
|
109
|
-
expect(tab.previous).to.deep.include({
|
|
110
|
-
url: 'about:blank',
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
context('0002-quick-navigation', function () {
|
|
116
|
-
it('runs without a crash', async function () {
|
|
117
|
-
const { seenTabIds } = await playScenario(chrome, {
|
|
118
|
-
scenarioName: '0002-quick-navigation',
|
|
119
|
-
scenarioRelease: '2024-09-27',
|
|
120
|
-
});
|
|
121
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.false;
|
|
122
|
-
expect(seenTabIds).to.have.property('size', 1);
|
|
123
|
-
const tabId = seenTabIds.values().next().value;
|
|
124
|
-
const tab = pipeline.pageStore.getPageForRequest({
|
|
125
|
-
tabId,
|
|
126
|
-
frameId: 0,
|
|
127
|
-
});
|
|
128
|
-
expect(tab).to.deep.include({
|
|
129
|
-
url: 'https://www.facebook.com/login/?next=https%3A%2F%2Fwww.facebook.com%2F',
|
|
130
|
-
});
|
|
131
|
-
expect(tab.previous).to.deep.include({
|
|
132
|
-
url: 'https://ghosterysearch.com/',
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
context('0003-prefetch', function () {
|
|
138
|
-
it('runs without a crash', async function () {
|
|
139
|
-
const { seenTabIds } = await playScenario(chrome, {
|
|
140
|
-
scenarioName: '0003-prefetch',
|
|
141
|
-
scenarioRelease: '2024-09-27',
|
|
142
|
-
});
|
|
143
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.false;
|
|
144
|
-
expect(seenTabIds).to.have.property('size', 1);
|
|
145
|
-
const tabId = seenTabIds.values().next().value;
|
|
146
|
-
const tab = pipeline.pageStore.getPageForRequest({
|
|
147
|
-
tabId,
|
|
148
|
-
frameId: 0,
|
|
149
|
-
});
|
|
150
|
-
expect(tab).to.deep.include({
|
|
151
|
-
url: 'http://localhost:8080/',
|
|
152
|
-
});
|
|
153
|
-
expect(tab.previous).to.deep.include({
|
|
154
|
-
url: 'about:blank',
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
@@ -1,251 +0,0 @@
|
|
|
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
|
-
/* eslint no-param-reassign: off */
|
|
13
|
-
|
|
14
|
-
import * as chai from 'chai';
|
|
15
|
-
import chrome from 'sinon-chrome';
|
|
16
|
-
|
|
17
|
-
import Pipeline from '../../src/webrequest-pipeline/pipeline';
|
|
18
|
-
|
|
19
|
-
describe('webrequest-pipeline/pipeline', function () {
|
|
20
|
-
let oldWindowChrome;
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
oldWindowChrome = window.chrome;
|
|
24
|
-
window.chrome = chrome;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
window.chrome = oldWindowChrome;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('constructor', () => {
|
|
32
|
-
it('creates an empty pipeline', () => {
|
|
33
|
-
const p = new Pipeline('name');
|
|
34
|
-
chai.expect(p.pipeline).to.have.length(0);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('#addPipelineStep', () => {
|
|
39
|
-
let p;
|
|
40
|
-
|
|
41
|
-
beforeEach(function () {
|
|
42
|
-
p = new Pipeline('name');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('adds a step to the pipeline', () => {
|
|
46
|
-
const step = { name: 'test', spec: 'blocking', fn: () => true };
|
|
47
|
-
p.addPipelineStep(step);
|
|
48
|
-
chai.expect(p.pipeline).to.eql([step]);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('adds to stage to the end of the pipeline', () => {
|
|
52
|
-
const step1 = { name: 'part1', spec: 'blocking', fn: () => true };
|
|
53
|
-
const step2 = { name: 'part2', spec: 'blocking', fn: () => true };
|
|
54
|
-
p.addAll([step1, step2]);
|
|
55
|
-
chai.expect(p.pipeline).to.eql([step1, step2]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('throws an Error if function with the same name as already been added', () => {
|
|
59
|
-
p.addPipelineStep({ name: 'part1', spec: 'blocking', fn: () => true });
|
|
60
|
-
chai
|
|
61
|
-
.expect(
|
|
62
|
-
p.addPipelineStep.bind(p, {
|
|
63
|
-
name: 'part1',
|
|
64
|
-
spec: 'blocking',
|
|
65
|
-
fn: () => false,
|
|
66
|
-
}),
|
|
67
|
-
)
|
|
68
|
-
.to.throw(Error);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
context('before option', () => {
|
|
72
|
-
it('inserts the step before the named steps', () => {
|
|
73
|
-
const step1 = { name: 'part1', spec: 'blocking', fn: () => true };
|
|
74
|
-
const step2 = {
|
|
75
|
-
name: 'part2',
|
|
76
|
-
spec: 'blocking',
|
|
77
|
-
fn: () => true,
|
|
78
|
-
before: ['part3'],
|
|
79
|
-
};
|
|
80
|
-
const step3 = { name: 'part3', spec: 'blocking', fn: () => true };
|
|
81
|
-
p.addAll([step1, step3, step2]);
|
|
82
|
-
chai.expect(p.pipeline).to.eql([step1, step2, step3]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('does not an Error if before dependencies do not exist', () => {
|
|
86
|
-
const step1 = { name: 'part1', spec: 'blocking', fn: () => true };
|
|
87
|
-
const step2 = {
|
|
88
|
-
name: 'part2',
|
|
89
|
-
spec: 'blocking',
|
|
90
|
-
fn: () => true,
|
|
91
|
-
before: ['part3'],
|
|
92
|
-
};
|
|
93
|
-
p.addAll([step1, step2]);
|
|
94
|
-
chai.expect(p.pipeline).to.eql([step1, step2]);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
context('after option', () => {
|
|
99
|
-
it('inserts the step after the named steps', () => {
|
|
100
|
-
const step1 = { name: 'part1', spec: 'blocking', fn: () => true };
|
|
101
|
-
const step2 = {
|
|
102
|
-
name: 'part2',
|
|
103
|
-
spec: 'blocking',
|
|
104
|
-
fn: () => true,
|
|
105
|
-
after: ['part1'],
|
|
106
|
-
};
|
|
107
|
-
const step3 = { name: 'part3', spec: 'blocking', fn: () => true };
|
|
108
|
-
const step4 = { name: 'part4', spec: 'blocking', fn: () => true };
|
|
109
|
-
p.addAll([step1, step3, step4, step2]);
|
|
110
|
-
|
|
111
|
-
chai.expect(p.pipeline).to.eql([step1, step2, step3, step4]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('inserts the step in last position', () => {
|
|
115
|
-
const step1 = { name: 'part1', spec: 'blocking', fn: () => true };
|
|
116
|
-
const step2 = { name: 'part2', spec: 'blocking', fn: () => true };
|
|
117
|
-
const step3 = {
|
|
118
|
-
name: 'part3',
|
|
119
|
-
spec: 'blocking',
|
|
120
|
-
fn: () => true,
|
|
121
|
-
after: ['part2'],
|
|
122
|
-
};
|
|
123
|
-
p.addAll([step1, step2, step3]);
|
|
124
|
-
|
|
125
|
-
chai.expect(p.pipeline).to.eql([step1, step2, step3]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('throws an Error if after dependencies do not exist', () => {
|
|
129
|
-
p.addPipelineStep({ name: 'part1', spec: 'blocking', fn: () => true });
|
|
130
|
-
chai
|
|
131
|
-
.expect(
|
|
132
|
-
p.addPipelineStep.bind(p, {
|
|
133
|
-
name: 'part2',
|
|
134
|
-
spec: 'blocking',
|
|
135
|
-
fn: () => true,
|
|
136
|
-
after: ['part3'],
|
|
137
|
-
}),
|
|
138
|
-
)
|
|
139
|
-
.to.throw(Error);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
context('before and after options', () => {
|
|
144
|
-
it('throws an Error if both are specified', () => {
|
|
145
|
-
p.addPipelineStep({ name: 'part1', spec: 'blocking', fn: () => true });
|
|
146
|
-
p.addPipelineStep({ name: 'part3', spec: 'blocking', fn: () => true });
|
|
147
|
-
|
|
148
|
-
chai
|
|
149
|
-
.expect(
|
|
150
|
-
p.addPipelineStep.bind(p, {
|
|
151
|
-
name: 'part2',
|
|
152
|
-
spec: 'blocking',
|
|
153
|
-
fn: () => true,
|
|
154
|
-
after: ['part1'],
|
|
155
|
-
before: ['part3'],
|
|
156
|
-
}),
|
|
157
|
-
)
|
|
158
|
-
.to.throw(Error);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe('#execute', () => {
|
|
164
|
-
let p;
|
|
165
|
-
|
|
166
|
-
const expectedKeys = new Set(['redirectTo', 'block', 'modifyHeader']);
|
|
167
|
-
|
|
168
|
-
function expectEmptyResponse(resp) {
|
|
169
|
-
const keys = Object.keys(resp).filter((k) => !expectedKeys.has(k));
|
|
170
|
-
chai.expect(keys).to.eql([]);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
beforeEach(function () {
|
|
174
|
-
p = new Pipeline('name');
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('returns object for empty pipeline', () => {
|
|
178
|
-
const response = {};
|
|
179
|
-
p.execute({}, response);
|
|
180
|
-
chai.expect(response).to.not.be.null;
|
|
181
|
-
expectEmptyResponse(response);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('calls functions in pipeline one with mutible state argument', () => {
|
|
185
|
-
let fn1Called = 0;
|
|
186
|
-
let fn2Called = 0;
|
|
187
|
-
|
|
188
|
-
function fn1(state) {
|
|
189
|
-
state.fn1 = true;
|
|
190
|
-
fn1Called += 1;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function fn2(state) {
|
|
194
|
-
chai.expect(state.fn1).to.be.true;
|
|
195
|
-
fn2Called += 1;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
p.addPipelineStep({ fn: fn1, name: 'fn1', spec: 'blocking' });
|
|
199
|
-
p.addPipelineStep({ fn: fn2, name: 'fn2', spec: 'blocking' });
|
|
200
|
-
|
|
201
|
-
const response = {};
|
|
202
|
-
p.execute({}, response);
|
|
203
|
-
chai.expect(fn1Called).to.eql(1);
|
|
204
|
-
chai.expect(fn2Called).to.eql(1);
|
|
205
|
-
expectEmptyResponse(response);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('stops when a function returns false', () => {
|
|
209
|
-
let fn1Called = 0;
|
|
210
|
-
let fn2Called = 0;
|
|
211
|
-
|
|
212
|
-
function fn1() {
|
|
213
|
-
fn1Called += 1;
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function fn2() {
|
|
218
|
-
fn2Called += 1;
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
p.addPipelineStep({ fn: fn1, name: 'fn1', spec: 'blocking' });
|
|
222
|
-
p.addPipelineStep({ fn: fn2, name: 'fn2', spec: 'blocking' });
|
|
223
|
-
|
|
224
|
-
const response = {};
|
|
225
|
-
p.execute({}, response);
|
|
226
|
-
chai.expect(fn1Called).to.eql(1);
|
|
227
|
-
chai.expect(fn2Called).to.eql(0);
|
|
228
|
-
expectEmptyResponse(response);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('returns the final value of the result', () => {
|
|
232
|
-
function fn1(state, res) {
|
|
233
|
-
res.fn1 = 4;
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function fn2(state, res) {
|
|
238
|
-
res.fn1 += 1;
|
|
239
|
-
res.fn2 = -4;
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
p.addPipelineStep({ fn: fn1, name: 'fn1', spec: 'blocking' });
|
|
243
|
-
p.addPipelineStep({ fn: fn2, name: 'fn2', spec: 'blocking' });
|
|
244
|
-
|
|
245
|
-
const response = {};
|
|
246
|
-
p.execute({}, response);
|
|
247
|
-
chai.expect(response.fn1).to.eql(5);
|
|
248
|
-
chai.expect(response.fn2).to.eql(-4);
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
});
|
|
File without changes
|