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

Side by Side Diff: net/http/http_response_headers_unittest.cc

Issue 11264: Drop Set-Cookie from XHR response headers (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 1 month 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 | « net/http/http_response_headers.cc ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 HeadersToRaw(&headers); 283 HeadersToRaw(&headers);
284 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); 284 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
285 285
286 std::string value; 286 std::string value;
287 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value)); 287 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value));
288 EXPECT_EQ("private, no-store", value); 288 EXPECT_EQ("private, no-store", value);
289 } 289 }
290 290
291 TEST(HttpResponseHeadersTest, Persist) { 291 TEST(HttpResponseHeadersTest, Persist) {
292 const struct { 292 const struct {
293 net::HttpResponseHeaders::PersistOptions options;
293 const char* raw_headers; 294 const char* raw_headers;
294 const char* expected_headers; 295 const char* expected_headers;
295 } tests[] = { 296 } tests[] = {
296 { "HTTP/1.1 200 OK\n" 297 { net::HttpResponseHeaders::PERSIST_ALL,
298 "HTTP/1.1 200 OK\n"
297 "Cache-control:private\n" 299 "Cache-control:private\n"
298 "cache-Control:no-store\n", 300 "cache-Control:no-store\n",
299 301
300 "HTTP/1.1 200 OK\n" 302 "HTTP/1.1 200 OK\n"
301 "Cache-control: private, no-store\n" 303 "Cache-control: private, no-store\n"
302 }, 304 },
303 { "HTTP/1.1 200 OK\n" 305 { net::HttpResponseHeaders::PERSIST_SANS_HOP_BY_HOP,
306 "HTTP/1.1 200 OK\n"
304 "connection: keep-alive\n" 307 "connection: keep-alive\n"
305 "server: blah\n", 308 "server: blah\n",
306 309
307 "HTTP/1.1 200 OK\n" 310 "HTTP/1.1 200 OK\n"
308 "server: blah\n" 311 "server: blah\n"
309 }, 312 },
310 { "HTTP/1.1 200 OK\n" 313 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE |
314 net::HttpResponseHeaders::PERSIST_SANS_HOP_BY_HOP,
315 "HTTP/1.1 200 OK\n"
311 "fOo: 1\n" 316 "fOo: 1\n"
312 "Foo: 2\n" 317 "Foo: 2\n"
313 "Transfer-Encoding: chunked\n" 318 "Transfer-Encoding: chunked\n"
314 "CoNnection: keep-alive\n" 319 "CoNnection: keep-alive\n"
315 "cache-control: private, no-cache=\"foo\"\n", 320 "cache-control: private, no-cache=\"foo\"\n",
316 321
317 "HTTP/1.1 200 OK\n" 322 "HTTP/1.1 200 OK\n"
318 "cache-control: private, no-cache=\"foo\"\n" 323 "cache-control: private, no-cache=\"foo\"\n"
319 }, 324 },
320 { "HTTP/1.1 200 OK\n" 325 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE,
326 "HTTP/1.1 200 OK\n"
321 "Foo: 2\n" 327 "Foo: 2\n"
322 "Cache-Control: private,no-cache=\"foo, bar\"\n" 328 "Cache-Control: private,no-cache=\"foo, bar\"\n"
323 "bar", 329 "bar",
324 330
325 "HTTP/1.1 200 OK\n" 331 "HTTP/1.1 200 OK\n"
326 "Cache-Control: private,no-cache=\"foo, bar\"\n" 332 "Cache-Control: private,no-cache=\"foo, bar\"\n"
327 }, 333 },
328 // ignore bogus no-cache value 334 // ignore bogus no-cache value
329 { "HTTP/1.1 200 OK\n" 335 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE,
336 "HTTP/1.1 200 OK\n"
330 "Foo: 2\n" 337 "Foo: 2\n"
331 "Cache-Control: private,no-cache=foo\n", 338 "Cache-Control: private,no-cache=foo\n",
332 339
333 "HTTP/1.1 200 OK\n" 340 "HTTP/1.1 200 OK\n"
334 "Foo: 2\n" 341 "Foo: 2\n"
335 "Cache-Control: private,no-cache=foo\n" 342 "Cache-Control: private,no-cache=foo\n"
336 }, 343 },
337 // ignore bogus no-cache value 344 // ignore bogus no-cache value
338 { "HTTP/1.1 200 OK\n" 345 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE,
346 "HTTP/1.1 200 OK\n"
339 "Foo: 2\n" 347 "Foo: 2\n"
340 "Cache-Control: private, no-cache=\n", 348 "Cache-Control: private, no-cache=\n",
341 349
342 "HTTP/1.1 200 OK\n" 350 "HTTP/1.1 200 OK\n"
343 "Foo: 2\n" 351 "Foo: 2\n"
344 "Cache-Control: private, no-cache=\n" 352 "Cache-Control: private, no-cache=\n"
345 }, 353 },
346 // ignore empty no-cache value 354 // ignore empty no-cache value
347 { "HTTP/1.1 200 OK\n" 355 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE,
356 "HTTP/1.1 200 OK\n"
348 "Foo: 2\n" 357 "Foo: 2\n"
349 "Cache-Control: private, no-cache=\"\"\n", 358 "Cache-Control: private, no-cache=\"\"\n",
350 359
351 "HTTP/1.1 200 OK\n" 360 "HTTP/1.1 200 OK\n"
352 "Foo: 2\n" 361 "Foo: 2\n"
353 "Cache-Control: private, no-cache=\"\"\n" 362 "Cache-Control: private, no-cache=\"\"\n"
354 }, 363 },
355 // ignore wrong quotes no-cache value 364 // ignore wrong quotes no-cache value
356 { "HTTP/1.1 200 OK\n" 365 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE,
366 "HTTP/1.1 200 OK\n"
357 "Foo: 2\n" 367 "Foo: 2\n"
358 "Cache-Control: private, no-cache=\'foo\'\n", 368 "Cache-Control: private, no-cache=\'foo\'\n",
359 369
360 "HTTP/1.1 200 OK\n" 370 "HTTP/1.1 200 OK\n"
361 "Foo: 2\n" 371 "Foo: 2\n"
362 "Cache-Control: private, no-cache=\'foo\'\n" 372 "Cache-Control: private, no-cache=\'foo\'\n"
363 }, 373 },
364 // ignore unterminated quotes no-cache value 374 // ignore unterminated quotes no-cache value
365 { "HTTP/1.1 200 OK\n" 375 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE,
376 "HTTP/1.1 200 OK\n"
366 "Foo: 2\n" 377 "Foo: 2\n"
367 "Cache-Control: private, no-cache=\"foo\n", 378 "Cache-Control: private, no-cache=\"foo\n",
368 379
369 "HTTP/1.1 200 OK\n" 380 "HTTP/1.1 200 OK\n"
370 "Foo: 2\n" 381 "Foo: 2\n"
371 "Cache-Control: private, no-cache=\"foo\n" 382 "Cache-Control: private, no-cache=\"foo\n"
372 }, 383 },
373 // accept sloppy LWS 384 // accept sloppy LWS
374 { "HTTP/1.1 200 OK\n" 385 { net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE,
386 "HTTP/1.1 200 OK\n"
375 "Foo: 2\n" 387 "Foo: 2\n"
376 "Cache-Control: private, no-cache=\" foo\t, bar\"\n", 388 "Cache-Control: private, no-cache=\" foo\t, bar\"\n",
377 389
378 "HTTP/1.1 200 OK\n" 390 "HTTP/1.1 200 OK\n"
379 "Cache-Control: private, no-cache=\" foo\t, bar\"\n" 391 "Cache-Control: private, no-cache=\" foo\t, bar\"\n"
380 }, 392 },
381 // header name appears twice, separated by another header 393 // header name appears twice, separated by another header
382 { "HTTP/1.1 200 OK\n" 394 { net::HttpResponseHeaders::PERSIST_ALL,
395 "HTTP/1.1 200 OK\n"
383 "Foo: 1\n" 396 "Foo: 1\n"
384 "Bar: 2\n" 397 "Bar: 2\n"
385 "Foo: 3\n", 398 "Foo: 3\n",
386 399
387 "HTTP/1.1 200 OK\n" 400 "HTTP/1.1 200 OK\n"
388 "Foo: 1, 3\n" 401 "Foo: 1, 3\n"
389 "Bar: 2\n" 402 "Bar: 2\n"
390 }, 403 },
391 // header name appears twice, separated by another header (type 2) 404 // header name appears twice, separated by another header (type 2)
392 { "HTTP/1.1 200 OK\n" 405 { net::HttpResponseHeaders::PERSIST_ALL,
406 "HTTP/1.1 200 OK\n"
393 "Foo: 1, 3\n" 407 "Foo: 1, 3\n"
394 "Bar: 2\n" 408 "Bar: 2\n"
395 "Foo: 4\n", 409 "Foo: 4\n",
396 410
397 "HTTP/1.1 200 OK\n" 411 "HTTP/1.1 200 OK\n"
398 "Foo: 1, 3, 4\n" 412 "Foo: 1, 3, 4\n"
399 "Bar: 2\n" 413 "Bar: 2\n"
400 }, 414 },
415 // Test filtering of cookie headers.
416 { net::HttpResponseHeaders::PERSIST_SANS_COOKIES,
417 "HTTP/1.1 200 OK\n"
418 "Set-Cookie: foo=bar; httponly\n"
419 "Set-Cookie: bar=foo\n"
420 "Bar: 1\n"
421 "Set-Cookie2: bar2=foo2\n",
422
423 "HTTP/1.1 200 OK\n"
424 "Bar: 1\n"
425 },
401 }; 426 };
402 427
403 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 428 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
404 std::string headers = tests[i].raw_headers; 429 std::string headers = tests[i].raw_headers;
405 HeadersToRaw(&headers); 430 HeadersToRaw(&headers);
406 scoped_refptr<HttpResponseHeaders> parsed1 = 431 scoped_refptr<HttpResponseHeaders> parsed1 =
407 new HttpResponseHeaders(headers); 432 new HttpResponseHeaders(headers);
408 433
409 Pickle pickle; 434 Pickle pickle;
410 parsed1->Persist(&pickle, true); 435 parsed1->Persist(&pickle, tests[i].options);
411 436
412 void* iter = NULL; 437 void* iter = NULL;
413 scoped_refptr<HttpResponseHeaders> parsed2 = 438 scoped_refptr<HttpResponseHeaders> parsed2 =
414 new HttpResponseHeaders(pickle, &iter); 439 new HttpResponseHeaders(pickle, &iter);
415 440
416 std::string h2; 441 std::string h2;
417 parsed2->GetNormalizedHeaders(&h2); 442 parsed2->GetNormalizedHeaders(&h2);
418 EXPECT_EQ(string(tests[i].expected_headers), h2); 443 EXPECT_EQ(string(tests[i].expected_headers), h2);
419 } 444 }
420 } 445 }
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 } 1110 }
1086 1111
1087 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { 1112 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) {
1088 std::string headers("Foo bar."); 1113 std::string headers("Foo bar.");
1089 HeadersToRaw(&headers); 1114 HeadersToRaw(&headers);
1090 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); 1115 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
1091 // The bad status line would have gotten rewritten as 1116 // The bad status line would have gotten rewritten as
1092 // HTTP/1.0 200 OK. 1117 // HTTP/1.0 200 OK.
1093 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); 1118 EXPECT_EQ(std::string("OK"), parsed->GetStatusText());
1094 } 1119 }
OLDNEW
« no previous file with comments | « net/http/http_response_headers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698