mirror of
https://github.com/telemt/telemt.git
synced 2026-06-23 02:00:10 +07:00
Account for full-word paddings in roundtrip tests
This commit is contained in:
@@ -331,7 +331,8 @@ where
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Secure Intermediate: strip validated trailing padding bytes.
|
// Secure Intermediate strips only non-aligned tail padding; full-word
|
||||||
|
// padding is indistinguishable from payload in VersionD framing.
|
||||||
if proto_tag == ProtoTag::Secure {
|
if proto_tag == ProtoTag::Secure {
|
||||||
payload.truncate(secure_payload_len);
|
payload.truncate(secure_payload_len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -523,6 +523,16 @@ mod tests {
|
|||||||
use tokio::io::duplex;
|
use tokio::io::duplex;
|
||||||
use tokio_util::codec::{FramedRead, FramedWrite};
|
use tokio_util::codec::{FramedRead, FramedWrite};
|
||||||
|
|
||||||
|
fn assert_secure_decoded_payload(decoded: &[u8], original: &[u8]) {
|
||||||
|
assert!(decoded.starts_with(original));
|
||||||
|
assert!(
|
||||||
|
(original.len()..=original.len() + 12).contains(&decoded.len()),
|
||||||
|
"Secure decoded payload may retain up to 12 bytes of full-word padding, got {}",
|
||||||
|
decoded.len()
|
||||||
|
);
|
||||||
|
assert_eq!(decoded.len() % 4, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_framed_abridged() {
|
async fn test_framed_abridged() {
|
||||||
let (client, server) = duplex(4096);
|
let (client, server) = duplex(4096);
|
||||||
@@ -565,7 +575,7 @@ mod tests {
|
|||||||
writer.send(frame).await.unwrap();
|
writer.send(frame).await.unwrap();
|
||||||
|
|
||||||
let received = reader.next().await.unwrap().unwrap();
|
let received = reader.next().await.unwrap().unwrap();
|
||||||
assert_eq!(&received.data[..], &original[..]);
|
assert_secure_decoded_payload(&received.data, &original);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -588,7 +598,11 @@ mod tests {
|
|||||||
writer.send(frame).await.unwrap();
|
writer.send(frame).await.unwrap();
|
||||||
|
|
||||||
let received = reader.next().await.unwrap().unwrap();
|
let received = reader.next().await.unwrap().unwrap();
|
||||||
assert_eq!(received.data.len(), 8);
|
if proto_tag == ProtoTag::Secure {
|
||||||
|
assert_secure_decoded_payload(&received.data, &original);
|
||||||
|
} else {
|
||||||
|
assert_eq!(received.data.len(), original.len());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -559,6 +559,16 @@ mod tests {
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io::duplex;
|
use tokio::io::duplex;
|
||||||
|
|
||||||
|
fn assert_secure_decoded_payload(decoded: &[u8], original: &[u8]) {
|
||||||
|
assert!(decoded.starts_with(original));
|
||||||
|
assert!(
|
||||||
|
(original.len()..=original.len() + 12).contains(&decoded.len()),
|
||||||
|
"Secure decoded payload may retain up to 12 bytes of full-word padding, got {}",
|
||||||
|
decoded.len()
|
||||||
|
);
|
||||||
|
assert_eq!(decoded.len() % 4, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_abridged_roundtrip() {
|
async fn test_abridged_roundtrip() {
|
||||||
let (client, server) = duplex(1024);
|
let (client, server) = duplex(1024);
|
||||||
@@ -625,7 +635,7 @@ mod tests {
|
|||||||
writer.flush().await.unwrap();
|
writer.flush().await.unwrap();
|
||||||
|
|
||||||
let (received, _meta) = reader.read_frame().await.unwrap();
|
let (received, _meta) = reader.read_frame().await.unwrap();
|
||||||
assert_eq!(received.len(), data.len());
|
assert_secure_decoded_payload(&received, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Reference in New Issue
Block a user