Index: net/quic/quic_crypto_server_stream_test.cc |
diff --git a/net/quic/quic_crypto_server_stream_test.cc b/net/quic/quic_crypto_server_stream_test.cc |
index b567f85b1f469baac3af99831dcfed51cb45c06e..c9b779c33a48aab1e3c7d8464f48a32cfe8c3d6b 100644 |
--- a/net/quic/quic_crypto_server_stream_test.cc |
+++ b/net/quic/quic_crypto_server_stream_test.cc |
@@ -12,9 +12,12 @@ |
#include "net/quic/crypto/crypto_framer.h" |
#include "net/quic/crypto/crypto_handshake.h" |
#include "net/quic/crypto/crypto_protocol.h" |
+#include "net/quic/crypto/crypto_server_config.h" |
#include "net/quic/crypto/crypto_utils.h" |
#include "net/quic/crypto/quic_decrypter.h" |
#include "net/quic/crypto/quic_encrypter.h" |
+#include "net/quic/quic_crypto_client_stream.h" |
+#include "net/quic/quic_crypto_server_stream.h" |
#include "net/quic/quic_protocol.h" |
#include "net/quic/quic_session.h" |
#include "net/quic/test_tools/crypto_test_utils.h" |
@@ -73,6 +76,12 @@ class QuicCryptoServerStreamTest : public ::testing::Test { |
session_(connection_, true), |
crypto_config_(QuicCryptoServerConfig::TESTING), |
stream_(config_, crypto_config_, &session_) { |
+ // We advance the clock initially because the default time is zero and the |
+ // strike register worries that we've just overflowed a uint32 time. |
+ connection_->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); |
+ // TODO(rtenneti): Enable testing of ProofSource. |
+ // crypto_config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting()); |
+ |
CryptoTestUtils::SetupCryptoServerConfigForTest( |
connection_->clock(), connection_->random_generator(), &config_, |
&crypto_config_); |
@@ -83,8 +92,8 @@ class QuicCryptoServerStreamTest : public ::testing::Test { |
message_data_.reset(framer.ConstructHandshakeMessage(message_)); |
} |
- void CompleteCryptoHandshake() { |
- CryptoTestUtils::HandshakeWithFakeClient(connection_, &stream_); |
+ int CompleteCryptoHandshake() { |
+ return CryptoTestUtils::HandshakeWithFakeClient(connection_, &stream_); |
} |
protected: |
@@ -115,10 +124,81 @@ TEST_F(QuicCryptoServerStreamTest, ConnectedAfterCHLO) { |
return; |
} |
- CompleteCryptoHandshake(); |
+ EXPECT_EQ(2, CompleteCryptoHandshake()); |
EXPECT_TRUE(stream_.handshake_complete()); |
} |
+TEST_F(QuicCryptoServerStreamTest, ZeroRTT) { |
+ if (!Aes128GcmEncrypter::IsSupported()) { |
+ LOG(INFO) << "AES GCM not supported. Test skipped."; |
+ return; |
+ } |
+ |
+ QuicGuid guid(1); |
+ IPAddressNumber ip; |
+ ParseIPLiteralToNumber("127.0.0.1", &ip); |
+ IPEndPoint addr(ip, 0); |
+ PacketSavingConnection* client_conn = |
+ new PacketSavingConnection(guid, addr, false); |
+ PacketSavingConnection* server_conn = |
+ new PacketSavingConnection(guid, addr, false); |
+ client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); |
+ server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); |
+ |
+ scoped_ptr<TestSession> client_session(new TestSession(client_conn, true)); |
+ scoped_ptr<TestSession> server_session(new TestSession(server_conn, true)); |
+ |
+ QuicConfig client_config; |
+ QuicCryptoClientConfig client_crypto_config; |
+ |
+ client_config.SetDefaults(); |
+ client_crypto_config.SetDefaults(); |
+ |
+ scoped_ptr<QuicCryptoClientStream> client(new QuicCryptoClientStream( |
+ "test.example.com", client_config, client_session.get(), |
+ &client_crypto_config)); |
+ |
+ // Do a first handshake in order to prime the client config with the server's |
+ // information. |
+ CHECK(client->CryptoConnect()); |
+ CHECK_EQ(1u, client_conn->packets_.size()); |
+ |
+ scoped_ptr<QuicCryptoServerStream> server( |
+ new QuicCryptoServerStream(config_, crypto_config_, |
+ server_session.get())); |
+ |
+ CryptoTestUtils::CommunicateHandshakeMessages( |
+ client_conn, client.get(), server_conn, server.get()); |
+ EXPECT_EQ(2, client->num_sent_client_hellos()); |
+ |
+ // Now do another handshake, hopefully in 0-RTT. |
+ LOG(INFO) << "Resetting for 0-RTT handshake attempt"; |
+ |
+ client_conn = new PacketSavingConnection(guid, addr, false); |
+ server_conn = new PacketSavingConnection(guid, addr, false); |
+ // We need to advance time past the strike-server window so that it's |
+ // authoritative in this time span. |
+ client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1002000)); |
+ server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1002000)); |
+ |
+ // This causes the client's nonce to be different and thus stops the |
+ // strike-register from rejecting the repeated nonce. |
+ client_conn->random_generator()->Reseed(NULL, 0); |
+ client_session.reset(new TestSession(client_conn, true)); |
+ server_session.reset(new TestSession(server_conn, true)); |
+ client.reset(new QuicCryptoClientStream( |
+ "test.example.com", client_config, client_session.get(), |
+ &client_crypto_config)); |
+ server.reset(new QuicCryptoServerStream(config_, crypto_config_, |
+ server_session.get())); |
+ |
+ CHECK(client->CryptoConnect()); |
+ |
+ CryptoTestUtils::CommunicateHandshakeMessages( |
+ client_conn, client.get(), server_conn, server.get()); |
+ EXPECT_EQ(1, client->num_sent_client_hellos()); |
+} |
+ |
TEST_F(QuicCryptoServerStreamTest, MessageAfterHandshake) { |
if (!Aes128GcmEncrypter::IsSupported()) { |
LOG(INFO) << "AES GCM not supported. Test skipped."; |