Skip to content

Added handshake unit tests #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ece0d37
baseline
anarthal Sep 5, 2024
5aa240f
Merge branch 'develop' into feature/231-missing-tests-sansio
anarthal Feb 17, 2025
287e48b
Correct baseline
anarthal Feb 17, 2025
2242064
Auth switch
anarthal Feb 17, 2025
29ed87b
Merge branch 'develop' into feature/442-handshake-tests
anarthal Feb 17, 2025
85a2090
Embed seqnums in generators
anarthal Feb 17, 2025
3daa79e
Auth switch error
anarthal Feb 17, 2025
b28325d
Bad auth challenge tests
anarthal Feb 17, 2025
b2f6a19
TLS test
anarthal Feb 17, 2025
cecf3cc
Failing more data fast track test
anarthal Apr 21, 2025
4735180
mnp double auth switch failing test
anarthal Apr 21, 2025
6942a94
mnp auth switch more data
anarthal Apr 21, 2025
8bcd1cc
csha2p fast track success
anarthal Apr 21, 2025
65117e7
ok follows
anarthal Apr 21, 2025
4db7fed
failing csha2p fast track error test
anarthal Apr 21, 2025
91dcadd
error before ok follows
anarthal Apr 21, 2025
affd847
restructure test in a more fsm way
anarthal Apr 21, 2025
d34f161
bad challenge length
anarthal Apr 21, 2025
fec04aa
fullauth ok
anarthal Apr 21, 2025
8a7b4b3
full auth error
anarthal Apr 21, 2025
1fc699d
fullauth no tls
anarthal Apr 21, 2025
7303e26
auth switch spotcheck
anarthal Apr 21, 2025
19f2050
Merge branch 'develop' into feature/442-handshake-tests
anarthal Apr 21, 2025
b2a844b
file headers
anarthal Apr 21, 2025
e9d195e
Use connection_status
anarthal Apr 21, 2025
dd8f9e2
connect with db
anarthal Apr 21, 2025
827f12a
TLS
anarthal Apr 21, 2025
3483545
multi_queries
anarthal Apr 21, 2025
1976daf
mandatory caps
anarthal Apr 21, 2025
2e8221a
Optional capabilities
anarthal Apr 21, 2025
ea057d2
ignored caps
anarthal Apr 21, 2025
4113867
auth plugin errors
anarthal Apr 21, 2025
8977af6
connection_id
anarthal Apr 21, 2025
c455ebe
flavor
anarthal Apr 21, 2025
67aba0d
collations
anarthal Apr 21, 2025
d0587e6
backslash escapes
anarthal Apr 21, 2025
1f3d7c5
add check for meta mode
anarthal Apr 21, 2025
c8ed056
metadata_mode check
anarthal Apr 21, 2025
e5d3ad2
status changes
anarthal Apr 21, 2025
7971a66
Correct and add integration tests
anarthal Apr 23, 2025
0e01b5d
comment
anarthal Apr 23, 2025
f9ad260
secure channel test
anarthal Apr 23, 2025
7cfe2c4
deserialization errors
anarthal Apr 23, 2025
c06da93
network errors
anarthal Apr 23, 2025
7b1545c
handshake cleanup
anarthal Apr 23, 2025
d3f4d02
Made collations an integration test
anarthal Apr 23, 2025
fe97ec7
cleanup
anarthal Apr 23, 2025
f30618c
Commented the clang 3.6 build
anarthal Apr 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def main(ctx):
find_package_b2_windows('Windows find_package b2 distribution'),

# B2 Linux
linux_b2('Linux B2 clang-3.6', _image('build-clang3_6'), toolset='clang-3.6', cxxstd='11,14'),
# linux_b2('Linux B2 clang-3.6', _image('build-clang3_6'), toolset='clang-3.6', cxxstd='11,14'),
linux_b2('Linux B2 clang-7', _image('build-clang7'), toolset='clang-7', cxxstd='14,17'),
linux_b2('Linux B2 clang-11', _image('build-clang11'), toolset='clang-11', cxxstd='20'),
linux_b2('Linux B2 clang-14-header-only', _image('build-clang14'), toolset='clang-14', cxxstd='11,20', separate_compilation=0),
Expand Down
1 change: 1 addition & 0 deletions bench/one_small_row_boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <boost/mysql/any_connection.hpp>
#include <boost/mysql/connect_params.hpp>
#include <boost/mysql/execution_state.hpp>
Expand Down
36 changes: 36 additions & 0 deletions test/integration/test/character_set_tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,42 @@ BOOST_FIXTURE_TEST_CASE(charset_lifecycle, any_connection_fixture)
validate_db_charset(conn, "greek");
}

// For some collations, we set the tracked character set after handshake.
// Check that all the collations that we know are supported by all the servers
// that we support. If the collation is not supported, the server falls back to
// a default charset, so we shouldn't be setting the value of the tracked character set.
BOOST_FIXTURE_TEST_CASE(connect_with_known_collation, io_context_fixture)
{
constexpr struct
{
const char* name;
std::uint16_t collation_id;
character_set charset;
} test_cases[] = {
{"utf8mb4_bin", mysql_collations::utf8mb4_bin, utf8mb4_charset},
{"utf8mb4_general_ci", mysql_collations::utf8mb4_general_ci, utf8mb4_charset},
{"ascii_general_ci", mysql_collations::ascii_general_ci, ascii_charset },
{"ascii_bin", mysql_collations::ascii_bin, ascii_charset },
};

for (const auto& tc : test_cases)
{
BOOST_TEST_CONTEXT(tc.name)
{
// Setup
any_connection conn(ctx);

// Connect
conn.async_connect(connect_params_builder().collation(tc.collation_id).build(), as_netresult)
.validate_no_error();

// Check that the tracked character set and the one chosen by the DB match
BOOST_TEST(conn.current_character_set().value() == tc.charset);
validate_db_charset(conn, tc.charset.name);
}
}
}

BOOST_FIXTURE_TEST_CASE(connect_with_unknown_collation, any_connection_fixture)
{
// Connect with a collation that some servers may not support, or that we don't know of
Expand Down
52 changes: 38 additions & 14 deletions test/integration/test/handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,44 @@ BOOST_FIXTURE_TEST_CASE(bad_password_cache_miss, any_connection_fixture)
.validate_error_contains(common_server_errc::er_access_denied_error, {"access denied", regular_user});
}

// Spotcheck: an invalid DB error after cache miss works
BOOST_FIXTURE_TEST_CASE(bad_db_cache_miss, any_connection_fixture)
{
// Setup
auto params = connect_params_builder().ssl(ssl_mode::require).database("bad_db").build();
clear_sha256_cache();

// Connect fails
conn.async_connect(params, as_netresult)
.validate_error(
common_server_errc::er_dbaccess_denied_error,
"Access denied for user 'integ_user'@'%' to database 'bad_db'"
);
}
// TODO: re-enable these tests when https://github.com/boostorg/mysql/issues/468 is fixed
// // Spotcheck: an invalid DB error after a cache miss works
// BOOST_FIXTURE_TEST_CASE(bad_db_cache_miss, any_connection_fixture)
// {
// // Setup
// auto params = connect_params_builder()
// .ssl(ssl_mode::require)
// .credentials(regular_user, regular_passwd)
// .database("bad_db")
// .build();
// clear_sha256_cache();

// // Connect fails
// conn.async_connect(params, as_netresult)
// .validate_error(
// common_server_errc::er_dbaccess_denied_error,
// "Access denied for user 'integ_user'@'%' to database 'bad_db'"
// );
// }

// // Spotcheck: an invalid DB error after a cache hit works
// BOOST_FIXTURE_TEST_CASE(bad_db_cache_hit, any_connection_fixture)
// {
// // Setup
// auto params = connect_params_builder()
// .ssl(ssl_mode::disable)
// .credentials(regular_user, regular_passwd)
// .database("bad_db")
// .build();
// load_sha256_cache(regular_user, regular_passwd);

// // Connect fails
// conn.async_connect(params, as_netresult)
// .validate_error(
// common_server_errc::er_dbaccess_denied_error,
// "Access denied for user 'integ_user'@'%' to database 'bad_db'"
// );
// }

// Spotcheck: caching_sha2_password works with old connection
BOOST_FIXTURE_TEST_CASE(tcp_ssl_connection_, io_context_fixture)
Expand Down
1 change: 1 addition & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_executable(
test/sansio/message_reader.cpp
test/sansio/top_level_algo.cpp

test/sansio/handshake.cpp
test/sansio/read_resultset_head.cpp
test/sansio/start_execution.cpp
test/sansio/read_some_rows.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unit/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ run
test/sansio/message_reader.cpp
test/sansio/top_level_algo.cpp

test/sansio/handshake.cpp
test/sansio/read_resultset_head.cpp
test/sansio/start_execution.cpp
test/sansio/read_some_rows.cpp
Expand Down
21 changes: 21 additions & 0 deletions test/unit/include/test_unit/algo_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ class BOOST_ATTRIBUTE_NODISCARD algo_test
return *this;
}

BOOST_ATTRIBUTE_NODISCARD
algo_test& will_set_capabilities(detail::capabilities expected)
{
state_changes_.current_capabilities = expected;
return *this;
}

BOOST_ATTRIBUTE_NODISCARD
algo_test& will_set_connection_id(std::uint32_t expected)
{
state_changes_.connection_id = expected;
return *this;
}

BOOST_ATTRIBUTE_NODISCARD
algo_test& will_set_flavor(detail::db_flavor expected)
{
state_changes_.flavor = expected;
return *this;
}

BOOST_ATTRIBUTE_NODISCARD
algo_test& will_set_tls_active(bool expected)
{
Expand Down
4 changes: 4 additions & 0 deletions test/unit/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <boost/mysql/diagnostics.hpp>
#include <boost/mysql/error_code.hpp>
#include <boost/mysql/error_with_diagnostics.hpp>
#include <boost/mysql/metadata_mode.hpp>

#include <boost/mysql/detail/access.hpp>
#include <boost/mysql/detail/coldef_view.hpp>
Expand Down Expand Up @@ -144,6 +145,7 @@ class boost::mysql::test::algo_test::state_checker
detail::db_flavor expected_flavor;
detail::capabilities expected_capabilities;
std::uint32_t expected_connection_id;
metadata_mode expected_meta_mode;
bool expected_tls_supported;
bool expected_tls_active;
bool expected_backslash_escapes;
Expand All @@ -156,6 +158,7 @@ class boost::mysql::test::algo_test::state_checker
expected_flavor(changes.flavor.value_or(st.flavor)),
expected_capabilities(changes.current_capabilities.value_or(st.current_capabilities)),
expected_connection_id(changes.connection_id.value_or(st.connection_id)),
expected_meta_mode(st.meta_mode), // no algorithm should modify this
expected_tls_supported(changes.tls_active.value_or(st.tls_supported)),
expected_tls_active(changes.tls_active.value_or(st.tls_active)),
expected_backslash_escapes(changes.backslash_escapes.value_or(st.backslash_escapes)),
Expand All @@ -169,6 +172,7 @@ class boost::mysql::test::algo_test::state_checker
BOOST_TEST(st_.flavor == expected_flavor);
BOOST_TEST(st_.current_capabilities == expected_capabilities);
BOOST_TEST(st_.connection_id == expected_connection_id);
BOOST_TEST(st_.meta_mode == expected_meta_mode);
BOOST_TEST(st_.tls_supported == expected_tls_supported);
BOOST_TEST(st_.tls_active == expected_tls_active);
BOOST_TEST(st_.backslash_escapes == expected_backslash_escapes);
Expand Down
Loading