Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-fetch.html

Issue 1279163005: Initial Fetch integration for Subresource Integrity (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add integration with FetchFormDataConsumerHandle Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/core/dom/ScriptLoader.cpp » ('j') | Source/modules/fetch/FetchManager.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..38ce5738545557681c5a748e262f16af92631852
--- /dev/null
+++ b/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-fetch.html
@@ -0,0 +1,66 @@
+<!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 integrity = this.integrity;
+ var expectedValue = this.expectedValue;
+ var options = {};
+ if (integrity !== '') {
+ options.integrity = integrity;
+ }
+ fetch(this.src, options)
+ .then(test.step_func(function(response) {
yhirano 2015/08/19 10:42:36 You can use promise_test. Then you don't have to i
jww 2015/08/19 16:43:40 Done.
+ if (pass) {
+ if (expectedValue) {
+ consume(response.body.getReader(), test, expectedValue, '');
yhirano 2015/08/19 10:42:36 You can use response.text().
jww 2015/08/19 16:43:40 Done.
+ } else {
+ test.done();
+ }
+ } else {
+ assert_unreached("Response on bad fetch.");
+ }
+ }))
+ .catch(test.step_func(function(error) {
+ if (pass) {
+ assert_unreached("Network error on good fetch.");
+ } else {
+ test.done();
+ }
+ }));
+}
+
+function consume(reader, test, expectedValue, actualValue) {
+ return reader.read().then(function(result) {
+ if (result.done) {
+ assert_equals(actualValue, expectedValue, "Value consumed must match hashed value.");
+ test.done();
+ return;
+ }
+ actualValue = actualValue + String.fromCharCode.apply(null, result.value);
+ return consume(reader, test, expectedValue, actualValue);
+ });
+}
+
+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>
« no previous file with comments | « no previous file | Source/core/dom/ScriptLoader.cpp » ('j') | Source/modules/fetch/FetchManager.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698