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

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

Issue 1831963002: Fix number parsing for max-age for HSTS/HPKP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@parse_refactor
Patch Set: rebase Created 4 years, 8 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
« no previous file with comments | « net/http/http_security_headers.cc ('k') | net/http/transport_security_state.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 #include <algorithm> 6 #include <algorithm>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "crypto/sha2.h" 10 #include "crypto/sha2.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 EXPECT_FALSE(ParseHSTSHeader("max-ag=3488923", &max_age, 131 EXPECT_FALSE(ParseHSTSHeader("max-ag=3488923", &max_age,
132 &include_subdomains)); 132 &include_subdomains));
133 EXPECT_FALSE(ParseHSTSHeader("max-aged=3488923", &max_age, 133 EXPECT_FALSE(ParseHSTSHeader("max-aged=3488923", &max_age,
134 &include_subdomains)); 134 &include_subdomains));
135 EXPECT_FALSE(ParseHSTSHeader("max-age==3488923", &max_age, 135 EXPECT_FALSE(ParseHSTSHeader("max-age==3488923", &max_age,
136 &include_subdomains)); 136 &include_subdomains));
137 EXPECT_FALSE(ParseHSTSHeader("amax-age=3488923", &max_age, 137 EXPECT_FALSE(ParseHSTSHeader("amax-age=3488923", &max_age,
138 &include_subdomains)); 138 &include_subdomains));
139 EXPECT_FALSE(ParseHSTSHeader("max-age=-3488923", &max_age, 139 EXPECT_FALSE(ParseHSTSHeader("max-age=-3488923", &max_age,
140 &include_subdomains)); 140 &include_subdomains));
141 EXPECT_FALSE(
142 ParseHSTSHeader("max-age=+3488923", &max_age, &include_subdomains));
143 EXPECT_FALSE(
144 ParseHSTSHeader("max-age=13####", &max_age, &include_subdomains));
145 EXPECT_FALSE(ParseHSTSHeader("max-age=9223372036854775807#####", &max_age,
146 &include_subdomains));
147 EXPECT_FALSE(ParseHSTSHeader("max-age=18446744073709551615####", &max_age,
148 &include_subdomains));
149 EXPECT_FALSE(ParseHSTSHeader("max-age=999999999999999999999999$.&#!",
150 &max_age, &include_subdomains));
141 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 e", &max_age, 151 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 e", &max_age,
142 &include_subdomains)); 152 &include_subdomains));
143 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomain", 153 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomain",
144 &max_age, &include_subdomains)); 154 &max_age, &include_subdomains));
145 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923includesubdomains", 155 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923includesubdomains",
146 &max_age, &include_subdomains)); 156 &max_age, &include_subdomains));
147 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923=includesubdomains", 157 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923=includesubdomains",
148 &max_age, &include_subdomains)); 158 &max_age, &include_subdomains));
149 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomainx", 159 EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomainx",
150 &max_age, &include_subdomains)); 160 &max_age, &include_subdomains));
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 391
382 EXPECT_TRUE(ParseHSTSHeader("max-age=394082; incLudesUbdOmains", 392 EXPECT_TRUE(ParseHSTSHeader("max-age=394082; incLudesUbdOmains",
383 &max_age, &include_subdomains)); 393 &max_age, &include_subdomains));
384 expect_max_age = base::TimeDelta::FromSeconds(394082); 394 expect_max_age = base::TimeDelta::FromSeconds(394082);
385 EXPECT_EQ(expect_max_age, max_age); 395 EXPECT_EQ(expect_max_age, max_age);
386 EXPECT_TRUE(include_subdomains); 396 EXPECT_TRUE(include_subdomains);
387 397
388 EXPECT_TRUE(ParseHSTSHeader( 398 EXPECT_TRUE(ParseHSTSHeader(
389 "max-age=39408299 ;incLudesUbdOmains", &max_age, 399 "max-age=39408299 ;incLudesUbdOmains", &max_age,
390 &include_subdomains)); 400 &include_subdomains));
391 expect_max_age = base::TimeDelta::FromSeconds( 401 expect_max_age =
392 std::min(kMaxHSTSAgeSecs, static_cast<int64_t>(INT64_C(39408299)))); 402 base::TimeDelta::FromSeconds(std::min(kMaxHSTSAgeSecs, 39408299u));
393 EXPECT_EQ(expect_max_age, max_age); 403 EXPECT_EQ(expect_max_age, max_age);
394 EXPECT_TRUE(include_subdomains); 404 EXPECT_TRUE(include_subdomains);
395 405
396 EXPECT_TRUE(ParseHSTSHeader( 406 EXPECT_TRUE(ParseHSTSHeader(
397 "max-age=394082038 ; incLudesUbdOmains", &max_age, 407 "max-age=394082038 ; incLudesUbdOmains", &max_age,
398 &include_subdomains)); 408 &include_subdomains));
399 expect_max_age = base::TimeDelta::FromSeconds( 409 expect_max_age =
400 std::min(kMaxHSTSAgeSecs, static_cast<int64_t>(INT64_C(394082038)))); 410 base::TimeDelta::FromSeconds(std::min(kMaxHSTSAgeSecs, 394082038u));
401 EXPECT_EQ(expect_max_age, max_age); 411 EXPECT_EQ(expect_max_age, max_age);
402 EXPECT_TRUE(include_subdomains); 412 EXPECT_TRUE(include_subdomains);
403 413
404 EXPECT_TRUE(ParseHSTSHeader( 414 EXPECT_TRUE(ParseHSTSHeader(
405 "max-age=394082038 ; incLudesUbdOmains;", &max_age, 415 "max-age=394082038 ; incLudesUbdOmains;", &max_age,
406 &include_subdomains)); 416 &include_subdomains));
407 expect_max_age = base::TimeDelta::FromSeconds( 417 expect_max_age =
408 std::min(kMaxHSTSAgeSecs, static_cast<int64_t>(INT64_C(394082038)))); 418 base::TimeDelta::FromSeconds(std::min(kMaxHSTSAgeSecs, 394082038u));
409 EXPECT_EQ(expect_max_age, max_age); 419 EXPECT_EQ(expect_max_age, max_age);
410 EXPECT_TRUE(include_subdomains); 420 EXPECT_TRUE(include_subdomains);
411 421
412 EXPECT_TRUE(ParseHSTSHeader( 422 EXPECT_TRUE(ParseHSTSHeader(
413 ";; max-age=394082038 ; incLudesUbdOmains; ;", &max_age, 423 ";; max-age=394082038 ; incLudesUbdOmains; ;", &max_age,
414 &include_subdomains)); 424 &include_subdomains));
415 expect_max_age = base::TimeDelta::FromSeconds( 425 expect_max_age =
416 std::min(kMaxHSTSAgeSecs, static_cast<int64_t>(INT64_C(394082038)))); 426 base::TimeDelta::FromSeconds(std::min(kMaxHSTSAgeSecs, 394082038u));
417 EXPECT_EQ(expect_max_age, max_age); 427 EXPECT_EQ(expect_max_age, max_age);
418 EXPECT_TRUE(include_subdomains); 428 EXPECT_TRUE(include_subdomains);
419 429
420 EXPECT_TRUE(ParseHSTSHeader( 430 EXPECT_TRUE(ParseHSTSHeader(
421 ";; max-age=394082038 ;", &max_age, 431 ";; max-age=394082038 ;", &max_age,
422 &include_subdomains)); 432 &include_subdomains));
423 expect_max_age = base::TimeDelta::FromSeconds( 433 expect_max_age =
424 std::min(kMaxHSTSAgeSecs, static_cast<int64_t>(INT64_C(394082038)))); 434 base::TimeDelta::FromSeconds(std::min(kMaxHSTSAgeSecs, 394082038u));
425 EXPECT_EQ(expect_max_age, max_age); 435 EXPECT_EQ(expect_max_age, max_age);
426 EXPECT_FALSE(include_subdomains); 436 EXPECT_FALSE(include_subdomains);
427 437
428 EXPECT_TRUE(ParseHSTSHeader( 438 EXPECT_TRUE(ParseHSTSHeader(
429 ";; ; ; max-age=394082038;;; includeSubdomains ;; ;", &max_age, 439 ";; ; ; max-age=394082038;;; includeSubdomains ;; ;", &max_age,
430 &include_subdomains)); 440 &include_subdomains));
431 expect_max_age = base::TimeDelta::FromSeconds( 441 expect_max_age =
432 std::min(kMaxHSTSAgeSecs, static_cast<int64_t>(INT64_C(394082038)))); 442 base::TimeDelta::FromSeconds(std::min(kMaxHSTSAgeSecs, 394082038u));
433 EXPECT_EQ(expect_max_age, max_age); 443 EXPECT_EQ(expect_max_age, max_age);
434 EXPECT_TRUE(include_subdomains); 444 EXPECT_TRUE(include_subdomains);
435 445
436 EXPECT_TRUE(ParseHSTSHeader( 446 EXPECT_TRUE(ParseHSTSHeader(
437 "incLudesUbdOmains ; max-age=394082038 ;;", &max_age, 447 "incLudesUbdOmains ; max-age=394082038 ;;", &max_age,
438 &include_subdomains)); 448 &include_subdomains));
439 expect_max_age = base::TimeDelta::FromSeconds( 449 expect_max_age =
440 std::min(kMaxHSTSAgeSecs, static_cast<int64_t>(INT64_C(394082038)))); 450 base::TimeDelta::FromSeconds(std::min(kMaxHSTSAgeSecs, 394082038u));
441 EXPECT_EQ(expect_max_age, max_age); 451 EXPECT_EQ(expect_max_age, max_age);
442 EXPECT_TRUE(include_subdomains); 452 EXPECT_TRUE(include_subdomains);
443 453
444 EXPECT_TRUE(ParseHSTSHeader( 454 EXPECT_TRUE(ParseHSTSHeader(
445 " max-age=0 ; incLudesUbdOmains ", &max_age, 455 " max-age=0 ; incLudesUbdOmains ", &max_age,
446 &include_subdomains)); 456 &include_subdomains));
447 expect_max_age = base::TimeDelta::FromSeconds(0); 457 expect_max_age = base::TimeDelta::FromSeconds(0);
448 EXPECT_EQ(expect_max_age, max_age); 458 EXPECT_EQ(expect_max_age, max_age);
449 EXPECT_TRUE(include_subdomains); 459 EXPECT_TRUE(include_subdomains);
450 460
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 EXPECT_TRUE(ParseAsHPKPHeader( 532 EXPECT_TRUE(ParseAsHPKPHeader(
523 "max-age=394082;" + backup_pin + ";" + good_pin + "; ", chain_hashes, 533 "max-age=394082;" + backup_pin + ";" + good_pin + "; ", chain_hashes,
524 &max_age, &include_subdomains, &hashes, &report_uri)); 534 &max_age, &include_subdomains, &hashes, &report_uri));
525 expect_max_age = base::TimeDelta::FromSeconds(394082); 535 expect_max_age = base::TimeDelta::FromSeconds(394082);
526 EXPECT_EQ(expect_max_age, max_age); 536 EXPECT_EQ(expect_max_age, max_age);
527 EXPECT_FALSE(include_subdomains); 537 EXPECT_FALSE(include_subdomains);
528 538
529 EXPECT_TRUE(ParseAsHPKPHeader( 539 EXPECT_TRUE(ParseAsHPKPHeader(
530 "max-age=39408299 ;" + backup_pin + ";" + good_pin + "; ", chain_hashes, 540 "max-age=39408299 ;" + backup_pin + ";" + good_pin + "; ", chain_hashes,
531 &max_age, &include_subdomains, &hashes, &report_uri)); 541 &max_age, &include_subdomains, &hashes, &report_uri));
532 expect_max_age = base::TimeDelta::FromSeconds( 542 expect_max_age =
533 std::min(kMaxHPKPAgeSecs, static_cast<int64_t>(INT64_C(39408299)))); 543 base::TimeDelta::FromSeconds(std::min(kMaxHPKPAgeSecs, 39408299u));
534 EXPECT_EQ(expect_max_age, max_age); 544 EXPECT_EQ(expect_max_age, max_age);
535 EXPECT_FALSE(include_subdomains); 545 EXPECT_FALSE(include_subdomains);
536 546
537 EXPECT_TRUE(ParseAsHPKPHeader( 547 EXPECT_TRUE(ParseAsHPKPHeader(
538 "max-age=39408038 ; cybers=39408038 ; includeSubdomains; " + 548 "max-age=39408038 ; cybers=39408038 ; includeSubdomains; " +
539 good_pin + ";" + backup_pin + "; ", 549 good_pin + ";" + backup_pin + "; ",
540 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri)); 550 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
541 expect_max_age = base::TimeDelta::FromSeconds( 551 expect_max_age =
542 std::min(kMaxHPKPAgeSecs, static_cast<int64_t>(INT64_C(394082038)))); 552 base::TimeDelta::FromSeconds(std::min(kMaxHPKPAgeSecs, 394082038u));
543 EXPECT_EQ(expect_max_age, max_age); 553 EXPECT_EQ(expect_max_age, max_age);
544 EXPECT_TRUE(include_subdomains); 554 EXPECT_TRUE(include_subdomains);
545 555
546 EXPECT_TRUE(ParseAsHPKPHeader( 556 EXPECT_TRUE(ParseAsHPKPHeader(
547 " max-age=0 ; " + good_pin + ";" + backup_pin, chain_hashes, &max_age, 557 " max-age=0 ; " + good_pin + ";" + backup_pin, chain_hashes, &max_age,
548 &include_subdomains, &hashes, &report_uri)); 558 &include_subdomains, &hashes, &report_uri));
549 expect_max_age = base::TimeDelta::FromSeconds(0); 559 expect_max_age = base::TimeDelta::FromSeconds(0);
550 EXPECT_EQ(expect_max_age, max_age); 560 EXPECT_EQ(expect_max_age, max_age);
551 EXPECT_FALSE(include_subdomains); 561 EXPECT_FALSE(include_subdomains);
552 562
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 ssl_info)); 910 ssl_info));
901 911
902 // The old pins must still exist. 912 // The old pins must still exist.
903 EXPECT_TRUE(state.HasPublicKeyPins("example.com")); 913 EXPECT_TRUE(state.HasPublicKeyPins("example.com"));
904 EXPECT_TRUE(state.CheckPublicKeyPins( 914 EXPECT_TRUE(state.CheckPublicKeyPins(
905 domain_port, is_issued_by_known_root, ssl_info.public_key_hashes, nullptr, 915 domain_port, is_issued_by_known_root, ssl_info.public_key_hashes, nullptr,
906 nullptr, TransportSecurityState::DISABLE_PIN_REPORTS, &failure_log)); 916 nullptr, TransportSecurityState::DISABLE_PIN_REPORTS, &failure_log));
907 } 917 }
908 918
909 }; // namespace net 919 }; // namespace net
OLDNEW
« no previous file with comments | « net/http/http_security_headers.cc ('k') | net/http/transport_security_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698