diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:55:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:55:34 +0000 |
commit | 75417f5e3d32645859d94cec82255dc130ec4a2e (patch) | |
tree | 5fd46925c6b4a881c9208772ed8e5cc0588bc164 /src/tests/tests/multiDomainFirstParties.js | |
parent | Initial commit. (diff) | |
download | privacybadger-75417f5e3d32645859d94cec82255dc130ec4a2e.tar.xz privacybadger-75417f5e3d32645859d94cec82255dc130ec4a2e.zip |
Adding upstream version 2020.10.7.upstream/2020.10.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tests/tests/multiDomainFirstParties.js')
-rw-r--r-- | src/tests/tests/multiDomainFirstParties.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/tests/tests/multiDomainFirstParties.js b/src/tests/tests/multiDomainFirstParties.js new file mode 100644 index 0000000..4961b03 --- /dev/null +++ b/src/tests/tests/multiDomainFirstParties.js @@ -0,0 +1,73 @@ +(function () { + +QUnit.module("Multi-domain first parties"); + +let mdfp = require('multiDomainFP'); + +QUnit.test('isMultiDomainFirstParty test', function (assert) { + let testData = [ + ['foo.bar', 'yep.com', 'maybe.idk'], + ['related.com', 'larry.com'], + ]; + + let isMdfp = mdfp.makeIsMultiDomainFirstParty(mdfp.makeDomainLookup(testData)); + + assert.ok( + isMdfp('yep.com', 'maybe.idk'), + "these are related domains according to test data" + ); + assert.ok( + isMdfp('maybe.idk', 'yep.com'), + "the domains are related regardless of ordering" + ); + assert.ok( + isMdfp('related.com', 'larry.com'), + "these should also be related domains, from a different set in test data" + ); + assert.notOk( + isMdfp('yep.com', 'related.com'), + "these domains are both present in test data but should not be related" + ); + assert.notOk( + isMdfp('larry.com', 'yep.com'), + "these domains are also both present but should be unrelated" + ); + assert.notOk( + isMdfp('yep.com', 'google.com'), + "one of these domains is not in test data" + ); + assert.notOk( + isMdfp('reddit.com', 'eff.org'), + "both domains are not in test data" + ); +}); + +// "lint" our MDFP definitions to avoid accidentally adding PSL domains +// for example: +// https://github.com/EFForg/privacybadger/pull/1550#pullrequestreview-54480652 +QUnit.test('MDFP domains are all base domains', (assert) => { + for (let group of mdfp.multiDomainFirstPartiesArray) { + for (let domain of group) { + assert.ok( + window.getBaseDomain('fakesubdomain.' + domain) == domain, + domain + ' is a base domain (eTLD+1)' + ); + } + } +}); + +// lint for duplicates +QUnit.test('MDFP domains do not contain duplicates', (assert) => { + let domains = new Set(); + for (let group of mdfp.multiDomainFirstPartiesArray) { + for (let domain of group) { + assert.notOk( + domains.has(domain), + domain + ' does not appear more than once' + ); + domains.add(domain); + } + } +}); + +}()); |