Commit 03351b22 authored by Renjie Tang's avatar Renjie Tang Committed by Commit Bot

Add explicit fake timing information for test SSL sessions to prevent crashes.

Bug: 1088365
Change-Id: Ib5d66b482cba23ae85f44de653caedd3a491c88b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225349Reviewed-by: default avatarNick Harper <nharper@chromium.org>
Commit-Queue: Renjie Tang <renjietang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773919}
parent b89434c7
...@@ -17,6 +17,7 @@ namespace net { ...@@ -17,6 +17,7 @@ namespace net {
namespace { namespace {
const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(1000);
const quic::QuicVersionLabel kFakeVersionLabel = 0x01234567; const quic::QuicVersionLabel kFakeVersionLabel = 0x01234567;
const quic::QuicVersionLabel kFakeVersionLabel2 = 0x89ABCDEF; const quic::QuicVersionLabel kFakeVersionLabel2 = 0x89ABCDEF;
const uint64_t kFakeIdleTimeoutMilliseconds = 12012; const uint64_t kFakeIdleTimeoutMilliseconds = 12012;
...@@ -120,11 +121,10 @@ static const char kCachedSession[] = ...@@ -120,11 +121,10 @@ static const char kCachedSession[] =
} // namespace } // namespace
// https://crbug.com/1088365 class QuicClientSessionCacheTest : public testing::Test {
#define MAYBE_QuicClientSessionCacheTest DISABLED_QuicClientSessionCacheTest
class MAYBE_QuicClientSessionCacheTest : public testing::Test {
public: public:
MAYBE_QuicClientSessionCacheTest() : ssl_ctx_(SSL_CTX_new(TLS_method())) {} QuicClientSessionCacheTest()
: ssl_ctx_(SSL_CTX_new(TLS_method())), clock_(MakeTestClock()) {}
protected: protected:
bssl::UniquePtr<SSL_SESSION> NewSSLSession() { bssl::UniquePtr<SSL_SESSION> NewSSLSession() {
...@@ -136,29 +136,31 @@ class MAYBE_QuicClientSessionCacheTest : public testing::Test { ...@@ -136,29 +136,31 @@ class MAYBE_QuicClientSessionCacheTest : public testing::Test {
return bssl::UniquePtr<SSL_SESSION>(session); return bssl::UniquePtr<SSL_SESSION>(session);
} }
bssl::UniquePtr<SSL_SESSION> MakeTestSession(base::Time now, bssl::UniquePtr<SSL_SESSION> MakeTestSession(
base::TimeDelta timeout) { base::TimeDelta timeout = kTimeout) {
bssl::UniquePtr<SSL_SESSION> session = NewSSLSession(); bssl::UniquePtr<SSL_SESSION> session = NewSSLSession();
SSL_SESSION_set_time(session.get(), now.ToTimeT()); SSL_SESSION_set_time(session.get(), clock_->Now().ToTimeT());
SSL_SESSION_set_timeout(session.get(), timeout.InSeconds()); SSL_SESSION_set_timeout(session.get(), timeout.InSeconds());
return session; return session;
} }
bssl::UniquePtr<SSL_CTX> ssl_ctx_; bssl::UniquePtr<SSL_CTX> ssl_ctx_;
std::unique_ptr<base::SimpleTestClock> clock_;
}; };
} // namespace } // namespace
// Tests that simple insertion and lookup work correctly. // Tests that simple insertion and lookup work correctly.
TEST_F(MAYBE_QuicClientSessionCacheTest, SingleSession) { TEST_F(QuicClientSessionCacheTest, SingleSession) {
QuicClientSessionCache cache; QuicClientSessionCache cache;
cache.SetClockForTesting(clock_.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = NewSSLSession(); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto params2 = MakeFakeTransportParams(); auto params2 = MakeFakeTransportParams();
auto session2 = NewSSLSession(); auto session2 = MakeTestSession();
SSL_SESSION* unowned2 = session2.get(); SSL_SESSION* unowned2 = session2.get();
quic::QuicServerId id2("b.com", 443); quic::QuicServerId id2("b.com", 443);
...@@ -176,7 +178,7 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, SingleSession) { ...@@ -176,7 +178,7 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, SingleSession) {
// Lookup() will trigger a deletion of invalid entry. // Lookup() will trigger a deletion of invalid entry.
EXPECT_EQ(0u, cache.size()); EXPECT_EQ(0u, cache.size());
auto session3 = NewSSLSession(); auto session3 = MakeTestSession();
SSL_SESSION* unowned3 = session3.get(); SSL_SESSION* unowned3 = session3.get();
quic::QuicServerId id3("c.com", 443); quic::QuicServerId id3("c.com", 443);
cache.Insert(id3, std::move(session3), *params, nullptr); cache.Insert(id3, std::move(session3), *params, nullptr);
...@@ -192,15 +194,16 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, SingleSession) { ...@@ -192,15 +194,16 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, SingleSession) {
EXPECT_EQ(0u, cache.size()); EXPECT_EQ(0u, cache.size());
} }
TEST_F(MAYBE_QuicClientSessionCacheTest, MultipleSessions) { TEST_F(QuicClientSessionCacheTest, MultipleSessions) {
QuicClientSessionCache cache; QuicClientSessionCache cache;
cache.SetClockForTesting(clock_.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = NewSSLSession(); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = NewSSLSession(); auto session2 = MakeTestSession();
SSL_SESSION* unowned2 = session2.get(); SSL_SESSION* unowned2 = session2.get();
auto session3 = NewSSLSession(); auto session3 = MakeTestSession();
SSL_SESSION* unowned3 = session3.get(); SSL_SESSION* unowned3 = session3.get();
cache.Insert(id1, std::move(session), *params, nullptr); cache.Insert(id1, std::move(session), *params, nullptr);
...@@ -215,14 +218,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, MultipleSessions) { ...@@ -215,14 +218,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, MultipleSessions) {
// Test that when a different TransportParameter is inserted for // Test that when a different TransportParameter is inserted for
// the same server id, the existing entry is removed. // the same server id, the existing entry is removed.
TEST_F(MAYBE_QuicClientSessionCacheTest, DifferentTransportParams) { TEST_F(QuicClientSessionCacheTest, DifferentTransportParams) {
QuicClientSessionCache cache; QuicClientSessionCache cache;
cache.SetClockForTesting(clock_.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = NewSSLSession(); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = NewSSLSession(); auto session2 = MakeTestSession();
auto session3 = NewSSLSession(); auto session3 = MakeTestSession();
SSL_SESSION* unowned3 = session3.get(); SSL_SESSION* unowned3 = session3.get();
cache.Insert(id1, std::move(session), *params, nullptr); cache.Insert(id1, std::move(session), *params, nullptr);
...@@ -236,14 +240,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, DifferentTransportParams) { ...@@ -236,14 +240,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, DifferentTransportParams) {
EXPECT_EQ(nullptr, cache.Lookup(id1, ssl_ctx_.get())); EXPECT_EQ(nullptr, cache.Lookup(id1, ssl_ctx_.get()));
} }
TEST_F(MAYBE_QuicClientSessionCacheTest, DifferentApplicationState) { TEST_F(QuicClientSessionCacheTest, DifferentApplicationState) {
QuicClientSessionCache cache; QuicClientSessionCache cache;
cache.SetClockForTesting(clock_.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = NewSSLSession(); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = NewSSLSession(); auto session2 = MakeTestSession();
auto session3 = NewSSLSession(); auto session3 = MakeTestSession();
SSL_SESSION* unowned3 = session3.get(); SSL_SESSION* unowned3 = session3.get();
quic::ApplicationState state; quic::ApplicationState state;
state.push_back('a'); state.push_back('a');
...@@ -257,14 +262,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, DifferentApplicationState) { ...@@ -257,14 +262,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, DifferentApplicationState) {
EXPECT_EQ(nullptr, cache.Lookup(id1, ssl_ctx_.get())); EXPECT_EQ(nullptr, cache.Lookup(id1, ssl_ctx_.get()));
} }
TEST_F(MAYBE_QuicClientSessionCacheTest, BothStatesDifferent) { TEST_F(QuicClientSessionCacheTest, BothStatesDifferent) {
QuicClientSessionCache cache; QuicClientSessionCache cache;
cache.SetClockForTesting(clock_.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = NewSSLSession(); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = NewSSLSession(); auto session2 = MakeTestSession();
auto session3 = NewSSLSession(); auto session3 = MakeTestSession();
SSL_SESSION* unowned3 = session3.get(); SSL_SESSION* unowned3 = session3.get();
quic::ApplicationState state; quic::ApplicationState state;
state.push_back('a'); state.push_back('a');
...@@ -281,18 +287,19 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, BothStatesDifferent) { ...@@ -281,18 +287,19 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, BothStatesDifferent) {
} }
// When the size limit is exceeded, the oldest entry should be erased. // When the size limit is exceeded, the oldest entry should be erased.
TEST_F(MAYBE_QuicClientSessionCacheTest, SizeLimit) { TEST_F(QuicClientSessionCacheTest, SizeLimit) {
QuicClientSessionCache cache(2); QuicClientSessionCache cache(2);
cache.SetClockForTesting(clock_.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = NewSSLSession(); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = NewSSLSession(); auto session2 = MakeTestSession();
SSL_SESSION* unowned2 = session2.get(); SSL_SESSION* unowned2 = session2.get();
quic::QuicServerId id2("b.com", 443); quic::QuicServerId id2("b.com", 443);
auto session3 = NewSSLSession(); auto session3 = MakeTestSession();
SSL_SESSION* unowned3 = session3.get(); SSL_SESSION* unowned3 = session3.get();
quic::QuicServerId id3("c.com", 443); quic::QuicServerId id3("c.com", 443);
...@@ -306,13 +313,14 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, SizeLimit) { ...@@ -306,13 +313,14 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, SizeLimit) {
EXPECT_EQ(nullptr, cache.Lookup(id1, ssl_ctx_.get())); EXPECT_EQ(nullptr, cache.Lookup(id1, ssl_ctx_.get()));
} }
TEST_F(MAYBE_QuicClientSessionCacheTest, ClearEarlyData) { TEST_F(QuicClientSessionCacheTest, ClearEarlyData) {
QuicClientSessionCache cache; QuicClientSessionCache cache;
cache.SetClockForTesting(clock_.get());
SSL_CTX_set_early_data_enabled(ssl_ctx_.get(), 1); SSL_CTX_set_early_data_enabled(ssl_ctx_.get(), 1);
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = NewSSLSession(); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = NewSSLSession(); auto session2 = MakeTestSession();
EXPECT_TRUE(SSL_SESSION_early_data_capable(session.get())); EXPECT_TRUE(SSL_SESSION_early_data_capable(session.get()));
EXPECT_TRUE(SSL_SESSION_early_data_capable(session2.get())); EXPECT_TRUE(SSL_SESSION_early_data_capable(session2.get()));
...@@ -333,17 +341,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, ClearEarlyData) { ...@@ -333,17 +341,15 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, ClearEarlyData) {
// Expired session isn't considered valid and nullptr will be returned upon // Expired session isn't considered valid and nullptr will be returned upon
// Lookup. // Lookup.
TEST_F(MAYBE_QuicClientSessionCacheTest, Expiration) { TEST_F(QuicClientSessionCacheTest, Expiration) {
const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(1000);
QuicClientSessionCache cache; QuicClientSessionCache cache;
std::unique_ptr<base::SimpleTestClock> clock = MakeTestClock(); cache.SetClockForTesting(clock_.get());
cache.SetClockForTesting(clock.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = MakeTestSession(clock->Now(), kTimeout); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = MakeTestSession(clock->Now(), 3 * kTimeout); auto session2 = MakeTestSession(3 * kTimeout);
SSL_SESSION* unowned2 = session2.get(); SSL_SESSION* unowned2 = session2.get();
quic::QuicServerId id2("b.com", 443); quic::QuicServerId id2("b.com", 443);
...@@ -352,7 +358,7 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, Expiration) { ...@@ -352,7 +358,7 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, Expiration) {
EXPECT_EQ(2u, cache.size()); EXPECT_EQ(2u, cache.size());
// Expire the session. // Expire the session.
clock->Advance(kTimeout * 2); clock_->Advance(kTimeout * 2);
// The entry has not been removed yet. // The entry has not been removed yet.
EXPECT_EQ(2u, cache.size()); EXPECT_EQ(2u, cache.size());
...@@ -362,18 +368,16 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, Expiration) { ...@@ -362,18 +368,16 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, Expiration) {
EXPECT_EQ(1u, cache.size()); EXPECT_EQ(1u, cache.size());
} }
TEST_F(MAYBE_QuicClientSessionCacheTest, FlushOnMemoryNotifications) { TEST_F(QuicClientSessionCacheTest, FlushOnMemoryNotifications) {
base::test::TaskEnvironment task_environment; base::test::TaskEnvironment task_environment;
const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(1000);
QuicClientSessionCache cache; QuicClientSessionCache cache;
std::unique_ptr<base::SimpleTestClock> clock = MakeTestClock(); cache.SetClockForTesting(clock_.get());
cache.SetClockForTesting(clock.get());
auto params = MakeFakeTransportParams(); auto params = MakeFakeTransportParams();
auto session = MakeTestSession(clock->Now(), kTimeout); auto session = MakeTestSession();
quic::QuicServerId id1("a.com", 443); quic::QuicServerId id1("a.com", 443);
auto session2 = MakeTestSession(clock->Now(), 3 * kTimeout); auto session2 = MakeTestSession(3 * kTimeout);
quic::QuicServerId id2("b.com", 443); quic::QuicServerId id2("b.com", 443);
cache.Insert(id1, std::move(session), *params, nullptr); cache.Insert(id1, std::move(session), *params, nullptr);
...@@ -381,7 +385,7 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, FlushOnMemoryNotifications) { ...@@ -381,7 +385,7 @@ TEST_F(MAYBE_QuicClientSessionCacheTest, FlushOnMemoryNotifications) {
EXPECT_EQ(2u, cache.size()); EXPECT_EQ(2u, cache.size());
// Expire the session. // Expire the session.
clock->Advance(kTimeout * 2); clock_->Advance(kTimeout * 2);
// The entry has not been removed yet. // The entry has not been removed yet.
EXPECT_EQ(2u, cache.size()); EXPECT_EQ(2u, cache.size());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment