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

Side by Side Diff: Source/core/frame/SubresourceIntegrityTest.cpp

Issue 798043002: SRI: Accept dashed hash algorithms. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Feedback. Created 6 years 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 unified diff | Download patch
« no previous file with comments | « Source/core/frame/SubresourceIntegrity.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/frame/SubresourceIntegrity.h" 6 #include "core/frame/SubresourceIntegrity.h"
7 7
8 #include "core/HTMLNames.h" 8 #include "core/HTMLNames.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/html/HTMLScriptElement.h" 10 #include "core/html/HTMLScriptElement.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 RefPtrWillBePersistent<Document> document; 129 RefPtrWillBePersistent<Document> document;
130 RefPtrWillBePersistent<HTMLScriptElement> scriptElement; 130 RefPtrWillBePersistent<HTMLScriptElement> scriptElement;
131 }; 131 };
132 132
133 TEST_F(SubresourceIntegrityTest, ParseAlgorithm) 133 TEST_F(SubresourceIntegrityTest, ParseAlgorithm)
134 { 134 {
135 expectAlgorithm("sha256;", HashAlgorithmSha256); 135 expectAlgorithm("sha256;", HashAlgorithmSha256);
136 expectAlgorithm("sha384;", HashAlgorithmSha384); 136 expectAlgorithm("sha384;", HashAlgorithmSha384);
137 expectAlgorithm("sha512;", HashAlgorithmSha512); 137 expectAlgorithm("sha512;", HashAlgorithmSha512);
138 expectAlgorithm("sha-256;", HashAlgorithmSha256);
139 expectAlgorithm("sha-384;", HashAlgorithmSha384);
140 expectAlgorithm("sha-512;", HashAlgorithmSha512);
138 141
139 expectAlgorithmFailure("sha1;"); 142 expectAlgorithmFailure("sha1;");
140 expectAlgorithmFailure("sha-1;"); 143 expectAlgorithmFailure("sha-1;");
141 expectAlgorithmFailure("sha-256;");
142 expectAlgorithmFailure("sha-384;");
143 expectAlgorithmFailure("sha-512;");
144 } 144 }
145 145
146 TEST_F(SubresourceIntegrityTest, ParseDigest) 146 TEST_F(SubresourceIntegrityTest, ParseDigest)
147 { 147 {
148 expectDigest("abcdefg", "abcdefg"); 148 expectDigest("abcdefg", "abcdefg");
149 expectDigest("abcdefg?", "abcdefg"); 149 expectDigest("abcdefg?", "abcdefg");
150 150
151 expectDigestFailure("?"); 151 expectDigestFailure("?");
152 expectDigestFailure("&&&foobar&&&"); 152 expectDigestFailure("&&&foobar&&&");
153 expectDigestFailure("\x01\x02\x03\x04"); 153 expectDigestFailure("\x01\x02\x03\x04");
(...skipping 12 matching lines...) Expand all
166 expectParseFailure("ni:///not-sha256-at-all;abcdefg"); 166 expectParseFailure("ni:///not-sha256-at-all;abcdefg");
167 expectParseFailure("ni:///sha256;&&&foobar&&&"); 167 expectParseFailure("ni:///sha256;&&&foobar&&&");
168 expectParseFailure("ni:///sha256;\x01\x02\x03\x04"); 168 expectParseFailure("ni:///sha256;\x01\x02\x03\x04");
169 169
170 expectParse( 170 expectParse(
171 "ni:///sha256;BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=", 171 "ni:///sha256;BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=",
172 "BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=", 172 "BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=",
173 HashAlgorithmSha256); 173 HashAlgorithmSha256);
174 174
175 expectParse( 175 expectParse(
176 "ni:///sha-256;BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=",
177 "BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=",
178 HashAlgorithmSha256);
179
180 expectParse(
176 " ni:///sha256;BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE= ", 181 " ni:///sha256;BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE= ",
177 "BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=", 182 "BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=",
178 HashAlgorithmSha256); 183 HashAlgorithmSha256);
179 184
180 expectParse( 185 expectParse(
181 "ni:///sha384;XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/tA 1v5GPr", 186 "ni:///sha384;XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/tA 1v5GPr",
182 "XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/tA1v5GPr", 187 "XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/tA1v5GPr",
183 HashAlgorithmSha384); 188 HashAlgorithmSha384);
184 189
185 expectParse( 190 expectParse(
191 "ni:///sha-384;XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/t A1v5GPr",
192 "XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/tA1v5GPr",
193 HashAlgorithmSha384);
194
195 expectParse(
186 "ni:///sha512;tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK81 ytlg0MPaIrPAjcHqba5csorDWtKg==", 196 "ni:///sha512;tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK81 ytlg0MPaIrPAjcHqba5csorDWtKg==",
187 "tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK81ytlg0MPaIrPAj cHqba5csorDWtKg==", 197 "tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK81ytlg0MPaIrPAj cHqba5csorDWtKg==",
188 HashAlgorithmSha512); 198 HashAlgorithmSha512);
199
200 expectParse(
201 "ni:///sha-512;tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK8 1ytlg0MPaIrPAjcHqba5csorDWtKg==",
202 "tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK81ytlg0MPaIrPAj cHqba5csorDWtKg==",
203 HashAlgorithmSha512);
189 } 204 }
190 205
191 // 206 //
192 // End-to-end tests of ::CheckSubresourceIntegrity. 207 // End-to-end tests of ::CheckSubresourceIntegrity.
193 // 208 //
194 209
195 TEST_F(SubresourceIntegrityTest, CheckSubresourceIntegrityInSecureOrigin) 210 TEST_F(SubresourceIntegrityTest, CheckSubresourceIntegrityInSecureOrigin)
196 { 211 {
197 document->updateSecurityOrigin(secureOrigin->isolatedCopy()); 212 document->updateSecurityOrigin(secureOrigin->isolatedCopy());
198 213
(...skipping 15 matching lines...) Expand all
214 document->updateSecurityOrigin(insecureOrigin->isolatedCopy()); 229 document->updateSecurityOrigin(insecureOrigin->isolatedCopy());
215 230
216 expectIntegrityFailure(kSha256Integrity, kBasicScript, secureURL); 231 expectIntegrityFailure(kSha256Integrity, kBasicScript, secureURL);
217 expectIntegrityFailure(kSha384Integrity, kBasicScript, secureURL); 232 expectIntegrityFailure(kSha384Integrity, kBasicScript, secureURL);
218 expectIntegrityFailure(kSha512Integrity, kBasicScript, secureURL); 233 expectIntegrityFailure(kSha512Integrity, kBasicScript, secureURL);
219 expectIntegrityFailure(kSha384IntegrityLabeledAs256, kBasicScript, secureURL ); 234 expectIntegrityFailure(kSha384IntegrityLabeledAs256, kBasicScript, secureURL );
220 expectIntegrityFailure(kUnsupportedHashFunctionIntegrity, kBasicScript, secu reURL); 235 expectIntegrityFailure(kUnsupportedHashFunctionIntegrity, kBasicScript, secu reURL);
221 } 236 }
222 237
223 } // namespace blink 238 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/SubresourceIntegrity.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698