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

Unified Diff: net/socket/ssl_client_socket_unittest.cc

Issue 446623004: This CL adds unit tests for false start connections. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sslcallback
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/ssl_client_socket_unittest.cc
diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc
index 28083fcf8c0dcbbcd180315597ed4c0dc3f8948e..8bf86e5795436e4e3e24d2ed25167eecad4c9596 100644
--- a/net/socket/ssl_client_socket_unittest.cc
+++ b/net/socket/ssl_client_socket_unittest.cc
@@ -796,6 +796,9 @@ class SSLClientSocketCertRequestInfoTest : public SSLClientSocketTest {
};
class SSLClientSocketFalseStartTest : public SSLClientSocketTest {
+ public:
+ SSLClientSocketFalseStartTest() : monitor_handshake_callback_(false) {}
+
protected:
// Creates an SSLClientSocket with |client_config| attached to a
// FakeBlockingStreamSocket, returning both in |*out_raw_transport| and
@@ -830,6 +833,12 @@ class SSLClientSocketFalseStartTest : public SSLClientSocketTest {
test_server()->host_port_pair(),
client_config);
+ if (monitor_handshake_callback_) {
+ sock->SetHandshakeCompletionCallback(
+ base::Bind(&SSLClientSocketTest::RecordCompletedHandshake,
+ base::Unretained(this)));
+ }
+
// Connect. Stop before the client processes the first server leg
// (ServerHello, etc.)
raw_transport->BlockReadResult();
@@ -904,6 +913,10 @@ class SSLClientSocketFalseStartTest : public SSLClientSocketTest {
EXPECT_FALSE(callback.have_result());
}
}
+
+ // Indicates that the socket's handshake completion callback should
+ // be monitored.
+ bool monitor_handshake_callback_;
};
class SSLClientSocketChannelIDTest : public SSLClientSocketTest {
@@ -2770,6 +2783,64 @@ TEST_F(SSLClientSocketTest, HandshakeCallbackIsRun_WithNoneSessionCache) {
EXPECT_TRUE(sock->IsConnected());
EXPECT_TRUE(ran_handshake_completion_callback_);
}
+
+TEST_F(SSLClientSocketTest, HandshakeCallbackIsRun_WithFalseStartFailure) {
davidben 2014/08/06 19:12:46 Hrm. I'm not sure this test actually does anything
+ // False Start requires NPN and a forward-secret cipher suite.
+ SpawnedTestServer::SSLOptions server_options;
+ server_options.key_exchanges =
+ SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA;
+ server_options.enable_npn = true;
+ SSLConfig client_config;
+ client_config.next_protos.push_back("http/1.1");
+
+ SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
+ server_options,
+ base::FilePath());
+ ASSERT_TRUE(test_server.Start());
+
+ AddressList addr;
+ ASSERT_TRUE(test_server.GetAddressList(&addr));
+
+ TestCompletionCallback callback;
+ scoped_ptr<StreamSocket> real_transport(
+ new TCPClientSocket(addr, NULL, NetLog::Source()));
+ scoped_ptr<SynchronousErrorStreamSocket> transport(
+ new SynchronousErrorStreamSocket(real_transport.Pass()));
+ int rv = callback.GetResult(transport->Connect(callback.callback()));
+ EXPECT_EQ(OK, rv);
+
+ SynchronousErrorStreamSocket* raw_transport = transport.get();
+ scoped_ptr<SSLClientSocket> sock(
+ CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
+ test_server.host_port_pair(),
+ client_config));
+
+ sock->SetHandshakeCompletionCallback(base::Bind(
+ &SSLClientSocketTest::RecordCompletedHandshake, base::Unretained(this)));
+
+ raw_transport->SetNextWriteError(ERR_CONNECTION_RESET);
+
+ rv = callback.GetResult(sock->Connect(callback.callback()));
+ EXPECT_EQ(ERR_CONNECTION_RESET, rv);
+ EXPECT_FALSE(sock->IsConnected());
+
+ EXPECT_TRUE(ran_handshake_completion_callback_);
+}
+
+TEST_F(SSLClientSocketFalseStartTest,
+ HandshakeCallbackIsRun_WithFalseStartSuccess) {
+ // False Start requires NPN and a forward-secret cipher suite.
+ SpawnedTestServer::SSLOptions server_options;
+ server_options.key_exchanges =
+ SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA;
+ server_options.enable_npn = true;
+ SSLConfig client_config;
+ client_config.next_protos.push_back("http/1.1");
+ monitor_handshake_callback_ = true;
+ ASSERT_NO_FATAL_FAILURE(TestFalseStart(server_options, client_config, true));
+ ASSERT_TRUE(ran_handshake_completion_callback_);
+}
+
#endif // defined(USE_OPENSSL)
TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698