| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "net/spdy/spdy_alt_svc_wire_format.h" | 5 #include "net/spdy/spdy_alt_svc_wire_format.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
| 10 | 10 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( | 422 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( |
| 423 input.begin(), input.end(), &host, &port)); | 423 input.begin(), input.end(), &host, &port)); |
| 424 EXPECT_TRUE(host.empty()); | 424 EXPECT_TRUE(host.empty()); |
| 425 EXPECT_EQ(42, port); | 425 EXPECT_EQ(42, port); |
| 426 | 426 |
| 427 input = StringPiece("foo:137"); | 427 input = StringPiece("foo:137"); |
| 428 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( | 428 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( |
| 429 input.begin(), input.end(), &host, &port)); | 429 input.begin(), input.end(), &host, &port)); |
| 430 EXPECT_EQ("foo", host); | 430 EXPECT_EQ("foo", host); |
| 431 EXPECT_EQ(137, port); | 431 EXPECT_EQ(137, port); |
| 432 |
| 433 input = StringPiece("[2003:8:0:16::509d:9615]:443"); |
| 434 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( |
| 435 input.begin(), input.end(), &host, &port)); |
| 436 EXPECT_EQ("[2003:8:0:16::509d:9615]", host); |
| 437 EXPECT_EQ(443, port); |
| 432 } | 438 } |
| 433 | 439 |
| 434 // Test ParseAltAuthority() on invalid input: empty string, no port, zero port, | 440 // Test ParseAltAuthority() on invalid input: empty string, no port, zero port, |
| 435 // non-digit characters following port. | 441 // non-digit characters following port. |
| 436 TEST(SpdyAltSvcWireFormatTest, ParseAltAuthorityInvalid) { | 442 TEST(SpdyAltSvcWireFormatTest, ParseAltAuthorityInvalid) { |
| 437 const char* invalid_input_array[] = {"", ":", "foo:", ":bar", | 443 const char* invalid_input_array[] = {"", |
| 438 ":0", "foo:0", ":12bar", "foo:23bar", | 444 ":", |
| 439 " ", ":12 ", "foo:12 "}; | 445 "foo:", |
| 446 ":bar", |
| 447 ":0", |
| 448 "foo:0", |
| 449 ":12bar", |
| 450 "foo:23bar", |
| 451 " ", |
| 452 ":12 ", |
| 453 "foo:12 ", |
| 454 "[2003:8:0:16::509d:9615]", |
| 455 "[2003:8:0:16::509d:9615]:", |
| 456 "[2003:8:0:16::509d:9615]foo:443", |
| 457 "[2003:8:0:16::509d:9615:443", |
| 458 "2003:8:0:16::509d:9615]:443"}; |
| 440 for (const char* invalid_input : invalid_input_array) { | 459 for (const char* invalid_input : invalid_input_array) { |
| 441 StringPiece input(invalid_input); | 460 StringPiece input(invalid_input); |
| 442 std::string host; | 461 std::string host; |
| 443 uint16_t port; | 462 uint16_t port; |
| 444 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( | 463 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( |
| 445 input.begin(), input.end(), &host, &port)) | 464 input.begin(), input.end(), &host, &port)) |
| 446 << input; | 465 << input; |
| 447 } | 466 } |
| 448 } | 467 } |
| 449 | 468 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 input.begin(), input.end(), &value32)); | 526 input.begin(), input.end(), &value32)); |
| 508 | 527 |
| 509 // However, even if overflow is not checked for, 4294967296 overflows to 0, | 528 // However, even if overflow is not checked for, 4294967296 overflows to 0, |
| 510 // which returns false anyway. Check for a larger number which overflows to | 529 // which returns false anyway. Check for a larger number which overflows to |
| 511 // 1. | 530 // 1. |
| 512 input = StringPiece("4294967297"); | 531 input = StringPiece("4294967297"); |
| 513 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32( | 532 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32( |
| 514 input.begin(), input.end(), &value32)); | 533 input.begin(), input.end(), &value32)); |
| 515 } | 534 } |
| 516 | 535 |
| 536 // Test parsing an Alt-Svc entry with IP literal hostname. |
| 537 // Regression test for https://crbug.com/664173. |
| 538 TEST(SpdyAltSvcWireFormatTest, ParseIPLiteral) { |
| 539 const char* input = |
| 540 "quic=\"[2003:8:0:16::509d:9615]:443\"; v=\"36,35\"; ma=60"; |
| 541 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 542 ASSERT_TRUE( |
| 543 SpdyAltSvcWireFormat::ParseHeaderFieldValue(input, &altsvc_vector)); |
| 544 EXPECT_EQ(1u, altsvc_vector.size()); |
| 545 EXPECT_EQ("quic", altsvc_vector[0].protocol_id); |
| 546 EXPECT_EQ("[2003:8:0:16::509d:9615]", altsvc_vector[0].host); |
| 547 EXPECT_EQ(443u, altsvc_vector[0].port); |
| 548 EXPECT_EQ(60u, altsvc_vector[0].max_age); |
| 549 EXPECT_THAT(altsvc_vector[0].version, ::testing::ElementsAre(36, 35)); |
| 550 } |
| 551 |
| 517 } // namespace | 552 } // namespace |
| 518 | 553 |
| 519 } // namespace net | 554 } // namespace net |
| OLD | NEW |