refactor(proto): consolidate tests
This commit is contained in:
13 files changed
+1000
-1802
No files matched your search
@@ -98,53 +98,3 @@ pub fn decode_open_reply(packet: &[u8], hmac_key: Option<&[u8]>) -> Result<OpenR
|
||||
params: Params::decode(&packet[pos..])?,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
hmac,
|
||||
params::{Clock, ReceivedStats, StampAt},
|
||||
FLAG_HMAC, HMAC_SIZE,
|
||||
};
|
||||
|
||||
fn default_params() -> Params {
|
||||
Params {
|
||||
protocol_version: 1,
|
||||
duration_ns: 3_000_000_000,
|
||||
interval_ns: 1_000_000_000,
|
||||
received_stats: ReceivedStats::Both,
|
||||
stamp_at: StampAt::Both,
|
||||
clock: Clock::Both,
|
||||
..Params::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_reply_decodes_token() {
|
||||
let mut packet = vec![0x14, 0xa7, 0x5b, 0x03];
|
||||
packet.extend_from_slice(&0x7896_b6ab_8771_5213u64.to_le_bytes());
|
||||
packet.extend_from_slice(&default_params().encode());
|
||||
|
||||
let reply = decode_open_reply(&packet, None).unwrap();
|
||||
assert_eq!(reply.token, 0x7896_b6ab_8771_5213);
|
||||
assert_eq!(reply.params, default_params());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hmac_open_reply_decodes_token_after_hmac_field() {
|
||||
let mut packet = vec![0x14, 0xa7, 0x5b, FLAG_OPEN | FLAG_REPLY | FLAG_HMAC];
|
||||
packet.extend_from_slice(&[0; HMAC_SIZE]);
|
||||
packet.extend_from_slice(&0x7896_b6ab_8771_5213u64.to_le_bytes());
|
||||
packet.extend_from_slice(&default_params().encode());
|
||||
hmac::compute_hmac_in_place(b"testkey", &mut packet, hmac::hmac_offset()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
packet.len(),
|
||||
4 + HMAC_SIZE + TOKEN_SIZE + default_params().encode().len()
|
||||
);
|
||||
let reply = decode_open_reply(&packet, Some(b"testkey")).unwrap();
|
||||
assert_eq!(reply.token, 0x7896_b6ab_8771_5213);
|
||||
assert_eq!(reply.params, default_params());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user