@whotracksme/reporting 7.12.3 → 8.0.1
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/.eslintignore +1 -0
- package/CHANGELOG.md +24 -0
- package/communication/test/helpers/in-memory-database.js +45 -0
- package/package.json +1 -1
- package/reporting/README.md +26 -0
- package/reporting/example/README.md +65 -0
- package/reporting/example/logs/.gitignore +2 -0
- package/reporting/example/run.mjs +288 -0
- package/reporting/karma.conf.cjs +3 -2
- package/reporting/package.json +8 -2
- package/reporting/rollup.common-config.cjs +7 -1
- package/reporting/scenarios/README.md +77 -0
- package/reporting/src/hash-detector-v2/index.js +164 -0
- package/reporting/src/hash-detector-v2/prob.js +599 -0
- package/reporting/src/hash-detector-v2.js +18 -0
- package/reporting/src/observable.js +43 -0
- package/reporting/src/pages.js +11 -12
- package/reporting/src/paused-domains-reporter.js +50 -0
- package/reporting/src/persisted-counters.js +158 -0
- package/reporting/src/popularity-estimator.js +625 -0
- package/reporting/src/popularity-vote-handler.js +219 -0
- package/reporting/src/popularity-vote-sanitizer.js +384 -0
- package/reporting/src/random.js +90 -1
- package/reporting/src/reporting.js +98 -13
- package/reporting/src/utils.js +41 -1
- package/reporting/test/README.md +42 -2
- package/reporting/test/activity-estimator.spec.js +3 -2
- package/reporting/test/alive-check.spec.js +2 -2
- package/reporting/test/country-provider.spec.js +2 -2
- package/reporting/test/helpers/scenarios.js +4 -1
- package/reporting/test/index.js +6 -0
- package/reporting/test/job-scheduler.spec.js +2 -2
- package/reporting/test/observable.spec.js +72 -0
- package/reporting/test/page-aggregator.spec.js +3 -0
- package/reporting/test/patterns-updater.spec.js +2 -2
- package/reporting/test/persisted-counters.spec.js +132 -0
- package/reporting/test/popularity-estimator.spec.js +710 -0
- package/reporting/test/popularity-vote-handler.spec.js +420 -0
- package/reporting/test/popularity-vote-sanitizer.spec.js +635 -0
- package/reporting/test/random.spec.js +157 -0
- package/reporting/test/reporting.spec.js +202 -180
- package/reporting/test/request/index.test.js +6 -2
- package/reporting/test/request.js +14 -0
- package/reporting/test/utils.spec.js +42 -0
|
@@ -0,0 +1,157 @@
|
|
|
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
|
+
import * as fc from 'fast-check';
|
|
14
|
+
|
|
15
|
+
import { randomSafeIntBetween, shuffleInPlace } from '../src/random.js';
|
|
16
|
+
|
|
17
|
+
describe('#randomSafeIntBetween', function () {
|
|
18
|
+
it('should reach all buckets of six-side dime', function () {
|
|
19
|
+
const bucket = {
|
|
20
|
+
1: 0,
|
|
21
|
+
2: 0,
|
|
22
|
+
3: 0,
|
|
23
|
+
4: 0,
|
|
24
|
+
5: 0,
|
|
25
|
+
6: 0,
|
|
26
|
+
};
|
|
27
|
+
for (let i = 0; i < 6 * 1000; i += 1) {
|
|
28
|
+
bucket[randomSafeIntBetween(1, 6)] += 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (let i = 1; i <= 6; i += 1) {
|
|
32
|
+
expect(bucket[i]).to.be.greaterThan(800).and.lessThan(1200);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should reach all buckets of { 0, 1, 2 }', function () {
|
|
37
|
+
const bucket = [0, 0, 0];
|
|
38
|
+
for (let i = 0; i < 3 * 1000; i += 1) {
|
|
39
|
+
bucket[randomSafeIntBetween(0, 2)] += 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const hits of bucket) {
|
|
43
|
+
expect(hits).to.be.greaterThan(800).and.lessThan(1200);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('should support the full range of safe integers', function () {
|
|
48
|
+
it('{ Number.MIN_SAFE_INTEGER, .., Number.MAX_SAFE_INTEGER }', function () {
|
|
49
|
+
let above0 = 0;
|
|
50
|
+
let below0 = 0;
|
|
51
|
+
for (let i = 0; i < 2 * 1000; i += 1) {
|
|
52
|
+
const num = randomSafeIntBetween(
|
|
53
|
+
Number.MIN_SAFE_INTEGER,
|
|
54
|
+
Number.MAX_SAFE_INTEGER,
|
|
55
|
+
);
|
|
56
|
+
expect(Number.isSafeInteger(num)).to.be.true;
|
|
57
|
+
if (num > 0) {
|
|
58
|
+
above0 += 1;
|
|
59
|
+
} else if (num < 0) {
|
|
60
|
+
below0 += 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
expect(above0 + below0).to.be.greaterThan(998);
|
|
65
|
+
expect(above0).to.be.greaterThan(800).and.lessThan(1200);
|
|
66
|
+
expect(below0).to.be.greaterThan(800).and.lessThan(1200);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('testing edge case that are barely within or barely outside the safe integers range', function () {
|
|
70
|
+
[-3, -2, -1, 0, 1].forEach((min) => {
|
|
71
|
+
[0, 1, 2, 3]
|
|
72
|
+
.map((maxDec) => Number.MAX_SAFE_INTEGER - maxDec)
|
|
73
|
+
.forEach((max) => {
|
|
74
|
+
it(`{ ${min}, .., ${max} }`, function () {
|
|
75
|
+
const middle = (max - min) / 2;
|
|
76
|
+
let above = 0;
|
|
77
|
+
let below = 0;
|
|
78
|
+
for (let i = 0; i < 2 * 1000; i += 1) {
|
|
79
|
+
const num = randomSafeIntBetween(min, max);
|
|
80
|
+
expect(Number.isSafeInteger(num)).to.be.true;
|
|
81
|
+
|
|
82
|
+
if (num > middle) {
|
|
83
|
+
above += 1;
|
|
84
|
+
} else if (num < middle) {
|
|
85
|
+
below += 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
expect(above + below).to.be.greaterThan(998);
|
|
90
|
+
expect(above).to.be.greaterThan(800).and.lessThan(1200);
|
|
91
|
+
expect(below).to.be.greaterThan(800).and.lessThan(1200);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('[property based testing]', function () {
|
|
99
|
+
it('should support intervals where min equals max', function () {
|
|
100
|
+
fc.assert(
|
|
101
|
+
fc.property(fc.maxSafeInteger(), (num) => {
|
|
102
|
+
return randomSafeIntBetween(num, num) === num;
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should return an integer between min and max', function () {
|
|
108
|
+
fc.assert(
|
|
109
|
+
fc.property(fc.maxSafeInteger(), fc.maxSafeInteger(), (min, max) => {
|
|
110
|
+
if (min > max) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const result = randomSafeIntBetween(min, max);
|
|
115
|
+
return Number.isSafeInteger(result) && result >= min && result <= max;
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('#shuffleInPlace', function () {
|
|
123
|
+
it('should have uniform distribution of elements in each position for small arrays', function () {
|
|
124
|
+
const counts = [
|
|
125
|
+
[0, 0, 0],
|
|
126
|
+
[0, 0, 0],
|
|
127
|
+
[0, 0, 0],
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
for (let i = 0; i < 3 * 1000; i++) {
|
|
131
|
+
const [x, y, z] = shuffleInPlace([0, 1, 2]);
|
|
132
|
+
counts[0][x] += 1;
|
|
133
|
+
counts[1][y] += 1;
|
|
134
|
+
counts[2][z] += 1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (let i = 0; i < 3; i += 1) {
|
|
138
|
+
for (let j = 0; j < 3; j += 1) {
|
|
139
|
+
expect(counts[i][j])
|
|
140
|
+
.to.be.greaterThan(1000 * 0.8)
|
|
141
|
+
.and.lessThan(1000 * 1.2);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('[property based testing]', function () {
|
|
147
|
+
it('should produce a permutation of the input array: sort(shuffle(arr)) == sort(arr)', function () {
|
|
148
|
+
fc.assert(
|
|
149
|
+
fc.property(fc.array(fc.integer()), (arr) => {
|
|
150
|
+
const shuffled = shuffleInPlace([...arr]).sort((x, y) => x - y);
|
|
151
|
+
const notShuffled = [...arr].sort((x, y) => x - y);
|
|
152
|
+
expect(shuffled).to.eql(notShuffled);
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -14,6 +14,8 @@ import sinon from 'sinon';
|
|
|
14
14
|
|
|
15
15
|
import Reporting from '../src/reporting.js';
|
|
16
16
|
|
|
17
|
+
import InMemoryDatabase from './helpers/in-memory-database.js';
|
|
18
|
+
|
|
17
19
|
function waitForPromisesToFinish() {
|
|
18
20
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
19
21
|
}
|
|
@@ -21,184 +23,204 @@ function waitForPromisesToFinish() {
|
|
|
21
23
|
describe('#Reporting', function () {
|
|
22
24
|
let uut;
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
26
|
+
for (const withPauseState of [true, false]) {
|
|
27
|
+
describe(
|
|
28
|
+
withPauseState
|
|
29
|
+
? '"pauseState" config present'
|
|
30
|
+
: '"pauseState" config absent',
|
|
31
|
+
|
|
32
|
+
function () {
|
|
33
|
+
beforeEach(async function () {
|
|
34
|
+
const config = {
|
|
35
|
+
ALLOWED_COUNTRY_CODES: ['us', 'de'],
|
|
36
|
+
PATTERNS_URL: 'https://some-patterns-endpoint.test',
|
|
37
|
+
CONFIG_URL: 'https://some-config-endpoint.test',
|
|
38
|
+
};
|
|
39
|
+
const storage = {
|
|
40
|
+
get: async () => undefined, // assume nothing was stored yet
|
|
41
|
+
};
|
|
42
|
+
const communication = {
|
|
43
|
+
async send() {},
|
|
44
|
+
trustedClock: {},
|
|
45
|
+
};
|
|
46
|
+
const connectDatabase = (/*prefix*/) => new InMemoryDatabase();
|
|
47
|
+
sinon.stub(window, 'fetch').callsFake(async (url) => ({
|
|
48
|
+
ok: false,
|
|
49
|
+
statusText: `Stub server has been configured to fail (this is expected): request to ${url}`,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
// optional components
|
|
53
|
+
let pauseState;
|
|
54
|
+
if (withPauseState) {
|
|
55
|
+
pauseState = {
|
|
56
|
+
getFilteringMode: () => 'default',
|
|
57
|
+
isHostnamePaused: (/*hostname*/) => false,
|
|
58
|
+
connectHostnamePausingEvents: (/*notify*/) => {},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
uut = new Reporting({
|
|
62
|
+
config,
|
|
63
|
+
storage,
|
|
64
|
+
communication,
|
|
65
|
+
connectDatabase,
|
|
66
|
+
pauseState,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterEach(function () {
|
|
71
|
+
try {
|
|
72
|
+
uut.unload();
|
|
73
|
+
uut = null;
|
|
74
|
+
} finally {
|
|
75
|
+
window.fetch.restore();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('should load and unload correctly', function () {
|
|
80
|
+
it('happy path', async () => {
|
|
81
|
+
expect(uut.isActive).to.be.false;
|
|
82
|
+
await uut.init();
|
|
83
|
+
expect(uut.isActive).to.be.true;
|
|
84
|
+
uut.unload();
|
|
85
|
+
expect(uut.isActive).to.be.false;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('multiple inits should be OK', async () => {
|
|
89
|
+
await Promise.all([uut.init(), uut.init(), uut.init()]);
|
|
90
|
+
expect(uut.isActive).to.be.true;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('multiple unloads should be OK', async () => {
|
|
94
|
+
uut.unload();
|
|
95
|
+
uut.unload();
|
|
96
|
+
uut.unload();
|
|
97
|
+
expect(uut.isActive).to.be.false;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('multiple mixed init/unloads should be OK', async () => {
|
|
101
|
+
const pending = [];
|
|
102
|
+
pending.push(uut.init());
|
|
103
|
+
pending.push(uut.init());
|
|
104
|
+
pending.push(uut.init());
|
|
105
|
+
|
|
106
|
+
uut.unload();
|
|
107
|
+
expect(uut.isActive).to.be.false;
|
|
108
|
+
|
|
109
|
+
pending.push(uut.init());
|
|
110
|
+
uut.unload();
|
|
111
|
+
expect(uut.isActive).to.be.false;
|
|
112
|
+
|
|
113
|
+
uut.unload();
|
|
114
|
+
expect(uut.isActive).to.be.false;
|
|
115
|
+
|
|
116
|
+
await Promise.all(pending);
|
|
117
|
+
uut.unload();
|
|
118
|
+
expect(uut.isActive).to.be.false;
|
|
119
|
+
|
|
120
|
+
await uut.init();
|
|
121
|
+
expect(uut.isActive).to.be.true;
|
|
122
|
+
|
|
123
|
+
uut.unload();
|
|
124
|
+
expect(uut.isActive).to.be.false;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('should make ensure that "unload" at the end always wins', () => {
|
|
128
|
+
it('when calling init once', async () => {
|
|
129
|
+
const pending = uut.init();
|
|
130
|
+
uut.unload();
|
|
131
|
+
expect(uut.isActive).to.be.false;
|
|
132
|
+
|
|
133
|
+
await pending;
|
|
134
|
+
await waitForPromisesToFinish();
|
|
135
|
+
expect(uut.isActive).to.be.false;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('when calling init multiple times', async () => {
|
|
139
|
+
const pending = [];
|
|
140
|
+
pending.push(uut.init());
|
|
141
|
+
pending.push(uut.init());
|
|
142
|
+
pending.push(uut.init());
|
|
143
|
+
uut.unload();
|
|
144
|
+
expect(uut.isActive).to.be.false;
|
|
145
|
+
|
|
146
|
+
await Promise.all(pending);
|
|
147
|
+
await waitForPromisesToFinish();
|
|
148
|
+
expect(uut.isActive).to.be.false;
|
|
149
|
+
|
|
150
|
+
// and addition unload operations should not change anything
|
|
151
|
+
uut.unload();
|
|
152
|
+
expect(uut.isActive).to.be.false;
|
|
153
|
+
uut.unload();
|
|
154
|
+
uut.unload();
|
|
155
|
+
expect(uut.isActive).to.be.false;
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('when calling unload multiple times', async () => {
|
|
159
|
+
const pending = [];
|
|
160
|
+
pending.push(uut.init());
|
|
161
|
+
pending.push(uut.init());
|
|
162
|
+
pending.push(uut.init());
|
|
163
|
+
uut.unload();
|
|
164
|
+
expect(uut.isActive).to.be.false;
|
|
165
|
+
uut.unload();
|
|
166
|
+
expect(uut.isActive).to.be.false;
|
|
167
|
+
|
|
168
|
+
await Promise.all(pending);
|
|
169
|
+
await waitForPromisesToFinish();
|
|
170
|
+
expect(uut.isActive).to.be.false;
|
|
171
|
+
|
|
172
|
+
// and addition unload operations should not change anything
|
|
173
|
+
uut.unload();
|
|
174
|
+
expect(uut.isActive).to.be.false;
|
|
175
|
+
uut.unload();
|
|
176
|
+
uut.unload();
|
|
177
|
+
expect(uut.isActive).to.be.false;
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('should make ensure that "init" at the end always wins', () => {
|
|
182
|
+
it('in a simple example', async () => {
|
|
183
|
+
const pending = [];
|
|
184
|
+
pending.push(uut.init());
|
|
185
|
+
uut.unload();
|
|
186
|
+
expect(uut.isActive).to.be.false;
|
|
187
|
+
pending.push(uut.init());
|
|
188
|
+
|
|
189
|
+
await Promise.all([pending]);
|
|
190
|
+
await waitForPromisesToFinish();
|
|
191
|
+
expect(uut.isActive).to.be.true;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('in a complex example', async () => {
|
|
195
|
+
const pending = [];
|
|
196
|
+
pending.push(uut.init());
|
|
197
|
+
uut.unload();
|
|
198
|
+
expect(uut.isActive).to.be.false;
|
|
199
|
+
pending.push(uut.init());
|
|
200
|
+
pending.push(uut.init());
|
|
201
|
+
uut.unload();
|
|
202
|
+
expect(uut.isActive).to.be.false;
|
|
203
|
+
pending.push(uut.init());
|
|
204
|
+
pending.push(uut.init());
|
|
205
|
+
uut.unload();
|
|
206
|
+
expect(uut.isActive).to.be.false;
|
|
207
|
+
uut.unload();
|
|
208
|
+
expect(uut.isActive).to.be.false;
|
|
209
|
+
pending.push(uut.init());
|
|
210
|
+
|
|
211
|
+
await Promise.all([pending]);
|
|
212
|
+
await waitForPromisesToFinish();
|
|
213
|
+
expect(uut.isActive).to.be.true;
|
|
214
|
+
|
|
215
|
+
await uut.init();
|
|
216
|
+
expect(uut.isActive).to.be.true;
|
|
217
|
+
|
|
218
|
+
await uut.init();
|
|
219
|
+
expect(uut.isActive).to.be.true;
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
}
|
|
204
226
|
});
|
|
@@ -335,10 +335,14 @@ describe('RequestReporter', function () {
|
|
|
335
335
|
.NEW_ENTRY_MIN_AGE,
|
|
336
336
|
);
|
|
337
337
|
|
|
338
|
-
|
|
339
|
-
if (
|
|
338
|
+
/* eslint-disable no-undef */
|
|
339
|
+
if (
|
|
340
|
+
process.argv.includes('--record-snapshot') ||
|
|
341
|
+
process.env.RECORD_SNAPSHOT
|
|
342
|
+
) {
|
|
340
343
|
recordSnapshot(snapshotName, messages);
|
|
341
344
|
}
|
|
345
|
+
/* eslint-enable no-undef */
|
|
342
346
|
|
|
343
347
|
const snapshot = await readSnapshot(snapshotName);
|
|
344
348
|
expect(messages).to.have.lengthOf(snapshot.length);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import './setup.js';
|
|
2
|
+
|
|
3
|
+
import './request/qs-whitelist2.spec.js';
|
|
4
|
+
import './request/hash/index.spec.js';
|
|
5
|
+
import './request/database.spec.js';
|
|
6
|
+
import './request/index.spec.js';
|
|
7
|
+
|
|
8
|
+
import './request/utils/tldts.spec.js';
|
|
9
|
+
import './request/utils/bloom-filter-packed.spec.js';
|
|
10
|
+
import './request/utils/chrome-storage-map.spec.js';
|
|
11
|
+
import './request/utils/utils.spec.js';
|
|
12
|
+
|
|
13
|
+
import './request/steps/check-context.spec.js';
|
|
14
|
+
import './request/steps/oauth-detector.spec.js';
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
chunk,
|
|
17
17
|
flattenObject,
|
|
18
18
|
equalityCanBeProven,
|
|
19
|
+
includesMiddleChar,
|
|
19
20
|
parseUntrustedJSON,
|
|
20
21
|
lazyInitAsync,
|
|
21
22
|
} from '../src/utils.js';
|
|
@@ -154,6 +155,47 @@ describe('#equalityCanBeProven', function () {
|
|
|
154
155
|
});
|
|
155
156
|
});
|
|
156
157
|
|
|
158
|
+
describe('#includesMiddleChar', function () {
|
|
159
|
+
it('should detect inner matches', function () {
|
|
160
|
+
expect(includesMiddleChar('a+b', '+')).to.be.true;
|
|
161
|
+
expect(includesMiddleChar('a+b+c', '+')).to.be.true;
|
|
162
|
+
expect(includesMiddleChar('+a+b+c', '+')).to.be.true;
|
|
163
|
+
expect(includesMiddleChar('a+b+c+', '+')).to.be.true;
|
|
164
|
+
expect(includesMiddleChar('+a+b+c+', '+')).to.be.true;
|
|
165
|
+
expect(includesMiddleChar('++a++b++c++', '+')).to.be.true;
|
|
166
|
+
expect(includesMiddleChar('+a+b+', '+')).to.be.true;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should ignore leading matches', function () {
|
|
170
|
+
expect(includesMiddleChar('+ab', '+')).to.be.false;
|
|
171
|
+
expect(includesMiddleChar('++ab', '+')).to.be.false;
|
|
172
|
+
expect(includesMiddleChar('++ab', '+')).to.be.false;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('should ignore trailing matches', function () {
|
|
176
|
+
expect(includesMiddleChar('ab+', '+')).to.be.false;
|
|
177
|
+
expect(includesMiddleChar('ab++', '+')).to.be.false;
|
|
178
|
+
expect(includesMiddleChar('ab+++', '+')).to.be.false;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('should handle empty inputs', function () {
|
|
182
|
+
expect(includesMiddleChar('', '+')).be.false;
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should handle inputs with no other chars', function () {
|
|
186
|
+
expect(includesMiddleChar('+', '+')).be.false;
|
|
187
|
+
expect(includesMiddleChar('++', '+')).be.false;
|
|
188
|
+
expect(includesMiddleChar('+++', '+')).be.false;
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('should handle non-matching inputs', function () {
|
|
192
|
+
expect(includesMiddleChar('foo', '+')).be.false;
|
|
193
|
+
expect(includesMiddleChar('+a+', '+')).be.false;
|
|
194
|
+
expect(includesMiddleChar('+ab+', '+')).be.false;
|
|
195
|
+
expect(includesMiddleChar('+++a+++', '+')).be.false;
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
157
199
|
describe('#parseUntrustedJSON', function () {
|
|
158
200
|
describe('should be a drop-in replacement for JSON.parse for safe data', function () {
|
|
159
201
|
for (const json of [
|