Skip to content

Commit

Permalink
fix(mysql): correct Capabilities assertions in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Aug 21, 2024
1 parent 37f53cc commit 0bb3fe0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
11 changes: 8 additions & 3 deletions sqlx-mysql/src/protocol/connect/auth_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ fn test_decode_auth_switch_cleartext_disabled() {

let e = AuthSwitchRequest::decode_with(AUTH_SWITCH_CLEARTEXT.into(), false).unwrap_err();

assert_eq!(
e.to_string(),
"encountered unexpected or invalid data: mysql_cleartext_plugin disabled"
let e_str = e.to_string();

let expected = "encountered unexpected or invalid data: mysql_cleartext_plugin disabled";

assert!(
// Don't want to assert the full string since it contains the module path now.
e_str.starts_with(expected),
"expected error string to start with {expected:?}, got {e_str:?}"
);
}

Expand Down
61 changes: 31 additions & 30 deletions sqlx-mysql/src/protocol/connect/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ impl ProtocolDecode<'_> for Handshake {
fn test_decode_handshake_mysql_8_0_18() {
const HANDSHAKE_MYSQL_8_0_18: &[u8] = b"\n8.0.18\x00\x19\x00\x00\x00\x114aB0c\x06g\x00\xff\xff\xff\x02\x00\xff\xc7\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00tL\x03s\x0f[4\rl4. \x00caching_sha2_password\x00";

let mut p = Handshake::decode(HANDSHAKE_MYSQL_8_0_18.into()).unwrap();
let p = Handshake::decode(HANDSHAKE_MYSQL_8_0_18.into()).unwrap();

assert_eq!(p.protocol_version, 10);

p.server_capabilities.toggle(
assert_eq!(
p.server_capabilities,
Capabilities::MYSQL
| Capabilities::FOUND_ROWS
| Capabilities::LONG_FLAG
Expand Down Expand Up @@ -128,8 +129,6 @@ fn test_decode_handshake_mysql_8_0_18() {
| Capabilities::REMEMBER_OPTIONS,
);

assert!(p.server_capabilities.is_empty());

assert_eq!(p.server_default_collation, 255);
assert!(p.status.contains(Status::SERVER_STATUS_AUTOCOMMIT));

Expand All @@ -148,7 +147,7 @@ fn test_decode_handshake_mysql_8_0_18() {
fn test_decode_handshake_mariadb_10_4_7() {
const HANDSHAKE_MARIA_DB_10_4_7: &[u8] = b"\n5.5.5-10.4.7-MariaDB-1:10.4.7+maria~bionic\x00\x0b\x00\x00\x00t6L\\j\"dS\x00\xfe\xf7\x08\x02\x00\xff\x81\x15\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00U14Oph9\"<H5n\x00mysql_native_password\x00";

let mut p = Handshake::decode(HANDSHAKE_MARIA_DB_10_4_7.into()).unwrap();
let p = Handshake::decode(HANDSHAKE_MARIA_DB_10_4_7.into()).unwrap();

assert_eq!(p.protocol_version, 10);

Expand All @@ -157,33 +156,35 @@ fn test_decode_handshake_mariadb_10_4_7() {
"5.5.5-10.4.7-MariaDB-1:10.4.7+maria~bionic"
);

p.server_capabilities.toggle(
Capabilities::FOUND_ROWS
| Capabilities::LONG_FLAG
| Capabilities::CONNECT_WITH_DB
| Capabilities::NO_SCHEMA
| Capabilities::COMPRESS
| Capabilities::ODBC
| Capabilities::LOCAL_FILES
| Capabilities::IGNORE_SPACE
| Capabilities::PROTOCOL_41
| Capabilities::INTERACTIVE
| Capabilities::TRANSACTIONS
| Capabilities::SECURE_CONNECTION
| Capabilities::MULTI_STATEMENTS
| Capabilities::MULTI_RESULTS
| Capabilities::PS_MULTI_RESULTS
| Capabilities::PLUGIN_AUTH
| Capabilities::CONNECT_ATTRS
| Capabilities::PLUGIN_AUTH_LENENC_DATA
| Capabilities::CAN_HANDLE_EXPIRED_PASSWORDS
| Capabilities::SESSION_TRACK
| Capabilities::DEPRECATE_EOF
| Capabilities::REMEMBER_OPTIONS,
assert_eq!(
p.server_capabilities,
Capabilities::FOUND_ROWS
| Capabilities::LONG_FLAG
| Capabilities::CONNECT_WITH_DB
| Capabilities::NO_SCHEMA
| Capabilities::COMPRESS
| Capabilities::ODBC
| Capabilities::LOCAL_FILES
| Capabilities::IGNORE_SPACE
| Capabilities::PROTOCOL_41
| Capabilities::INTERACTIVE
| Capabilities::TRANSACTIONS
| Capabilities::SECURE_CONNECTION
| Capabilities::MULTI_STATEMENTS
| Capabilities::MULTI_RESULTS
| Capabilities::PS_MULTI_RESULTS
| Capabilities::PLUGIN_AUTH
| Capabilities::CONNECT_ATTRS
| Capabilities::PLUGIN_AUTH_LENENC_DATA
| Capabilities::CAN_HANDLE_EXPIRED_PASSWORDS
| Capabilities::SESSION_TRACK
| Capabilities::DEPRECATE_EOF
| Capabilities::REMEMBER_OPTIONS
| Capabilities::MARIADB_CLIENT_PROGRESS
| Capabilities::MARIADB_CLIENT_MULTI
| Capabilities::MARIADB_CLIENT_STMT_BULK_OPERATIONS
);

assert!(p.server_capabilities.is_empty());

assert_eq!(p.server_default_collation, 8);
assert!(p.status.contains(Status::SERVER_STATUS_AUTOCOMMIT));
assert!(matches!(
Expand Down

0 comments on commit 0bb3fe0

Please sign in to comment.