Skip to content

Commit 9dc43d3

Browse files
add test for tumblr link unwrapping firstparty script
1 parent 2d89cf8 commit 9dc43d3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/tests/tests/firstparties.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let fb_wrap = 'https://facebook.com/l.php?u=' + destination;
55
let fb_xss = 'https://facebook.com/l.php?u=javascript://bad.site/%250Aalert(1)';
66
let g_wrap = 'https://www.google.com/url?q=' + destination;
77
let g_ping = '/url?url=' + destination;
8+
let tumblr_wrap = 'https://t.umblr.com/redirect?z=' + destination;
89

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

168+
QUnit.test('tumblr link unwrapping', (assert) => {
169+
const NUM_CHECKS = 2,
170+
done = assert.async();
171+
assert.expect(NUM_CHECKS);
172+
173+
let fixture = document.getElementById('qunit-fixture');
174+
let tumblr_link = makeLink(tumblr_wrap);
175+
176+
// create first-party utility script
177+
let util_script = document.createElement('script');
178+
util_script.src = '../js/firstparties/lib/utils.js';
179+
180+
// create the content script
181+
let tumblr_script = document.createElement('script');
182+
tumblr_script.src = '../js/firstparties/tumblr.js';
183+
tumblr_script.onload = function() {
184+
assert.equal(tumblr_link.href, destination, 'unwrapped tumblr link');
185+
assert.ok(tumblr_link.rel.includes('noreferrer'),
186+
'added noreferrer to tumblr link');
187+
188+
unstub();
189+
done();
190+
};
191+
192+
// after the utility script has finished loading, add the content script
193+
util_script.onload = function() {
194+
fixture.append(tumblr_script);
195+
};
196+
197+
stub([tumblr_link], '/url?');
198+
fixture.appendChild(tumblr_link);
199+
fixture.appendChild(util_script);
200+
});
201+
167202
}());

0 commit comments

Comments
 (0)