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 <folly/portability/GMock.h>
12 
13 #include <fizz/crypto/exchange/KeyExchange.h>
14 
15 namespace fizz {
16 
17 /* using override */
18 using namespace testing;
19 
20 class MockKeyExchange : public KeyExchange {
21  public:
22   MOCK_METHOD0(generateKeyPair, void());
23   MOCK_CONST_METHOD0(getKeyShare, std::unique_ptr<folly::IOBuf>());
24   MOCK_CONST_METHOD1(
25       generateSharedSecret,
26       std::unique_ptr<folly::IOBuf>(folly::ByteRange keyShare));
27   MOCK_CONST_METHOD0(clone, std::unique_ptr<KeyExchange>());
28 
setDefaults()29   void setDefaults() {
30     ON_CALL(*this, getKeyShare()).WillByDefault(InvokeWithoutArgs([]() {
31       return folly::IOBuf::copyBuffer("keyshare");
32     }));
33     ON_CALL(*this, generateSharedSecret(_))
34         .WillByDefault(InvokeWithoutArgs(
35             []() { return folly::IOBuf::copyBuffer("sharedsecret"); }));
36   }
37 };
38 
39 } // namespace fizz
40