-
Notifications
You must be signed in to change notification settings - Fork 5
/
computed-value-test.js
63 lines (53 loc) · 1.94 KB
/
computed-value-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
/**
* @fileoverview
* Test that sanitization of computed data bindings does not
* force stringification of the function that computes the value
* and gets the computed value in time to reject unsafe values.
*/
goog.provide('security.polymer_resin.computed_value_tests');
goog.require('goog.html.SafeUrl');
suite(
'ComputedValueTests',
function () {
var computedValueFixture;
var links;
setup(function (done) {
computedValueFixture = fixture('computed-value-fixture');
computedValueFixture.links = linkContent;
flush(function () {
// Don't run tests until dom-repeat terminates
links = Polymer.dom(computedValueFixture.root).querySelectorAll('a');
done();
});
});
var linkContent = [
{ url: "http://example.com/#frag", text: "example" },
{ url: "javascript:alert(1)", text: "XSS" }
];
function trim(s) {
return (s || '').replace(/^\s+|\s+$/g, '');
}
test('urls', function() {
assert.equal(2, links.length);
assert.equal('http://example.com/', links[0].href);
assert.equal(goog.html.SafeUrl.INNOCUOUS_STRING, links[1].href);
});
test('text', function() {
assert.equal(2, links.length);
assert.equal('example (example.com)', trim(links[0].textContent));
assert.equal('XSS ()', trim(links[1].textContent));
});
});