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 <fizz/crypto/aead/Aead.h>
12 #include <gmock/gmock.h>
13 
14 /* using override */
15 using namespace testing;
16 
17 namespace fizz {
18 namespace test {
19 
20 class MockAead : public Aead {
21  public:
22  MOCK_CONST_METHOD0(keyLength, size_t());
23  MOCK_CONST_METHOD0(ivLength, size_t());
24  MOCK_CONST_METHOD0(getCipherOverhead, size_t());
25  MOCK_METHOD1(setEncryptedBufferHeadroom, void(size_t));
26 
27  MOCK_METHOD1(_setKey, void(TrafficKey& key));
28  void setKey(TrafficKey key) override {
29  return _setKey(key);
30  }
31 
33  _encrypt,
34  std::unique_ptr<folly::IOBuf>(
35  std::unique_ptr<folly::IOBuf>& plaintext,
36  const folly::IOBuf* associatedData,
37  uint64_t seqNum));
38  std::unique_ptr<folly::IOBuf> encrypt(
39  std::unique_ptr<folly::IOBuf>&& plaintext,
40  const folly::IOBuf* associatedData,
41  uint64_t seqNum) const override {
42  return _encrypt(plaintext, associatedData, seqNum);
43  }
44 
46  _decrypt,
47  std::unique_ptr<folly::IOBuf>(
48  std::unique_ptr<folly::IOBuf>& ciphertext,
49  const folly::IOBuf* associatedData,
50  uint64_t seqNum));
51  std::unique_ptr<folly::IOBuf> decrypt(
52  std::unique_ptr<folly::IOBuf>&& ciphertext,
53  const folly::IOBuf* associatedData,
54  uint64_t seqNum) const override {
55  return _decrypt(ciphertext, associatedData, seqNum);
56  }
57 
59  _tryDecrypt,
60  folly::Optional<std::unique_ptr<folly::IOBuf>>(
61  std::unique_ptr<folly::IOBuf>& ciphertext,
62  const folly::IOBuf* associatedData,
63  uint64_t seqNum));
65  std::unique_ptr<folly::IOBuf>&& ciphertext,
66  const folly::IOBuf* associatedData,
67  uint64_t seqNum) const override {
68  return _tryDecrypt(ciphertext, associatedData, seqNum);
69  }
70 
71  void setDefaults() {
72  ON_CALL(*this, _encrypt(_, _, _)).WillByDefault(InvokeWithoutArgs([]() {
73  return folly::IOBuf::copyBuffer("ciphertext");
74  }));
75  ON_CALL(*this, _decrypt(_, _, _)).WillByDefault(InvokeWithoutArgs([]() {
76  return folly::IOBuf::copyBuffer("plaintext");
77  }));
78  ON_CALL(*this, _tryDecrypt(_, _, _)).WillByDefault(InvokeWithoutArgs([]() {
79  return folly::IOBuf::copyBuffer("plaintext");
80  }));
81  }
82 };
83 } // namespace test
84 } // namespace fizz
std::unique_ptr< folly::IOBuf > decrypt(std::unique_ptr< folly::IOBuf > &&ciphertext, const folly::IOBuf *associatedData, uint64_t seqNum) const override
Definition: Mocks.h:51
folly::Optional< std::unique_ptr< folly::IOBuf > > tryDecrypt(std::unique_ptr< folly::IOBuf > &&ciphertext, const folly::IOBuf *associatedData, uint64_t seqNum) const override
Definition: Mocks.h:64
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Definition: Actions.h:16
#define MOCK_CONST_METHOD3(m,...)
void setDefaults()
Definition: Mocks.h:71
std::unique_ptr< folly::IOBuf > encrypt(std::unique_ptr< folly::IOBuf > &&plaintext, const folly::IOBuf *associatedData, uint64_t seqNum) const override
Definition: Mocks.h:38
#define ON_CALL(obj, call)
#define MOCK_METHOD1(m,...)
#define MOCK_CONST_METHOD0(m,...)
const internal::AnythingMatcher _
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 setKey(TrafficKey key) override
Definition: Mocks.h:28