proxygen
fizz::test::ProtocolTest< SM, Actions > Class Template Reference

#include <ProtocolTest.h>

Inheritance diagram for fizz::test::ProtocolTest< SM, Actions >:
testing::Test

Protected Types

using MutateState = folly::Function< void(typename SM::State &)>
 

Protected Member Functions

template<typename... Args>
void expectActions (const Actions &actions)
 
template<typename T >
T expectAction (Actions &actions)
 
template<typename T >
T expectSingleAction (Actions actions)
 
void processStateMutations (Actions &actions)
 
template<typename T >
uint32_t getNumActions (const Actions &actions, bool expectNonZero)
 
template<typename T1 , typename T2 , typename... Args>
uint32_t getNumActions (const Actions &actions, bool expectNonZero)
 
void expectExceptionType (Actions &actions)
 
template<typename ExceptionType >
void expectError (Actions &actions, folly::Optional< AlertDescription > alert, std::string msg="")
 
void expectAeadCreation (std::map< std::string, MockAead ** > keys)
 
void expectAeadCreation (MockAead **clientAead, MockAead **serverAead)
 
void expectEncryptedReadRecordLayerCreation (MockEncryptedReadRecordLayer **recordLayer, MockAead **readAead, folly::ByteRange expectedBaseSecret, folly::Optional< bool > skipFailedDecryption=folly::none, Sequence *s=nullptr)
 
void expectEncryptedWriteRecordLayerCreation (MockEncryptedWriteRecordLayer **recordLayer, MockAead **writeAead, folly::ByteRange expectedBaseSecret, std::function< TLSContent(TLSMessage &, MockEncryptedWriteRecordLayer *)> expectedWrite=nullptr, Sequence *s=nullptr)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Protected Attributes

SM::State state_
 
MockFactoryfactory_
 

Additional Inherited Members

- Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 

Detailed Description

template<typename SM, typename Actions>
class fizz::test::ProtocolTest< SM, Actions >

Definition at line 25 of file ProtocolTest.h.

Member Typedef Documentation

template<typename SM, typename Actions>
using fizz::test::ProtocolTest< SM, Actions >::MutateState = folly::Function<void(typename SM::State&)>
protected

Definition at line 27 of file ProtocolTest.h.

Member Function Documentation

template<typename SM, typename Actions>
template<typename T >
T fizz::test::ProtocolTest< SM, Actions >::expectAction ( Actions actions)
inlineprotected

Definition at line 35 of file ProtocolTest.h.

35  {
36  for (auto& action : actions) {
37  try {
38  return std::move(boost::get<T>(action));
39  } catch (const boost::bad_get&) {
40  }
41  }
42  throw std::runtime_error("did not find expected action");
43  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Actions actions(Args &&...act)
Definition: Actions.h:86
action
Definition: upload.py:393
template<typename SM, typename Actions>
template<typename... Args>
void fizz::test::ProtocolTest< SM, Actions >::expectActions ( const Actions actions)
inlineprotected

Definition at line 30 of file ProtocolTest.h.

30  {
31  EXPECT_EQ(getNumActions<Args...>(actions, true), actions.size());
32  }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
template<typename SM, typename Actions>
void fizz::test::ProtocolTest< SM, Actions >::expectAeadCreation ( std::map< std::string, MockAead ** >  keys)
inlineprotected

Definition at line 112 of file ProtocolTest.h.

Referenced by fizz::test::ProtocolTest< ClientTypes, Actions >::expectAeadCreation().

112  {
113  EXPECT_CALL(*factory_, makeAead(_)).WillRepeatedly(InvokeWithoutArgs([=]() {
114  auto ret = std::make_unique<MockAead>();
115  EXPECT_CALL(*ret, _setKey(_))
116  .WillOnce(Invoke([keys, ptr = ret.get()](TrafficKey& key) {
117  *keys.at(key.key->clone()->moveToFbString().toStdString()) = ptr;
118  }));
119  return ret;
120  }));
121  }
void * ptr
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
template<typename SM, typename Actions>
void fizz::test::ProtocolTest< SM, Actions >::expectAeadCreation ( MockAead **  clientAead,
MockAead **  serverAead 
)
inlineprotected

Definition at line 123 of file ProtocolTest.h.

123  {
124  return expectAeadCreation(
125  {{"clientkey", clientAead}, {"serverkey", serverAead}});
126  }
void expectAeadCreation(std::map< std::string, MockAead ** > keys)
Definition: ProtocolTest.h:112
template<typename SM, typename Actions>
void fizz::test::ProtocolTest< SM, Actions >::expectEncryptedReadRecordLayerCreation ( MockEncryptedReadRecordLayer **  recordLayer,
MockAead **  readAead,
folly::ByteRange  expectedBaseSecret,
folly::Optional< bool >  skipFailedDecryption = folly::none,
Sequence s = nullptr 
)
inlineprotected

Definition at line 128 of file ProtocolTest.h.

133  {
134  EXPECT_CALL(*factory_, makeEncryptedReadRecordLayer(_))
135  .InSequence(s ? *s : Sequence())
136  .WillOnce(Invoke([=](EncryptionLevel encryptionLevel) {
137  auto ret =
138  std::make_unique<MockEncryptedReadRecordLayer>(encryptionLevel);
139  *recordLayer = ret.get();
140  EXPECT_CALL(*ret, _setAead(_, _))
141  .WillOnce(Invoke([=](folly::ByteRange baseSecret, Aead* aead) {
142  EXPECT_TRUE(baseSecret == expectedBaseSecret);
143  EXPECT_EQ(aead, *readAead);
144  }));
145  if (skipFailedDecryption.hasValue()) {
146  EXPECT_CALL(
147  *ret, setSkipFailedDecryption(skipFailedDecryption.value()));
148  }
149  return ret;
150  }));
151  }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
EncryptionLevel
Definition: Types.h:29
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
FOLLY_CPP14_CONSTEXPR const Value & value() const &
Definition: Optional.h:268
template<typename SM, typename Actions>
void fizz::test::ProtocolTest< SM, Actions >::expectEncryptedWriteRecordLayerCreation ( MockEncryptedWriteRecordLayer **  recordLayer,
MockAead **  writeAead,
folly::ByteRange  expectedBaseSecret,
std::function< TLSContent(TLSMessage &, MockEncryptedWriteRecordLayer *)>  expectedWrite = nullptr,
Sequence s = nullptr 
)
inlineprotected

Definition at line 153 of file ProtocolTest.h.

159  {
160  EXPECT_CALL(*factory_, makeEncryptedWriteRecordLayer(_))
161  .InSequence(s ? *s : Sequence())
162  .WillOnce(Invoke([=](EncryptionLevel encryptionLevel) {
163  auto ret =
164  std::make_unique<MockEncryptedWriteRecordLayer>(encryptionLevel);
165  ret->setDefaults();
166  *recordLayer = ret.get();
167  EXPECT_CALL(*ret, _setAead(_, _))
168  .WillOnce(Invoke([=](folly::ByteRange baseSecret, Aead* aead) {
169  EXPECT_TRUE(baseSecret == expectedBaseSecret);
170  EXPECT_EQ(aead, *writeAead);
171  }));
172  if (expectedWrite) {
173  EXPECT_CALL(*ret, _write(_))
174  .WillOnce(
175  Invoke([writeFunc = std::move(expectedWrite),
176  writeRecord = *recordLayer](auto& msg) mutable {
177  return writeFunc(msg, writeRecord);
178  }));
179  }
180  return ret;
181  }));
182  }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
EncryptionLevel
Definition: Types.h:29
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
template<typename SM, typename Actions>
template<typename ExceptionType >
void fizz::test::ProtocolTest< SM, Actions >::expectError ( Actions actions,
folly::Optional< AlertDescription alert,
std::string  msg = "" 
)
inlineprotected

Definition at line 87 of file ProtocolTest.h.

90  {
91  if (alert) {
92  expectActions<MutateState, ReportError, WriteToSocket>(actions);
93  auto write = expectAction<WriteToSocket>(actions);
94  Alert a;
95  a.description = *alert;
96  auto buf = folly::IOBuf::copyBuffer("alert");
97  buf->prependChain(encode(std::move(a)));
98  EXPECT_TRUE(folly::IOBufEqualTo()(write.contents[0].data, buf));
99  } else {
100  expectActions<MutateState, ReportError>(actions);
101  }
102  auto error = expectAction<ReportError>(actions);
103  auto ex = error.error.template get_exception<ExceptionType>();
104  EXPECT_NE(ex, nullptr);
105  EXPECT_THAT(error.error.what().toStdString(), HasSubstr(msg));
108  EXPECT_EQ(state_.readRecordLayer(), nullptr);
109  EXPECT_EQ(state_.writeRecordLayer(), nullptr);
110  }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
char a
error_stage Error
Actions actions(Args &&...act)
Definition: Actions.h:86
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_THAT(value, matcher)
Buf encode(TokenBindingMessage &&message)
Definition: Types.cpp:124
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
void processStateMutations(Actions &actions)
Definition: ProtocolTest.h:51
template<typename SM, typename Actions>
void fizz::test::ProtocolTest< SM, Actions >::expectExceptionType ( Actions actions)
inlineprotected

Definition at line 82 of file ProtocolTest.h.

82  {
83  auto error = expectAction<ReportError>(actions);
84  }
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
Actions actions(Args &&...act)
Definition: Actions.h:86
template<typename SM, typename Actions>
template<typename T >
T fizz::test::ProtocolTest< SM, Actions >::expectSingleAction ( Actions  actions)
inlineprotected

Definition at line 46 of file ProtocolTest.h.

46  {
47  EXPECT_EQ(actions.size(), 1);
48  return expectAction<T>(actions);
49  }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Actions actions(Args &&...act)
Definition: Actions.h:86
template<typename SM, typename Actions>
template<typename T >
uint32_t fizz::test::ProtocolTest< SM, Actions >::getNumActions ( const Actions actions,
bool  expectNonZero 
)
inlineprotected

Definition at line 61 of file ProtocolTest.h.

61  {
62  uint32_t count = 0;
63  for (const auto& action : actions) {
64  try {
65  boost::get<T>(action);
66  count++;
67  } catch (const boost::bad_get&) {
68  }
69  }
70  if (expectNonZero) {
71  EXPECT_NE(count, 0);
72  }
73  return count;
74  }
Actions actions(Args &&...act)
Definition: Actions.h:86
int * count
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
action
Definition: upload.py:393
template<typename SM, typename Actions>
template<typename T1 , typename T2 , typename... Args>
uint32_t fizz::test::ProtocolTest< SM, Actions >::getNumActions ( const Actions actions,
bool  expectNonZero 
)
inlineprotected

Definition at line 77 of file ProtocolTest.h.

77  {
78  return getNumActions<T1>(actions, expectNonZero) +
79  getNumActions<T2, Args...>(actions, expectNonZero);
80  }
Actions actions(Args &&...act)
Definition: Actions.h:86
template<typename SM, typename Actions>
void fizz::test::ProtocolTest< SM, Actions >::processStateMutations ( Actions actions)
inlineprotected

Definition at line 51 of file ProtocolTest.h.

Referenced by fizz::test::ProtocolTest< ClientTypes, Actions >::expectError().

51  {
52  for (auto& action : actions) {
53  try {
54  boost::get<MutateState>(action)(state_);
55  } catch (const boost::bad_get&) {
56  }
57  }
58  }
Actions actions(Args &&...act)
Definition: Actions.h:86
action
Definition: upload.py:393

Member Data Documentation

template<typename SM, typename Actions>
SM::State fizz::test::ProtocolTest< SM, Actions >::state_
protected

The documentation for this class was generated from the following file: