MySQL 8.0.39
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
41
42namespace server_mock {
43
45 public:
47
49 std::vector<uint8_t> &payload);
50
51 // throws std::system_error
52 void encode_error(const ErrorResponse &msg) override;
53
54 // throws std::system_error
55 void encode_ok(const uint64_t affected_rows = 0,
56 const uint64_t last_insert_id = 0,
57 const uint16_t server_status = 0,
58 const uint16_t warning_count = 0) override;
59
60 // throws std::system_error
61 void encode_resultset(const ResultsetResponse &response) override;
62
64
67
70
71 void seq_no(uint8_t no) { seq_no_ = no; }
72
73 uint8_t seq_no() const { return seq_no_; }
74
77 }
78
81 }
82
85 }
86
89 }
90
93 }
94
95 private:
96 uint8_t seq_no_{0};
97
100};
101
103 public:
105 ProtocolBase::socket_type client_sock,
106 ProtocolBase::endpoint_type client_ep, TlsServerContext &tls_server_ctx,
107 std::unique_ptr<StatementReaderBase> statement_processor,
108 const bool debug_mode, const bool with_tls)
109 : MySQLServerMockSession(std::move(statement_processor), debug_mode),
110 protocol_{std::move(client_sock), client_ep, tls_server_ctx},
111 with_tls_{with_tls} {}
112
113 void run() override;
114
115 void cancel() override { protocol_.cancel(); }
116
117 void terminate() override { protocol_.terminate(); }
118
119 private:
120 void server_greeting();
121 void client_greeting();
122 void auth_switched();
123 void idle();
126 void finish();
127
128 bool authenticate(const std::vector<uint8_t> &client_auth_method_data);
129
131
132 bool with_tls_{false};
133};
134
135} // namespace server_mock
136
137#endif // MYSQLD_MOCK_CLASSIC_MOCK_SESSION_INCLUDED
TLS Context for the server side.
Definition: tls_server_context.h:46
Definition: classic_mock_session.h:44
void server_capabilities(classic_protocol::capabilities::value_type v)
Definition: classic_mock_session.h:79
classic_protocol::capabilities::value_type shared_capabilities() const
Definition: classic_mock_session.h:91
uint8_t seq_no_
Definition: classic_mock_session.h:96
void encode_server_greeting(const classic_protocol::message::server::Greeting &greeting)
Definition: classic_mock_session.cc:600
classic_protocol::capabilities::value_type client_capabilities_
Definition: classic_mock_session.h:99
classic_protocol::capabilities::value_type server_capabilities_
Definition: classic_mock_session.h:98
void encode_auth_fast_message()
Definition: classic_mock_session.cc:585
uint8_t seq_no() const
Definition: classic_mock_session.h:73
void client_capabilities(classic_protocol::capabilities::value_type v)
Definition: classic_mock_session.h:87
stdx::expected< size_t, std::error_code > read_packet(std::vector< uint8_t > &payload)
Definition: classic_mock_session.cc:68
classic_protocol::capabilities::value_type server_capabilities() const
Definition: classic_mock_session.h:75
classic_protocol::capabilities::value_type client_capabilities() const
Definition: classic_mock_session.h:83
void encode_error(const ErrorResponse &msg) override
Definition: classic_mock_session.cc:709
void encode_auth_switch_message(const classic_protocol::message::server::AuthMethodSwitch &msg)
Definition: classic_mock_session.cc:592
void seq_no(uint8_t no)
Definition: classic_mock_session.h:71
void encode_ok(const uint64_t affected_rows=0, const uint64_t last_insert_id=0, const uint16_t server_status=0, const uint16_t warning_count=0) override
Definition: classic_mock_session.cc:791
void encode_resultset(const ResultsetResponse &response) override
Definition: classic_mock_session.cc:811
Definition: classic_mock_session.h:102
void send_response_then_disconnect()
Definition: classic_mock_session.cc:407
bool with_tls_
Definition: classic_mock_session.h:132
void idle()
Definition: classic_mock_session.cc:452
MySQLServerMockSessionClassic(ProtocolBase::socket_type client_sock, ProtocolBase::endpoint_type client_ep, TlsServerContext &tls_server_ctx, std::unique_ptr< StatementReaderBase > statement_processor, const bool debug_mode, const bool with_tls)
Definition: classic_mock_session.h:104
void cancel() override
Definition: classic_mock_session.h:115
MySQLClassicProtocol protocol_
Definition: classic_mock_session.h:130
void server_greeting()
Definition: classic_mock_session.cc:106
void terminate() override
Definition: classic_mock_session.h:117
void run() override
Definition: classic_mock_session.cc:583
void auth_switched()
Definition: classic_mock_session.cc:354
bool authenticate(const std::vector< uint8_t > &client_auth_method_data)
Definition: classic_mock_session.cc:641
void send_response_then_idle()
Definition: classic_mock_session.cc:429
void finish()
Definition: classic_mock_session.cc:581
void client_greeting()
Definition: classic_mock_session.cc:182
Definition: mock_session.h:35
bool debug_mode() const
Definition: mock_session.h:50
Definition: statement_reader.h:81
void terminate()
terminate the current connection.
Definition: protocol_base.cc:138
ProtocolBase(socket_type client_sock, endpoint_type client_ep, TlsServerContext &tls_ctx)
Definition: protocol_base.cc:36
void cancel()
Definition: protocol_base.cc:133
typename protocol_type::endpoint endpoint_type
Definition: statement_reader.h:85
typename protocol_type::socket socket_type
Definition: statement_reader.h:84
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
borrowable::message::server::AuthMethodSwitch< false > AuthMethodSwitch
Definition: classic_protocol_message.h:1404
borrowable::message::server::Greeting< false > Greeting
Definition: classic_protocol_message.h:1401
Definition: mock_server_component.h:36
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:70
Definition: gcs_xcom_synode.h:64
Keeps result data for single SQL statement that returns resultset.
Definition: statement_reader.h:64