MySQL 8.0.33
Source Code Documentation
classic_mock_session.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2020, 2023, 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 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 02110-1301 USA
23*/
24
25#ifndef MYSQLD_MOCK_CLASSIC_MOCK_SESSION_INCLUDED
26#define MYSQLD_MOCK_CLASSIC_MOCK_SESSION_INCLUDED
27
28#include "mock_session.h"
29
30#include <memory> // unique_ptr
31
32#include <openssl/ssl.h>
33
36
40
41namespace server_mock {
42
44 public:
46
48 std::vector<uint8_t> &payload);
49
50 // throws std::system_error
51 void encode_error(const ErrorResponse &msg) override;
52
53 // throws std::system_error
54 void encode_ok(const uint64_t affected_rows = 0,
55 const uint64_t last_insert_id = 0,
56 const uint16_t server_status = 0,
57 const uint16_t warning_count = 0) 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:
104 MySQLClassicProtocol protocol,
105 std::unique_ptr<StatementReaderBase> statement_processor,
106 const bool debug_mode, const bool with_tls)
107 : MySQLServerMockSession(std::move(statement_processor), debug_mode),
108 protocol_{std::move(protocol)},
109 with_tls_{with_tls} {}
110
111 void run() override;
112
113 void cancel() override { protocol_.cancel(); }
114
115 private:
116 void server_greeting();
117 void client_greeting();
118 void auth_switched();
119 void idle();
122 void finish();
123
124 bool authenticate(const std::vector<uint8_t> &client_auth_method_data);
125
127
128 bool with_tls_{false};
129};
130
131} // namespace server_mock
132
133#endif // MYSQLD_MOCK_CLASSIC_MOCK_SESSION_INCLUDED
Definition: classic_mock_session.h:43
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:598
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:583
uint8_t seq_no() const
Definition: classic_mock_session.h:72
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:67
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:707
void encode_auth_switch_message(const classic_protocol::message::server::AuthMethodSwitch &msg)
Definition: classic_mock_session.cc:590
void seq_no(uint8_t no)
Definition: classic_mock_session.h:70
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:789
void encode_resultset(const ResultsetResponse &response) override
Definition: classic_mock_session.cc:809
Definition: classic_mock_session.h:101
void send_response_then_disconnect()
Definition: classic_mock_session.cc:405
MySQLServerMockSessionClassic(MySQLClassicProtocol protocol, std::unique_ptr< StatementReaderBase > statement_processor, const bool debug_mode, const bool with_tls)
Definition: classic_mock_session.h:103
bool with_tls_
Definition: classic_mock_session.h:128
void idle()
Definition: classic_mock_session.cc:450
void cancel() override
Definition: classic_mock_session.h:113
MySQLClassicProtocol protocol_
Definition: classic_mock_session.h:126
void server_greeting()
Definition: classic_mock_session.cc:105
void run() override
Definition: classic_mock_session.cc:581
void auth_switched()
Definition: classic_mock_session.cc:352
bool authenticate(const std::vector< uint8_t > &client_auth_method_data)
Definition: classic_mock_session.cc:639
void send_response_then_idle()
Definition: classic_mock_session.cc:427
void finish()
Definition: classic_mock_session.cc:579
void client_greeting()
Definition: classic_mock_session.cc:181
Definition: mock_session.h:34
bool debug_mode() const
Definition: mock_session.h:47
Definition: statement_reader.h:79
ProtocolBase(socket_type client_sock, endpoint_type client_ep, TlsServerContext &tls_ctx)
Definition: protocol_base.cc:35
void cancel()
Definition: protocol_base.cc:132
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:72
borrowable::message::server::AuthMethodSwitch< false > AuthMethodSwitch
Definition: classic_protocol_message.h:1362
borrowable::message::server::Greeting< false > Greeting
Definition: classic_protocol_message.h:1359
Definition: mock_server_component.h:35
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:68
Definition: varlen_sort.h:183
Keeps result data for single SQL statement that returns resultset.
Definition: statement_reader.h:62