Skip to content

Commit

Permalink
add test for tumblr link unwrapping firstparty script
Browse files Browse the repository at this point in the history
  • Loading branch information
ablanathtanalba committed Feb 3, 2021
1 parent f20df99 commit fcc658a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/tests/tests/firstparties.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let fb_wrap = 'https://facebook.com/l.php?u=' + destination;
let fb_xss = 'https://facebook.com/l.php?u=javascript://bad.site/%250Aalert(1)';
let g_wrap = 'https://www.google.com/url?q=' + destination;
let g_ping = '/url?url=' + destination;
let tumblr_wrap = 'https://t.umblr.com/redirect?z=' + destination;

function makeLink(href) {
let element = document.createElement('a');
Expand Down Expand Up @@ -164,4 +165,38 @@ QUnit.test('google search de-instrumentation', (assert) => {
fixture.appendChild(util_script);
});

QUnit.test('tumblr link unwrapping', (assert) => {
const NUM_CHECKS = 2,
done = assert.async();
assert.expect(NUM_CHECKS);

let fixture = document.getElementById('qunit-fixture');
let tumblr_link = makeLink(tumblr_wrap);

// create first-party utility script
let util_script = document.createElement('script');
util_script.src = '../js/firstparties/lib/utils.js';

// create the content script
let tumblr_script = document.createElement('script');
tumblr_script.src = '../js/firstparties/tumblr.js';
tumblr_script.onload = function() {
assert.equal(tumblr_link.href, destination, 'unwrapped tumblr link');
assert.ok(tumblr_link.rel.includes('noreferrer'),
'added noreferrer to tumblr link');

unstub();
done();
};

// after the utility script has finished loading, add the content script
util_script.onload = function() {
fixture.append(tumblr_script);
};

stub([tumblr_link], '/url?');
fixture.appendChild(tumblr_link);
fixture.appendChild(util_script);
});

}());

0 comments on commit fcc658a

Please sign in to comment.