@whotracksme/reporting 5.1.17
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/.editorconfig +12 -0
- package/.eslintignore +3 -0
- package/.eslintrc +16 -0
- package/.github/workflows/release.yml +34 -0
- package/.github/workflows/tests.yml +20 -0
- package/.prettierrc +9 -0
- package/.tool-versions +1 -0
- package/CHANGELOG.md +795 -0
- package/LICENSE +373 -0
- package/README.md +1 -0
- package/communication/README.md +11 -0
- package/communication/example/index.js +43 -0
- package/communication/example/manifest.json +16 -0
- package/communication/karma.conf.cjs +19 -0
- package/communication/package.json +52 -0
- package/communication/rollup.common-config.cjs +17 -0
- package/communication/rollup.config.cjs +10 -0
- package/communication/src/encoding.js +54 -0
- package/communication/src/errors.js +84 -0
- package/communication/src/index.js +76 -0
- package/communication/src/logger.js +41 -0
- package/communication/src/padding.js +60 -0
- package/communication/src/proxied-http.js +231 -0
- package/communication/src/server-public-key-accessor.js +123 -0
- package/communication/src/timestamps.js +37 -0
- package/communication/src/trusted-clock.js +58 -0
- package/communication/src/utils.js +28 -0
- package/communication/src/zlib.js +17 -0
- package/communication/test/helpers/in-memory-database.js +43 -0
- package/communication/test/server-public-key-accessor.spec.js +135 -0
- package/communication/test/utils.spec.js +43 -0
- package/package.json +50 -0
- package/reporting/TODO.md +2 -0
- package/reporting/assets/request/bloom_filter.dat +0 -0
- package/reporting/assets/request/update.json +1 -0
- package/reporting/example/content.js +11 -0
- package/reporting/example/index.js +132 -0
- package/reporting/example/inspector/index.html +17 -0
- package/reporting/example/inspector/index.js +27 -0
- package/reporting/example/manifests/chromium.json +37 -0
- package/reporting/example/manifests/firefox.json +35 -0
- package/reporting/example/rules.json +62 -0
- package/reporting/example/setup.js +1 -0
- package/reporting/example/tests/test1.html +10 -0
- package/reporting/karma.conf.cjs +22 -0
- package/reporting/package.json +63 -0
- package/reporting/rollup.common-config.cjs +19 -0
- package/reporting/rollup.config.cjs +20 -0
- package/reporting/src/LRU.js +149 -0
- package/reporting/src/activity-estimator.js +298 -0
- package/reporting/src/alive-check.js +139 -0
- package/reporting/src/alive-message-generator.js +142 -0
- package/reporting/src/bloom-filters.js +345 -0
- package/reporting/src/country-provider.js +295 -0
- package/reporting/src/cyrb53.js +32 -0
- package/reporting/src/digest.js +33 -0
- package/reporting/src/doublefetch-page-handler.js +548 -0
- package/reporting/src/duplicate-detector.js +233 -0
- package/reporting/src/errors.js +84 -0
- package/reporting/src/event-listener-queue.js +121 -0
- package/reporting/src/fixed-size-cache.js +63 -0
- package/reporting/src/hash-detector.js +1526 -0
- package/reporting/src/html-parser.js +17 -0
- package/reporting/src/http.js +265 -0
- package/reporting/src/index.js +14 -0
- package/reporting/src/job-scheduler.js +912 -0
- package/reporting/src/logger.js +121 -0
- package/reporting/src/md5.js +334 -0
- package/reporting/src/message-sender.js +51 -0
- package/reporting/src/network.js +140 -0
- package/reporting/src/new-page-approver.js +119 -0
- package/reporting/src/page-aggregator.js +185 -0
- package/reporting/src/page-quorum-check-handler.js +200 -0
- package/reporting/src/page-structure.js +136 -0
- package/reporting/src/pagedb.js +671 -0
- package/reporting/src/pages.js +1798 -0
- package/reporting/src/patterns-updater.js +310 -0
- package/reporting/src/patterns.js +416 -0
- package/reporting/src/persisted-bitarray.js +265 -0
- package/reporting/src/persisted-hashes.js +189 -0
- package/reporting/src/quorum-checker.js +327 -0
- package/reporting/src/random.js +39 -0
- package/reporting/src/reporting.js +290 -0
- package/reporting/src/request/config.js +116 -0
- package/reporting/src/request/content-script.js +77 -0
- package/reporting/src/request/database.js +147 -0
- package/reporting/src/request/dnt.js +24 -0
- package/reporting/src/request/hash.js +101 -0
- package/reporting/src/request/index.js +874 -0
- package/reporting/src/request/page-telemetry.js +42 -0
- package/reporting/src/request/qs-whitelist2.js +247 -0
- package/reporting/src/request/resources/prob.js +601 -0
- package/reporting/src/request/steps/block-rules.js +40 -0
- package/reporting/src/request/steps/check-context.js +37 -0
- package/reporting/src/request/steps/cookie-context.js +209 -0
- package/reporting/src/request/steps/oauth-detector.js +101 -0
- package/reporting/src/request/steps/page-logger.js +177 -0
- package/reporting/src/request/steps/redirect-tagger.js +75 -0
- package/reporting/src/request/steps/subdomain-check.js +34 -0
- package/reporting/src/request/steps/token-checker/index.js +189 -0
- package/reporting/src/request/steps/token-checker/token-domain.js +129 -0
- package/reporting/src/request/steps/token-examiner.js +182 -0
- package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +210 -0
- package/reporting/src/request/steps/token-telemetry/index.js +234 -0
- package/reporting/src/request/steps/token-telemetry/key-pipeline.js +109 -0
- package/reporting/src/request/steps/token-telemetry/token-pipeline.js +105 -0
- package/reporting/src/request/time.js +73 -0
- package/reporting/src/request/utils/bloom-filter-packed.js +107 -0
- package/reporting/src/request/utils/chrome-storage-map.js +282 -0
- package/reporting/src/request/utils/subject.js +37 -0
- package/reporting/src/request/utils/temp-set.js +56 -0
- package/reporting/src/request/utils/tlds.js +55 -0
- package/reporting/src/request/utils.js +41 -0
- package/reporting/src/request-reporter.js +111 -0
- package/reporting/src/sanitizer.js +519 -0
- package/reporting/src/search-extractor.js +338 -0
- package/reporting/src/self-check.js +105 -0
- package/reporting/src/seq-executor.js +43 -0
- package/reporting/src/session-storage.js +399 -0
- package/reporting/src/url-analyzer.js +161 -0
- package/reporting/src/url-cleaner.js +60 -0
- package/reporting/src/utils/pacemaker.js +279 -0
- package/reporting/src/utils/url.js +114 -0
- package/reporting/src/utils.js +345 -0
- package/reporting/src/webrequest-pipeline/cname-uncloak.js +110 -0
- package/reporting/src/webrequest-pipeline/index.js +287 -0
- package/reporting/src/webrequest-pipeline/logger.js +14 -0
- package/reporting/src/webrequest-pipeline/page-store.js +282 -0
- package/reporting/src/webrequest-pipeline/page.js +140 -0
- package/reporting/src/webrequest-pipeline/pipeline.js +249 -0
- package/reporting/src/webrequest-pipeline/utils/webrequest.js +113 -0
- package/reporting/src/webrequest-pipeline/webrequest-context.js +153 -0
- package/reporting/test/README.md +2 -0
- package/reporting/test/activity-estimator.spec.js +356 -0
- package/reporting/test/alive-check.spec.js +156 -0
- package/reporting/test/alive-message-generator.spec.js +186 -0
- package/reporting/test/country-provider.spec.js +263 -0
- package/reporting/test/doublefetch-page-handler.spec.js +818 -0
- package/reporting/test/duplicate-detector.spec.js +689 -0
- package/reporting/test/helpers/dom-parsers.js +41 -0
- package/reporting/test/helpers/fake-session-storage.js +69 -0
- package/reporting/test/helpers/fast-check-utils.js +28 -0
- package/reporting/test/helpers/fetch-mock.js +57 -0
- package/reporting/test/helpers/in-memory-database.js +14 -0
- package/reporting/test/helpers/memory-map.js +72 -0
- package/reporting/test/helpers/pagedb-mocks.js +41 -0
- package/reporting/test/index.js +47 -0
- package/reporting/test/job-scheduler.spec.js +691 -0
- package/reporting/test/network.spec.js +72 -0
- package/reporting/test/page-aggregator.spec.js +104 -0
- package/reporting/test/page-quorum-check-handler.spec.js +86 -0
- package/reporting/test/pagedb.spec.js +250 -0
- package/reporting/test/pages.spec.js +693 -0
- package/reporting/test/patterns-updater.spec.js +446 -0
- package/reporting/test/patterns.spec.js +751 -0
- package/reporting/test/persisted-hashes.spec.js +169 -0
- package/reporting/test/reporting.spec.js +205 -0
- package/reporting/test/request/database.spec.js +59 -0
- package/reporting/test/request/hash.spec.js +108 -0
- package/reporting/test/request/index.spec.js +378 -0
- package/reporting/test/request/qs-whitelist2.spec.js +189 -0
- package/reporting/test/request/steps/check-context.spec.js +51 -0
- package/reporting/test/request/steps/oauth-detector.spec.js +339 -0
- package/reporting/test/request/test-pages.js +1246 -0
- package/reporting/test/request/utils/bloom-filter-packed.spec.js +37 -0
- package/reporting/test/request/utils/chrome-storage-map.spec.js +28 -0
- package/reporting/test/request/utils/tldts.spec.js +62 -0
- package/reporting/test/request/utils.spec.js +168 -0
- package/reporting/test/sanitizer.spec.js +1087 -0
- package/reporting/test/search-extractor.spec.js +590 -0
- package/reporting/test/seq-executor.spec.js +158 -0
- package/reporting/test/session-storage.spec.js +400 -0
- package/reporting/test/setup.js +24 -0
- package/reporting/test/url-analyzer.spec.js +451 -0
- package/reporting/test/url-cleaner.spec.js +102 -0
- package/reporting/test/utils/pacemaker.spec.js +222 -0
- package/reporting/test/utils/url.spec.js +660 -0
- package/reporting/test/utils.spec.js +299 -0
- package/reporting/test/webrequest-pipeline/pipeline.spec.js +251 -0
|
@@ -0,0 +1,169 @@
|
|
|
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 fc from 'fast-check';
|
|
13
|
+
import { expect } from 'chai';
|
|
14
|
+
import sinon from 'sinon';
|
|
15
|
+
|
|
16
|
+
import PersistedHashes from '../src/persisted-hashes.js';
|
|
17
|
+
|
|
18
|
+
const NEVER_EXPIRES = Number.MAX_SAFE_INTEGER;
|
|
19
|
+
|
|
20
|
+
describe('#PersistedHashes', function () {
|
|
21
|
+
let storage = new Map();
|
|
22
|
+
let uut;
|
|
23
|
+
let clock;
|
|
24
|
+
|
|
25
|
+
const assumeExistingHashesOnDisk = async (existingHashes) => {
|
|
26
|
+
const dummyTTL = Date.now() + 1;
|
|
27
|
+
await storage.set('dummy-key', {
|
|
28
|
+
hashes: existingHashes.map((key) => [key, dummyTTL]),
|
|
29
|
+
nextPrune: dummyTTL,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const initMocks = () => {
|
|
34
|
+
clock?.restore();
|
|
35
|
+
clock = sinon.useFakeTimers(new Date('2020-01-17'));
|
|
36
|
+
uut = new PersistedHashes({ storage, storageKey: 'dummy-key' });
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
beforeEach(async function () {
|
|
40
|
+
initMocks();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(function () {
|
|
44
|
+
clock?.restore();
|
|
45
|
+
clock = null;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should allow adding and deleting keys (happy path)', async function () {
|
|
49
|
+
expect(await uut.has('x')).to.be.false;
|
|
50
|
+
expect(await uut.add('x', NEVER_EXPIRES)).to.be.true;
|
|
51
|
+
|
|
52
|
+
// now the key should exist
|
|
53
|
+
expect(await uut.has('x')).to.be.true;
|
|
54
|
+
expect(await uut.add('x', NEVER_EXPIRES)).to.be.false; // not modified
|
|
55
|
+
|
|
56
|
+
// now delete it
|
|
57
|
+
expect(await uut.delete('x')).to.be.true;
|
|
58
|
+
expect(await uut.has('x')).to.be.false;
|
|
59
|
+
expect(await uut.delete('x')).to.be.false; // not modified
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should load existing data from disk (happy path)', async function () {
|
|
63
|
+
await assumeExistingHashesOnDisk(['old1', 'old2']);
|
|
64
|
+
|
|
65
|
+
// then
|
|
66
|
+
expect(await uut.has('old1')).to.be.true;
|
|
67
|
+
expect(await uut.has('old2')).to.be.true;
|
|
68
|
+
expect(await uut.has('new1')).to.be.false;
|
|
69
|
+
|
|
70
|
+
// when a new key is added
|
|
71
|
+
expect(await uut.add('new1', NEVER_EXPIRES)).to.be.true;
|
|
72
|
+
|
|
73
|
+
// then
|
|
74
|
+
expect(await uut.has('old1')).to.be.true;
|
|
75
|
+
expect(await uut.has('old2')).to.be.true;
|
|
76
|
+
expect(await uut.has('new1')).to.be.true;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should clean up keys with expired TTL', async function () {
|
|
80
|
+
// given
|
|
81
|
+
const ttl = 60;
|
|
82
|
+
await uut.add('x', Date.now() + ttl);
|
|
83
|
+
expect(await uut.has('x')).to.be.true;
|
|
84
|
+
|
|
85
|
+
// when
|
|
86
|
+
clock.tick(ttl + 1);
|
|
87
|
+
|
|
88
|
+
// then
|
|
89
|
+
expect(await uut.has('x')).to.be.false;
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should have no false-negatives (i.e. hashes being added must never be forgotten)', async function () {
|
|
93
|
+
await fc.assert(
|
|
94
|
+
fc
|
|
95
|
+
.asyncProperty(fc.array(fc.string()), async (keys) => {
|
|
96
|
+
// given
|
|
97
|
+
await Promise.all(keys.map((key) => uut.add(key, NEVER_EXPIRES)));
|
|
98
|
+
|
|
99
|
+
// then
|
|
100
|
+
for (const key of keys) {
|
|
101
|
+
expect(await uut.has(key)).to.equal(
|
|
102
|
+
true,
|
|
103
|
+
`key <${key}> not found by "has"`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
for (const key of keys) {
|
|
107
|
+
expect(await uut.add(key, NEVER_EXPIRES)).to.equal(
|
|
108
|
+
false,
|
|
109
|
+
`key <${key}> not found by "add"`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
.beforeEach(() => {
|
|
114
|
+
initMocks();
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should purge expired keys', async function () {
|
|
120
|
+
let countWrites = 0;
|
|
121
|
+
let lastWritten = null;
|
|
122
|
+
storage.set = async (key, value) => {
|
|
123
|
+
lastWritten = value;
|
|
124
|
+
countWrites += 1;
|
|
125
|
+
};
|
|
126
|
+
const ttl = 60;
|
|
127
|
+
|
|
128
|
+
await uut.add('x', Date.now() + ttl);
|
|
129
|
+
await uut.add('y', Date.now() + ttl);
|
|
130
|
+
await uut.flush();
|
|
131
|
+
expect(lastWritten.hashes.map((x) => x[0])).to.have.same.members([
|
|
132
|
+
'x',
|
|
133
|
+
'y',
|
|
134
|
+
]);
|
|
135
|
+
expect(countWrites).to.equal(1);
|
|
136
|
+
|
|
137
|
+
await uut.add('z', Date.now() + ttl);
|
|
138
|
+
await uut.flush();
|
|
139
|
+
expect(lastWritten.hashes.map((x) => x[0])).to.have.same.members([
|
|
140
|
+
'x',
|
|
141
|
+
'y',
|
|
142
|
+
'z',
|
|
143
|
+
]);
|
|
144
|
+
expect(countWrites).to.equal(2);
|
|
145
|
+
|
|
146
|
+
// make sure the default pruning interval has expired
|
|
147
|
+
clock.tick(365 * 24 * 60 * 60 * 1000);
|
|
148
|
+
|
|
149
|
+
// now all entries should have been purged
|
|
150
|
+
await uut.flush();
|
|
151
|
+
expect(lastWritten.hashes.map((x) => x[0])).to.have.same.members([]);
|
|
152
|
+
expect(countWrites).to.equal(3);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should persist all written keys', async function () {
|
|
156
|
+
let countWrites = 0;
|
|
157
|
+
let lastWritten = null;
|
|
158
|
+
storage.set = async (key, value) => {
|
|
159
|
+
lastWritten = value;
|
|
160
|
+
countWrites += 1;
|
|
161
|
+
};
|
|
162
|
+
const keys = [...new Array(1000)].map((_, i) => `key${i}`);
|
|
163
|
+
await Promise.all(keys.map((key) => uut.add(key, NEVER_EXPIRES)));
|
|
164
|
+
|
|
165
|
+
await uut.flush();
|
|
166
|
+
expect(lastWritten.hashes.map((x) => x[0])).to.have.same.members(keys);
|
|
167
|
+
expect(countWrites).to.equal(1);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,205 @@
|
|
|
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 sinon from 'sinon';
|
|
14
|
+
|
|
15
|
+
import Reporting from '../src/reporting.js';
|
|
16
|
+
|
|
17
|
+
function waitForPromisesToFinish() {
|
|
18
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('#Reporting', function () {
|
|
22
|
+
let uut;
|
|
23
|
+
|
|
24
|
+
beforeEach(async function () {
|
|
25
|
+
const config = {
|
|
26
|
+
ALLOWED_COUNTRY_CODES: ['us', 'de'],
|
|
27
|
+
PATTERNS_URL: 'https://some-patterns-endpoint.test',
|
|
28
|
+
CONFIG_URL: 'https://some-config-endpoint.test',
|
|
29
|
+
};
|
|
30
|
+
const storage = {
|
|
31
|
+
get: () => undefined, // assume nothing was stored yet
|
|
32
|
+
flush: () => {},
|
|
33
|
+
};
|
|
34
|
+
const communication = {
|
|
35
|
+
async send() {},
|
|
36
|
+
trustedClock: {},
|
|
37
|
+
};
|
|
38
|
+
const connectDatabase = () => {};
|
|
39
|
+
sinon.stub(window, 'fetch').callsFake(async (url) => ({
|
|
40
|
+
ok: false,
|
|
41
|
+
statusText: `Stub server has been configured to fail (this is expected): request to ${url}`,
|
|
42
|
+
}));
|
|
43
|
+
uut = new Reporting({
|
|
44
|
+
config,
|
|
45
|
+
storage,
|
|
46
|
+
communication,
|
|
47
|
+
connectDatabase,
|
|
48
|
+
browserInfoProvider: async () => ({ browser: 'test' }),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(function () {
|
|
53
|
+
try {
|
|
54
|
+
uut.unload();
|
|
55
|
+
uut = null;
|
|
56
|
+
} finally {
|
|
57
|
+
window.fetch.restore();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('should load and unload correctly', function () {
|
|
62
|
+
it('happy path', async () => {
|
|
63
|
+
expect(uut.isActive).to.be.false;
|
|
64
|
+
await uut.init();
|
|
65
|
+
expect(uut.isActive).to.be.true;
|
|
66
|
+
uut.unload();
|
|
67
|
+
expect(uut.isActive).to.be.false;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('multiple inits should be OK', async () => {
|
|
71
|
+
await Promise.all([uut.init(), uut.init(), uut.init()]);
|
|
72
|
+
expect(uut.isActive).to.be.true;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('multiple unloads should be OK', async () => {
|
|
76
|
+
uut.unload();
|
|
77
|
+
uut.unload();
|
|
78
|
+
uut.unload();
|
|
79
|
+
expect(uut.isActive).to.be.false;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('multiple mixed init/unloads should be OK', async () => {
|
|
83
|
+
const pending = [];
|
|
84
|
+
pending.push(uut.init());
|
|
85
|
+
pending.push(uut.init());
|
|
86
|
+
pending.push(uut.init());
|
|
87
|
+
|
|
88
|
+
uut.unload();
|
|
89
|
+
expect(uut.isActive).to.be.false;
|
|
90
|
+
|
|
91
|
+
pending.push(uut.init());
|
|
92
|
+
uut.unload();
|
|
93
|
+
expect(uut.isActive).to.be.false;
|
|
94
|
+
|
|
95
|
+
uut.unload();
|
|
96
|
+
expect(uut.isActive).to.be.false;
|
|
97
|
+
|
|
98
|
+
await Promise.all(pending);
|
|
99
|
+
uut.unload();
|
|
100
|
+
expect(uut.isActive).to.be.false;
|
|
101
|
+
|
|
102
|
+
await uut.init();
|
|
103
|
+
expect(uut.isActive).to.be.true;
|
|
104
|
+
|
|
105
|
+
uut.unload();
|
|
106
|
+
expect(uut.isActive).to.be.false;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('should make ensure that "unload" at the end always wins', () => {
|
|
110
|
+
it('when calling init once', async () => {
|
|
111
|
+
const pending = uut.init();
|
|
112
|
+
uut.unload();
|
|
113
|
+
expect(uut.isActive).to.be.false;
|
|
114
|
+
|
|
115
|
+
await pending;
|
|
116
|
+
await waitForPromisesToFinish();
|
|
117
|
+
expect(uut.isActive).to.be.false;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('when calling init multiple times', async () => {
|
|
121
|
+
const pending = [];
|
|
122
|
+
pending.push(uut.init());
|
|
123
|
+
pending.push(uut.init());
|
|
124
|
+
pending.push(uut.init());
|
|
125
|
+
uut.unload();
|
|
126
|
+
expect(uut.isActive).to.be.false;
|
|
127
|
+
|
|
128
|
+
await Promise.all(pending);
|
|
129
|
+
await waitForPromisesToFinish();
|
|
130
|
+
expect(uut.isActive).to.be.false;
|
|
131
|
+
|
|
132
|
+
// and addition unload operations should not change anything
|
|
133
|
+
uut.unload();
|
|
134
|
+
expect(uut.isActive).to.be.false;
|
|
135
|
+
uut.unload();
|
|
136
|
+
uut.unload();
|
|
137
|
+
expect(uut.isActive).to.be.false;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('when calling unload multiple times', async () => {
|
|
141
|
+
const pending = [];
|
|
142
|
+
pending.push(uut.init());
|
|
143
|
+
pending.push(uut.init());
|
|
144
|
+
pending.push(uut.init());
|
|
145
|
+
uut.unload();
|
|
146
|
+
expect(uut.isActive).to.be.false;
|
|
147
|
+
uut.unload();
|
|
148
|
+
expect(uut.isActive).to.be.false;
|
|
149
|
+
|
|
150
|
+
await Promise.all(pending);
|
|
151
|
+
await waitForPromisesToFinish();
|
|
152
|
+
expect(uut.isActive).to.be.false;
|
|
153
|
+
|
|
154
|
+
// and addition unload operations should not change anything
|
|
155
|
+
uut.unload();
|
|
156
|
+
expect(uut.isActive).to.be.false;
|
|
157
|
+
uut.unload();
|
|
158
|
+
uut.unload();
|
|
159
|
+
expect(uut.isActive).to.be.false;
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('should make ensure that "init" at the end always wins', () => {
|
|
164
|
+
it('in a simple example', async () => {
|
|
165
|
+
const pending = [];
|
|
166
|
+
pending.push(uut.init());
|
|
167
|
+
uut.unload();
|
|
168
|
+
expect(uut.isActive).to.be.false;
|
|
169
|
+
pending.push(uut.init());
|
|
170
|
+
|
|
171
|
+
await Promise.all([pending]);
|
|
172
|
+
await waitForPromisesToFinish();
|
|
173
|
+
expect(uut.isActive).to.be.true;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('in a complex example', async () => {
|
|
177
|
+
const pending = [];
|
|
178
|
+
pending.push(uut.init());
|
|
179
|
+
uut.unload();
|
|
180
|
+
expect(uut.isActive).to.be.false;
|
|
181
|
+
pending.push(uut.init());
|
|
182
|
+
pending.push(uut.init());
|
|
183
|
+
uut.unload();
|
|
184
|
+
expect(uut.isActive).to.be.false;
|
|
185
|
+
pending.push(uut.init());
|
|
186
|
+
pending.push(uut.init());
|
|
187
|
+
uut.unload();
|
|
188
|
+
expect(uut.isActive).to.be.false;
|
|
189
|
+
uut.unload();
|
|
190
|
+
expect(uut.isActive).to.be.false;
|
|
191
|
+
pending.push(uut.init());
|
|
192
|
+
|
|
193
|
+
await Promise.all([pending]);
|
|
194
|
+
await waitForPromisesToFinish();
|
|
195
|
+
expect(uut.isActive).to.be.true;
|
|
196
|
+
|
|
197
|
+
await uut.init();
|
|
198
|
+
expect(uut.isActive).to.be.true;
|
|
199
|
+
|
|
200
|
+
await uut.init();
|
|
201
|
+
expect(uut.isActive).to.be.true;
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { deleteDB } from 'idb';
|
|
14
|
+
|
|
15
|
+
import Database from '../../src/request/database.js';
|
|
16
|
+
|
|
17
|
+
describe('Database', function () {
|
|
18
|
+
let database;
|
|
19
|
+
|
|
20
|
+
beforeEach(async function () {
|
|
21
|
+
if (database) {
|
|
22
|
+
await database.unload();
|
|
23
|
+
await deleteDB(database.tableName);
|
|
24
|
+
}
|
|
25
|
+
database = new Database();
|
|
26
|
+
await database.init();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('key-value storage', function () {
|
|
30
|
+
const key = 'test';
|
|
31
|
+
|
|
32
|
+
it('saves strings', async function () {
|
|
33
|
+
const value = 'test';
|
|
34
|
+
await database.set(key, value);
|
|
35
|
+
return expect(database.get(key)).to.eventually.equal(value);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('saves numbers', async function () {
|
|
39
|
+
const value = Date.now();
|
|
40
|
+
await database.set(key, value);
|
|
41
|
+
return expect(database.get(key)).to.eventually.equal(value);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('saves objects', async function () {
|
|
45
|
+
const value = {
|
|
46
|
+
a: 1,
|
|
47
|
+
b: '2',
|
|
48
|
+
};
|
|
49
|
+
await database.set(key, value);
|
|
50
|
+
return expect(database.get(key)).to.eventually.deep.equal(value);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('saves ArrayBuffers', async function () {
|
|
54
|
+
const value = new Uint8Array([0, 1, 2, 3]);
|
|
55
|
+
await database.set(key, value.buffer);
|
|
56
|
+
return expect(database.get(key)).to.eventually.deep.equal(value.buffer);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
|
|
14
|
+
import probData from '../../src/request/resources/prob.js';
|
|
15
|
+
import {
|
|
16
|
+
isMostlyNumeric,
|
|
17
|
+
HashProb,
|
|
18
|
+
shouldCheckToken,
|
|
19
|
+
} from '../../src/request/hash.js';
|
|
20
|
+
|
|
21
|
+
const nonNumeric = ['', 'ithinkthereis1numberhere', '1240abcd'];
|
|
22
|
+
const mostlyNumeric = ['4902', '1024x768'];
|
|
23
|
+
|
|
24
|
+
describe('request/hash', function () {
|
|
25
|
+
describe('#isMostlyNumeric', function () {
|
|
26
|
+
nonNumeric.forEach((testInput) => {
|
|
27
|
+
it(`returns false for "${testInput}"`, function () {
|
|
28
|
+
chai.expect(isMostlyNumeric(testInput)).to.eql(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
mostlyNumeric.forEach((testInput) => {
|
|
33
|
+
it(`returns true for "${testInput}"`, function () {
|
|
34
|
+
chai.expect(isMostlyNumeric(testInput)).to.eql(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('HashProb', function () {
|
|
40
|
+
let hashProb;
|
|
41
|
+
|
|
42
|
+
beforeEach(function () {
|
|
43
|
+
hashProb = new HashProb();
|
|
44
|
+
hashProb._update(probData);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const notHash = [
|
|
48
|
+
'',
|
|
49
|
+
'Firefox',
|
|
50
|
+
'cliqz.com', // a url
|
|
51
|
+
'anti-tracking',
|
|
52
|
+
'front/ng',
|
|
53
|
+
'javascript',
|
|
54
|
+
'callback',
|
|
55
|
+
'compress-format-enhance',
|
|
56
|
+
'compress%2Cformat%2Cenhance',
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const hashes = [
|
|
60
|
+
'04C2EAD03B',
|
|
61
|
+
'54f5095c96e',
|
|
62
|
+
'B62a15974a93',
|
|
63
|
+
'22163a4ff903',
|
|
64
|
+
'468x742',
|
|
65
|
+
'1021x952',
|
|
66
|
+
'1024x768',
|
|
67
|
+
'1440x900',
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
notHash.forEach(function (str) {
|
|
71
|
+
it(`'${str}' is not a hash`, function () {
|
|
72
|
+
chai.expect(hashProb.isHash(str)).to.be.false;
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
hashes.forEach(function (str) {
|
|
77
|
+
it(`'${str}' is a hash`, function () {
|
|
78
|
+
chai.expect(hashProb.isHash(str)).to.be.true;
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('shouldCheckToken', function () {
|
|
83
|
+
it('returns false for short tokens', () => {
|
|
84
|
+
chai.expect(shouldCheckToken(hashProb, 6, '1234')).to.be.false;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('returns false for timestamps', () => {
|
|
88
|
+
chai.expect(shouldCheckToken(hashProb, 6, `${Date.now()}`)).to.be.false;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('returns false for IP addresses', () => {
|
|
92
|
+
chai.expect(shouldCheckToken(hashProb, 6, '192.168.3.4')).to.be.false;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
notHash.forEach(function (str) {
|
|
96
|
+
it(`should not check '${str}'`, function () {
|
|
97
|
+
chai.expect(shouldCheckToken(hashProb, 6, str)).to.be.false;
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
hashes.forEach(function (str) {
|
|
102
|
+
it(`should check '${str}'`, function () {
|
|
103
|
+
chai.expect(shouldCheckToken(hashProb, 6, str)).to.be.true;
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|