20 #include <gmock/gmock.h> 22 #include <gtest/gtest.h> 38 void advance(std::chrono::milliseconds ms) {
42 std::chrono::time_point<std::chrono::system_clock>
now()
const override {
47 std::chrono::time_point<std::chrono::system_clock>
t_;
57 sessions_.emplace_back(it.first, it.second);
60 sessions_.emplace_back(sessionWithTicket_.first, sessionWithTicket_.second);
65 50, std::chrono::seconds(150)));
67 std::unique_ptr<SSLSessionPersistentCache::TimeUtil>(mockTimeUtil_));
71 for (
const auto& it : sessions_) {
72 SSL_SESSION_free(it.first);
81 std::pair<SSL_SESSION*, size_t> session,
82 bool inCache =
true) {
83 auto s = cache_->getSSLSession(hostname);
89 std::make_pair(
s.get(), session.second)));
98 std::unique_ptr<SSLSessionPersistentCache>
cache_;
99 std::vector<std::pair<SSL_SESSION*, size_t>>
sessions_;
104 for (
size_t i = 0;
i < sessions_.size(); ++
i) {
115 verifyEntryInCache(hostname, sessions_[i]);
120 for (
size_t i = 0;
i < sessions_.size(); ++
i) {
122 verifyEntryInCache(hostname, sessions_[
i]);
123 cache_->removeSSLSession(hostname);
124 verifyEntryInCache(hostname, sessions_[i],
false);
144 verifyEntryInCache(
"host0", sessions_[0]);
145 verifyEntryInCache(
"host1", sessions_[1]);
155 verifyEntryInCache(
"host0", sessions_[0]);
156 verifyEntryInCache(
"host1", sessions_[1]);
162 verifyEntryInCache(
"host0", sessions_[0]);
163 verifyEntryInCache(
"host1", sessions_[3]);
170 cache_->setSSLSession(
175 auto s = cache_->getSSLSession(myhost);
178 verifyEntryInCache(myhost, sessions_[3]);
186 mockTimeUtil_->advance(
187 duration_cast<milliseconds>(seconds(lifetime_seconds - 10)));
189 verifyEntryInCache(myhost, sessions_[3]);
193 mockTimeUtil_->advance(duration_cast<milliseconds>(seconds(15)));
std::vector< std::pair< SSL_SESSION *, size_t > > sessions_
SSLSessionPersistentCacheTest()
#define ASSERT_EQ(val1, val2)
void verifyEntryInCache(const std::string &hostname, std::pair< SSL_SESSION *, size_t > session, bool inCache=true)
SSLSessionPtr createPersistentTestSession(std::pair< SSL_SESSION *, size_t > session)
TEST_F(TestInfoTest, Names)
std::string sformat(StringPiece fmt, Args &&...args)
bool isSameSession(std::pair< SSL_SESSION *, size_t > lhs, std::pair< SSL_SESSION *, size_t > rhs)
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
void advance(std::chrono::milliseconds ms)
std::pair< SSL_SESSION *, size_t > sessionWithTicket_
std::vector< std::pair< SSL_SESSION *, size_t > > getSessions()
std::chrono::time_point< std::chrono::system_clock > now() const override
std::unique_ptr< SSLSessionPersistentCache > cache_
int SSL_SESSION_has_ticket(const SSL_SESSION *s)
TimeUtilGeneric<> TimeUtil
#define EXPECT_TRUE(condition)
MockTimeUtilGeneric<> MockTimeUtil
unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
std::chrono::time_point< std::chrono::system_clock > t_
MockTimeUtil * mockTimeUtil_
#define ASSERT_NE(val1, val2)
#define ASSERT_FALSE(condition)
std::pair< SSL_SESSION *, size_t > getSessionWithTicket()
#define ASSERT_TRUE(condition)
std::string getPersistentCacheFilename()