Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved C2P Script Injection #528

Merged
merged 11 commits into from Apr 28, 2020

more code coverage

  • Loading branch information
christophertino committed Apr 26, 2020
commit f1249f5ba97ab44600128b38a7ba77955711315d
@@ -19,19 +19,22 @@ yarn-error.log
tools/i18n_results
tools/leet/*.json

# Cliqz
## Cliqz
cliqz/

# Tools
## Tools
tools/amo/*.zip

## JSDoc
docs/
jsdocs/
out/

#OSX
## Jest
coverage/

## OSX
.DS_Store

#Other Files
## Other Files
bug-list.md
@@ -81,7 +81,6 @@ export function fuzzyUrlMatcher(url, urls) {

for (let i = 0; i < urls.length; i++) {
const { host, path } = processFpeUrl(urls[i]);

if (host === tab_host) {
if (!path) {
log(`[fuzzyUrlMatcher] host (${host}) match`);
@@ -207,7 +206,7 @@ function _matchesRegex(src) {
}

/**
* Match a path part of a url agains the path property of database patterns section.
* Match a path part of a url against the path property of database patterns section.
* @private
*
* @param {string} src_path path part of an url
@@ -74,7 +74,7 @@ jest.mock('../../src/classes/Click2PlayDb', () => ({
}
}
}));
jest.mock('../../src/classes/bugDb', () => ({
jest.mock('../../src/classes/BugDb', () => ({
db: {
apps: {
464: [{
@@ -13,7 +13,7 @@

import bugDb from '../../src/classes/BugDb';
import conf from '../../src/classes/Conf';
import { isBug } from '../../src/utils/matcher';
import { isBug, fuzzyUrlMatcher } from '../../src/utils/matcher';

describe('src/utils/matcher.js', () => {
beforeAll(done => {
@@ -65,6 +65,9 @@ describe('src/utils/matcher.js', () => {
},
"path": {
"js/tracking.js": 13
},
"regex": {
15: "(googletagservices\\.com\\/.*\\.js)"
}
}
});
@@ -86,57 +89,85 @@ describe('src/utils/matcher.js', () => {

describe('testing isBug()', () => {
describe('testing basic pattern matching', () => {
test('host only tracker matching works', () => {
expect(isBug('https://gmodules.com/', 'example.com')).toBe(101);
});

test('host+path tracker matching works', () => {
return expect(isBug('https://apis.google.com/js/plusone.js', 'example.com')).toBe(1240);
expect(isBug('https://apis.google.com/js/plusone.js', 'example.com')).toBe(1240);
});

test('path only tracker matching works', () => {
return expect(isBug('https://apis.google.com/js/tracking.js', 'example.com')).toBe(13);
expect(isBug('https://apis.google.com/js/tracking.js', 'example.com')).toBe(13);
});

test('regex tracker matching works', () => {
expect(isBug('https://apis.google.com/js/tracking.js', 'example.com')).toBe(13);
});

test('pattern matching is case insensitive', () => {
return expect(isBug('https://APIS.Google.com/js/Tracking.js', 'example.com')).toBe(13);
expect(isBug('https://googletagservices.com/anything/tracker.js', 'example.com')).toBe(15);
expect(isBug('https://googletagservices.com/anything/tracker.css', 'example.com')).toBeFalsy();
});
});

describe('testing isBug() first party exceptions for twitter', () => {
const twitter_button = 'http://platform.twitter.com/widgets/';

test('first confirm Twitter Button is a tracker', () => {
return expect(isBug(twitter_button)).toBe(991);
expect(isBug(twitter_button)).toBe(991);
});

test('host-only first-party exception', () => {
return expect(isBug(twitter_button, 'https://twitter.com/ghostery')).toBeFalsy();
expect(isBug(twitter_button, 'https://twitter.com/ghostery')).toBeFalsy();
});

test('same exception on the same page URL as above, but with www', () => {
return expect(isBug(twitter_button, 'https://www.twitter.com/ghostery')).toBeFalsy();
expect(isBug(twitter_button, 'https://www.twitter.com/ghostery')).toBeFalsy();
});
});

describe('testing isBug() first party exceptions for google widgets', () => {
const google_widgets = 'http://gmodules.com/blah';

test('first confirm Google Widgets is a tracker', () => {
return expect(isBug(google_widgets)).toBe(101);
expect(isBug(google_widgets)).toBe(101);
});

test('host and exact path exception', () => {
return expect(isBug(google_widgets, 'http://google.com/ig')).toBeFalsy();
expect(isBug(google_widgets, 'http://google.com/ig')).toBeFalsy();
});
});

describe('testing isBug() first party exceptions for google plus one', () => {
const google_plus_one = 'https://apis.google.com/js/plusone.js';

test('first confirm Google +1 is a tracker', () => {
return expect(isBug(google_plus_one)).toBe(1240);
expect(isBug(google_plus_one)).toBe(1240);
});

test('host and fuzzy path exception', () => {
return expect(isBug(google_plus_one, 'https://chrome.google.com/webstore/detail/ghostery/mlomiejdfkolichcflejclcbmpeaniij?hl=en')).toBeFalsy();
expect(isBug(google_plus_one, 'https://chrome.google.com/webstore/detail/ghostery/mlomiejdfkolichcflejclcbmpeaniij?hl=en')).toBeFalsy();
});
});
});

describe('testing fuzzyUrlMatcher()', () => {
const urls = ['google.com', 'ghostery.com/products', 'example.com/page*'];

test('host match', () => {
expect(fuzzyUrlMatcher('https://google.com/analytics', urls)).toBeTruthy();
expect(fuzzyUrlMatcher('https://analytics.google.com/something', urls)).toBeFalsy();
});

test('host and path fuzzy match', () => {
expect(fuzzyUrlMatcher('https://example.com/page_anything', urls)).toBeTruthy();
expect(fuzzyUrlMatcher('https://example.com/p', urls)).toBeFalsy();
});

test('host and path match', () => {
expect(fuzzyUrlMatcher('https://ghostery.com/products', urls)).toBeTruthy();
expect(fuzzyUrlMatcher('https://ghostery.com/products1', urls)).toBeFalsy();
});
});
});
@@ -11,7 +11,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import { getJson, defineLazyProperty, semverCompare } from '../../src/utils/utils';
import { getJson, defineLazyProperty, processFpeUrl, semverCompare } from '../../src/utils/utils';

describe('tests for getJson()', () => {
// Tests for getJson()
@@ -62,6 +62,15 @@ describe('tests for defineLazyProperty()', () => {
test('property function is still lazy', () => expect(neverCalledSpy).not.toHaveBeenCalled());
});

describe('test for processFpeUrl()', () => {
test('host only', () => {
expect(processFpeUrl('ghostery.com')).toMatchObject({host: 'ghostery.com', path: ''});
});
test('host and path', () => {
expect(processFpeUrl('ghostery.com/products')).toMatchObject({host: 'ghostery.com', path: 'products'});
});
});

describe('tests for semverCompare()', () => {
const versions = [
'1.2.1',
ProTip! Use n and p to navigate between commits in a pull request.