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

Unified Diff: tests/standalone/io/http_headers_test.dart

Issue 364313002: Validate headers when added to HttpHeaders. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_headers_test.dart
diff --git a/tests/standalone/io/http_headers_test.dart b/tests/standalone/io/http_headers_test.dart
index 6b4c1f15b61cbbb328c31b95be71df595c1c0d13..ad891b153b7afd1b74d3e479ad2666ef95f7e8d6 100644
--- a/tests/standalone/io/http_headers_test.dart
+++ b/tests/standalone/io/http_headers_test.dart
@@ -462,6 +462,43 @@ void testHeaderLists() {
HttpHeaders.REQUEST_HEADERS.forEach((x) => null);
}
+void testInvalidFieldName() {
+ void test(String field) {
+ _HttpHeaders headers = new _HttpHeaders("1.1");
+ Expect.throws(() => headers.add(field, "value"),
+ (e) => e is FormatException);
+ Expect.throws(() => headers.set(field, "value"),
+ (e) => e is FormatException);
+ Expect.throws(() => headers.remove(field, "value"),
+ (e) => e is FormatException);
+ Expect.throws(() => headers.removeAll(field),
+ (e) => e is FormatException);
+ }
+ test('\r');
+ test('\n');
+ test(',');
+ test('test\x00');
+}
+
+void testInvalidFieldValue() {
+ void test(value, {bool remove: true}) {
+ _HttpHeaders headers = new _HttpHeaders("1.1");
+ Expect.throws(() => headers.add("field", value),
+ (e) => e is FormatException);
+ Expect.throws(() => headers.set("field", value),
+ (e) => e is FormatException);
+ if (remove) {
+ Expect.throws(() => headers.remove("field", value),
+ (e) => e is FormatException);
+ }
+ }
+ test('\r');
+ test('\n');
+ test('test\x00');
+ // Test we handle other types correctly.
+ test(new StringBuffer('\x00'), remove: false);
+}
+
main() {
testMultiValue();
testDate();
@@ -475,4 +512,6 @@ main() {
testCookie();
testInvalidCookie();
testHeaderLists();
+ testInvalidFieldName();
+ testInvalidFieldValue();
}
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698