Add test case with multiple options with same code

This commit is contained in:
Ensar Sarajčić 2024-02-28 10:44:10 +01:00 committed by Benjamin Fry
parent e9eeb6533d
commit 0a2ee2c655

View File

@ -861,6 +861,42 @@ mod tests {
assert_eq!(opt, options);
}
#[test]
fn test_multiple_options_with_same_code() {
let bytes: Vec<u8> = vec![
0x00, 0x0f, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x09, 0x55, 0x6E,
0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72,
];
let mut decoder: BinDecoder<'_> = BinDecoder::new(&bytes);
let read_rdata = OPT::read_data(&mut decoder, Restrict::new(bytes.len() as u16));
assert!(
read_rdata.is_ok(),
"error decoding: {:?}",
read_rdata.unwrap_err()
);
let opt = read_rdata.unwrap();
let options = vec![
(
EdnsCode::Unknown(15u16),
EdnsOption::Unknown(15u16, vec![0x00, 0x06]),
),
(
EdnsCode::Unknown(15u16),
EdnsOption::Unknown(
15u16,
vec![
0x00, 0x09, 0x55, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x20, 0x65, 0x72,
0x72, 0x6F, 0x72,
],
),
),
];
let options = OPT::new(options);
assert_eq!(opt, options);
}
#[test]
fn test_write_client_subnet() {
let expected_bytes: Vec<u8> = vec![0x00, 0x01, 0x18, 0x00, 0xac, 0x01, 0x01];