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 pass = this.pass; |
| 19 var src = this.src; |
| 20 var integrity = this.integrity; |
| 21 var expectedValue = this.expectedValue; |
| 22 var options = {}; |
| 23 if (integrity !== '') { |
| 24 options.integrity = integrity; |
| 25 } |
| 26 promise_test(function() { |
| 27 return fetch(src, options) |
| 28 .then(function(response) { |
| 29 assert_true(pass, "Response should resolve"); |
| 30 |
| 31 if (expectedValue) { |
| 32 return response.text().then(function(actualValue) { |
| 33 assert_equals(actualValue, expectedValue, "Value consume
d must match hashed value."); |
| 34 }); |
| 35 } |
| 36 }, function() { |
| 37 assert_false(pass, "Response should be rejected"); |
| 38 }) |
| 39 }, this.name); |
| 40 } |
| 41 |
| 42 new SRITest(true, 'No integrity', 'call-success.js', '', 'success();\n').execute
(); |
| 43 new SRITest(true, 'Good integrity', 'call-success.js', 'sha256-B0/62fJSJFrdjEFR9
ba04m/D+LHQ+zG6PGcaR0Trpxg=', 'success();\n').execute(); |
| 44 new SRITest(false, 'Bad integrity', 'call-success.js', 'sha256-deadbeef').execut
e(); |
| 45 new SRITest(false, 'Bad integrity and an img', '/resources/square100.png', 'sha2
56-B0/62fJSJFrdjEFR9ba04m/D+LHQ+zG6PGcaR0Trpxg=').execute(); |
| 46 new SRITest(true, 'Good integrity and an img', '/resources/square100.png', 'sha2
56-xZjdcorjj+TiKGteFFcrNbdqrDns2iVURBpGpAwp12k=').execute(); |
| 47 </script> |
| 48 </body> |
| 49 </html> |
OLD | NEW |