mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-30 05:11:13 +00:00
Inital handshake packet test
This commit is contained in:
parent
a11241f6c5
commit
0bcd4336d1
@ -93,9 +93,9 @@ pub fn deserialize_string_eof(buf: &Vec<u8>, index: &mut usize) -> Bytes {
|
||||
|
||||
#[inline]
|
||||
pub fn deserialize_string_null(buf: &Vec<u8>, index: &mut usize) -> Bytes {
|
||||
let null_index = memchr::memchr(b'\0', &buf[*index..]).unwrap();
|
||||
let value = Bytes::from(&buf[*index..null_index]);
|
||||
*index = null_index + 1;
|
||||
let null_index = memchr::memchr(0, &buf[*index..]).unwrap();
|
||||
let value = Bytes::from(&buf[*index..*index + null_index]);
|
||||
*index = *index + null_index + 1;
|
||||
value
|
||||
}
|
||||
|
||||
@ -273,17 +273,22 @@ mod tests {
|
||||
assert_eq!(index, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_decodes_string_null() {
|
||||
let mut buf = &b"\x01\x00\x01".to_vec();
|
||||
let mut index = 0;
|
||||
let string: Bytes = deserialize_string_null(&buf, &mut index);
|
||||
// #[test]
|
||||
// fn it_decodes_string_null() {
|
||||
// let mut buf = &b"random\x00\x01".to_vec();
|
||||
// let mut index = 0;
|
||||
// let string: Bytes = deserialize_string_null(&buf, &mut index);
|
||||
|
||||
assert_eq!(string[0], b'\x01');
|
||||
assert_eq!(string.len(), 1);
|
||||
// Skips null byte
|
||||
assert_eq!(index, 2);
|
||||
}
|
||||
// assert_eq!(string[0], b'r');
|
||||
// assert_eq!(string[1], b'a');
|
||||
// assert_eq!(string[2], b'n');
|
||||
// assert_eq!(string[3], b'd');
|
||||
// assert_eq!(string[4], b'o');
|
||||
// assert_eq!(string[5], b'm');
|
||||
// assert_eq!(string.len(), 6);
|
||||
// // Skips null byte
|
||||
// assert_eq!(index, 7);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn it_decodes_byte_fix() {
|
||||
|
||||
@ -156,7 +156,8 @@ impl Deserialize for InitialHandshakePacket {
|
||||
let status = deserialize_int_2(&buf, &mut index);
|
||||
|
||||
capabilities |=
|
||||
Capabilities::from_bits(deserialize_int_2(&buf, &mut index).into()).unwrap();
|
||||
Capabilities::from_bits(((deserialize_int_2(&buf, &mut index) as u32) << 16).into())
|
||||
.unwrap();
|
||||
|
||||
let mut plugin_data_length = 0;
|
||||
if !(capabilities & Capabilities::PLUGIN_AUTH).is_empty() {
|
||||
@ -170,8 +171,10 @@ impl Deserialize for InitialHandshakePacket {
|
||||
index += 6;
|
||||
|
||||
if (capabilities & Capabilities::CLIENT_MYSQL).is_empty() {
|
||||
capabilities |=
|
||||
Capabilities::from_bits(deserialize_int_4(&buf, &mut index).into()).unwrap();
|
||||
capabilities |= Capabilities::from_bits(
|
||||
((deserialize_int_4(&buf, &mut index) as u128) << 32).into(),
|
||||
)
|
||||
.unwrap();
|
||||
} else {
|
||||
// Skip filler
|
||||
index += 4;
|
||||
@ -271,3 +274,43 @@ impl Deserialize for ErrPacket {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_decodes_capabilities() {
|
||||
let buf = b"\x00\x10".to_vec();
|
||||
let mut index = 0;
|
||||
Capabilities::from_bits(deserialize_int_2(&buf, &mut index).into()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_decodes_initialhandshakepacket() -> Result<(), Error> {
|
||||
let mut buf = b"\
|
||||
\x54\x00\x00\
|
||||
\0\
|
||||
\x01\
|
||||
5.5.5-7\0\
|
||||
\x01\0\0\0\
|
||||
authseed\
|
||||
\0\
|
||||
\x00\x10\
|
||||
\0\
|
||||
\x00\x00\
|
||||
\x08\x00\
|
||||
\x0A\
|
||||
\0\0\0\0\0\0\
|
||||
\x01\x00\x00\x00\
|
||||
scrambled2nd\
|
||||
\0\
|
||||
authentication_plugin_name\0\
|
||||
"
|
||||
.to_vec();
|
||||
|
||||
let _message = InitialHandshakePacket::deserialize(&mut buf)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user