proxygen
SSLSessionCacheDataTest.cpp File Reference
#include <chrono>
#include <vector>
#include <folly/DynamicConverter.h>
#include <gtest/gtest.h>
#include <wangle/client/ssl/SSLSession.h>
#include <wangle/client/ssl/SSLSessionCacheData.h>
#include <wangle/client/ssl/SSLSessionCacheUtils.h>
#include <wangle/client/ssl/test/TestUtil.h>
#include <wangle/ssl/SSLUtil.h>

Go to the source code of this file.

Classes

class  SSLSessionCacheDataTest
 

Typedefs

using SSLCtxDeleter = folly::static_function_deleter< SSL_CTX,&SSL_CTX_free >
 
using SSLCtxPtr = std::unique_ptr< SSL_CTX, SSLCtxDeleter >
 

Functions

 TEST_F (SSLSessionCacheDataTest, Basic)
 
 TEST_F (SSLSessionCacheDataTest, CloneSSLSession)
 
 TEST_F (SSLSessionCacheDataTest, ServiceIdentity)
 

Typedef Documentation

using SSLCtxDeleter = folly::static_function_deleter<SSL_CTX, &SSL_CTX_free>

Definition at line 31 of file SSLSessionCacheDataTest.cpp.

using SSLCtxPtr = std::unique_ptr<SSL_CTX, SSLCtxDeleter>

Definition at line 32 of file SSLSessionCacheDataTest.cpp.

Function Documentation

TEST_F ( SSLSessionCacheDataTest  ,
Basic   
)

Definition at line 51 of file SSLSessionCacheDataTest.cpp.

References wangle::SSLSessionCacheData::addedTime, data, EXPECT_EQ, now(), wangle::SSLSessionCacheData::serviceIdentity, wangle::SSLSessionCacheData::sessionData, and folly::toDynamic().

51  {
53  data.sessionData = folly::fbstring("some session data");
55  data.serviceIdentity = "some service";
56 
57  auto d = folly::toDynamic(data);
58  auto deserializedData = folly::convertTo<SSLSessionCacheData>(d);
59 
60  EXPECT_EQ(deserializedData.sessionData, data.sessionData);
61  EXPECT_EQ(deserializedData.addedTime, data.addedTime);
62  EXPECT_EQ(deserializedData.serviceIdentity, data.serviceIdentity);
63 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::chrono::steady_clock::time_point now()
std::chrono::time_point< std::chrono::system_clock > addedTime
basic_fbstring< char > fbstring
Definition: FBString.h:2904
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
dynamic toDynamic(const T &)
TEST_F ( SSLSessionCacheDataTest  ,
CloneSSLSession   
)

Definition at line 65 of file SSLSessionCacheDataTest.cpp.

References wangle::cloneSSLSession(), and EXPECT_TRUE.

65  {
66  for (auto& it : sessions_) {
67  auto sess = SSLSessionPtr(cloneSSLSession(it.first));
68  EXPECT_TRUE(sess);
69  }
70 }
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
SSL_SESSION * cloneSSLSession(SSL_SESSION *toClone)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST_F ( SSLSessionCacheDataTest  ,
ServiceIdentity   
)

Definition at line 72 of file SSLSessionCacheDataTest.cpp.

References wangle::cloneSSLSession(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::gen::first, wangle::getCacheDataForSession(), wangle::getSessionFromCacheData(), wangle::getSessionServiceIdentity(), wangle::setSessionServiceIdentity(), and string.

72  {
73  auto sessionPtr = SSLSessionPtr(cloneSSLSession(sessions_[0].first));
74  auto session = sessionPtr.get();
75  auto ident = getSessionServiceIdentity(session);
76  EXPECT_FALSE(ident);
77 
78  std::string id("serviceId");
80  ident = getSessionServiceIdentity(session);
81  EXPECT_TRUE(ident);
82  EXPECT_EQ(ident.value(), id);
83 
84  auto cloned = SSLSessionPtr(cloneSSLSession(session));
85  EXPECT_TRUE(cloned);
86  ident = getSessionServiceIdentity(cloned.get());
87  EXPECT_TRUE(ident);
88  EXPECT_EQ(ident.value(), id);
89 
90  auto cacheDataOpt = getCacheDataForSession(session);
91  EXPECT_TRUE(cacheDataOpt);
92  auto& cacheData = cacheDataOpt.value();
93  EXPECT_EQ(id, cacheData.serviceIdentity);
94 
95  auto deserialized = SSLSessionPtr(getSessionFromCacheData(cacheData));
96  EXPECT_TRUE(deserialized);
97  ident = getSessionServiceIdentity(deserialized.get());
98  EXPECT_TRUE(ident);
99  EXPECT_EQ(ident.value(), id);
100 }
bool setSessionServiceIdentity(SSL_SESSION *session, const std::string &str)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::Optional< std::string > getSessionServiceIdentity(SSL_SESSION *session)
folly::Optional< SSLSessionCacheData > getCacheDataForSession(SSL_SESSION *sess)
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
SSL_SESSION * getSessionFromCacheData(const SSLSessionCacheData &data)
SSL_SESSION * cloneSSLSession(SSL_SESSION *toClone)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
constexpr detail::First first
Definition: Base-inl.h:2553