@whotracksme/reporting 12.1.7 β†’ 12.1.8

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 CHANGED
@@ -1,3 +1,15 @@
1
+ # v12.1.8 (Wed Nov 18 2026)
2
+
3
+ #### πŸ› Bug Fix
4
+
5
+ - fix: bloom filter always returns false [#250](https://github.com/whotracksme/webextension-packages/pull/250) ([@philipp-classen](https://github.com/philipp-classen))
6
+
7
+ #### Authors: 1
8
+
9
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
10
+
11
+ ---
12
+
1
13
  # v12.1.7 (Fri Oct 23 2026)
2
14
 
3
15
  #### πŸ› Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "12.1.7",
3
+ "version": "12.1.8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./sanitizer": "./reporting/src/sanitizer.js",
@@ -309,9 +309,12 @@ export class BloomFilter {
309
309
  for (let i = this.generations.length - 1; i >= 0; i -= 1) {
310
310
  const generation = this.generations[i];
311
311
  const found = await generation.testMany(bitsToTest);
312
- if (found && updateTTLIfFound && i !== this.generations.length - 1) {
313
- const latestGeneration = this.generations[this.generations.length - 1];
314
- await latestGeneration.setMany(bitsToTest);
312
+ if (found) {
313
+ if (updateTTLIfFound && i !== this.generations.length - 1) {
314
+ const latestGeneration =
315
+ this.generations[this.generations.length - 1];
316
+ await latestGeneration.setMany(bitsToTest);
317
+ }
315
318
  return true;
316
319
  }
317
320
  }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * WhoTracks.Me
3
+ * https://whotracks.me/
4
+ *
5
+ * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at http://mozilla.org/MPL/2.0
10
+ */
11
+
12
+ import { expect } from 'chai';
13
+
14
+ import { BloomFilter } from '../src/bloom-filters.js';
15
+ import InMemoryDatabase from './helpers/in-memory-database.js';
16
+
17
+ const DAY = 24 * 60 * 60 * 1000;
18
+
19
+ describe('#BloomFilter', function () {
20
+ let database;
21
+
22
+ function newBloomFilter(options = {}) {
23
+ return new BloomFilter({
24
+ database,
25
+ name: 'test',
26
+ partitions: [1009, 1013, 1019],
27
+ ...options,
28
+ });
29
+ }
30
+
31
+ // simulates a restart of the extension at the given time
32
+ async function restartBloomFilter(oldBloomFilter, { now, ...options }) {
33
+ await Promise.all(oldBloomFilter.generations.map((gen) => gen.flush()));
34
+ const uut = newBloomFilter(options);
35
+ await uut.ready(now);
36
+ return uut;
37
+ }
38
+
39
+ beforeEach(function () {
40
+ database = new InMemoryDatabase();
41
+ });
42
+
43
+ describe('#mightContain', function () {
44
+ it('should not find a value in an empty filter', async function () {
45
+ const uut = newBloomFilter();
46
+ expect(await uut.mightContain('foo')).to.eql(false);
47
+ });
48
+
49
+ it('should find a value that was added', async function () {
50
+ const uut = newBloomFilter();
51
+ await uut.add('foo');
52
+
53
+ expect(await uut.mightContain('foo')).to.eql(true);
54
+ expect(await uut.mightContain('bar')).to.eql(false);
55
+ });
56
+
57
+ it('should find a value that was added if there is only one generation', async function () {
58
+ const uut = newBloomFilter({
59
+ maxGenerations: 1,
60
+ rotationIntervalInMs: 0,
61
+ });
62
+ await uut.add('foo');
63
+
64
+ expect(await uut.mightContain('foo')).to.eql(true);
65
+ expect(await uut.mightContain('bar')).to.eql(false);
66
+ });
67
+
68
+ it('should find a value after a restart', async function () {
69
+ const now = Date.now();
70
+ let uut = newBloomFilter();
71
+ await uut.ready(now);
72
+ await uut.add('foo');
73
+
74
+ uut = await restartBloomFilter(uut, { now: now + DAY });
75
+ expect(uut.generations).to.have.lengthOf(1);
76
+ expect(await uut.mightContain('foo')).to.eql(true);
77
+ expect(await uut.mightContain('bar')).to.eql(false);
78
+ });
79
+
80
+ describe('with a value in an older generation', function () {
81
+ const rotationIntervalInMs = 30 * DAY;
82
+ let uut;
83
+
84
+ beforeEach(async function () {
85
+ const now = Date.now();
86
+ uut = newBloomFilter({ rotationIntervalInMs });
87
+ await uut.ready(now);
88
+ await uut.add('foo');
89
+
90
+ uut = await restartBloomFilter(uut, {
91
+ now: now + rotationIntervalInMs + DAY,
92
+ rotationIntervalInMs,
93
+ });
94
+ expect(uut.generations).to.have.lengthOf(2);
95
+ });
96
+
97
+ it('should find the value', async function () {
98
+ expect(await uut.mightContain('foo')).to.eql(true);
99
+ expect(await uut.mightContain('bar')).to.eql(false);
100
+ });
101
+
102
+ it('should not copy the value to the latest generation by default', async function () {
103
+ expect(await uut.mightContain('foo')).to.eql(true);
104
+
105
+ const bits = uut._computeBits('foo');
106
+ expect(await uut.generations[1].testMany(bits)).to.eql(false);
107
+ });
108
+
109
+ it('should copy the value to the latest generation with "updateTTLIfFound"', async function () {
110
+ const found = await uut.mightContain('foo', { updateTTLIfFound: true });
111
+ expect(found).to.eql(true);
112
+
113
+ const bits = uut._computeBits('foo');
114
+ expect(await uut.generations[1].testMany(bits)).to.eql(true);
115
+ });
116
+ });
117
+ });
118
+ });
@@ -8,6 +8,7 @@ import './http.spec.js';
8
8
  import './patterns.spec.js';
9
9
  import './patterns-updater.spec.js';
10
10
  import './job-scheduler.spec.js';
11
+ import './bloom-filters.spec.js';
11
12
  import './country-provider.spec.js';
12
13
  import './persisted-hashes.spec.js';
13
14
  import './doublefetch-unbreak.spec.js';
@@ -24,6 +25,7 @@ import './persisted-counters.spec.js';
24
25
  import './popularity-estimator.spec.js';
25
26
  import './popularity-vote-handler.spec.js';
26
27
  import './popularity-vote-sanitizer.spec.js';
28
+ import './quorum-checker.spec.js';
27
29
  import './random.spec.js';
28
30
  import './sanitizer.spec.js';
29
31
  import './search-extractor.spec.js';
@@ -0,0 +1,85 @@
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 QuorumChecker from '../src/quorum-checker.js';
16
+ import { BloomFilter } from '../src/bloom-filters.js';
17
+ import InMemoryDatabase from './helpers/in-memory-database.js';
18
+
19
+ describe('#QuorumChecker', function () {
20
+ let uut;
21
+ let fetchStub;
22
+ let sentIncrements;
23
+
24
+ beforeEach(function () {
25
+ // quorum config endpoint
26
+ fetchStub = sinon.stub(globalThis, 'fetch').callsFake(async () => ({
27
+ ok: true,
28
+ json: async () => ({ oc: 42 }),
29
+ }));
30
+
31
+ sentIncrements = [];
32
+ const communication = {
33
+ async sendInstant({ path, payload }) {
34
+ if (path === 'incrquorum') {
35
+ sentIncrements.push(payload);
36
+ }
37
+ return { ok: true, json: async () => ({ result: false }) };
38
+ },
39
+ };
40
+
41
+ let persistedConfig;
42
+ const storage = {
43
+ async get() {
44
+ return persistedConfig;
45
+ },
46
+ async set(_, value) {
47
+ persistedConfig = value;
48
+ },
49
+ };
50
+
51
+ uut = new QuorumChecker({
52
+ config: { SAFE_QUORUM_CONFIG_ENDPOINT: 'https://quorum.test/config' },
53
+ storage,
54
+ storageKey: 'quorum_check',
55
+ bloomFilter: new BloomFilter({
56
+ database: new InMemoryDatabase(),
57
+ name: 'test',
58
+ partitions: [1009, 1013, 1019],
59
+ }),
60
+ communication,
61
+ });
62
+ });
63
+
64
+ afterEach(function () {
65
+ fetchStub.restore();
66
+ });
67
+
68
+ describe('#sendQuorumIncrement', function () {
69
+ it('should vote only once for the same text', async function () {
70
+ const text = 'https://example.test/foo';
71
+ await uut.sendQuorumIncrement({ text });
72
+ await uut.sendQuorumIncrement({ text });
73
+ await uut.sendQuorumIncrement({ text });
74
+
75
+ expect(sentIncrements).to.have.lengthOf(1);
76
+ });
77
+
78
+ it('should vote for each text', async function () {
79
+ await uut.sendQuorumIncrement({ text: 'https://example.test/foo' });
80
+ await uut.sendQuorumIncrement({ text: 'https://example.test/bar' });
81
+
82
+ expect(sentIncrements).to.have.lengthOf(2);
83
+ });
84
+ });
85
+ });