Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / net / quic / crypto / crypto_server_test.cc
index 568cd06..f3738ff 100644 (file)
@@ -8,6 +8,7 @@
 #include "net/quic/crypto/crypto_utils.h"
 #include "net/quic/crypto/quic_crypto_server_config.h"
 #include "net/quic/crypto/quic_random.h"
+#include "net/quic/quic_socket_address_coder.h"
 #include "net/quic/quic_utils.h"
 #include "net/quic/test_tools/crypto_test_utils.h"
 #include "net/quic/test_tools/delayed_verify_strike_register_client.h"
@@ -43,6 +44,8 @@ class CryptoServerTest : public ::testing::Test {
         config_(QuicCryptoServerConfig::TESTING, rand_) {
     config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting());
     supported_versions_ = QuicSupportedVersions();
+    client_version_ = QuicUtils::TagToString(
+        QuicVersionToQuicTag(supported_versions_.front()));
   }
 
   virtual void SetUp() {
@@ -68,6 +71,7 @@ class CryptoServerTest : public ::testing::Test {
         "KEXS", "C255",
         "PUBS", pub_hex_.c_str(),
         "NONC", nonce_hex_.c_str(),
+        "VER\0", client_version_.data(),
         "$padding", static_cast<int>(kClientHelloMinimumSize),
         NULL);
     ShouldSucceed(client_hello);
@@ -127,6 +131,23 @@ class CryptoServerTest : public ::testing::Test {
     bool* called_;
   };
 
+  void CheckServerHello(const CryptoHandshakeMessage& server_hello) {
+    const QuicTag* versions;
+    size_t num_versions;
+    server_hello.GetTaglist(kVER, &versions, &num_versions);
+    ASSERT_EQ(QuicSupportedVersions().size(), num_versions);
+    for (size_t i = 0; i < num_versions; ++i) {
+      EXPECT_EQ(QuicVersionToQuicTag(QuicSupportedVersions()[i]), versions[i]);
+    }
+
+    StringPiece address;
+    ASSERT_TRUE(server_hello.GetStringPiece(kCADR, &address));
+    QuicSocketAddressCoder decoder;
+    ASSERT_TRUE(decoder.Decode(address.data(), address.size()));
+    EXPECT_EQ(client_address_.address(), decoder.ip());
+    EXPECT_EQ(client_address_.port(), decoder.port());
+  }
+
   void ShouldSucceed(const CryptoHandshakeMessage& message) {
     bool called = false;
     RunValidate(message, new ValidateCallback(this, true, "", &called));
@@ -160,9 +181,10 @@ class CryptoServerTest : public ::testing::Test {
                                const char* error_substr) {
     string error_details;
     QuicErrorCode error = config_.ProcessClientHello(
-        result, 1 /* GUID */, client_address_,
-        supported_versions_.front(), supported_versions_, &clock_, rand_,
-        &params_, &out_, &error_details);
+        result, 1 /* ConnectionId */, client_address_,
+        supported_versions_.front(), supported_versions_,
+        kInitialFlowControlWindowForTest, &clock_, rand_, &params_, &out_,
+        &error_details);
 
     if (should_succeed) {
       ASSERT_EQ(error, QUIC_NO_ERROR)
@@ -203,6 +225,7 @@ class CryptoServerTest : public ::testing::Test {
   MockClock clock_;
   const IPEndPoint client_address_;
   QuicVersionVector supported_versions_;
+  string client_version_;
   QuicCryptoServerConfig config_;
   QuicCryptoServerConfig::ConfigOptions config_options_;
   QuicCryptoNegotiatedParameters params_;
@@ -225,10 +248,14 @@ TEST_F(CryptoServerTest, BadSNI) {
     "ffee::1",
   };
 
+  string client_version = QuicUtils::TagToString(
+      QuicVersionToQuicTag(supported_versions_.front()));
+
   for (size_t i = 0; i < arraysize(kBadSNIs); i++) {
     ShouldFailMentioning("SNI", InchoateClientHello(
         "CHLO",
         "SNI", kBadSNIs[i],
+        "VER\0", client_version.data(),
         NULL));
   }
 }
@@ -247,6 +274,7 @@ TEST_F(CryptoServerTest, DISABLED_DefaultCert) {
       "NONC", nonce_hex_.c_str(),
       "$padding", static_cast<int>(kClientHelloMinimumSize),
       "PDMD", "X509",
+      "VER\0", client_version_.data(),
       NULL));
 
   StringPiece cert, proof;
@@ -259,6 +287,7 @@ TEST_F(CryptoServerTest, DISABLED_DefaultCert) {
 TEST_F(CryptoServerTest, TooSmall) {
   ShouldFailMentioning("too small", CryptoTestUtils::Message(
         "CHLO",
+        "VER\0", client_version_.data(),
         NULL));
 }
 
@@ -275,6 +304,7 @@ TEST_F(CryptoServerTest, BadSourceAddressToken) {
     ShouldSucceed(InchoateClientHello(
         "CHLO",
         "STK", kBadSourceAddressTokens[i],
+        "VER\0", client_version_.data(),
         NULL));
   }
 }
@@ -291,6 +321,7 @@ TEST_F(CryptoServerTest, BadClientNonce) {
     ShouldSucceed(InchoateClientHello(
         "CHLO",
         "NONC", kBadNonces[i],
+        "VER\0", client_version_.data(),
         NULL));
   }
 }
@@ -302,12 +333,12 @@ TEST_F(CryptoServerTest, DowngradeAttack) {
   }
   // Set the client's preferred version to a supported version that
   // is not the "current" version (supported_versions_.front()).
-  string client_version = QuicUtils::TagToString(
+  string bad_version = QuicUtils::TagToString(
       QuicVersionToQuicTag(supported_versions_.back()));
 
   ShouldFailMentioning("Downgrade", InchoateClientHello(
       "CHLO",
-      "VER\0", client_version.data(),
+      "VER\0", bad_version.data(),
       NULL));
 }
 
@@ -321,6 +352,7 @@ TEST_F(CryptoServerTest, ReplayProtection) {
       "#004b5453", srct_hex_.c_str(),
       "PUBS", pub_hex_.c_str(),
       "NONC", nonce_hex_.c_str(),
+      "VER\0", client_version_.data(),
       "$padding", static_cast<int>(kClientHelloMinimumSize),
       NULL);
   ShouldSucceed(msg);
@@ -333,17 +365,12 @@ TEST_F(CryptoServerTest, ReplayProtection) {
   ShouldSucceed(msg);
   // The message should be accepted now.
   ASSERT_EQ(kSHLO, out_.tag());
+  CheckServerHello(out_);
 
   ShouldSucceed(msg);
   // The message should accepted twice when replay protection is off.
   ASSERT_EQ(kSHLO, out_.tag());
-  const QuicTag* versions;
-  size_t num_versions;
-  out_.GetTaglist(kVER, &versions, &num_versions);
-  ASSERT_EQ(QuicSupportedVersions().size(), num_versions);
-  for (size_t i = 0; i < num_versions; ++i) {
-    EXPECT_EQ(QuicVersionToQuicTag(QuicSupportedVersions()[i]), versions[i]);
-  }
+  CheckServerHello(out_);
 }
 
 TEST(CryptoServerConfigGenerationTest, Determinism) {
@@ -426,6 +453,7 @@ class CryptoServerTestNoConfig : public CryptoServerTest {
 TEST_F(CryptoServerTestNoConfig, DontCrash) {
     ShouldFailMentioning("No config", InchoateClientHello(
         "CHLO",
+        "VER\0", client_version_.data(),
         NULL));
 }
 
@@ -461,6 +489,7 @@ TEST_F(AsyncStrikeServerVerificationTest, AsyncReplayProtection) {
       "#004b5453", srct_hex_.c_str(),
       "PUBS", pub_hex_.c_str(),
       "NONC", nonce_hex_.c_str(),
+      "VER\0", client_version_.data(),
       "$padding", static_cast<int>(kClientHelloMinimumSize),
       NULL);
 
@@ -494,5 +523,35 @@ TEST_F(AsyncStrikeServerVerificationTest, AsyncReplayProtection) {
   EXPECT_EQ(kREJ, out_.tag());
 }
 
+TEST_F(CryptoServerTest, InitialFlowControlWindow) {
+  // Test that the SHLO contains a value for initial flow control window.
+  CryptoHandshakeMessage msg = CryptoTestUtils::Message(
+      "CHLO",
+      "AEAD", "AESG",
+      "KEXS", "C255",
+      "SCID", scid_hex_.c_str(),
+      "#004b5453", srct_hex_.c_str(),
+      "PUBS", pub_hex_.c_str(),
+      "NONC", nonce_hex_.c_str(),
+      "VER\0", client_version_.data(),
+      "$padding", static_cast<int>(kClientHelloMinimumSize),
+      NULL);
+  ShouldSucceed(msg);
+  // The message should be rejected because the strike-register is still
+  // quiescent.
+  ASSERT_EQ(kREJ, out_.tag());
+  config_.set_replay_protection(false);
+
+  // The message should be accepted now.
+  ShouldSucceed(msg);
+  ASSERT_EQ(kSHLO, out_.tag());
+  CheckServerHello(out_);
+
+  // Ensure that the kIFCW tag is populated correctly.
+  QuicTag ifcw;
+  EXPECT_EQ(QUIC_NO_ERROR, out_.GetUint32(kIFCW, &ifcw));
+  EXPECT_EQ(kInitialFlowControlWindowForTest, ifcw);
+}
+
 }  // namespace test
 }  // namespace net