proxygen
wangle Namespace Reference

Namespaces

 client
 
 detail
 
 test
 

Classes

class  Acceptor
 
class  AcceptorException
 
class  AcceptorFactory
 
class  AcceptorHandshakeHelper
 
class  AcceptorHandshakeManager
 
class  AcceptorTest
 
class  AcceptPipelineFactory
 
class  AcceptRoutingHandler
 
class  AcceptRoutingPipelineFactory
 
class  AppendFilter
 
class  AsyncServerSocketFactory
 
class  AsyncSocketHandler
 
class  AsyncUDPServerSocketFactory
 
class  BaseClientBootstrap
 
class  BaseClientBootstrapFactory
 
class  BaseWithOptional
 
class  BaseWithoutOptional
 
class  BroadcastHandler
 
class  BroadcastPipelineFactory
 
class  BroadcastPool
 
class  ByteToMessageDecoder
 
struct  CacheLockGuard
 
struct  CacheLockGuard< folly::SharedMutex >
 
struct  CacheLockGuard< std::mutex >
 
class  CachePersistence
 
class  ChangeTypeFilter
 
class  ClientBootstrap
 
class  ClientBootstrapFactory
 
class  ClientDispatcherBase
 
class  ClientHelloExtStats
 
class  ClientPipelineFactory
 
class  ClientServiceFactory
 
class  CloseOnReleaseFilter
 
class  ConnectionCountFilter
 
class  ConnectionManager
 
struct  ConnInfo
 
class  ConstFactory
 
class  ContextImpl
 
class  ContextImplBase
 
struct  ContextType
 
class  DefaultAcceptPipelineFactory
 
class  DefaultToFizzPeekingCallback
 
class  DefaultToSSLPeekingCallback
 
struct  dn_char_traits
 
class  EchoIntService
 
class  EchoService
 
class  EvbHandshakeHelper
 
class  EventBaseHandler
 
class  ExecutorFilter
 
class  ExpiringFilter
 
class  FactoryToService
 
class  FilePersistenceLayer
 
class  FilePersistentCache
 
class  FilePoller
 
class  FixedLengthFrameDecoder
 
class  FizzAcceptorHandshakeHelper
 
struct  FizzClientConfig
 
struct  FizzConfig
 
class  FizzConfigUtil
 
class  FizzHandshakeException
 
struct  FunctionObserver
 
class  Handler
 
class  HandlerAdapter
 
class  HandlerBase
 
class  HandlerContext
 
struct  HTTPHeaderSize
 
class  IConnectionCounter
 
class  InboundContextImpl
 
class  InboundHandler
 
class  InboundHandlerContext
 
class  InboundLink
 
class  IntToStringFilter
 
class  LengthFieldBasedFrameDecoder
 
class  LengthFieldPrepender
 
class  LineBasedFrameDecoder
 
class  LoadShedConfiguration
 
class  LocalSSLSessionCache
 
class  LRUInMemoryCache
 
class  LRUPersistentCache
 
class  ManagedConnection
 
class  MessageToByteEncoder
 
class  MockAcceptPipelineFactory
 
class  MockAcceptRoutingHandler
 
class  MockBroadcastHandler
 
class  MockBroadcastPipelineFactory
 
class  MockBroadcastPool
 
class  MockBytesToBytesHandler
 
class  MockByteToMessageDecoder
 
class  MockDownstreamPipelineFactory
 
class  MockHandler
 
class  MockMessageToByteEncoder
 
class  MockObservingHandler
 
class  MockObservingPipelineFactory
 
class  MockPersistentCache
 
class  MockPipelineManager
 
class  MockRoutingDataHandler
 
class  MockRoutingDataHandlerFactory
 
class  MockServerPool
 
class  MockSSLSessionCallbacks
 
class  MockSubscriber
 
class  MockTimeUtil
 
class  MultiFilePoller
 
class  MultiplexServerDispatcher
 
class  NetworkAddress
 
class  Observable
 
struct  Observer
 
class  ObservingHandler
 
class  ObservingPipelineFactory
 
class  OutboundContextImpl
 
class  OutboundHandler
 
class  OutboundHandlerContext
 
class  OutboundLink
 
class  OutputBufferingHandler
 
class  PeekingAcceptorHandshakeHelper
 
class  PeekingAcceptorHandshakeManager
 
struct  PendingLookup
 
class  PersistentCache
 
class  Pipeline
 
class  PipelineBase
 
class  PipelineContext
 
class  PipelinedClientDispatcher
 
class  PipelinedServerDispatcher
 
class  PipelineFactory
 
class  PipelineManager
 
struct  ProtocolInfo
 
class  RoutingDataHandler
 
class  RoutingDataHandlerFactory
 
class  RoutingDataPipelineFactory
 
class  SecurityProtocolContextManager
 
class  SerialClientDispatcher
 
class  SerialServerDispatcher
 
class  ServerAcceptor
 
class  ServerAcceptorFactory
 
class  ServerBootstrap
 
class  ServerPipelineFactory
 
class  ServerPool
 
struct  ServerSocketConfig
 
class  ServerSocketFactory
 
class  ServerSSLContext
 
class  ServerWorkerPool
 
class  Service
 
class  ServiceFactory
 
class  ServiceFactoryFilter
 
class  ServiceFilter
 
class  SessionDestructor
 
class  ShardedLocalSSLSessionCache
 
class  SimpleConnectionCounter
 
class  SimpleConnectionCounterForTest
 
class  SimpleDecode
 
class  SocketPeeker
 
class  SSLAcceptorHandshakeHelper
 
struct  SSLCacheOptions
 
class  SSLCacheProvider
 
struct  SSLContextConfig
 
struct  SSLContextKey
 
struct  SSLContextKeyHash
 
class  SSLContextManager
 
class  SSLContextManagerForTest
 
class  SSLException
 
struct  SSLSessionCacheData
 
class  SSLSessionCacheManager
 
class  SSLSessionCallbacks
 
class  SSLSessionEstablishedCallback
 
class  SSLSessionPersistentCache
 
class  SSLSessionPersistentCacheBase
 
class  SSLSessionPersistentCacheTest
 
class  SSLStats
 
class  SSLUtil
 
class  StaticPipeline
 
class  StaticPipeline< R, W >
 
class  StaticPipeline< R, W, Handler, Handlers... >
 
class  StringCodec
 
struct  Subject
 
class  Subscriber
 
class  Subscription
 
class  TestableAcceptor
 
class  ThreadSafeSSLSessionCache
 
class  TimekeeperTester
 
class  TLSCredProcessor
 
class  TLSPlaintextPeekingCallback
 
class  TLSTicketKeyManager
 
struct  TLSTicketKeySeeds
 
struct  TokenBindingConfig
 
struct  TransportInfo
 
class  UnencryptedAcceptorHandshakeHelper
 

Typedefs

using PeekingCallbackPtr = PeekingAcceptorHandshakeHelper::PeekCallback *
 
typedef std::basic_string< char, dn_char_traitsDNString
 
using SSLSessionEstablishedCallbackUniquePtr = std::unique_ptr< SSLSessionEstablishedCallback >
 
template<typename T >
using ObservingPipeline = Pipeline< folly::IOBufQueue &, T >
 
typedef HandlerAdapter< folly::IOBufQueue &, std::unique_ptr< folly::IOBuf > > BytesToBytesHandler
 
typedef InboundHandler< folly::IOBufQueue &, std::unique_ptr< folly::IOBuf > > InboundBytesToBytesHandler
 
typedef OutboundHandler< std::unique_ptr< folly::IOBuf > > OutboundBytesToBytesHandler
 
using DefaultPipeline = Pipeline< folly::IOBufQueue &, std::unique_ptr< folly::IOBuf >>
 
typedef boost::variant< folly::IOBuf *, folly::AsyncTransportWrapper *, ConnInfo &, ConnEvent, std::tuple< folly::IOBuf *, std::shared_ptr< folly::AsyncUDPSocket >, folly::SocketAddress > > AcceptPipelineType
 
typedef Pipeline< AcceptPipelineTypeAcceptPipeline
 
template<class R , class W = R>
using MockHandlerAdapter = MockHandler< R, R, W, W >
 
using CacheDataVersion = uint64_t
 
typedef std::unique_ptr< SSL_SESSION, SessionDestructorSSLSessionPtr
 
typedef ByteToMessageDecoder< std::unique_ptr< folly::IOBuf > > ByteToByteDecoder
 
typedef folly::exception_wrapper Error
 
typedef std::shared_ptr< folly::ExecutorSchedulerPtr
 
template<class T >
using ObservablePtr = std::shared_ptr< Observable< T >>
 
template<class T >
using ObserverPtr = std::shared_ptr< Observer< T >>
 
template<class T >
using SubjectPtr = std::shared_ptr< Subject< T >>
 
typedef Pipeline< IOBufQueue &, std::stringServicePipeline
 
typedef folly::EvictingCacheMap< std::string, SSL_SESSION * > SSLSessionCacheMap
 
typedef std::pair< folly::AsyncSSLSocket *, std::unique_ptr< folly::DelayedDestruction::DestructorGuard > > AttachedLookup
 
typedef std::map< std::string, PendingLookupPendingLookupMap
 

Enumerations

enum  SecureTransportType { SecureTransportType::NONE, SecureTransportType::TLS, SecureTransportType::ZERO }
 
enum  CertCrypto { CertCrypto::BEST_AVAILABLE, CertCrypto::SHA1_SIGNATURE }
 
enum  HandlerDir { HandlerDir::IN, HandlerDir::OUT, HandlerDir::BOTH }
 
enum  ConnEvent { ConnEvent::CONN_ADDED, ConnEvent::CONN_REMOVED }
 
enum  SSLResumeEnum : uint8_t { SSLResumeEnum::HANDSHAKE = 0, SSLResumeEnum::RESUME_SESSION_ID = 1, SSLResumeEnum::RESUME_TICKET = 3, SSLResumeEnum::NA = 2 }
 
enum  SSLErrorEnum { SSLErrorEnum::NO_ERROR, SSLErrorEnum::TIMEOUT, SSLErrorEnum::DROPPED }
 

Functions

std::ostream & operator<< (std::ostream &os, const ManagedConnection &conn)
 
std::string getSecureTransportName (const SecureTransportType &type)
 
AsyncSocket::OptionMap filterIPSocketOptions (const AsyncSocket::OptionMap &allOptions, const int addrFamily)
 
 TEST_F (AcceptorTest, TestCanAcceptWithNoConnectionCounter)
 
 TEST_F (AcceptorTest, TestCanAcceptWithMaxConnectionsZero)
 
 TEST_F (AcceptorTest, TestCanAcceptWithCurrentConnsLessThanMax)
 
 TEST_F (AcceptorTest, TestCanAcceptWithCurrentConnsGreaterThanMax)
 
 TEST_F (AcceptorTest, TestCanAcceptWhiteListedAddress)
 
 TEST_F (AcceptorTest, TestCanAcceptWithNoLoadShed)
 
 TEST_F (AcceptorTest, TestCanAcceptWithMaxActiveConnectionsNotSet)
 
 TEST_F (AcceptorTest, TestCanAcceptWithActiveConnectionsBreachingThreshold)
 
 TEST_F (AcceptorTest, TestCanAcceptWithTotalConnectionsBreachingThreshold)
 
 TEST_F (AcceptorTest, TestCanAcceptWithBothConnectionCountsBreachingThresholds)
 
std::string getPersistentCacheFilename ()
 
template<typename K , typename V , typename MutexT = std::mutex>
void testSimplePutGet (const std::vector< K > &keys, const std::vector< V > &values)
 
bool setSessionServiceIdentity (SSL_SESSION *session, const std::string &str)
 
folly::Optional< std::stringgetSessionServiceIdentity (SSL_SESSION *session)
 
folly::Optional< SSLSessionCacheDatagetCacheDataForSession (SSL_SESSION *sess)
 
SSL_SESSION * getSessionFromCacheData (const SSLSessionCacheData &data)
 
SSL_SESSION * cloneSSLSession (SSL_SESSION *toClone)
 
 TEST_F (SSLSessionPersistentCacheTest, Basic)
 
 TEST_F (SSLSessionPersistentCacheTest, BadSession)
 
 TEST_F (SSLSessionPersistentCacheTest, Overwrite)
 
 TEST_F (SSLSessionPersistentCacheTest, SessionTicketTimeout)
 
std::vector< std::pair< SSL_SESSION *, size_t > > getSessions ()
 
std::pair< SSL_SESSION *, size_t > getSessionWithTicket ()
 
SSLSessionPtr createPersistentTestSession (std::pair< SSL_SESSION *, size_t > session)
 
std::string getSessionData (SSL_SESSION *s, size_t expectedLength)
 
bool isSameSession (std::pair< SSL_SESSION *, size_t > lhs, std::pair< SSL_SESSION *, size_t > rhs)
 
 TEST (Wangle, ClientServerTest)
 
 TEST (Wangle, FilterTest)
 
 TEST (Wangle, ComplexFilterTest)
 
 TEST (Wangle, SuperComplexFilterTest)
 
 TEST (Wangle, ServiceFactoryFilter)
 
 TEST (Wangle, FactoryToService)
 
 TEST (ServiceFilter, ExpiringMax)
 
 TEST (ServiceFilter, ExpiringIdle)
 
 TEST (ServiceFilter, NoIdleDuringRequests)
 
 TEST (SSLContextManagerTest, Test1)
 
 TEST (SSLContextManagerTest, DISABLED_TestSessionContextIfSupplied)
 
 TEST (SSLContextManagerTest, DISABLED_TestSessionContextIfSessionCacheAbsent)
 

Variables

static const std::string empty_string
 
static const std::string empty_string
 
const size_t kNumSessions = 3
 
const size_t kSessionDataLen = 1060
 
const unsigned char kSessionData [kNumSessions][kSessionDataLen]
 
const unsigned char kSessionDataWithTicket []
 

Detailed Description

SSLContextConfig helps to describe the configs/options for a SSL_CTX. For example:

  1. Filename of X509, private key and its password.
  2. ciphers list
  3. NPN list
  4. Is session cache enabled?
  5. Is it the default X509 in SNI operation?
  6. .... and a few more

SSLContextManager helps to create and manage all SSL_CTX, SSLSessionCacheManager and TLSTicketManager for a listening VIP:PORT. (Note, in SNI, a listening VIP:PORT can have >1 SSL_CTX(s)).

Other responsibilities:

  1. It also handles the SSL_CTX selection after getting the tlsext_hostname in the client hello message.

Usage:

  1. Each listening VIP:PORT serving SSL should have one SSLContextManager. It maps to Acceptor in the wangle vocabulary.
  2. Create a SSLContextConfig object (e.g. by parsing the JSON config).
  3. Call SSLContextManager::addSSLContextConfig() which will then create and configure the SSL_CTX

Note: Each Acceptor, with SSL support, should have one SSLContextManager to manage all SSL_CTX for the VIP:PORT.

Typedef Documentation

Definition at line 278 of file Pipeline.h.

Definition at line 277 of file Pipeline.h.

Definition at line 85 of file SSLSessionCacheManager.h.

Definition at line 173 of file Handler.h.

Definition at line 82 of file ByteToMessageDecoder.h.

A counter that represents a "version" of the data. This is used to determine if two components have been synced to the same version. A valid version is 1 or higher. A version of 0 implies no version.

Definition at line 40 of file PersistentCacheCommon.h.

using wangle::DefaultPipeline = typedef Pipeline<folly::IOBufQueue&, std::unique_ptr<folly::IOBuf>>

Definition at line 241 of file Pipeline.h.

typedef std::basic_string<char, dn_char_traits> wangle::DNString

Definition at line 70 of file SSLContextSelectionMisc.h.

Definition at line 24 of file types.h.

Definition at line 176 of file Handler.h.

template<class R , class W = R>
using wangle::MockHandlerAdapter = typedef MockHandler<R, R, W, W>

Definition at line 71 of file MockHandler.h.

template<class T >
using wangle::ObservablePtr = typedef std::shared_ptr<Observable<T>>

Definition at line 33 of file types.h.

template<class T >
using wangle::ObserverPtr = typedef std::shared_ptr<Observer<T>>

Definition at line 34 of file types.h.

template<typename T >
using wangle::ObservingPipeline = typedef Pipeline<folly::IOBufQueue&, T>

Definition at line 71 of file ObservingHandler.h.

Definition at line 179 of file Handler.h.

typedef std::shared_ptr<folly::Executor> wangle::SchedulerPtr

Definition at line 27 of file types.h.

Definition at line 32 of file ServiceTest.cpp.

Basic SSL session cache map: Maps session id -> session

Definition at line 28 of file SSLSessionCacheManager.h.

Definition at line 36 of file BaseClientBootstrap.h.

typedef std::unique_ptr<SSL_SESSION, SessionDestructor> wangle::SSLSessionPtr

Definition at line 32 of file SSLSession.h.

template<class T >
using wangle::SubjectPtr = typedef std::shared_ptr<Subject<T>>

Definition at line 35 of file types.h.

Enumeration Type Documentation

enum wangle::CertCrypto
strong
Enumerator
BEST_AVAILABLE 
SHA1_SIGNATURE 

Definition at line 24 of file SSLContextSelectionMisc.h.

enum wangle::ConnEvent
strong
Enumerator
CONN_ADDED 
CONN_REMOVED 

Definition at line 266 of file Pipeline.h.

enum wangle::HandlerDir
strong
Enumerator
IN 
OUT 
BOTH 

Definition at line 117 of file HandlerContext.h.

An enum representing different kinds of secure transports we can negotiate.

Enumerator
NONE 
TLS 
ZERO 

Definition at line 26 of file SecureTransportType.h.

26  {
27  NONE, // Transport is not secure.
28  TLS, // Transport is based on TLS
29  ZERO, // Transport is based on zero protocol
30 };
enum wangle::SSLErrorEnum
strong
Enumerator
NO_ERROR 
TIMEOUT 
DROPPED 

Definition at line 42 of file SSLUtil.h.

SSL session establish/resume status

changing these values will break logging pipelines

Enumerator
HANDSHAKE 
RESUME_SESSION_ID 
RESUME_TICKET 
NA 

Definition at line 35 of file SSLUtil.h.

Function Documentation

SSL_SESSION * wangle::cloneSSLSession ( SSL_SESSION *  toClone)

Definition at line 131 of file SSLSessionCacheUtils.cpp.

References getSessionServiceIdentity(), folly::gen::move, and setSessionServiceIdentity().

Referenced by TEST_F().

131  {
132  if (!toClone) {
133  return nullptr;
134  }
135 
136 #ifdef WANGLE_HAVE_SSL_SESSION_DUP
137  return SSL_SESSION_dup(toClone);
138 #else
139  auto sessionData = sessionToFbString(toClone);
140  if (!sessionData) {
141  return nullptr;
142  }
143  auto clone = fbStringToSession(std::move(*sessionData));
144 
145  if (!clone) {
146  return nullptr;
147  }
148  auto serviceIdentity = getSessionServiceIdentity(toClone);
149  if (serviceIdentity) {
150  setSessionServiceIdentity(clone, serviceIdentity.value());
151  }
152  return clone;
153 #endif
154 }
bool setSessionServiceIdentity(SSL_SESSION *session, const std::string &str)
folly::Optional< std::string > getSessionServiceIdentity(SSL_SESSION *session)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
SSLSessionPtr wangle::createPersistentTestSession ( std::pair< SSL_SESSION *, size_t >  session)

Definition at line 350 of file TestUtil.cpp.

Referenced by TEST_F(), and TEST_F().

351  {
352  if (session.first) {
353  // This simulates what openssl does before handing control to the cache.
354  SSL_SESSION_up_ref(session.first);
355  }
356  return SSLSessionPtr(session.first);
357 }
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
folly::AsyncSocket::OptionMap wangle::filterIPSocketOptions ( const folly::AsyncSocket::OptionMap allOptions,
const int  addrFamily 
)

Returns a copy of the socket options excluding options with the given level.

Definition at line 24 of file SocketOptions.cpp.

References folly::FATAL.

Referenced by wangle::ServerSocketConfig::setSocketOptions().

26  {
27  AsyncSocket::OptionMap opts;
28  int exclude;
29  if (addrFamily == AF_INET) {
30  exclude = IPPROTO_IPV6;
31  } else if (addrFamily == AF_INET6) {
32  exclude = IPPROTO_IP;
33  } else {
34  LOG(FATAL) << "Address family " << addrFamily << " was not IPv4 or IPv6";
35  }
36  for (const auto& opt: allOptions) {
37  if (opt.first.level != exclude) {
38  opts[opt.first] = opt.second;
39  }
40  }
41  return opts;
42 }
folly::Optional< SSLSessionCacheData > wangle::getCacheDataForSession ( SSL_SESSION *  sess)

Definition at line 99 of file SSLSessionCacheUtils.cpp.

References getSessionServiceIdentity(), and folly::gen::move.

Referenced by wangle::SSLSessionPersistentCacheBase< K >::setSSLSession(), and TEST_F().

99  {
100  auto sessionData = sessionToFbString(sess);
101  if (!sessionData) {
103  }
104  SSLSessionCacheData result;
105  result.sessionData = std::move(*sessionData);
106  auto serviceIdentity = getSessionServiceIdentity(sess);
107  if (serviceIdentity) {
108  result.serviceIdentity = std::move(*serviceIdentity);
109  }
110 #ifdef WANGLE_HAVE_SSL_SESSION_DUP
111  result.sessionDuplicateTemplate =
112  std::shared_ptr<SSL_SESSION>(SSL_SESSION_dup(sess), SessionDestructor{});
113 #endif
114  return result;
115 }
folly::Optional< std::string > getSessionServiceIdentity(SSL_SESSION *session)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::string wangle::getPersistentCacheFilename ( )

Definition at line 22 of file TestUtil.cpp.

References folly::test::TemporaryFile::path().

Referenced by testEmptyFile(), testInvalidFile(), testSimplePutGet(), testValidFile(), and TYPED_TEST().

22  {
23  folly::test::TemporaryFile file("fbtls");
24  return file.path().string();
25 }
std::string wangle::getSecureTransportName ( const SecureTransportType type)

Definition at line 20 of file SecureTransportType.cpp.

References TLS, and ZERO.

20  {
21  switch (type) {
22  case SecureTransportType::TLS:
23  return "TLS";
24  case SecureTransportType::ZERO:
25  return "Zero";
26  default:
27  return "";
28  }
29 }
PskType type
std::string wangle::getSessionData ( SSL_SESSION *  s,
size_t  expectedLength 
)

Definition at line 359 of file TestUtil.cpp.

References string.

Referenced by isSameSession().

359  {
360  std::unique_ptr<unsigned char[]>
361  sessionData(new unsigned char[expectedLength]);
362  auto p = sessionData.get();
363  auto len = (size_t)i2d_SSL_SESSION(s, &p);
364  CHECK(expectedLength == len);
365  return std::string(reinterpret_cast<const char*>(sessionData.get()), len);
366 }
const char * string
Definition: Conv.cpp:212
static set< string > s
SSL_SESSION * wangle::getSessionFromCacheData ( const SSLSessionCacheData data)

Definition at line 117 of file SSLSessionCacheUtils.cpp.

References wangle::SSLSessionCacheData::serviceIdentity, wangle::SSLSessionCacheData::sessionData, wangle::SSLSessionCacheData::sessionDuplicateTemplate, setSessionServiceIdentity(), and folly::basic_fbstring< E, T, A, Storage >::toStdString().

Referenced by wangle::SSLSessionPersistentCacheBase< K >::getSSLSession(), and TEST_F().

117  {
118 #ifdef WANGLE_HAVE_SSL_SESSION_DUP
119  if (data.sessionDuplicateTemplate) {
120  return SSL_SESSION_dup(data.sessionDuplicateTemplate.get());
121  }
122 #endif
123  auto result = fbStringToSession(data.sessionData);
124  if (!result) {
125  return nullptr;
126  }
127  setSessionServiceIdentity(result, data.serviceIdentity.toStdString());
128  return result;
129 }
bool setSessionServiceIdentity(SSL_SESSION *session, const std::string &str)
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
std::vector< std::pair< SSL_SESSION *, size_t > > wangle::getSessions ( )

Definition at line 320 of file TestUtil.cpp.

References i, isSameSession(), kNumSessions, and s.

Referenced by SSLSessionCacheDataTest::SetUp(), wangle::SSLSessionPersistentCacheTest::SetUp(), and ThreadSafeSSLSessionCacheTest::SetUp().

320  {
321  std::vector<std::pair<SSL_SESSION*, size_t>> sessions;
322 
323  for (size_t i = 0; i < kNumSessions; ++i) {
324  const unsigned char* p = kSessionData[i];
325  auto s = d2i_SSL_SESSION(nullptr, &p, kSessionDataLen);
326  CHECK(s) << "Invalid session " << i;
327  sessions.emplace_back(s, kSessionDataLen);
328 
329  // Make sure the same session compares same to itself.
330  CHECK(isSameSession(sessions[i], sessions[i]));
331  }
332  // Make sure all sessions are different from each other
333  CHECK(!isSameSession(sessions[0], sessions[1]));
334  CHECK(!isSameSession(sessions[1], sessions[2]));
335  CHECK(!isSameSession(sessions[2], sessions[0]));
336 
337  return sessions;
338 }
const size_t kNumSessions
Definition: TestUtil.cpp:20
const size_t kSessionDataLen
Definition: TestUtil.cpp:21
bool isSameSession(std::pair< SSL_SESSION *, size_t > lhs, std::pair< SSL_SESSION *, size_t > rhs)
Definition: TestUtil.cpp:368
const unsigned char kSessionData[kNumSessions][kSessionDataLen]
Definition: TestUtil.cpp:24
static set< string > s
folly::Optional< std::string > wangle::getSessionServiceIdentity ( SSL_SESSION *  session)

Definition at line 88 of file SSLSessionCacheUtils.cpp.

References data, and string.

Referenced by cloneSSLSession(), getCacheDataForSession(), wangle::SSLSessionCallbacks::removeSessionCallback(), and TEST_F().

88  {
89  if (!session) {
91  }
92  auto data = SSL_SESSION_get_ex_data(session, getSessionServiceIdentityIdx());
93  if (!data) {
95  }
96  return *(reinterpret_cast<std::string*>(data));
97 }
const char * string
Definition: Conv.cpp:212
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
std::pair< SSL_SESSION *, size_t > wangle::getSessionWithTicket ( )

Definition at line 340 of file TestUtil.cpp.

References isSameSession(), kSessionDataWithTicket, and s.

Referenced by wangle::SSLSessionPersistentCacheTest::SetUp().

340  {
341  const unsigned char* p = kSessionDataWithTicket;
342  size_t sessionDataWithTicketLen = sizeof(kSessionDataWithTicket);
343  auto s = d2i_SSL_SESSION(nullptr, &p, sessionDataWithTicketLen);
344  CHECK(isSameSession(
345  std::make_pair(s, sessionDataWithTicketLen),
346  std::make_pair(s, sessionDataWithTicketLen)));
347  return std::make_pair(s, sessionDataWithTicketLen);
348 }
bool isSameSession(std::pair< SSL_SESSION *, size_t > lhs, std::pair< SSL_SESSION *, size_t > rhs)
Definition: TestUtil.cpp:368
const unsigned char kSessionDataWithTicket[]
Definition: TestUtil.cpp:218
static set< string > s
bool wangle::isSameSession ( std::pair< SSL_SESSION *, size_t >  lhs,
std::pair< SSL_SESSION *, size_t >  rhs 
)

Definition at line 368 of file TestUtil.cpp.

References getSessionData().

Referenced by getSessions(), getSessionWithTicket(), and wangle::SSLSessionPersistentCacheTest::verifyEntryInCache().

370  {
371  return getSessionData(lhs.first, lhs.second) ==
372  getSessionData(rhs.first, rhs.second);
373 }
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
std::string getSessionData(SSL_SESSION *s, size_t expectedLength)
Definition: TestUtil.cpp:359
std::ostream & wangle::operator<< ( std::ostream &  os,
const ManagedConnection conn 
)

Definition at line 59 of file ManagedConnection.cpp.

References wangle::ManagedConnection::describe().

59  {
60  conn.describe(os);
61  return os;
62 }
bool wangle::setSessionServiceIdentity ( SSL_SESSION *  session,
const std::string str 
)

Definition at line 78 of file SSLSessionCacheUtils.cpp.

References string.

Referenced by cloneSSLSession(), getSessionFromCacheData(), wangle::SSLSessionCallbacks::newSessionCallback(), and TEST_F().

78  {
79  if (!session || str.empty()) {
80  return false;
81  }
82  auto serviceExData = new std::string(str);
83  return SSL_SESSION_set_ex_data(
84  session, getSessionServiceIdentityIdx(), serviceExData) > 0;
85 }
const char * string
Definition: Conv.cpp:212
wangle::TEST ( SSLContextManagerTest  ,
Test1   
)

Definition at line 35 of file SSLContextManagerTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, wangle::SSLContextManager::getSSLCtxByExactDomain(), wangle::SSLContextManager::getSSLCtxBySuffix(), wangle::SSLContextManager::insertSSLCtxByDomainName(), and folly::EventBase::loop().

36 {
37  EventBase eventBase;
38  SSLContextManagerForTest sslCtxMgr(&eventBase,
39  "vip_ssl_context_manager_test_",
40  true,
41  nullptr);
42  auto www_facebook_com_ctx = std::make_shared<SSLContext>();
43  auto start_facebook_com_ctx = std::make_shared<SSLContext>();
44  auto start_abc_facebook_com_ctx = std::make_shared<SSLContext>();
45  auto www_facebook_com_ctx_sha1 = std::make_shared<SSLContext>();
46  auto start_facebook_com_ctx_sha1 = std::make_shared<SSLContext>();
47  auto www_bookface_com_ctx_sha1 = std::make_shared<SSLContext>();
48 
49  sslCtxMgr.insertSSLCtxByDomainName(
50  "*.facebook.com",
51  strlen("*.facebook.com"),
52  start_facebook_com_ctx_sha1,
53  CertCrypto::SHA1_SIGNATURE);
54  sslCtxMgr.insertSSLCtxByDomainName(
55  "www.facebook.com",
56  strlen("www.facebook.com"),
57  www_facebook_com_ctx);
58  sslCtxMgr.insertSSLCtxByDomainName(
59  "www.facebook.com",
60  strlen("www.facebook.com"),
61  www_facebook_com_ctx);
62  sslCtxMgr.insertSSLCtxByDomainName(
63  "*.facebook.com",
64  strlen("*.facebook.com"),
65  start_facebook_com_ctx);
66  sslCtxMgr.insertSSLCtxByDomainName(
67  "*.abc.facebook.com",
68  strlen("*.abc.facebook.com"),
69  start_abc_facebook_com_ctx);
70  sslCtxMgr.insertSSLCtxByDomainName(
71  "www.facebook.com",
72  strlen("www.facebook.com"),
73  www_facebook_com_ctx_sha1,
74  CertCrypto::SHA1_SIGNATURE);
75  sslCtxMgr.insertSSLCtxByDomainName(
76  "www.bookface.com",
77  strlen("www.bookface.com"),
78  www_bookface_com_ctx_sha1,
79  CertCrypto::SHA1_SIGNATURE);
80 
81 
82  shared_ptr<SSLContext> retCtx;
83  retCtx = sslCtxMgr.getSSLCtxByExactDomain(SSLContextKey("www.facebook.com"));
84  EXPECT_EQ(retCtx, www_facebook_com_ctx);
85  retCtx = sslCtxMgr.getSSLCtxByExactDomain(SSLContextKey("WWW.facebook.com"));
86  EXPECT_EQ(retCtx, www_facebook_com_ctx);
88  sslCtxMgr.getSSLCtxByExactDomain(SSLContextKey("xyz.facebook.com")));
89 
90  retCtx = sslCtxMgr.getSSLCtxBySuffix(SSLContextKey("xyz.facebook.com"));
91  EXPECT_EQ(retCtx, start_facebook_com_ctx);
92  retCtx = sslCtxMgr.getSSLCtxBySuffix(SSLContextKey("XYZ.facebook.com"));
93  EXPECT_EQ(retCtx, start_facebook_com_ctx);
94 
95  retCtx = sslCtxMgr.getSSLCtxBySuffix(SSLContextKey("www.abc.facebook.com"));
96  EXPECT_EQ(retCtx, start_abc_facebook_com_ctx);
97 
98  // ensure "facebook.com" does not match "*.facebook.com"
99  EXPECT_FALSE(sslCtxMgr.getSSLCtxBySuffix(SSLContextKey("facebook.com")));
100  // ensure "Xfacebook.com" does not match "*.facebook.com"
101  EXPECT_FALSE(sslCtxMgr.getSSLCtxBySuffix(SSLContextKey("Xfacebook.com")));
102  // ensure wildcard name only matches one domain up
103  EXPECT_FALSE(sslCtxMgr.getSSLCtxBySuffix(
104  SSLContextKey("abc.xyz.facebook.com")));
105 
106  retCtx = sslCtxMgr.getSSLCtxByExactDomain(SSLContextKey("www.facebook.com",
107  CertCrypto::SHA1_SIGNATURE));
108  EXPECT_EQ(retCtx, www_facebook_com_ctx_sha1);
109  retCtx = sslCtxMgr.getSSLCtxBySuffix(SSLContextKey("abc.facebook.com",
110  CertCrypto::SHA1_SIGNATURE));
111  EXPECT_EQ(retCtx, start_facebook_com_ctx_sha1);
112  retCtx = sslCtxMgr.getSSLCtxBySuffix(SSLContextKey("xyz.abc.facebook.com",
113  CertCrypto::SHA1_SIGNATURE));
114  EXPECT_FALSE(retCtx);
115 
116  retCtx = sslCtxMgr.getSSLCtxByExactDomain(SSLContextKey("www.bookface.com",
117  CertCrypto::SHA1_SIGNATURE));
118  EXPECT_EQ(retCtx, www_bookface_com_ctx_sha1);
119  retCtx = sslCtxMgr.getSSLCtxByExactDomain(SSLContextKey("www.bookface.com"));
120  EXPECT_EQ(retCtx, www_bookface_com_ctx_sha1);
121 
122 
123  eventBase.loop(); // Clean up events before SSLContextManager is destructed
124 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
wangle::TEST ( Wangle  ,
ClientServerTest   
)

Definition at line 114 of file ServiceTest.cpp.

References addr, wangle::ServerBootstrap< Pipeline >::bind(), wangle::ServerBootstrap< Pipeline >::childPipeline(), EXPECT_EQ, folly::EventBaseManager::get(), folly::EventBaseManager::getEventBase(), folly::getEventBase(), wangle::ServerBootstrap< Pipeline >::getSockets(), folly::EventBase::loopForever(), folly::gen::move, wangle::ServerBootstrap< Pipeline >::stop(), string, folly::EventBase::terminateLoopSoon(), and value.

114  {
115  // server
117  server.childPipeline(
119  server.bind(0);
120 
121  // client
122  auto client = std::make_shared<ClientBootstrap<ServicePipeline>>();
124  client->pipelineFactory(
127  server.getSockets()[0]->getAddress(&addr);
128  client->connect(addr).waitVia(EventBaseManager::get()->getEventBase());
129 
130  auto service = serviceFactory(client).value();
131  auto rep = (*service)("test");
132 
133  std::move(rep).thenValue([&](std::string value) {
134  EXPECT_EQ("test", value);
135  EventBaseManager::get()->getEventBase()->terminateLoopSoon();
136  });
137  EventBaseManager::get()->getEventBase()->loopForever();
138  server.stop();
139 }
void bind(folly::AsyncServerSocket::UniquePtr s)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
EventBase * getEventBase()
ServerBootstrap * childPipeline(std::shared_ptr< PipelineFactory< Pipeline >> factory)
static const char *const value
Definition: Conv.cpp:50
const std::vector< std::shared_ptr< folly::AsyncSocketBase > > & getSockets() const
const char * string
Definition: Conv.cpp:212
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
Definition: submit.h:391
ThreadPoolListHook * addr
wangle::TEST ( SSLContextManagerTest  ,
DISABLED_TestSessionContextIfSupplied   
)

Definition at line 129 of file SSLContextManagerTest.cpp.

References wangle::SSLContextConfig::addCertificate(), addr, wangle::SSLContextManager::addSSLContextConfig(), ASSERT_NE, EXPECT_EQ, wangle::SSLContextManager::getSSLCtx(), folly::EventBase::loop(), wangle::SSLContextConfig::sessionContext, and string.

130 {
131  EventBase eventBase;
132  SSLContextManagerForTest sslCtxMgr(&eventBase,
133  "vip_ssl_context_manager_test_",
134  true,
135  nullptr);
136  SSLContextConfig ctxConfig;
137  ctxConfig.sessionContext = "test";
138  ctxConfig.addCertificate(
139  "wangle/ssl/test/certs/test.cert.pem",
140  "wangle/ssl/test/certs/test.key.pem",
141  "");
142 
143  SSLCacheOptions cacheOptions;
145 
146  sslCtxMgr.addSSLContextConfig(
147  ctxConfig, cacheOptions, nullptr, addr, nullptr);
148 
149  SSLContextKey key("test.com", CertCrypto::BEST_AVAILABLE);
150  auto ctx = sslCtxMgr.getSSLCtx(key);
151  ASSERT_NE(ctx, nullptr);
152  auto sessCtxFromCtx = std::string(
153  reinterpret_cast<char*>(ctx->getSSLCtx()->sid_ctx),
154  ctx->getSSLCtx()->sid_ctx_length);
155  EXPECT_EQ(*ctxConfig.sessionContext, sessCtxFromCtx);
156  eventBase.loop();
157 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const char * string
Definition: Conv.cpp:212
#define ASSERT_NE(val1, val2)
Definition: gtest.h:1960
ThreadPoolListHook * addr
wangle::TEST ( SSLContextManagerTest  ,
DISABLED_TestSessionContextIfSessionCacheAbsent   
)

Definition at line 160 of file SSLContextManagerTest.cpp.

References wangle::SSLContextConfig::addCertificate(), addr, wangle::SSLContextManager::addSSLContextConfig(), ASSERT_NE, EXPECT_EQ, wangle::SSLContextManager::getSSLCtx(), folly::EventBase::loop(), wangle::SSLContextConfig::sessionCacheEnabled, wangle::SSLContextConfig::sessionContext, and string.

161 {
162  EventBase eventBase;
163  SSLContextManagerForTest sslCtxMgr(&eventBase,
164  "vip_ssl_context_manager_test_",
165  true,
166  nullptr);
167  SSLContextConfig ctxConfig;
168  ctxConfig.sessionContext = "test";
169  ctxConfig.sessionCacheEnabled = false;
170  ctxConfig.addCertificate(
171  "wangle/ssl/test/certs/test.cert.pem",
172  "wangle/ssl/test/certs/test.key.pem",
173  "");
174 
175  SSLCacheOptions cacheOptions;
177 
178  sslCtxMgr.addSSLContextConfig(
179  ctxConfig, cacheOptions, nullptr, addr, nullptr);
180 
181  SSLContextKey key("test.com", CertCrypto::BEST_AVAILABLE);
182  auto ctx = sslCtxMgr.getSSLCtx(key);
183  ASSERT_NE(ctx, nullptr);
184  auto sessCtxFromCtx = std::string(
185  reinterpret_cast<char*>(ctx->getSSLCtx()->sid_ctx),
186  ctx->getSSLCtx()->sid_ctx_length);
187  EXPECT_EQ(*ctxConfig.sessionContext, sessCtxFromCtx);
188  eventBase.loop();
189 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const char * string
Definition: Conv.cpp:212
#define ASSERT_NE(val1, val2)
Definition: gtest.h:1960
ThreadPoolListHook * addr
wangle::TEST ( Wangle  ,
FilterTest   
)

Definition at line 165 of file ServiceTest.cpp.

References EXPECT_EQ, and folly::pushmi::operators::filter.

165  {
166  auto service = std::make_shared<EchoService>();
167  auto filter = std::make_shared<AppendFilter>(service);
168  auto result = (*filter)("test");
169  EXPECT_EQ(result.value(), "test\n");
170 }
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
wangle::TEST ( Wangle  ,
ComplexFilterTest   
)

Definition at line 172 of file ServiceTest.cpp.

References EXPECT_EQ, and folly::pushmi::operators::filter.

172  {
173  auto service = std::make_shared<EchoService>();
174  auto filter = std::make_shared<IntToStringFilter>(service);
175  auto result = (*filter)(1);
176  EXPECT_EQ(result.value(), 1);
177 }
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
wangle::TEST ( Wangle  ,
SuperComplexFilterTest   
)

Definition at line 193 of file ServiceTest.cpp.

References EXPECT_EQ, and folly::pushmi::operators::filter.

193  {
194  auto service = std::make_shared<EchoIntService>();
195  auto filter = std::make_shared<ChangeTypeFilter>(service);
196  auto result = (*filter)(1);
197  EXPECT_EQ(result.value(), "1");
198 }
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
wangle::TEST ( Wangle  ,
ServiceFactoryFilter   
)

Definition at line 216 of file ServiceTest.cpp.

References addr, wangle::ServerBootstrap< Pipeline >::bind(), wangle::ServerBootstrap< Pipeline >::childPipeline(), EXPECT_EQ, folly::EventBaseManager::get(), folly::getEventBase(), wangle::ServerBootstrap< Pipeline >::getSockets(), wangle::ServerBootstrap< Pipeline >::stop(), and value.

216  {
217  // server
219  server.childPipeline(
221  server.bind(0);
222 
223  // client
224  auto clientFactory =
225  std::make_shared<
227  auto countingFactory =
228  std::make_shared<
230  clientFactory);
231 
232  auto client = std::make_shared<ClientBootstrap<ServicePipeline>>();
233  client->pipelineFactory(
236  server.getSockets()[0]->getAddress(&addr);
237  client->connect(addr).waitVia(EventBaseManager::get()->getEventBase());
238 
239  auto service = (*countingFactory)(client).value();
240 
241  // After the first service goes away, the client can be reused
242  service = (*countingFactory)(client).value();
243  EXPECT_EQ(2, countingFactory->connectionCount);
244 
245  server.stop();
246 }
void bind(folly::AsyncServerSocket::UniquePtr s)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
EventBase * getEventBase()
ServerBootstrap * childPipeline(std::shared_ptr< PipelineFactory< Pipeline >> factory)
static const char *const value
Definition: Conv.cpp:50
const std::vector< std::shared_ptr< folly::AsyncSocketBase > > & getSockets() const
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
Definition: submit.h:391
ThreadPoolListHook * addr
wangle::TEST ( Wangle  ,
FactoryToService   
)

Definition at line 248 of file ServiceTest.cpp.

References EXPECT_EQ, and value.

248  {
249  auto constfactory =
250  std::make_shared<ConstFactory<ServicePipeline, std::string, std::string>>(
251  std::make_shared<EchoService>());
253  constfactory);
254 
255  EXPECT_EQ("test", service("test").value());
256 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static const char *const value
Definition: Conv.cpp:50
wangle::TEST ( ServiceFilter  ,
ExpiringMax   
)

Definition at line 276 of file ServiceTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, and wangle::TimekeeperTester::promises_.

276  {
277  TimekeeperTester timekeeper;
278 
279  std::shared_ptr<Service<std::string, std::string>> service =
280  std::make_shared<EchoService>();
281  std::shared_ptr<Service<std::string, std::string>> closeOnReleaseService =
282  std::make_shared<CloseOnReleaseFilter<std::string, std::string>>(service);
283  std::shared_ptr<Service<std::string, std::string>> expiringService =
284  std::make_shared<ExpiringFilter<std::string, std::string>>(
285  closeOnReleaseService,
286  std::chrono::milliseconds(0),
287  std::chrono::milliseconds(400),
288  &timekeeper);
289 
290  EXPECT_EQ("test", (*expiringService)("test").get());
291  timekeeper.promises_[0].setValue();
292  EXPECT_TRUE((*expiringService)("test").getTry().hasException());
293 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::vector< Promise< Unit > > promises_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
wangle::TEST ( ServiceFilter  ,
ExpiringIdle   
)

Definition at line 295 of file ServiceTest.cpp.

References EXPECT_EQ, and wangle::TimekeeperTester::promises_.

295  {
296  TimekeeperTester timekeeper;
297 
298  std::shared_ptr<Service<std::string, std::string>> service =
299  std::make_shared<EchoService>();
300  std::shared_ptr<Service<std::string, std::string>> closeOnReleaseService =
301  std::make_shared<CloseOnReleaseFilter<std::string, std::string>>(service);
302  std::shared_ptr<Service<std::string, std::string>> expiringService =
303  std::make_shared<ExpiringFilter<std::string, std::string>>(
304  closeOnReleaseService,
305  std::chrono::milliseconds(100),
306  std::chrono::milliseconds(0),
307  &timekeeper);
308 
309  EXPECT_EQ(1, timekeeper.promises_.size());
310 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::vector< Promise< Unit > > promises_
wangle::TEST ( ServiceFilter  ,
NoIdleDuringRequests   
)

Definition at line 312 of file ServiceTest.cpp.

References EXPECT_EQ, f, folly::gen::move, and wangle::TimekeeperTester::promises_.

312  {
313  TimekeeperTester timekeeper;
314 
315  std::shared_ptr<Service<std::string, std::string>> service =
316  std::make_shared<EchoService>();
317  std::shared_ptr<Service<std::string, std::string>> closeOnReleaseService =
318  std::make_shared<CloseOnReleaseFilter<std::string, std::string>>(service);
319  std::shared_ptr<Service<std::string, std::string>> expiringService =
320  std::make_shared<ExpiringFilter<std::string, std::string>>(
321  closeOnReleaseService,
322  std::chrono::milliseconds(1),
323  std::chrono::milliseconds(0),
324  &timekeeper);
325 
326  auto f = (*expiringService)("2000");
327  EXPECT_EQ(2, timekeeper.promises_.size());
328  std::move(f).get();
329  EXPECT_EQ("2000", (*expiringService)("2000").get());
330  EXPECT_EQ(3, timekeeper.promises_.size());
331 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::vector< Promise< Unit > > promises_
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithNoConnectionCounter   
)

Definition at line 78 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_TRUE.

78  {
79  acceptor_.setLoadShedConfig(loadShedConfig_, nullptr);
80  // Should accept if there is no IConnectionCounter set
81  EXPECT_TRUE(acceptor_.canAccept(address_));
82 }
FizzServerAcceptor * acceptor_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithMaxConnectionsZero   
)

Definition at line 84 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_TRUE.

84  {
85  // Should accept if maxConnections is zero
86  connectionCounter_.setMaxConnections(0);
87  EXPECT_TRUE(acceptor_.canAccept(address_));
88 }
FizzServerAcceptor * acceptor_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithCurrentConnsLessThanMax   
)

Definition at line 90 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_TRUE.

90  {
91  // Should accept if currentConnections is less than maxConnections
92  connectionCounter_.setNumConnections(100);
93  connectionCounter_.setMaxConnections(200);
94  EXPECT_TRUE(acceptor_.canAccept(address_));
95 }
FizzServerAcceptor * acceptor_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithCurrentConnsGreaterThanMax   
)

Definition at line 97 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_FALSE.

97  {
98  // Should not accept if currentConnections is larger than maxConnections
99  connectionCounter_.setNumConnections(300);
100  connectionCounter_.setMaxConnections(200);
101  acceptor_.setConnectionCountForLoadShedding(300);
102  loadShedConfig_->setMaxConnections(200);
103  acceptor_.setLoadShedConfig(loadShedConfig_, &connectionCounter_);
104  EXPECT_FALSE(acceptor_.canAccept(address_));
105 }
FizzServerAcceptor * acceptor_
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
wangle::TEST_F ( SSLSessionPersistentCacheTest  ,
Basic   
)

Definition at line 103 of file SSLSessionPersistentCacheTest.cpp.

References ASSERT_EQ, ASSERT_FALSE, createPersistentTestSession(), i, and folly::sformat().

103  {
104  for (size_t i = 0; i < sessions_.size(); ++i) {
105  auto hostname = folly::sformat("host{}", i);
106 
107  // The session data does not exist before set.
108  ASSERT_EQ(i, cache_->size());
109  ASSERT_FALSE(cache_->getSSLSession(hostname));
110 
111  cache_->setSSLSession(hostname, createPersistentTestSession(sessions_[i]));
112 
113  // The session data should exist before set.
114  ASSERT_EQ(i + 1, cache_->size());
115  verifyEntryInCache(hostname, sessions_[i]);
116  }
117 
118  // The previously inserted sessions shouldn't have changed. Then remove them
119  // one by one and verify they are not in cache after the removal.
120  for (size_t i = 0; i < sessions_.size(); ++i) {
121  auto hostname = folly::sformat("host{}", i);
122  verifyEntryInCache(hostname, sessions_[i]);
123  cache_->removeSSLSession(hostname);
124  verifyEntryInCache(hostname, sessions_[i], false);
125  }
126 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
SSLSessionPtr createPersistentTestSession(std::pair< SSL_SESSION *, size_t > session)
Definition: TestUtil.cpp:350
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWhiteListedAddress   
)

Definition at line 107 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_TRUE.

107  {
108  // Should accept if currentConnections is larger than maxConnections
109  // but the address is whitelisted
110  connectionCounter_.setNumConnections(300);
111  connectionCounter_.setMaxConnections(200);
112  LoadShedConfiguration::AddressSet addrs = { address_ };
113  loadShedConfig_->setWhitelistAddrs(addrs);
114  acceptor_.setLoadShedConfig(loadShedConfig_, &connectionCounter_);
115  EXPECT_TRUE(acceptor_.canAccept(address_));
116 }
FizzServerAcceptor * acceptor_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithNoLoadShed   
)

Definition at line 118 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_TRUE.

118  {
119  // Should accept if currentConnections is larger than maxConnections,
120  // the address is not whitelisted and the current active and total connections
121  // counts are below the corresponding thresholds
122  connectionCounter_.setNumConnections(300);
123  connectionCounter_.setMaxConnections(200);
124  loadShedConfig_->setMaxActiveConnections(100);
125  loadShedConfig_->setMaxConnections(200);
126  acceptor_.setLoadShedConfig(loadShedConfig_, &connectionCounter_);
127  EXPECT_TRUE(acceptor_.canAccept(address_));
128 }
FizzServerAcceptor * acceptor_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
wangle::TEST_F ( SSLSessionPersistentCacheTest  ,
BadSession   
)

Definition at line 128 of file SSLSessionPersistentCacheTest.cpp.

References ASSERT_EQ, ASSERT_FALSE, createPersistentTestSession(), and string.

128  {
129  std::string badHost = "bad";
130 
131  // Insert bad session to an empty cache.
132  cache_->setSSLSession(badHost, SSLSessionPtr(nullptr));
133  ASSERT_FALSE(cache_->getSSLSession(badHost));
134  ASSERT_EQ(0, cache_->size());
135 
136  cache_->setSSLSession("host0", createPersistentTestSession(sessions_[0]));
137  cache_->setSSLSession("host1", createPersistentTestSession(sessions_[1]));
138 
139  // Insert bad session to non-empty cache
140  cache_->setSSLSession(badHost, SSLSessionPtr(nullptr));
141  ASSERT_FALSE(cache_->getSSLSession(badHost));
142  ASSERT_EQ(2, cache_->size());
143 
144  verifyEntryInCache("host0", sessions_[0]);
145  verifyEntryInCache("host1", sessions_[1]);
146 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
SSLSessionPtr createPersistentTestSession(std::pair< SSL_SESSION *, size_t > session)
Definition: TestUtil.cpp:350
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
const char * string
Definition: Conv.cpp:212
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithMaxActiveConnectionsNotSet   
)

Definition at line 130 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_TRUE.

130  {
131  // Should accept if max active connections threshold is not set and
132  // total connections is within the overall max connections limit
133  connectionCounter_.setNumConnections(300);
134  connectionCounter_.setMaxConnections(200);
135  loadShedConfig_->setMaxConnections(400);
136  acceptor_.setLoadShedConfig(loadShedConfig_, &connectionCounter_);
137  acceptor_.setActiveConnectionCountForLoadShedding(300);
138  acceptor_.setConnectionCountForLoadShedding(300);
139  EXPECT_TRUE(acceptor_.canAccept(address_));
140 }
FizzServerAcceptor * acceptor_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithActiveConnectionsBreachingThreshold   
)

Definition at line 142 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_FALSE.

142  {
143  // Should not accept if currentConnections is larger than maxConnections,
144  // the address is not whitelisted and the current active connection is larger
145  // than the threshold
146  connectionCounter_.setNumConnections(300);
147  connectionCounter_.setMaxConnections(200);
148  loadShedConfig_->setMaxActiveConnections(100);
149  loadShedConfig_->setMaxConnections(200);
150  acceptor_.setLoadShedConfig(loadShedConfig_, &connectionCounter_);
151  acceptor_.setActiveConnectionCountForLoadShedding(110);
152  EXPECT_FALSE(acceptor_.canAccept(address_));
153 }
FizzServerAcceptor * acceptor_
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
wangle::TEST_F ( SSLSessionPersistentCacheTest  ,
Overwrite   
)

Definition at line 148 of file SSLSessionPersistentCacheTest.cpp.

References createPersistentTestSession().

148  {
149  cache_->setSSLSession("host0", createPersistentTestSession(sessions_[0]));
150  cache_->setSSLSession("host1", createPersistentTestSession(sessions_[1]));
151 
152  {
153  // Overwrite host1 with a nullptr, the cache shouldn't have changed.
154  cache_->setSSLSession("host1", SSLSessionPtr(nullptr));
155  verifyEntryInCache("host0", sessions_[0]);
156  verifyEntryInCache("host1", sessions_[1]);
157  }
158 
159  {
160  // Valid overwrite.
161  cache_->setSSLSession("host1", createPersistentTestSession(sessions_[3]));
162  verifyEntryInCache("host0", sessions_[0]);
163  verifyEntryInCache("host1", sessions_[3]);
164  }
165 
166 }
SSLSessionPtr createPersistentTestSession(std::pair< SSL_SESSION *, size_t > session)
Definition: TestUtil.cpp:350
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithTotalConnectionsBreachingThreshold   
)

Definition at line 155 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_FALSE.

155  {
156  // Should not accept if currentConnections is larger than maxConnections,
157  // the address is not whitelisted and the current connection is larger
158  // than the threshold
159  connectionCounter_.setNumConnections(300);
160  connectionCounter_.setMaxConnections(200);
161  loadShedConfig_->setMaxActiveConnections(100);
162  loadShedConfig_->setMaxConnections(200);
163  acceptor_.setLoadShedConfig(loadShedConfig_, &connectionCounter_);
164  acceptor_.setConnectionCountForLoadShedding(210);
165  EXPECT_FALSE(acceptor_.canAccept(address_));
166 }
FizzServerAcceptor * acceptor_
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
wangle::TEST_F ( AcceptorTest  ,
TestCanAcceptWithBothConnectionCountsBreachingThresholds   
)

Definition at line 168 of file AcceptorTest.cpp.

References acceptor_, and EXPECT_FALSE.

168  {
169  // Should not accept if currentConnections is larger than maxConnections,
170  // the address is not whitelisted and the both current active and total
171  // connections counts are larger than the corresponding thresholds
172  connectionCounter_.setNumConnections(300);
173  connectionCounter_.setMaxConnections(200);
174  loadShedConfig_->setMaxActiveConnections(100);
175  loadShedConfig_->setMaxConnections(200);
176  acceptor_.setLoadShedConfig(loadShedConfig_, &connectionCounter_);
177  acceptor_.setActiveConnectionCountForLoadShedding(110);
178  acceptor_.setConnectionCountForLoadShedding(210);
179  EXPECT_FALSE(acceptor_.canAccept(address_));
180 }
FizzServerAcceptor * acceptor_
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
wangle::TEST_F ( SSLSessionPersistentCacheTest  ,
SessionTicketTimeout   
)

Definition at line 168 of file SSLSessionPersistentCacheTest.cpp.

References ASSERT_FALSE, ASSERT_NE, ASSERT_TRUE, createPersistentTestSession(), s, folly::portability::ssl::SSL_SESSION_get_ticket_lifetime_hint(), folly::portability::ssl::SSL_SESSION_has_ticket(), and string.

168  {
169  std::string myhost("host3");
170  cache_->setSSLSession(
171  myhost,
172  createPersistentTestSession(sessionWithTicket_));
173 
174  // First verify element is successfully added to the cache
175  auto s = cache_->getSSLSession(myhost);
176  ASSERT_TRUE(s != nullptr);
178  verifyEntryInCache(myhost, sessions_[3]);
179 
180  // Verify that if element is added to cache within
181  // tlsext_tick_lifetime_hint seconds ago, we can retrieve it
182 
183  // advance current time by slightly less than tlsext_tick_lifetime_hint
184  // Ticket should still be in cache
185  long lifetime_seconds = SSL_SESSION_get_ticket_lifetime_hint(s.get());
186  mockTimeUtil_->advance(
187  duration_cast<milliseconds>(seconds(lifetime_seconds - 10)));
188 
189  verifyEntryInCache(myhost, sessions_[3]);
190 
191  // advance current time to >= tlsext_tick_lifetime_hint
192  // Ticket should not be in cache
193  mockTimeUtil_->advance(duration_cast<milliseconds>(seconds(15)));
194  ASSERT_FALSE(cache_->getSSLSession(myhost));
195 }
SSLSessionPtr createPersistentTestSession(std::pair< SSL_SESSION *, size_t > session)
Definition: TestUtil.cpp:350
int SSL_SESSION_has_ticket(const SSL_SESSION *s)
Definition: OpenSSL.cpp:203
unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
Definition: OpenSSL.cpp:207
const char * string
Definition: Conv.cpp:212
static set< string > s
#define ASSERT_NE(val1, val2)
Definition: gtest.h:1960
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
template<typename K , typename V , typename MutexT = std::mutex>
void wangle::testSimplePutGet ( const std::vector< K > &  keys,
const std::vector< V > &  values 
)

Definition at line 32 of file TestUtil.h.

References EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, getPersistentCacheFilename(), and string.

34  {
36  typedef FilePersistentCache<K, V, MutexT> CacheType;
37  size_t cacheCapacity = 10;
38  {
39  CacheType cache(filename, cacheCapacity, std::chrono::seconds(150));
40  EXPECT_FALSE(cache.get(keys[0]).hasValue());
41  EXPECT_FALSE(cache.get(keys[1]).hasValue());
42  cache.put(keys[0], values[0]);
43  cache.put(keys[1], values[1]);
44  EXPECT_EQ(cache.size(), 2);
45  EXPECT_EQ(cache.get(keys[0]).value(), values[0]);
46  EXPECT_EQ(cache.get(keys[1]).value(), values[1]);
47  }
48  {
49  CacheType cache(filename, cacheCapacity, std::chrono::seconds(150));
50  EXPECT_EQ(cache.size(), 2);
51  EXPECT_EQ(cache.get(keys[0]).value(), values[0]);
52  EXPECT_EQ(cache.get(keys[1]).value(), values[1]);
53  EXPECT_TRUE(cache.remove(keys[1]));
54  EXPECT_FALSE(cache.remove(keys[1]));
55  EXPECT_EQ(cache.size(), 1);
56  EXPECT_EQ(cache.get(keys[0]).value(), values[0]);
57  EXPECT_FALSE(cache.get(keys[1]).hasValue());
58  }
59  {
60  CacheType cache(filename, cacheCapacity, std::chrono::seconds(150));
61  EXPECT_EQ(cache.size(), 1);
62  EXPECT_EQ(cache.get(keys[0]).value(), values[0]);
63  EXPECT_FALSE(cache.get(keys[1]).hasValue());
64  cache.clear();
65  EXPECT_EQ(cache.size(), 0);
66  EXPECT_FALSE(cache.get(keys[0]).hasValue());
67  EXPECT_FALSE(cache.get(keys[1]).hasValue());
68  }
69  {
70  CacheType cache(filename, cacheCapacity, std::chrono::seconds(150));
71  EXPECT_EQ(cache.size(), 0);
72  EXPECT_FALSE(cache.get(keys[0]).hasValue());
73  EXPECT_FALSE(cache.get(keys[1]).hasValue());
74  }
75  EXPECT_TRUE(unlink(filename.c_str()) != -1);
76 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
std::string getPersistentCacheFilename()
Definition: TestUtil.cpp:22

Variable Documentation

const std::string wangle::empty_string
static

Definition at line 24 of file SSLAcceptorHandshakeHelper.cpp.

const std::string wangle::empty_string
static

Definition at line 51 of file Acceptor.cpp.

Referenced by wangle::SSLAcceptorHandshakeHelper::handshakeSuc().

const size_t wangle::kNumSessions = 3

Definition at line 20 of file TestUtil.cpp.

Referenced by getSessions().

const unsigned char wangle::kSessionData[kNumSessions][kSessionDataLen]

Definition at line 24 of file TestUtil.cpp.

const size_t wangle::kSessionDataLen = 1060

Definition at line 21 of file TestUtil.cpp.

const unsigned char wangle::kSessionDataWithTicket[]

Definition at line 218 of file TestUtil.cpp.

Referenced by getSessionWithTicket().