MySQL 9.2.0
Source Code Documentation
classic_mock_session.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2020, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLD_MOCK_CLASSIC_MOCK_SESSION_INCLUDED
27#define MYSQLD_MOCK_CLASSIC_MOCK_SESSION_INCLUDED
28
29#include "mock_session.h"
30
31#include <memory> // unique_ptr
32
33#include <openssl/ssl.h>
34
37
43
44namespace server_mock {
45
47 public:
49
51 std::vector<uint8_t> &payload);
52
53 // throws std::system_error
54 void encode_error(const ErrorResponse &msg) override;
55
56 // throws std::system_error
57 void encode_ok(const OkResponse &msg) override;
58
59 // throws std::system_error
60 void encode_resultset(const ResultsetResponse &response) override;
61
63
66
69
70 void seq_no(uint8_t no) { seq_no_ = no; }
71
72 uint8_t seq_no() const { return seq_no_; }
73
76 }
77
80 }
81
84 }
85
88 }
89
92 }
93
94 private:
95 uint8_t seq_no_{0};
96
99};
100
102 public:
106 std::unique_ptr<StatementReaderBase> statement_processor,
107 const bool debug_mode, const bool with_tls)
108 : MySQLServerMockSession(std::move(statement_processor), debug_mode),
109 protocol_(std::move(sock), std::move(ep), tls_ctx),
110 with_tls_{with_tls} {}
111
112 void run() override;
113
114 void cancel() override { protocol_.cancel(); }
115
116 void terminate() override { protocol_.terminate(); }
117
118 private:
119 void server_greeting();
120 void client_greeting();
121 void auth_switched();
122 void idle();
125 void finish();
126
129 const std::vector<uint8_t> &client_auth_method_data);
130
132
133 bool with_tls_{false};
134
135 std::optional<StatementReaderBase::handshake_data> expected_handshake_;
136
138};
139
140} // namespace server_mock
141
142#endif // MYSQLD_MOCK_CLASSIC_MOCK_SESSION_INCLUDED
TLS Context for the server side.
Definition: tls_server_context.h:51
Definition: destination_endpoint.h:38
Definition: destination_socket.h:40
Definition: classic_mock_session.h:46
void server_capabilities(classic_protocol::capabilities::value_type v)
Definition: classic_mock_session.h:78
classic_protocol::capabilities::value_type shared_capabilities() const
Definition: classic_mock_session.h:90
uint8_t seq_no_
Definition: classic_mock_session.h:95
void encode_server_greeting(const classic_protocol::message::server::Greeting &greeting)
Definition: classic_mock_session.cc:737
classic_protocol::capabilities::value_type client_capabilities_
Definition: classic_mock_session.h:98
classic_protocol::capabilities::value_type server_capabilities_
Definition: classic_mock_session.h:97
void encode_auth_fast_message()
Definition: classic_mock_session.cc:715
uint8_t seq_no() const
Definition: classic_mock_session.h:72
void encode_ok(const OkResponse &msg) override
Definition: classic_mock_session.cc:875
void client_capabilities(classic_protocol::capabilities::value_type v)
Definition: classic_mock_session.h:86
stdx::expected< size_t, std::error_code > read_packet(std::vector< uint8_t > &payload)
Definition: classic_mock_session.cc:71
classic_protocol::capabilities::value_type server_capabilities() const
Definition: classic_mock_session.h:74
classic_protocol::capabilities::value_type client_capabilities() const
Definition: classic_mock_session.h:82
void encode_error(const ErrorResponse &msg) override
Definition: classic_mock_session.cc:863
void encode_auth_switch_message(const classic_protocol::message::server::AuthMethodSwitch &msg)
Definition: classic_mock_session.cc:726
void seq_no(uint8_t no)
Definition: classic_mock_session.h:70
void encode_resultset(const ResultsetResponse &response) override
Definition: classic_mock_session.cc:896
Definition: classic_mock_session.h:101
MySQLServerMockSessionClassic(mysql_harness::DestinationSocket sock, mysql_harness::DestinationEndpoint ep, TlsServerContext &tls_ctx, std::unique_ptr< StatementReaderBase > statement_processor, const bool debug_mode, const bool with_tls)
Definition: classic_mock_session.h:103
void send_response_then_disconnect()
Definition: classic_mock_session.cc:499
bool with_tls_
Definition: classic_mock_session.h:133
void idle()
Definition: classic_mock_session.cc:544
mysql_harness::logging::DomainLogger logger_
Definition: classic_mock_session.h:137
std::optional< StatementReaderBase::handshake_data > expected_handshake_
Definition: classic_mock_session.h:135
void cancel() override
Definition: classic_mock_session.h:114
MySQLClassicProtocol protocol_
Definition: classic_mock_session.h:131
void server_greeting()
Definition: classic_mock_session.cc:109
void terminate() override
Definition: classic_mock_session.h:116
void run() override
Definition: classic_mock_session.cc:713
stdx::expected< void, ErrorResponse > authenticate(const StatementReaderBase::handshake_data &handshake, const std::vector< uint8_t > &client_auth_method_data)
Definition: classic_mock_session.cc:782
void auth_switched()
Definition: classic_mock_session.cc:439
void send_response_then_idle()
Definition: classic_mock_session.cc:521
void finish()
Definition: classic_mock_session.cc:711
void client_greeting()
Definition: classic_mock_session.cc:173
Definition: mock_session.h:35
bool debug_mode() const
Definition: mock_session.h:50
Definition: statement_reader.h:331
void terminate()
terminate the current connection.
Definition: statement_reader.h:430
void cancel()
Definition: protocol_base.cc:120
ProtocolBase(mysql_harness::DestinationSocket sock, mysql_harness::DestinationEndpoint ep, TlsServerContext &tls_ctx)
Definition: statement_reader.h:333
static MYSQL * sock
Definition: mysqlcheck.cc:57
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
borrowable::message::server::AuthMethodSwitch< false > AuthMethodSwitch
Definition: classic_protocol_message.h:1416
borrowable::message::server::Greeting< false > Greeting
Definition: classic_protocol_message.h:1413
Definition: mock_server_component.h:36
classic_protocol::message::server::Ok OkResponse
Definition: statement_reader.h:83
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:84
Definition: gcs_xcom_synode.h:64
Keeps result data for single SQL statement that returns resultset.
Definition: statement_reader.h:76
Definition: statement_reader.h:451