OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <title>Tests integrity enforcement on fetch()</title> | |
5 <script src="/resources/testharness.js"></script> | |
6 <script src="/resources/testharnessreport.js"></script> | |
7 </head> | |
8 <body> | |
9 <script> | |
10 var SRITest = function(pass, name, src, integrity, expectedValue) { | |
11 this.pass = pass; | |
12 this.name = name; | |
13 this.src = src; | |
14 this.integrity = integrity; | |
15 this.expectedValue = expectedValue; | |
16 } | |
17 SRITest.prototype.execute = function() { | |
18 //var test = async_test(this.name); | |
19 var pass = this.pass; | |
20 var src = this.src; | |
21 var integrity = this.integrity; | |
22 var expectedValue = this.expectedValue; | |
23 var options = {}; | |
24 if (integrity !== '') { | |
25 options.integrity = integrity; | |
26 } | |
27 promise_test(function() { | |
28 return fetch(src, options) | |
29 .then(function(response) { | |
30 if (!pass) | |
yhirano
2015/08/20 02:23:37
assert_true(pass, ...);
jww
2015/08/20 02:57:28
Done.
| |
31 assert_unreached("Response on bad fetch."); | |
32 | |
33 if (pass && expectedValue) { | |
yhirano
2015/08/20 02:23:37
|pass| must be true here, you don't have to check
jww
2015/08/20 02:57:28
Done.
| |
34 return response.text().then(function(actualValue) { | |
35 assert_equals(actualValue, expectedValue, "Value consume d must match hashed value."); | |
36 }); | |
37 } | |
38 }, function() { | |
39 if (pass) | |
yhirano
2015/08/20 02:23:37
assert_false(pass, ...);
jww
2015/08/20 02:57:28
Done.
| |
40 assert_unreached("Failed on a good fetch"); | |
41 }) | |
42 }, this.name); | |
43 } | |
44 | |
45 new SRITest(true, 'No integrity', 'call-success.js', '', 'success();\n').execute (); | |
46 new SRITest(true, 'Good integrity', 'call-success.js', 'sha256-B0/62fJSJFrdjEFR9 ba04m/D+LHQ+zG6PGcaR0Trpxg=', 'success();\n').execute(); | |
47 new SRITest(false, 'Bad integrity', 'call-success.js', 'sha256-deadbeef').execut e(); | |
48 new SRITest(false, 'Bad integrity and an img', '/resources/square100.png', 'sha2 56-B0/62fJSJFrdjEFR9ba04m/D+LHQ+zG6PGcaR0Trpxg=').execute(); | |
49 new SRITest(true, 'Good integrity and an img', '/resources/square100.png', 'sha2 56-xZjdcorjj+TiKGteFFcrNbdqrDns2iVURBpGpAwp12k=').execute(); | |
50 </script> | |
51 </body> | |
52 </html> | |
OLD | NEW |