Update providedCiphersStr_ in one place.
[folly.git] / folly / io / async / test / MockAsyncSSLSocket.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17
18 #include <folly/io/async/AsyncSSLSocket.h>
19 #include <folly/portability/GMock.h>
20
21 namespace folly { namespace test {
22
23 class MockAsyncSSLSocket : public AsyncSSLSocket {
24  public:
25   MockAsyncSSLSocket(
26    const std::shared_ptr<SSLContext>& ctx,
27    EventBase* base,
28    bool deferSecurityNegotiation = false) :
29     AsyncSSLSocket(ctx, base, deferSecurityNegotiation) {
30   }
31
32   GMOCK_METHOD5_(, noexcept, ,
33    connect,
34    void(AsyncSocket::ConnectCallback*,
35     const folly::SocketAddress&,
36     int,
37     const OptionMap&,
38     const folly::SocketAddress&));
39   MOCK_CONST_METHOD1(getLocalAddress, void(folly::SocketAddress*));
40   MOCK_CONST_METHOD1(getPeerAddress, void(folly::SocketAddress*));
41   MOCK_METHOD0(closeNow, void());
42   MOCK_CONST_METHOD0(good, bool());
43   MOCK_CONST_METHOD0(readable, bool());
44   MOCK_CONST_METHOD0(hangup, bool());
45   MOCK_CONST_METHOD3(getSelectedNextProtocol,
46                      void(const unsigned char**,
47                           unsigned*,
48                           SSLContext::NextProtocolType*));
49   MOCK_CONST_METHOD3(getSelectedNextProtocolNoThrow,
50                      bool(const unsigned char**,
51                           unsigned*,
52                           SSLContext::NextProtocolType*));
53   MOCK_METHOD1(setReadCB, void(ReadCallback*));
54
55   void sslConn(
56       AsyncSSLSocket::HandshakeCB* cb,
57       std::chrono::milliseconds timeout,
58       const SSLContext::SSLVerifyPeerEnum& verify) override {
59     if (timeout > std::chrono::milliseconds::zero()) {
60       handshakeTimeout_.scheduleTimeout(timeout);
61     }
62
63     state_ = StateEnum::ESTABLISHED;
64     sslState_ = STATE_CONNECTING;
65     handshakeCallback_ = cb;
66
67     sslConnectMockable(cb, timeout, verify);
68   }
69
70   void sslAccept(
71       AsyncSSLSocket::HandshakeCB* cb,
72       std::chrono::milliseconds timeout,
73       const SSLContext::SSLVerifyPeerEnum& verify) override {
74     if (timeout > std::chrono::milliseconds::zero()) {
75       handshakeTimeout_.scheduleTimeout(timeout);
76     }
77
78     state_ = StateEnum::ESTABLISHED;
79     sslState_ = STATE_ACCEPTING;
80     handshakeCallback_ = cb;
81
82     sslAcceptMockable(cb, timeout, verify);
83   }
84
85   MOCK_METHOD3(
86       sslConnectMockable,
87       void(
88           AsyncSSLSocket::HandshakeCB*,
89           std::chrono::milliseconds,
90           const SSLContext::SSLVerifyPeerEnum&));
91
92   MOCK_METHOD3(
93       sslAcceptMockable,
94       void(
95           AsyncSSLSocket::HandshakeCB*,
96           std::chrono::milliseconds,
97           const SSLContext::SSLVerifyPeerEnum&));
98 };
99
100 }}