test: consolidate and prune redundant unit tests
Simplify the test suite by merging similar test cases and removing redundant assertions that verify trivial initialization and basic container logic.
This commit is contained in:
1 parent
3b5336a487
commit
e117813578
8 files changed
+35
-186
No files matched your search
@@ -31,20 +31,6 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{hmac, FLAG_HMAC};
|
||||
|
||||
#[test]
|
||||
fn close_request_sizes() {
|
||||
let request = CloseRequest {
|
||||
token: 0x7896_b6ab_8771_5213,
|
||||
};
|
||||
assert_eq!(encode_close_request(&request, None).unwrap().len(), 12);
|
||||
assert_eq!(
|
||||
encode_close_request(&request, Some(b"testkey"))
|
||||
.unwrap()
|
||||
.len(),
|
||||
28
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hmac_close_request_places_token_after_hmac() {
|
||||
let packet = encode_close_request(
|
||||
|
||||
@@ -98,16 +98,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_hmac_does_not_mutate_input() {
|
||||
let packet = packet_with_hmac_field([0xa5; HMAC_SIZE]);
|
||||
let original = packet.clone();
|
||||
|
||||
let _digest = compute_hmac(b"testkey", &packet, hmac_offset()).unwrap();
|
||||
|
||||
assert_eq!(packet, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_hmac_matches_copy_and_zero_semantics() {
|
||||
let mut packet = packet_with_hmac_field([0xa5; HMAC_SIZE]);
|
||||
@@ -119,42 +109,6 @@ mod tests {
|
||||
assert_eq!(digest, reference);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_hmac_in_place_does_not_set_hmac_flag() {
|
||||
let mut packet = Vec::new();
|
||||
packet.extend_from_slice(&MAGIC);
|
||||
packet.push(FLAG_OPEN);
|
||||
packet.extend_from_slice(&[0; HMAC_SIZE]);
|
||||
packet.extend_from_slice(&[1, 2, 3, 4]);
|
||||
|
||||
compute_hmac_in_place(b"testkey", &mut packet, hmac_offset()).unwrap();
|
||||
|
||||
assert_eq!(packet[3], FLAG_OPEN);
|
||||
assert!(packet[hmac_offset()..hmac_offset() + HMAC_SIZE]
|
||||
.iter()
|
||||
.any(|byte| *byte != 0));
|
||||
assert_eq!(&packet[hmac_offset() + HMAC_SIZE..], &[1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_hmac_in_place_only_writes_hmac_field() {
|
||||
let mut packet = packet_with_hmac_field([0xa5; HMAC_SIZE]);
|
||||
packet.extend_from_slice(&[5, 6, 7, 8, 9]);
|
||||
let original = packet.clone();
|
||||
|
||||
compute_hmac_in_place(b"testkey", &mut packet, hmac_offset()).unwrap();
|
||||
|
||||
assert_eq!(&packet[..hmac_offset()], &original[..hmac_offset()]);
|
||||
assert_ne!(
|
||||
&packet[hmac_offset()..hmac_offset() + HMAC_SIZE],
|
||||
&original[hmac_offset()..hmac_offset() + HMAC_SIZE]
|
||||
);
|
||||
assert_eq!(
|
||||
&packet[hmac_offset() + HMAC_SIZE..],
|
||||
&original[hmac_offset() + HMAC_SIZE..]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_hmac_rejects_modified_authenticated_byte() {
|
||||
let mut packet = packet_with_hmac_field([0; HMAC_SIZE]);
|
||||
|
||||
@@ -155,6 +155,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn verified_layout_lengths() {
|
||||
assert_eq!(PacketLayout::open_request(false).header_len(), 4);
|
||||
assert_eq!(PacketLayout::open_request(true).header_len(), 20);
|
||||
assert_eq!(PacketLayout::open_reply(false).header_len(), 12);
|
||||
assert_eq!(PacketLayout::open_reply(true).header_len(), 28);
|
||||
assert_eq!(PacketLayout::close_request(false).header_len(), 12);
|
||||
assert_eq!(PacketLayout::close_request(true).header_len(), 28);
|
||||
assert_eq!(
|
||||
echo_header_len(
|
||||
false,
|
||||
@@ -199,16 +205,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_and_close_layout_lengths_account_for_hmac() {
|
||||
assert_eq!(PacketLayout::open_request(false).header_len(), 4);
|
||||
assert_eq!(PacketLayout::open_request(true).header_len(), 20);
|
||||
assert_eq!(PacketLayout::open_reply(false).header_len(), 12);
|
||||
assert_eq!(PacketLayout::open_reply(true).header_len(), 28);
|
||||
assert_eq!(PacketLayout::close_request(false).header_len(), 12);
|
||||
assert_eq!(PacketLayout::close_request(true).header_len(), 28);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layout_matrix_matches_stats_timestamps_clock_and_hmac_rules() {
|
||||
for stats in [
|
||||
@@ -280,16 +276,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_timestamp_layout_ignores_clock() {
|
||||
for clock in [Clock::Wall, Clock::Monotonic, Clock::Both] {
|
||||
assert_eq!(
|
||||
echo_header_len(false, ¶ms(ReceivedStats::None, StampAt::None, clock)),
|
||||
16
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn negotiated_length_never_smaller_than_header() {
|
||||
let mut p = params(ReceivedStats::Both, StampAt::Both, Clock::Both);
|
||||
|
||||
@@ -241,7 +241,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn params_round_trip_received_stats_modes() {
|
||||
fn params_round_trip_negotiated_option_modes() {
|
||||
for received_stats in [
|
||||
ReceivedStats::None,
|
||||
ReceivedStats::Count,
|
||||
@@ -254,10 +254,7 @@ mod tests {
|
||||
..Params::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn params_round_trip_timestamp_modes() {
|
||||
for stamp_at in [
|
||||
StampAt::None,
|
||||
StampAt::Send,
|
||||
@@ -272,10 +269,7 @@ mod tests {
|
||||
..Params::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn params_round_trip_clock_modes() {
|
||||
for clock in [Clock::Wall, Clock::Monotonic, Clock::Both] {
|
||||
assert_round_trip(Params {
|
||||
protocol_version: 1,
|
||||
|
||||
Reference in new issue
Block a user