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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http_parser.dart ('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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart.io; 5 library dart.io;
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import "dart:async"; 8 import "dart:async";
9 import "dart:collection"; 9 import "dart:collection";
10 import "dart:convert"; 10 import "dart:convert";
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 headers._parseCookies().single.value); 455 headers._parseCookies().single.value);
456 } 456 }
457 457
458 void testHeaderLists() { 458 void testHeaderLists() {
459 HttpHeaders.GENERAL_HEADERS.forEach((x) => null); 459 HttpHeaders.GENERAL_HEADERS.forEach((x) => null);
460 HttpHeaders.ENTITY_HEADERS.forEach((x) => null); 460 HttpHeaders.ENTITY_HEADERS.forEach((x) => null);
461 HttpHeaders.RESPONSE_HEADERS.forEach((x) => null); 461 HttpHeaders.RESPONSE_HEADERS.forEach((x) => null);
462 HttpHeaders.REQUEST_HEADERS.forEach((x) => null); 462 HttpHeaders.REQUEST_HEADERS.forEach((x) => null);
463 } 463 }
464 464
465 void testInvalidFieldName() {
466 void test(String field) {
467 _HttpHeaders headers = new _HttpHeaders("1.1");
468 Expect.throws(() => headers.add(field, "value"),
469 (e) => e is FormatException);
470 Expect.throws(() => headers.set(field, "value"),
471 (e) => e is FormatException);
472 Expect.throws(() => headers.remove(field, "value"),
473 (e) => e is FormatException);
474 Expect.throws(() => headers.removeAll(field),
475 (e) => e is FormatException);
476 }
477 test('\r');
478 test('\n');
479 test(',');
480 test('test\x00');
481 }
482
483 void testInvalidFieldValue() {
484 void test(value, {bool remove: true}) {
485 _HttpHeaders headers = new _HttpHeaders("1.1");
486 Expect.throws(() => headers.add("field", value),
487 (e) => e is FormatException);
488 Expect.throws(() => headers.set("field", value),
489 (e) => e is FormatException);
490 if (remove) {
491 Expect.throws(() => headers.remove("field", value),
492 (e) => e is FormatException);
493 }
494 }
495 test('\r');
496 test('\n');
497 test('test\x00');
498 // Test we handle other types correctly.
499 test(new StringBuffer('\x00'), remove: false);
500 }
501
465 main() { 502 main() {
466 testMultiValue(); 503 testMultiValue();
467 testDate(); 504 testDate();
468 testExpires(); 505 testExpires();
469 testIfModifiedSince(); 506 testIfModifiedSince();
470 testHost(); 507 testHost();
471 testEnumeration(); 508 testEnumeration();
472 testHeaderValue(); 509 testHeaderValue();
473 testContentType(); 510 testContentType();
474 testContentTypeCache(); 511 testContentTypeCache();
475 testCookie(); 512 testCookie();
476 testInvalidCookie(); 513 testInvalidCookie();
477 testHeaderLists(); 514 testHeaderLists();
515 testInvalidFieldName();
516 testInvalidFieldValue();
478 } 517 }
OLDNEW
« 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