Skip to content

Commit 426c2c3

Browse files
committed
agent/tests: add test for data before stun with TCP
1 parent 1ca145c commit 426c2c3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

stun-proto/src/agent.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,22 @@ pub(crate) mod tests {
12321232
assert_eq!(&data[2..], received);
12331233
}
12341234

1235+
#[test]
1236+
fn tcp_data_before_request() {
1237+
init();
1238+
let local_addr = "127.0.0.1:2000".parse().unwrap();
1239+
let remote_addr = "127.0.0.1:1000".parse().unwrap();
1240+
let mut agent = StunAgent::builder(TransportType::Tcp, local_addr)
1241+
.remote_addr(remote_addr)
1242+
.build();
1243+
let data = [0, 2, 42, 42];
1244+
1245+
assert!(matches!(
1246+
agent.handle_incoming_data(&data, remote_addr),
1247+
Err(StunError::ProtocolViolation)
1248+
));
1249+
}
1250+
12351251
#[test]
12361252
fn request_cancel() {
12371253
let local_addr = "10.0.0.1:12345".parse().unwrap();

0 commit comments

Comments
 (0)