Index: LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-fetch.html |
diff --git a/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-fetch.html b/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-fetch.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3ca2ca5ee1b770c66bd62954488e4128d4a62237 |
--- /dev/null |
+++ b/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-fetch.html |
@@ -0,0 +1,52 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+<title>Tests integrity enforcement on fetch()</title> |
+<script src="/resources/testharness.js"></script> |
+<script src="/resources/testharnessreport.js"></script> |
+</head> |
+<body> |
+<script> |
+var SRITest = function(pass, name, src, integrity, expectedValue) { |
+ this.pass = pass; |
+ this.name = name; |
+ this.src = src; |
+ this.integrity = integrity; |
+ this.expectedValue = expectedValue; |
+} |
+SRITest.prototype.execute = function() { |
+ //var test = async_test(this.name); |
+ var pass = this.pass; |
+ var src = this.src; |
+ var integrity = this.integrity; |
+ var expectedValue = this.expectedValue; |
+ var options = {}; |
+ if (integrity !== '') { |
+ options.integrity = integrity; |
+ } |
+ promise_test(function() { |
+ return fetch(src, options) |
+ .then(function(response) { |
+ if (!pass) |
yhirano
2015/08/20 02:23:37
assert_true(pass, ...);
jww
2015/08/20 02:57:28
Done.
|
+ assert_unreached("Response on bad fetch."); |
+ |
+ 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.
|
+ return response.text().then(function(actualValue) { |
+ assert_equals(actualValue, expectedValue, "Value consumed must match hashed value."); |
+ }); |
+ } |
+ }, function() { |
+ if (pass) |
yhirano
2015/08/20 02:23:37
assert_false(pass, ...);
jww
2015/08/20 02:57:28
Done.
|
+ assert_unreached("Failed on a good fetch"); |
+ }) |
+ }, this.name); |
+} |
+ |
+new SRITest(true, 'No integrity', 'call-success.js', '', 'success();\n').execute(); |
+new SRITest(true, 'Good integrity', 'call-success.js', 'sha256-B0/62fJSJFrdjEFR9ba04m/D+LHQ+zG6PGcaR0Trpxg=', 'success();\n').execute(); |
+new SRITest(false, 'Bad integrity', 'call-success.js', 'sha256-deadbeef').execute(); |
+new SRITest(false, 'Bad integrity and an img', '/resources/square100.png', 'sha256-B0/62fJSJFrdjEFR9ba04m/D+LHQ+zG6PGcaR0Trpxg=').execute(); |
+new SRITest(true, 'Good integrity and an img', '/resources/square100.png', 'sha256-xZjdcorjj+TiKGteFFcrNbdqrDns2iVURBpGpAwp12k=').execute(); |
+</script> |
+</body> |
+</html> |