1 /* 2 * Copyright (c) 2015, 2021, Oracle and/or its affiliates. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License, version 2.0, 6 * as published by the Free Software Foundation. 7 * 8 * This program is also distributed with certain software (including 9 * but not limited to OpenSSL) that is licensed under separate terms, 10 * as designated in a particular file or component or in included license 11 * documentation. The authors of MySQL hereby grant you an additional 12 * permission to link the program and your derivative works with the 13 * separately licensed software that they have included with MySQL. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License, version 2.0, for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 23 * 02110-1301 USA 24 */ 25 26 #include "ngs_common/operations_factory_interface.h" 27 #include "ngs_common/socket_interface.h" 28 #include "ngs_common/options.h" 29 #include "ngs/socket_events_interface.h" 30 31 32 namespace ngs { 33 34 namespace test { 35 36 class Mock_options_session : public IOptions_session { 37 public: 38 MOCK_METHOD0(supports_tls,bool ()); 39 MOCK_METHOD0(active_tls, bool ()); 40 MOCK_METHOD0(ssl_cipher, std::string ()); 41 MOCK_METHOD0(ssl_cipher_list, std::vector<std::string> ()); 42 MOCK_METHOD0(ssl_version, std::string ()); 43 44 MOCK_METHOD0(ssl_verify_depth, long ()); 45 MOCK_METHOD0(ssl_verify_mode, long ()); 46 MOCK_METHOD0(ssl_sessions_reused, long ()); 47 MOCK_METHOD0(ssl_get_verify_result_and_cert, long ()); 48 49 MOCK_METHOD0(ssl_get_peer_certificate_issuer, std::string ()); 50 51 MOCK_METHOD0(ssl_get_peer_certificate_subject, std::string ()); 52 }; 53 54 class Mock_options_context : public IOptions_context { 55 public: 56 MOCK_METHOD0(ssl_ctx_verify_depth, long ()); 57 MOCK_METHOD0(ssl_ctx_verify_mode, long ()); 58 59 MOCK_METHOD0(ssl_server_not_after, std::string ()); 60 MOCK_METHOD0(ssl_server_not_before, std::string ()); 61 62 MOCK_METHOD0(ssl_accept_renegotiates ,long ()); 63 64 MOCK_METHOD0(ssl_session_cache_hits, long ()); 65 MOCK_METHOD0(ssl_session_cache_misses, long ()); 66 MOCK_METHOD0(ssl_session_cache_mode, std::string ()); 67 MOCK_METHOD0(ssl_session_cache_overflows, long ()); 68 MOCK_METHOD0(ssl_session_cache_size, long ()); 69 MOCK_METHOD0(ssl_session_cache_timeouts, long ()); 70 MOCK_METHOD0(ssl_used_session_cache_entries, long ()); 71 }; 72 73 class Mock_socket: public Socket_interface { 74 public: 75 76 MOCK_METHOD2(bind, int (const struct sockaddr*, socklen_t)); 77 MOCK_METHOD3(accept, MYSQL_SOCKET(PSI_socket_key, struct sockaddr*, socklen_t*)); 78 MOCK_METHOD1(listen, int(int)); 79 80 MOCK_METHOD0(close, void ()); 81 82 MOCK_METHOD0(get_socket_mysql, MYSQL_SOCKET ()); 83 MOCK_METHOD0(get_socket_fd, my_socket ()); 84 85 MOCK_METHOD4(set_socket_opt, int (int, int, const SOCKBUF_T *, socklen_t)); 86 MOCK_METHOD0(set_socket_thread_owner, void ()); 87 }; 88 89 class Mock_system: public System_interface { 90 public: 91 MOCK_METHOD1(unlink, int(const char*)); 92 MOCK_METHOD2(kill, int(int, int)); 93 94 MOCK_METHOD0(get_ppid, int()); 95 MOCK_METHOD0(get_pid, int()); 96 MOCK_METHOD0(get_errno, int()); 97 98 MOCK_METHOD0(get_socket_errno, int ()); 99 MOCK_METHOD2(get_socket_error_and_message, void (int&, std::string&)); 100 101 MOCK_METHOD1(freeaddrinfo, void (addrinfo *)); 102 MOCK_METHOD4(getaddrinfo, int ( 103 const char *, 104 const char *, 105 const addrinfo *, 106 addrinfo **)); 107 108 MOCK_METHOD1(sleep, void (uint32)); 109 }; 110 111 class Mock_file: public File_interface { 112 public: 113 MOCK_METHOD0(is_valid, bool ()); 114 115 MOCK_METHOD0(close, int()); 116 MOCK_METHOD2(read, int(void*, int)); 117 MOCK_METHOD2(write, int(void*, int)); 118 MOCK_METHOD0(fsync, int()); 119 }; 120 121 class Mock_factory: public Operations_factory_interface { 122 public: 123 MOCK_METHOD4(create_socket, Socket_interface::Shared_ptr (PSI_socket_key, int, int, int)); 124 MOCK_METHOD1(create_socket, Socket_interface::Shared_ptr (MYSQL_SOCKET)); 125 126 MOCK_METHOD3(open_file, File_interface::Shared_ptr (const char*, int, int)); 127 128 MOCK_METHOD0(create_system_interface, System_interface::Shared_ptr ()); 129 }; 130 131 class Mock_socket_events : public Socket_events_interface { 132 public: 133 MOCK_METHOD2(listen, bool (Socket_interface::Shared_ptr, ngs::function<void (Connection_acceptor_interface &)>)); 134 MOCK_METHOD2(add_timer, void (const std::size_t, ngs::function<bool ()>)); 135 MOCK_METHOD0(loop, void ()); 136 MOCK_METHOD0(break_loop, void ()); 137 }; 138 139 } // namespace test 140 141 } // namespace ngs 142