@whotracksme/reporting 5.1.29 → 5.1.31

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/package.json +1 -1
  3. package/reporting/example/index.js +2 -12
  4. package/reporting/example/manifests/chromium.json +1 -0
  5. package/reporting/snapshots/0001/snapshot.json +2933 -2933
  6. package/reporting/snapshots/0002/snapshot.json +2101 -1901
  7. package/reporting/snapshots/0003/events.log.br +0 -0
  8. package/reporting/snapshots/0003/snapshot.json +855 -0
  9. package/reporting/snapshots/0004/events.log.br +0 -0
  10. package/reporting/snapshots/0004/snapshot.json +802 -0
  11. package/reporting/src/hash-detector.js +1 -1
  12. package/reporting/src/index.js +1 -2
  13. package/reporting/src/request/config.js +9 -4
  14. package/reporting/src/request/{hash.js → hash/index.js} +3 -3
  15. package/reporting/src/request/index.js +427 -496
  16. package/reporting/src/{webrequest-pipeline → request}/page-store.js +62 -98
  17. package/reporting/src/request/qs-whitelist2.js +0 -2
  18. package/reporting/src/request/steps/cookie-context.js +6 -5
  19. package/reporting/src/request/steps/oauth-detector.js +3 -24
  20. package/reporting/src/request/steps/page-logger.js +3 -4
  21. package/reporting/src/request/steps/token-checker/token-domain.js +1 -1
  22. package/reporting/src/request/steps/token-examiner.js +3 -4
  23. package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +52 -68
  24. package/reporting/src/request/steps/token-telemetry/index.js +86 -113
  25. package/reporting/src/request/steps/token-telemetry/key-pipeline.js +3 -2
  26. package/reporting/src/request/steps/token-telemetry/token-pipeline.js +3 -2
  27. package/reporting/src/request/utils/temp-set.js +2 -4
  28. package/reporting/src/request/{time.js → utils/time.js} +0 -5
  29. package/reporting/src/request/utils/tlds.js +1 -11
  30. package/reporting/src/request/{utils.js → utils/utils.js} +9 -0
  31. package/reporting/src/{webrequest-pipeline/webrequest-context.js → request/utils/webrequest.js} +85 -10
  32. package/reporting/src/utils/url.js +0 -25
  33. package/reporting/test/helpers/scenarios.js +17 -2
  34. package/reporting/test/index.js +3 -8
  35. package/reporting/test/request/{hash.spec.js → hash/index.spec.js} +2 -2
  36. package/reporting/test/request/index.spec.js +25 -66
  37. package/reporting/test/{request-reporter.test.js → request/index.test.js} +13 -17
  38. package/reporting/test/{webrequest-pipeline → request}/page-store.test.js +1 -1
  39. package/reporting/test/request/steps/oauth-detector.spec.js +15 -25
  40. package/reporting/test/request/{utils.spec.js → utils/utils.spec.js} +2 -2
  41. package/reporting/test/utils/url.spec.js +1 -26
  42. package/reporting/src/request/page-telemetry.js +0 -42
  43. package/reporting/src/request/steps/subdomain-check.js +0 -34
  44. package/reporting/src/request/utils/subject.js +0 -37
  45. package/reporting/src/request-reporter.js +0 -111
  46. package/reporting/src/utils/pacemaker.js +0 -279
  47. package/reporting/src/webrequest-pipeline/cname-uncloak.js +0 -110
  48. package/reporting/src/webrequest-pipeline/index.js +0 -286
  49. package/reporting/src/webrequest-pipeline/logger.js +0 -14
  50. package/reporting/src/webrequest-pipeline/pipeline.js +0 -249
  51. package/reporting/src/webrequest-pipeline/utils/webrequest.js +0 -119
  52. package/reporting/test/utils/pacemaker.spec.js +0 -222
  53. package/reporting/test/webrequest-pipeline/index.test.js +0 -160
  54. package/reporting/test/webrequest-pipeline/pipeline.spec.js +0 -251
  55. /package/reporting/src/request/{resources → hash}/prob.js +0 -0
@@ -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 Config from '../../src/request/config.js';
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,36 +91,24 @@ describe('request/index', function () {
101
91
  return '';
102
92
  },
103
93
  };
104
- const db = new Database();
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: {},
126
104
  getBrowserInfo: () => ({ name: 'xx' }),
127
105
  },
128
106
  );
129
- await attrack.init(config);
107
+ await attrack.init();
130
108
  await attrack.qs_whitelist.initPromise;
131
- config.cookieEnabled = false;
132
- config.qsEnabled = false;
133
- config.placeHolder = '<removed>';
109
+ attrack.config.cookieEnabled = false;
110
+ attrack.config.qsEnabled = false;
111
+ attrack.config.placeHolder = '<removed>';
134
112
  });
135
113
 
136
114
  afterEach(() => {
@@ -143,18 +121,18 @@ describe('request/index', function () {
143
121
  chrome.tabs.onCreated.dispatch(pageSpec.tab);
144
122
  return {
145
123
  onBeforeRequest: pageSpec.onBeforeRequest.map(function (reqData) {
146
- const response = pipeline.onBeforeRequest(reqData);
124
+ const response = attrack.onBeforeRequest(reqData);
147
125
  return { url: reqData.url, response };
148
126
  }),
149
127
  onBeforeSendHeaders: pageSpec.onBeforeSendHeaders.map(function (reqData) {
150
128
  reqData.requestHeaders = mockRequestHeaders;
151
- const response = pipeline.onBeforeSendHeaders(reqData);
129
+ const response = attrack.onBeforeSendHeaders(reqData);
152
130
  return { url: reqData.url, response };
153
131
  }),
154
132
  onHeadersReceived: pageSpec.onHeadersReceived.map(function (reqData) {
155
133
  reqData.requestHeaders = mockRequestHeaders;
156
134
  reqData.responseHeaders = mockResponseHeaders;
157
- const response = pipeline.onHeadersReceived(reqData);
135
+ const response = attrack.onHeadersReceived(reqData);
158
136
  return { url: reqData.url, response };
159
137
  }),
160
138
  };
@@ -167,7 +145,7 @@ describe('request/index', function () {
167
145
  describe('cookie blocking', function () {
168
146
  describe('cookie blocking disabled', function () {
169
147
  beforeEach(function () {
170
- config.cookieEnabled = false;
148
+ attrack.config.cookieEnabled = false;
171
149
  });
172
150
 
173
151
  it('allows all cookies', function () {
@@ -179,7 +157,7 @@ describe('request/index', function () {
179
157
 
180
158
  describe('cookie blocking enabled', function () {
181
159
  beforeEach(function () {
182
- config.cookieEnabled = true;
160
+ attrack.config.cookieEnabled = true;
183
161
  });
184
162
 
185
163
  it('blocks third party cookies', function () {
@@ -199,7 +177,7 @@ describe('request/index', function () {
199
177
 
200
178
  context('QS blocking', function () {
201
179
  beforeEach(function () {
202
- config.qsEnabled = true;
180
+ attrack.config.qsEnabled = true;
203
181
  });
204
182
 
205
183
  it('allows query strings on domains not in the tracker list', function () {
@@ -217,8 +195,8 @@ describe('request/index', function () {
217
195
  key = md5('uid');
218
196
  trackerHash = truncatedHash('127.0.0.1');
219
197
  attrack.qs_whitelist.addSafeToken(trackerHash, '');
220
- config.tokenDomainCountThreshold = 2;
221
- attrack.pipelineSteps.tokenChecker.tokenDomain.clear();
198
+ attrack.config.tokenDomainCountThreshold = 2;
199
+ attrack.tokenChecker.tokenDomain.clear();
222
200
  });
223
201
 
224
202
  it('allows QS first time on tracker', function () {
@@ -239,7 +217,7 @@ describe('request/index', function () {
239
217
  }
240
218
 
241
219
  beforeEach(function () {
242
- config.tokenDomainCountThreshold = 0;
220
+ attrack.config.tokenDomainCountThreshold = 0;
243
221
  });
244
222
 
245
223
  it('blocks long tokens on tracker domain', function () {
@@ -280,26 +258,17 @@ describe('request/index', function () {
280
258
  const uid = '04C2EAD03BAB7F5E-2E85855CF4C75134';
281
259
 
282
260
  beforeEach(function () {
283
- config.qsEnabled = true;
261
+ attrack.config.qsEnabled = true;
284
262
  attrack.qs_whitelist.addSafeToken(truncatedHash('tracker.com'), '');
285
- config.tokenDomainCountThreshold = 0; // block first time
286
- return attrack.initPipeline();
263
+ attrack.config.tokenDomainCountThreshold = 0; // block first time
287
264
  });
288
265
 
289
266
  it('removes all occurances of uid in the request', function () {
290
- const mainDoc = pipeline.onBeforeRequest({
291
- tabId: 34,
292
- frameId: 0,
293
- parentFrameId: -1,
294
- method: 'GET',
295
- type: 'main_frame',
267
+ chrome.tabs.onCreated.dispatch({
268
+ id: 34,
296
269
  url: 'http://cliqztest.com/',
297
- requestHeaders: mockRequestHeaders,
298
270
  });
299
- chai.expect(mainDoc).to.not.have.property('cancel');
300
- chai.expect(mainDoc).to.not.have.property('redirectUrl');
301
- chai.expect(mainDoc).to.not.have.property('requestHeaders');
302
- const response = pipeline.onBeforeRequest({
271
+ const response = attrack.onBeforeRequest({
303
272
  tabId: 34,
304
273
  frameId: 0,
305
274
  parentFrameId: -1,
@@ -318,21 +287,11 @@ describe('request/index', function () {
318
287
  });
319
288
 
320
289
  it('removes also after subsequent redirect with same uid', function () {
321
- const mainDoc = pipeline.onBeforeRequest({
322
- tabId: 34,
323
- frameId: 0,
324
- parentFrameId: -1,
325
- method: 'GET',
326
- type: 'main_frame',
290
+ chrome.tabs.onCreated.dispatch({
291
+ id: 34,
327
292
  url: 'http://cliqztest.com/',
328
- requestHeaders: mockRequestHeaders,
329
- originUrl: '',
330
- tabUrl: '',
331
293
  });
332
- chai.expect(mainDoc).to.not.have.property('cancel');
333
- chai.expect(mainDoc).to.not.have.property('redirectUrl');
334
- chai.expect(mainDoc).to.not.have.property('requestHeaders');
335
- let response = pipeline.onBeforeRequest({
294
+ let response = attrack.onBeforeRequest({
336
295
  tabId: 34,
337
296
  frameId: 0,
338
297
  parentFrameId: -1,
@@ -350,7 +309,7 @@ describe('request/index', function () {
350
309
  chai.expect(response.redirectUrl).to.not.contain(uid);
351
310
  chai.expect(response.redirectUrl).to.not.contain(encodeURIComponent(uid));
352
311
 
353
- response = pipeline.onBeforeRequest({
312
+ response = attrack.onBeforeRequest({
354
313
  tabId: 34,
355
314
  frameId: 0,
356
315
  parentFrameId: -1,
@@ -21,12 +21,11 @@ import {
21
21
  playSnapshotScenario,
22
22
  recordSnapshot,
23
23
  readSnapshot,
24
- } from './helpers/scenarios.js';
25
- import { base64ToArrayBuffer } from './helpers/fetch-mock.js';
24
+ } from '../helpers/scenarios.js';
25
+ import { base64ToArrayBuffer } from '../helpers/fetch-mock.js';
26
26
 
27
- import { setLogLevel } from '../src/logger.js';
28
- import RequestReporter from '../src/request-reporter.js';
29
- import WebRequestPipeline from '../src/webrequest-pipeline/index.js';
27
+ import { setLogLevel } from '../../src/logger.js';
28
+ import RequestReporter from '../../src/request/index.js';
30
29
 
31
30
  const config = {
32
31
  configUrl: 'config',
@@ -74,6 +73,7 @@ describe('RequestReporter', function () {
74
73
  beforeEach(function () {
75
74
  chrome.flush();
76
75
  chrome.storage.session.get.yields({});
76
+ chrome.tabs.query.returns([]);
77
77
  });
78
78
 
79
79
  after(function () {
@@ -109,22 +109,18 @@ describe('RequestReporter', function () {
109
109
  },
110
110
  trustedClock,
111
111
  };
112
- const webRequestPipeline = new WebRequestPipeline();
113
- await webRequestPipeline.init();
114
112
  reporter = new RequestReporter(config, {
115
113
  communication,
116
- webRequestPipeline,
117
114
  trustedClock,
118
115
  getBrowserInfo: () => ({ name: 'xx' }),
119
116
  countryProvider: { getSafeCountryCode: () => 'en' },
120
117
  });
121
118
  await reporter.init();
122
- await reporter.requestMonitor.qs_whitelist.initPromise;
119
+ await reporter.qs_whitelist.initPromise;
123
120
  });
124
121
 
125
122
  afterEach(function () {
126
123
  reporter.unload();
127
- reporter.webRequestPipeline.unload();
128
124
  reporter = undefined;
129
125
  clock.restore();
130
126
  delete globalThis.indexedDB;
@@ -138,11 +134,11 @@ describe('RequestReporter', function () {
138
134
  });
139
135
  await clock.runToLast();
140
136
  expect(
141
- reporter.webRequestPipeline.pageStore.checkIfEmpty(),
137
+ reporter.pageStore.checkIfEmpty(),
142
138
  ).to.be.false;
143
139
  expect(seenTabIds).to.have.property('size', 1);
144
140
  const tabId = seenTabIds.values().next().value;
145
- const tab = reporter.webRequestPipeline.pageStore.getPageForRequest({
141
+ const tab = reporter.pageStore.getPageForRequest({
146
142
  tabId,
147
143
  frameId: 0,
148
144
  });
@@ -158,11 +154,11 @@ describe('RequestReporter', function () {
158
154
  });
159
155
  await clock.runToLast();
160
156
  expect(
161
- reporter.webRequestPipeline.pageStore.checkIfEmpty(),
157
+ reporter.pageStore.checkIfEmpty(),
162
158
  ).to.be.false;
163
159
  expect(seenTabIds).to.have.property('size', 1);
164
160
  const tabId = seenTabIds.values().next().value;
165
- const tab = reporter.webRequestPipeline.pageStore.getPageForRequest({
161
+ const tab = reporter.pageStore.getPageForRequest({
166
162
  tabId,
167
163
  frameId: 0,
168
164
  });
@@ -281,7 +277,7 @@ describe('RequestReporter', function () {
281
277
  }
282
278
  }
283
279
 
284
- for (const snapshotName of ['0001', '0002']) {
280
+ for (const snapshotName of ['0001', '0002', '0003', '0004']) {
285
281
  it(snapshotName, async function () {
286
282
  const messages = [];
287
283
  communicationEmiter.addListener('send', (message) =>
@@ -291,10 +287,10 @@ describe('RequestReporter', function () {
291
287
 
292
288
  // run twice to allow token telemetry to trigger
293
289
  playSnapshotScenario(chrome, snapshotName, {
294
- rewriteUrls: { 'onet.pl': 'wp.pl' },
290
+ rewriteUrls: { 'onet.pl': 'wp.pl', 'soundcloud.com': 'google.com' },
295
291
  });
296
292
  await processRunloopUntil(
297
- reporter.requestMonitor.pipelineSteps.tokenTelemetry
293
+ reporter.tokenTelemetry
298
294
  .NEW_ENTRY_MIN_AGE,
299
295
  );
300
296
 
@@ -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/webrequest-pipeline/page-store.js';
16
+ import PageStore from '../../src/request/page-store.js';
17
17
 
18
18
  describe('PageStore', function () {
19
19
  before(function () {
@@ -74,15 +74,11 @@ describe('request/steps/oauth-detector', function () {
74
74
  await detectorInstance.init();
75
75
  });
76
76
 
77
- afterEach(function () {
78
- detectorInstance.unload();
79
- });
80
-
81
77
  it('registers clicks on tabs', (done) => {
82
78
  const tab = 5;
83
79
  const url = 'https://cliqz.com';
84
80
  const sender = mockSender(tab, url);
85
- detectorInstance.recordClick(null, '', '', sender);
81
+ detectorInstance.recordClick(sender);
86
82
  delayedTest(
87
83
  () => {
88
84
  chai
@@ -102,8 +98,8 @@ describe('request/steps/oauth-detector', function () {
102
98
  const tab = 5;
103
99
  const url1 = 'https://cliqz.com';
104
100
  const url2 = 'https://ghostery.com';
105
- detectorInstance.recordClick(null, '', '', mockSender(tab, url1));
106
- detectorInstance.recordClick(null, '', '', mockSender(tab, url2));
101
+ detectorInstance.recordClick(mockSender(tab, url1));
102
+ detectorInstance.recordClick(mockSender(tab, url2));
107
103
  delayedTest(
108
104
  () => {
109
105
  chai
@@ -124,8 +120,8 @@ describe('request/steps/oauth-detector', function () {
124
120
  const tab2 = 6;
125
121
  const url1 = 'https://cliqz.com';
126
122
  const url2 = 'https://ghostery.com';
127
- detectorInstance.recordClick(null, '', '', mockSender(tab1, url1));
128
- detectorInstance.recordClick(null, '', '', mockSender(tab2, url2));
123
+ detectorInstance.recordClick(mockSender(tab1, url1));
124
+ detectorInstance.recordClick(mockSender(tab2, url2));
129
125
  delayedTest(
130
126
  () => {
131
127
  chai
@@ -146,7 +142,7 @@ describe('request/steps/oauth-detector', function () {
146
142
  const tab = 5;
147
143
  const url = 'https://cliqz.com';
148
144
  const sender = mockSender(tab, url);
149
- detectorInstance.recordClick(null, '', '', sender);
145
+ detectorInstance.recordClick(sender);
150
146
  delayedTest(
151
147
  () => {
152
148
  chai
@@ -165,10 +161,9 @@ describe('request/steps/oauth-detector', function () {
165
161
  const tab2 = 6;
166
162
  const url1 = 'https://cliqz.com';
167
163
  const url2 = 'https://ghostery.com';
168
- detectorInstance.recordClick(null, '', '', mockSender(tab1, url1));
164
+ detectorInstance.recordClick(mockSender(tab1, url1));
169
165
  setTimeout(
170
- () =>
171
- detectorInstance.recordClick(null, '', '', mockSender(tab2, url2)),
166
+ () => detectorInstance.recordClick(mockSender(tab2, url2)),
172
167
  10,
173
168
  );
174
169
  delayedTest(
@@ -191,11 +186,10 @@ describe('request/steps/oauth-detector', function () {
191
186
  const tab2 = 6;
192
187
  const url1 = 'https://cliqz.com';
193
188
  const url2 = 'https://ghostery.com';
194
- detectorInstance.recordClick(null, '', '', mockSender(tab1, url1));
195
- detectorInstance.recordClick(null, '', '', mockSender(tab2, url2));
189
+ detectorInstance.recordClick(mockSender(tab1, url1));
190
+ detectorInstance.recordClick(mockSender(tab2, url2));
196
191
  setTimeout(
197
- () =>
198
- detectorInstance.recordClick(null, '', '', mockSender(tab1, url1)),
192
+ () => detectorInstance.recordClick(mockSender(tab1, url1)),
199
193
  10,
200
194
  );
201
195
  delayedTest(
@@ -236,10 +230,6 @@ describe('request/steps/oauth-detector', function () {
236
230
  await detectorInstance.init();
237
231
  });
238
232
 
239
- afterEach(function () {
240
- detectorInstance.unload();
241
- });
242
-
243
233
  it('returns true when there has been no activity and the URL contains "/oauth"', () => {
244
234
  const state = mockState(
245
235
  5,
@@ -261,7 +251,7 @@ describe('request/steps/oauth-detector', function () {
261
251
  it('returns true when there is only a click', (done) => {
262
252
  const tab = 5;
263
253
  const tabUrl = 'https://cliqz.com/';
264
- detectorInstance.recordClick(null, '', '', mockSender(tab, tabUrl));
254
+ detectorInstance.recordClick(mockSender(tab, tabUrl));
265
255
  const state = mockState(tab, 'https://auth.ghostery.com/oauth', tabUrl);
266
256
  delayedTest(
267
257
  () => {
@@ -275,7 +265,7 @@ describe('request/steps/oauth-detector', function () {
275
265
  it('returns false with click and page', (done) => {
276
266
  const tab = 5;
277
267
  const tabUrl = 'https://cliqz.com/';
278
- detectorInstance.recordClick(null, '', '', mockSender(tab, tabUrl));
268
+ detectorInstance.recordClick(mockSender(tab, tabUrl));
279
269
  const fullPageState = mockState(
280
270
  tab + 1,
281
271
  'https://auth.ghostery.com/',
@@ -296,7 +286,7 @@ describe('request/steps/oauth-detector', function () {
296
286
  it('returns true if page domain does not match', (done) => {
297
287
  const tab = 5;
298
288
  const tabUrl = 'https://cliqz.com/';
299
- detectorInstance.recordClick(null, '', '', mockSender(tab, tabUrl));
289
+ detectorInstance.recordClick(mockSender(tab, tabUrl));
300
290
  const fullPageState = mockState(
301
291
  tab + 1,
302
292
  'https://www.ghostery.com/',
@@ -318,7 +308,7 @@ describe('request/steps/oauth-detector', function () {
318
308
  const tab = 5;
319
309
  const tabUrl = 'https://cliqz.com/';
320
310
  const tabUrl2 = 'https://www.cliqz.com/';
321
- detectorInstance.recordClick(null, '', '', mockSender(tab, tabUrl));
311
+ detectorInstance.recordClick(mockSender(tab, tabUrl));
322
312
  const fullPageState = mockState(
323
313
  tab + 1,
324
314
  'https://www.ghostery.com/',
@@ -11,9 +11,9 @@
11
11
 
12
12
  import * as chai from 'chai';
13
13
 
14
- import { truncateDomain } from '../../src/request/utils';
14
+ import { truncateDomain } from '../../../src/request/utils/utils';
15
15
 
16
- describe('request/utils', function () {
16
+ describe('request/utils/utils', function () {
17
17
  describe('truncateDomain', function () {
18
18
  it('does not change domain which is already tld+1', () => {
19
19
  chai
@@ -11,7 +11,7 @@
11
11
 
12
12
  import * as chai from 'chai';
13
13
 
14
- import { getName, parse } from '../../src/utils/url';
14
+ import { parse } from '../../src/utils/url';
15
15
 
16
16
  const plainUrls = [
17
17
  {
@@ -521,31 +521,6 @@ function fillInSpec(spec) {
521
521
  }
522
522
 
523
523
  describe('utils/url', function () {
524
- describe('#getName', () => {
525
- it('return "null" for invalid URL', () => {
526
- chai.expect(getName(parse('foo'))).to.equal(null);
527
- });
528
-
529
- it('return "IP" if URL is ipv4', () => {
530
- chai.expect(getName(parse('https://1.1.1.1/'))).to.equal('IP');
531
- });
532
-
533
- // Currently not handled by '@cliqz/url-parser' but will be fixed soon.
534
- it.skip('return "IP" if URL is ipv6', () => {
535
- chai.expect(getName(parse('https://[::1]/'))).to.equal('IP');
536
- });
537
-
538
- it('handle localhost', () => {
539
- chai
540
- .expect(getName(parse('http://localhost/path')))
541
- .to.equal('localhost');
542
- });
543
-
544
- it('return domain without suffix', () => {
545
- chai.expect(getName(parse('https://sub.foo.co.uk'))).to.equal('foo');
546
- });
547
- });
548
-
549
524
  describe('#parse', () => {
550
525
  function testSpecArray(name, spec) {
551
526
  describe(name, function () {
@@ -1,42 +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 { truncatedHash } from '../md5.js';
13
- import { parse } from '../utils/url.js';
14
-
15
- function truncatePath(path) {
16
- // extract the first part of the page path
17
- const [prefix] = path.substring(1).split('/');
18
- return `/${prefix}`;
19
- }
20
-
21
- export default function buildPageLoadObject(page) {
22
- const urlParts = parse(page.url);
23
- const tps = { ...page.requestStats };
24
- return {
25
- hostname: truncatedHash(urlParts.hostname),
26
- path: truncatedHash(truncatePath(urlParts.path)),
27
- scheme: urlParts.scheme,
28
- c: 1,
29
- t: Math.round(page.destroyed - page.created),
30
- active: page.activeTime,
31
- counter: page.counter,
32
- ra: 0,
33
- tps,
34
- placeHolder: false,
35
- redirects: [],
36
- redirectsPlaceHolder: [],
37
- triggeringTree: {},
38
- tsv: '',
39
- tsv_id: false,
40
- frames: {},
41
- };
42
- }
@@ -1,34 +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
- export default class SubdomainCheck {
13
- constructor(config) {
14
- this.config = config;
15
- }
16
-
17
- checkBadSubdomain(state, response) {
18
- const subdomainRewriteRules = this.config.subdomainRewriteRules || {};
19
- const requestHost = state.urlParts.hostname;
20
- const rules = Object.keys(subdomainRewriteRules);
21
- for (let i = 0; i < rules.length; i += 1) {
22
- const rule = rules[i];
23
- if (requestHost.endsWith(rule)) {
24
- const newUrl = state.url.replace(
25
- requestHost,
26
- subdomainRewriteRules[rule],
27
- );
28
- response.redirectTo(newUrl);
29
- return false;
30
- }
31
- }
32
- return true;
33
- }
34
- }
@@ -1,37 +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 logger from '../../logger.js';
13
-
14
- export default class Subject {
15
- constructor() {
16
- this.listeners = new Set();
17
- }
18
-
19
- subscribe(callback) {
20
- this.listeners.add(callback);
21
- return {
22
- unsubscribe: () => {
23
- this.listeners.delete(callback);
24
- },
25
- };
26
- }
27
-
28
- pub(message) {
29
- this.listeners.forEach((listener) => {
30
- try {
31
- listener(message);
32
- } catch (e) {
33
- logger.error('Subject failed to notify listener', e);
34
- }
35
- });
36
- }
37
- }