proxygen
Mocks.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <gmock/gmock.h>
12 
16 #include <fizz/record/test/Mocks.h>
23 
24 /* using override */
25 using namespace testing;
26 /* using override */
27 using namespace fizz::test;
28 
29 namespace fizz {
30 namespace server {
31 namespace test {
32 
34  public:
36  _processAccept,
38  const State&,
40  std::shared_ptr<const FizzServerContext> context,
41  const std::shared_ptr<ServerExtensions>& extensions));
43  const State& state,
45  std::shared_ptr<const FizzServerContext> context,
46  const std::shared_ptr<ServerExtensions>& extensions) override {
47  return *_processAccept(state, executor, std::move(context), extensions);
48  }
49 
51  _processSocketData,
54  override {
55  return *_processSocketData(state, queue);
56  }
57 
59  _processWriteNewSessionTicket,
62  const State& state,
63  WriteNewSessionTicket write) override {
64  return *_processWriteNewSessionTicket(state, write);
65  }
66 
68  _processAppWrite,
71  return *_processAppWrite(state, appWrite);
72  }
73 
75  _processEarlyAppWrite,
78  override {
79  return *_processEarlyAppWrite(state, appWrite);
80  }
81 
82  MOCK_METHOD1(_processAppClose, folly::Optional<Actions>(const State&));
83  Actions processAppClose(const State& state) override {
84  return *_processAppClose(state);
85  }
86 };
87 
89  public:
91  _encrypt,
92  folly::Future<folly::Optional<std::pair<Buf, std::chrono::seconds>>>(
93  ResumptionState&));
95  ResumptionState resState) const override {
96  return _encrypt(resState);
97  }
98 
100  _decrypt,
102  std::unique_ptr<folly::IOBuf>& encryptedTicket));
104  std::unique_ptr<folly::IOBuf> encryptedTicket) const override {
105  return _decrypt(encryptedTicket);
106  }
107 
108  void setDefaults() {
109  ON_CALL(*this, _decrypt(_)).WillByDefault(InvokeWithoutArgs([]() {
110  ResumptionState res;
111  res.version = ProtocolVersion::tls_1_3;
112  res.cipher = CipherSuite::TLS_AES_128_GCM_SHA256;
113  res.resumptionSecret = folly::IOBuf::copyBuffer("resumesecret");
114  res.alpn = "h2";
115  res.ticketAgeAdd = 0;
116  res.ticketIssueTime =
117  std::chrono::system_clock::now() - std::chrono::seconds(100);
118  return std::make_pair(PskType::Resumption, std::move(res));
119  }));
120  ON_CALL(*this, _encrypt(_)).WillByDefault(InvokeWithoutArgs([]() {
121  return std::make_pair(
122  folly::IOBuf::copyBuffer("ticket"), std::chrono::seconds(100));
123  }));
124  }
125 };
126 
128  public:
130  folly::Optional<CookieState> decrypt(Buf cookie) const override {
131  return _decrypt(cookie);
132  }
133 };
134 
135 template <typename SM>
137  public:
138  MOCK_METHOD0(_fizzHandshakeSuccess, void());
140  _fizzHandshakeSuccess();
141  }
142 
143  MOCK_METHOD1(_fizzHandshakeError, void(folly::exception_wrapper));
146  folly::exception_wrapper ew) noexcept override {
147  _fizzHandshakeError(std::move(ew));
148  }
149 
150  MOCK_METHOD1(
151  _fizzHandshakeAttemptFallback,
152  void(std::unique_ptr<folly::IOBuf>&));
154  std::unique_ptr<folly::IOBuf> clientHello) override {
155  return _fizzHandshakeAttemptFallback(clientHello);
156  }
157 };
158 
160 
161 template <typename SM>
163  public:
166  const std::shared_ptr<FizzServerContext>& fizzContext)
167  : AsyncFizzServerT<SM>(std::move(socket), fizzContext) {}
168 
169  using UniquePtr = std::
170  unique_ptr<MockAsyncFizzServerT, folly::DelayedDestruction::Destructor>;
171 
173 };
174 
176 
177 class MockCertManager : public CertManager {
178  public:
180  getCert,
181  CertMatch(
183  const std::vector<SignatureScheme>& supportedSigSchemes,
184  const std::vector<SignatureScheme>& peerSigSchemes));
186  getCert,
187  std::shared_ptr<SelfCert>(const std::string& identity));
188 };
189 
191  public:
192  MOCK_METHOD1(getExtensions, std::vector<Extension>(const ClientHello& chlo));
193 };
194 
195 class MockReplayCache : public ReplayCache {
196  public:
198 };
199 
201  public:
202  MOCK_CONST_METHOD1(validate, bool(const ResumptionState&));
203 };
204 } // namespace test
205 } // namespace server
206 } // namespace fizz
AsyncActions processEarlyAppWrite(const State &state, EarlyAppWrite appWrite) override
Definition: Mocks.h:77
#define MOCK_METHOD4(m,...)
#define MOCK_CONST_METHOD1(m,...)
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
static const std::string chlo
context
Definition: CMakeCache.txt:563
std::chrono::steady_clock::time_point now()
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
boost::variant< Actions, folly::Future< Actions >> AsyncActions
Definition: Actions.h:52
STL namespace.
AsyncActions processWriteNewSessionTicket(const State &state, WriteNewSessionTicket write) override
Definition: Mocks.h:61
static AppWrite appWrite(const std::string &str)
folly::Optional< std::string > alpn
requires E e noexcept(noexcept(s.error(std::move(e))))
std::chrono::system_clock::time_point ticketIssueTime
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
folly::ssl::X509UniquePtr getCert(folly::StringPiece cert)
Definition: TestUtil.cpp:48
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
void fizzHandshakeAttemptFallback(std::unique_ptr< folly::IOBuf > clientHello) override
Definition: Mocks.h:153
Actions processAppClose(const State &state) override
Definition: Mocks.h:83
AsyncActions processSocketData(const State &state, folly::IOBufQueue &queue) override
Definition: Mocks.h:53
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
void fizzHandshakeError(AsyncFizzServerT< SM > *, folly::exception_wrapper ew) noexceptoverride
Definition: Mocks.h:144
MockAsyncFizzServerT(folly::AsyncTransportWrapper::UniquePtr socket, const std::shared_ptr< FizzServerContext > &fizzContext)
Definition: Mocks.h:164
Definition: Actions.h:16
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
void fizzHandshakeSuccess(AsyncFizzServerT< SM > *) noexceptoverride
Definition: Mocks.h:139
#define MOCK_CONST_METHOD3(m,...)
PskType
Definition: Types.h:18
#define ON_CALL(obj, call)
std::unique_ptr< AsyncFizzBase, folly::DelayedDestruction::Destructor > UniquePtr
Definition: AsyncFizzBase.h:30
StringPiece sni
#define MOCK_METHOD1(m,...)
const char * string
Definition: Conv.cpp:212
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
folly::Future< std::pair< PskType, folly::Optional< ResumptionState > > > decrypt(std::unique_ptr< folly::IOBuf > encryptedTicket) const override
Definition: Mocks.h:103
const internal::AnythingMatcher _
folly::Future< folly::Optional< std::pair< Buf, std::chrono::seconds > > > encrypt(ResumptionState resState) const override
Definition: Mocks.h:94
AsyncActions processAccept(const State &state, folly::Executor *executor, std::shared_ptr< const FizzServerContext > context, const std::shared_ptr< ServerExtensions > &extensions) override
Definition: Mocks.h:42
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
#define MOCK_METHOD2(m,...)
folly::Optional< CookieState > decrypt(Buf cookie) const override
Definition: Mocks.h:130
bool check(const dynamic &schema, const dynamic &value, bool check=true)
state
Definition: http_parser.c:272
AsyncActions processAppWrite(const State &state, AppWrite appWrite) override
Definition: Mocks.h:70
#define MOCK_METHOD0(m,...)