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

Unified Diff: net/spdy/spdy_session_pool_unittest.cc

Issue 2365263004: Make (almost) all SpdySessions secure in unittests. (Closed)
Patch Set: Created 4 years, 3 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 | « net/spdy/spdy_proxy_client_socket_unittest.cc ('k') | net/spdy/spdy_session_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_session_pool_unittest.cc
diff --git a/net/spdy/spdy_session_pool_unittest.cc b/net/spdy/spdy_session_pool_unittest.cc
index e9fe0f2d617ff4f9be22d21f323dc6305f567238..0dace7b4545e62f39c117c62c8738258007945ab 100644
--- a/net/spdy/spdy_session_pool_unittest.cc
+++ b/net/spdy/spdy_session_pool_unittest.cc
@@ -9,6 +9,7 @@
#include <string>
#include <utility>
+#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "net/dns/host_cache.h"
@@ -18,7 +19,9 @@
#include "net/spdy/spdy_session.h"
#include "net/spdy/spdy_stream_test_util.h"
#include "net/spdy/spdy_test_util_common.h"
+#include "net/test/cert_test_util.h"
#include "net/test/gtest_util.h"
+#include "net/test/test_data_directory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -43,11 +46,20 @@ class SpdySessionPoolTest : public ::testing::Test {
spdy_session_pool_ = http_session_->spdy_session_pool();
}
+ void AddSSLSocketData() {
+ auto ssl = base::MakeUnique<SSLSocketDataProvider>(SYNCHRONOUS, OK);
+ ssl->cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem");
+ ASSERT_TRUE(ssl->cert);
+ session_deps_.socket_factory->AddSSLSocketDataProvider(ssl.get());
+ ssl_data_vector_.push_back(std::move(ssl));
+ }
+
void RunIPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type);
SpdySessionDependencies session_deps_;
std::unique_ptr<HttpNetworkSession> http_session_;
SpdySessionPool* spdy_session_pool_;
+ std::vector<std::unique_ptr<SSLSocketDataProvider>> ssl_data_vector_;
};
// A delegate that opens a new session when it is closed.
@@ -111,7 +123,7 @@ TEST_F(SpdySessionPoolTest, CloseCurrentSessions) {
CreateNetworkSession();
// Setup the first session to the first host.
- base::WeakPtr<SpdySession> session = CreateInsecureSpdySession(
+ base::WeakPtr<SpdySession> session = CreateSecureSpdySession(
http_session_.get(), test_key, NetLogWithSource());
// Flush the SpdySession::OnReadComplete() task.
@@ -145,18 +157,19 @@ TEST_F(SpdySessionPoolTest, CloseCurrentIdleSessions) {
data1.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&data1);
- SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
- session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
+ AddSSLSocketData();
+ AddSSLSocketData();
+ AddSSLSocketData();
CreateNetworkSession();
// Set up session 1
- const std::string kTestHost1("http://www.a.com");
+ const std::string kTestHost1("http://www.example.org");
HostPortPair test_host_port_pair1(kTestHost1, 80);
SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(),
PRIVACY_MODE_DISABLED);
base::WeakPtr<SpdySession> session1 =
- CreateInsecureSpdySession(http_session_.get(), key1, NetLogWithSource());
+ CreateSecureSpdySession(http_session_.get(), key1, NetLogWithSource());
GURL url1(kTestHost1);
base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously(
SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, NetLogWithSource());
@@ -166,12 +179,12 @@ TEST_F(SpdySessionPoolTest, CloseCurrentIdleSessions) {
StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0);
data2.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&data2);
- const std::string kTestHost2("http://www.b.com");
+ const std::string kTestHost2("http://mail.example.org");
HostPortPair test_host_port_pair2(kTestHost2, 80);
SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(),
PRIVACY_MODE_DISABLED);
base::WeakPtr<SpdySession> session2 =
- CreateInsecureSpdySession(http_session_.get(), key2, NetLogWithSource());
+ CreateSecureSpdySession(http_session_.get(), key2, NetLogWithSource());
GURL url2(kTestHost2);
base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously(
SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, NetLogWithSource());
@@ -181,12 +194,12 @@ TEST_F(SpdySessionPoolTest, CloseCurrentIdleSessions) {
StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0);
data3.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&data3);
- const std::string kTestHost3("http://www.c.com");
+ const std::string kTestHost3("http://mail.example.com");
HostPortPair test_host_port_pair3(kTestHost3, 80);
SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(),
PRIVACY_MODE_DISABLED);
base::WeakPtr<SpdySession> session3 =
- CreateInsecureSpdySession(http_session_.get(), key3, NetLogWithSource());
+ CreateSecureSpdySession(http_session_.get(), key3, NetLogWithSource());
GURL url3(kTestHost3);
base::WeakPtr<SpdyStream> spdy_stream3 = CreateStreamSynchronously(
SPDY_BIDIRECTIONAL_STREAM, session3, url3, MEDIUM, NetLogWithSource());
@@ -282,7 +295,7 @@ TEST_F(SpdySessionPoolTest, CloseAllSessions) {
CreateNetworkSession();
// Setup the first session to the first host.
- base::WeakPtr<SpdySession> session = CreateInsecureSpdySession(
+ base::WeakPtr<SpdySession> session = CreateSecureSpdySession(
http_session_.get(), test_key, NetLogWithSource());
// Flush the SpdySession::OnReadComplete() task.
@@ -321,18 +334,12 @@ void SpdySessionPoolTest::RunIPPoolingTest(
SpdySessionKey key;
AddressList addresses;
} test_hosts[] = {
- { "http:://www.foo.com",
- "www.foo.com",
- "192.0.2.33,192.168.0.1,192.168.0.5"
- },
- { "http://js.foo.com",
- "js.foo.com",
- "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33"
- },
- { "http://images.foo.com",
- "images.foo.com",
- "192.168.0.4,192.168.0.3"
- },
+ {"http:://www.example.org", "www.example.org",
+ "192.0.2.33,192.168.0.1,192.168.0.5"},
+ {"http://mail.example.org", "mail.example.org",
+ "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33"},
+ {"http://mail.example.com", "mail.example.com",
+ "192.168.0.4,192.168.0.3"},
};
session_deps_.host_resolver->set_synchronous_mode(true);
@@ -363,13 +370,12 @@ void SpdySessionPoolTest::RunIPPoolingTest(
data1.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&data1);
- SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
- session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
+ AddSSLSocketData();
CreateNetworkSession();
// Setup the first session to the first host.
- base::WeakPtr<SpdySession> session = CreateInsecureSpdySession(
+ base::WeakPtr<SpdySession> session = CreateSecureSpdySession(
http_session_.get(), test_hosts[0].key, NetLogWithSource());
// Flush the SpdySession::OnReadComplete() task.
@@ -394,7 +400,10 @@ void SpdySessionPoolTest::RunIPPoolingTest(
StaticSocketDataProvider data2(reads, arraysize(reads), NULL, 0);
data2.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&data2);
- base::WeakPtr<SpdySession> session2 = CreateInsecureSpdySession(
+
+ AddSSLSocketData();
+
+ base::WeakPtr<SpdySession> session2 = CreateSecureSpdySession(
http_session_.get(), test_hosts[2].key, NetLogWithSource());
// Verify that we have sessions for everything.
@@ -516,7 +525,7 @@ TEST_F(SpdySessionPoolTest, IPAddressChanged) {
MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
};
SpdySerializedFrame req(
- spdy_util.ConstructSpdyGet("http://www.a.com", 1, MEDIUM));
+ spdy_util.ConstructSpdyGet("http://www.example.org", 1, MEDIUM));
MockWrite writes[] = {CreateMockWrite(req, 1)};
StaticSocketDataProvider dataA(reads, arraysize(reads), writes,
@@ -524,18 +533,17 @@ TEST_F(SpdySessionPoolTest, IPAddressChanged) {
dataA.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&dataA);
- SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
- session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
+ AddSSLSocketData();
CreateNetworkSession();
// Set up session A: Going away, but with an active stream.
- const std::string kTestHostA("http://www.a.com");
+ const std::string kTestHostA("http://www.example.org");
HostPortPair test_host_port_pairA(kTestHostA, 80);
SpdySessionKey keyA(
test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
base::WeakPtr<SpdySession> sessionA =
- CreateInsecureSpdySession(http_session_.get(), keyA, NetLogWithSource());
+ CreateSecureSpdySession(http_session_.get(), keyA, NetLogWithSource());
GURL urlA(kTestHostA);
base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously(
@@ -558,12 +566,15 @@ TEST_F(SpdySessionPoolTest, IPAddressChanged) {
arraysize(writes));
dataB.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&dataB);
- const std::string kTestHostB("http://www.b.com");
+
+ AddSSLSocketData();
+
+ const std::string kTestHostB("http://mail.example.org");
HostPortPair test_host_port_pairB(kTestHostB, 80);
SpdySessionKey keyB(
test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
base::WeakPtr<SpdySession> sessionB =
- CreateInsecureSpdySession(http_session_.get(), keyB, NetLogWithSource());
+ CreateSecureSpdySession(http_session_.get(), keyB, NetLogWithSource());
EXPECT_TRUE(sessionB->IsAvailable());
GURL urlB(kTestHostB);
@@ -577,12 +588,15 @@ TEST_F(SpdySessionPoolTest, IPAddressChanged) {
arraysize(writes));
dataC.set_connect_data(connect_data);
session_deps_.socket_factory->AddSocketDataProvider(&dataC);
- const std::string kTestHostC("http://www.c.com");
+
+ AddSSLSocketData();
+
+ const std::string kTestHostC("http://mail.example.com");
HostPortPair test_host_port_pairC(kTestHostC, 80);
SpdySessionKey keyC(
test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
base::WeakPtr<SpdySession> sessionC =
- CreateInsecureSpdySession(http_session_.get(), keyC, NetLogWithSource());
+ CreateSecureSpdySession(http_session_.get(), keyC, NetLogWithSource());
sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!");
EXPECT_TRUE(sessionC->IsDraining());
@@ -634,7 +648,7 @@ TEST_F(SpdySessionPoolTest, FindAvailableSession) {
CreateNetworkSession();
base::WeakPtr<SpdySession> session =
- CreateInsecureSpdySession(http_session_.get(), key, NetLogWithSource());
+ CreateSecureSpdySession(http_session_.get(), key, NetLogWithSource());
// Flush the SpdySession::OnReadComplete() task.
base::RunLoop().RunUntilIdle();
« no previous file with comments | « net/spdy/spdy_proxy_client_socket_unittest.cc ('k') | net/spdy/spdy_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698