Skip to content

Commit cbe9270

Browse files
authored
Added handshake unit tests
close #442
1 parent d56b4cd commit cbe9270

File tree

10 files changed

+1632
-15
lines changed

10 files changed

+1632
-15
lines changed

.drone.star

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def main(ctx):
304304
find_package_b2_windows('Windows find_package b2 distribution'),
305305

306306
# B2 Linux
307-
linux_b2('Linux B2 clang-3.6', _image('build-clang3_6'), toolset='clang-3.6', cxxstd='11,14'),
307+
# linux_b2('Linux B2 clang-3.6', _image('build-clang3_6'), toolset='clang-3.6', cxxstd='11,14'),
308308
linux_b2('Linux B2 clang-7', _image('build-clang7'), toolset='clang-7', cxxstd='14,17'),
309309
linux_b2('Linux B2 clang-11', _image('build-clang11'), toolset='clang-11', cxxstd='20'),
310310
linux_b2('Linux B2 clang-14-header-only', _image('build-clang14'), toolset='clang-14', cxxstd='11,20', separate_compilation=0),

bench/one_small_row_boost.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Distributed under the Boost Software License, Version 1.0. (See accompanying
55
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
7+
78
#include <boost/mysql/any_connection.hpp>
89
#include <boost/mysql/connect_params.hpp>
910
#include <boost/mysql/execution_state.hpp>

test/integration/test/character_set_tracking.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,42 @@ BOOST_FIXTURE_TEST_CASE(charset_lifecycle, any_connection_fixture)
8383
validate_db_charset(conn, "greek");
8484
}
8585

86+
// For some collations, we set the tracked character set after handshake.
87+
// Check that all the collations that we know are supported by all the servers
88+
// that we support. If the collation is not supported, the server falls back to
89+
// a default charset, so we shouldn't be setting the value of the tracked character set.
90+
BOOST_FIXTURE_TEST_CASE(connect_with_known_collation, io_context_fixture)
91+
{
92+
constexpr struct
93+
{
94+
const char* name;
95+
std::uint16_t collation_id;
96+
character_set charset;
97+
} test_cases[] = {
98+
{"utf8mb4_bin", mysql_collations::utf8mb4_bin, utf8mb4_charset},
99+
{"utf8mb4_general_ci", mysql_collations::utf8mb4_general_ci, utf8mb4_charset},
100+
{"ascii_general_ci", mysql_collations::ascii_general_ci, ascii_charset },
101+
{"ascii_bin", mysql_collations::ascii_bin, ascii_charset },
102+
};
103+
104+
for (const auto& tc : test_cases)
105+
{
106+
BOOST_TEST_CONTEXT(tc.name)
107+
{
108+
// Setup
109+
any_connection conn(ctx);
110+
111+
// Connect
112+
conn.async_connect(connect_params_builder().collation(tc.collation_id).build(), as_netresult)
113+
.validate_no_error();
114+
115+
// Check that the tracked character set and the one chosen by the DB match
116+
BOOST_TEST(conn.current_character_set().value() == tc.charset);
117+
validate_db_charset(conn, tc.charset.name);
118+
}
119+
}
120+
}
121+
86122
BOOST_FIXTURE_TEST_CASE(connect_with_unknown_collation, any_connection_fixture)
87123
{
88124
// Connect with a collation that some servers may not support, or that we don't know of

test/integration/test/handshake.cpp

+38-14
Original file line numberDiff line numberDiff line change
@@ -309,20 +309,44 @@ BOOST_FIXTURE_TEST_CASE(bad_password_cache_miss, any_connection_fixture)
309309
.validate_error_contains(common_server_errc::er_access_denied_error, {"access denied", regular_user});
310310
}
311311

312-
// Spotcheck: an invalid DB error after cache miss works
313-
BOOST_FIXTURE_TEST_CASE(bad_db_cache_miss, any_connection_fixture)
314-
{
315-
// Setup
316-
auto params = connect_params_builder().ssl(ssl_mode::require).database("bad_db").build();
317-
clear_sha256_cache();
318-
319-
// Connect fails
320-
conn.async_connect(params, as_netresult)
321-
.validate_error(
322-
common_server_errc::er_dbaccess_denied_error,
323-
"Access denied for user 'integ_user'@'%' to database 'bad_db'"
324-
);
325-
}
312+
// TODO: re-enable these tests when https://github.com/boostorg/mysql/issues/468 is fixed
313+
// // Spotcheck: an invalid DB error after a cache miss works
314+
// BOOST_FIXTURE_TEST_CASE(bad_db_cache_miss, any_connection_fixture)
315+
// {
316+
// // Setup
317+
// auto params = connect_params_builder()
318+
// .ssl(ssl_mode::require)
319+
// .credentials(regular_user, regular_passwd)
320+
// .database("bad_db")
321+
// .build();
322+
// clear_sha256_cache();
323+
324+
// // Connect fails
325+
// conn.async_connect(params, as_netresult)
326+
// .validate_error(
327+
// common_server_errc::er_dbaccess_denied_error,
328+
// "Access denied for user 'integ_user'@'%' to database 'bad_db'"
329+
// );
330+
// }
331+
332+
// // Spotcheck: an invalid DB error after a cache hit works
333+
// BOOST_FIXTURE_TEST_CASE(bad_db_cache_hit, any_connection_fixture)
334+
// {
335+
// // Setup
336+
// auto params = connect_params_builder()
337+
// .ssl(ssl_mode::disable)
338+
// .credentials(regular_user, regular_passwd)
339+
// .database("bad_db")
340+
// .build();
341+
// load_sha256_cache(regular_user, regular_passwd);
342+
343+
// // Connect fails
344+
// conn.async_connect(params, as_netresult)
345+
// .validate_error(
346+
// common_server_errc::er_dbaccess_denied_error,
347+
// "Access denied for user 'integ_user'@'%' to database 'bad_db'"
348+
// );
349+
// }
326350

327351
// Spotcheck: caching_sha2_password works with old connection
328352
BOOST_FIXTURE_TEST_CASE(tcp_ssl_connection_, io_context_fixture)

test/unit/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_executable(
3131
test/sansio/message_reader.cpp
3232
test/sansio/top_level_algo.cpp
3333

34+
test/sansio/handshake.cpp
3435
test/sansio/read_resultset_head.cpp
3536
test/sansio/start_execution.cpp
3637
test/sansio/read_some_rows.cpp

test/unit/Jamfile

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ run
4040
test/sansio/message_reader.cpp
4141
test/sansio/top_level_algo.cpp
4242

43+
test/sansio/handshake.cpp
4344
test/sansio/read_resultset_head.cpp
4445
test/sansio/start_execution.cpp
4546
test/sansio/read_some_rows.cpp

test/unit/include/test_unit/algo_test.hpp

+21
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ class BOOST_ATTRIBUTE_NODISCARD algo_test
160160
return *this;
161161
}
162162

163+
BOOST_ATTRIBUTE_NODISCARD
164+
algo_test& will_set_capabilities(detail::capabilities expected)
165+
{
166+
state_changes_.current_capabilities = expected;
167+
return *this;
168+
}
169+
170+
BOOST_ATTRIBUTE_NODISCARD
171+
algo_test& will_set_connection_id(std::uint32_t expected)
172+
{
173+
state_changes_.connection_id = expected;
174+
return *this;
175+
}
176+
177+
BOOST_ATTRIBUTE_NODISCARD
178+
algo_test& will_set_flavor(detail::db_flavor expected)
179+
{
180+
state_changes_.flavor = expected;
181+
return *this;
182+
}
183+
163184
BOOST_ATTRIBUTE_NODISCARD
164185
algo_test& will_set_tls_active(bool expected)
165186
{

test/unit/src/utils.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <boost/mysql/diagnostics.hpp>
1313
#include <boost/mysql/error_code.hpp>
1414
#include <boost/mysql/error_with_diagnostics.hpp>
15+
#include <boost/mysql/metadata_mode.hpp>
1516

1617
#include <boost/mysql/detail/access.hpp>
1718
#include <boost/mysql/detail/coldef_view.hpp>
@@ -144,6 +145,7 @@ class boost::mysql::test::algo_test::state_checker
144145
detail::db_flavor expected_flavor;
145146
detail::capabilities expected_capabilities;
146147
std::uint32_t expected_connection_id;
148+
metadata_mode expected_meta_mode;
147149
bool expected_tls_supported;
148150
bool expected_tls_active;
149151
bool expected_backslash_escapes;
@@ -156,6 +158,7 @@ class boost::mysql::test::algo_test::state_checker
156158
expected_flavor(changes.flavor.value_or(st.flavor)),
157159
expected_capabilities(changes.current_capabilities.value_or(st.current_capabilities)),
158160
expected_connection_id(changes.connection_id.value_or(st.connection_id)),
161+
expected_meta_mode(st.meta_mode), // no algorithm should modify this
159162
expected_tls_supported(changes.tls_active.value_or(st.tls_supported)),
160163
expected_tls_active(changes.tls_active.value_or(st.tls_active)),
161164
expected_backslash_escapes(changes.backslash_escapes.value_or(st.backslash_escapes)),
@@ -169,6 +172,7 @@ class boost::mysql::test::algo_test::state_checker
169172
BOOST_TEST(st_.flavor == expected_flavor);
170173
BOOST_TEST(st_.current_capabilities == expected_capabilities);
171174
BOOST_TEST(st_.connection_id == expected_connection_id);
175+
BOOST_TEST(st_.meta_mode == expected_meta_mode);
172176
BOOST_TEST(st_.tls_supported == expected_tls_supported);
173177
BOOST_TEST(st_.tls_active == expected_tls_active);
174178
BOOST_TEST(st_.backslash_escapes == expected_backslash_escapes);

0 commit comments

Comments
 (0)