| 1 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 2 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 3 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 4 |
// option. This file may not be copied, modified, or distributed |
| 5 |
// except according to those terms. |
| 6 |
|
| 7 |
use std::{cmp::min, fmt::Debug}; |
| 8 |
|
| 9 |
use neqo_common::Encoder; |
| 10 |
use neqo_transport::{Connection, StreamId, StreamType}; |
| 11 |
use test_fixture::{connect, now}; |
| 12 |
|
| 13 |
use crate::{ |
| 14 |
frames::{ |
| 15 |
reader::FrameDecoder, FrameReader, HFrame, StreamReaderConnectionWrapper, WebTransportFrame, |
| 16 |
}, |
| 17 |
settings::{HSetting, HSettingType, HSettings}, |
| 18 |
Error, PushId, |
| 19 |
}; |
| 20 |
|
| 21 |
struct FrameReaderTest { |
| 22 |
pub fr: FrameReader, |
| 23 |
pub conn_c: Connection, |
| 24 |
pub conn_s: Connection, |
| 25 |
pub stream_id: StreamId, |
| 26 |
} |
| 27 |
|
| 28 |
impl FrameReaderTest { |
| 29 |
pub fn new() -> Self { |
| 30 |
let (conn_c, mut conn_s) = connect(); |
| 31 |
let stream_id = conn_s.stream_create(StreamType::BiDi).unwrap(); |
| 32 |
Self { |
| 33 |
fr: FrameReader::new(), |
| 34 |
conn_c, |
| 35 |
conn_s, |
| 36 |
stream_id, |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
fn process<T: FrameDecoder<T>>(&mut self, v: &[u8]) -> Option<T> { |
| 41 |
self.conn_s.stream_send(self.stream_id, v).ok()?; |
| 42 |
let out = self.conn_s.process_output(now()); |
| 43 |
drop(self.conn_c.process(out.dgram(), now())); |
| 44 |
let (frame, fin) = self |
| 45 |
.fr |
| 46 |
.receive::<T>(&mut StreamReaderConnectionWrapper::new( |
| 47 |
&mut self.conn_c, |
| 48 |
self.stream_id, |
| 49 |
)) |
| 50 |
.ok()?; |
| 51 |
assert!(!fin); |
| 52 |
frame |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
// Test receiving byte by byte for a SETTINGS frame. |
| 57 |
#[test] |
| 58 |
fn frame_reading_with_stream_settings1() { |
| 59 |
let mut fr = FrameReaderTest::new(); |
| 60 |
|
| 61 |
// Send and read settings frame 040406040804 |
| 62 |
assert!(fr.process::<HFrame>(&[0x4]).is_none()); |
| 63 |
assert!(fr.process::<HFrame>(&[0x4]).is_none()); |
| 64 |
assert!(fr.process::<HFrame>(&[0x6]).is_none()); |
| 65 |
assert!(fr.process::<HFrame>(&[0x4]).is_none()); |
| 66 |
assert!(fr.process::<HFrame>(&[0x8]).is_none()); |
| 67 |
let frame = fr.process(&[0x4]); |
| 68 |
|
| 69 |
assert!(frame.is_some()); |
| 70 |
if let HFrame::Settings { settings } = frame.unwrap() { |
| 71 |
assert!(settings.len() == 1); |
| 72 |
assert!(settings[0] == HSetting::new(HSettingType::MaxHeaderListSize, 4)); |
| 73 |
} else { |
| 74 |
panic!("wrong frame type"); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// Test receiving byte by byte for a SETTINGS frame with larger varints |
| 79 |
#[test] |
| 80 |
fn frame_reading_with_stream_settings2() { |
| 81 |
let mut fr = FrameReaderTest::new(); |
| 82 |
|
| 83 |
// Read settings frame 400406064004084100 |
| 84 |
for i in &[0x40, 0x04, 0x06, 0x06, 0x40, 0x04, 0x08, 0x41] { |
| 85 |
assert!(fr.process::<HFrame>(&[*i]).is_none()); |
| 86 |
} |
| 87 |
let frame = fr.process(&[0x0]); |
| 88 |
|
| 89 |
assert!(frame.is_some()); |
| 90 |
if let HFrame::Settings { settings } = frame.unwrap() { |
| 91 |
assert!(settings.len() == 1); |
| 92 |
assert!(settings[0] == HSetting::new(HSettingType::MaxHeaderListSize, 4)); |
| 93 |
} else { |
| 94 |
panic!("wrong frame type"); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
// Test receiving byte by byte for a PUSH_PROMISE frame. |
| 99 |
#[test] |
| 100 |
fn frame_reading_with_stream_push_promise() { |
| 101 |
let mut fr = FrameReaderTest::new(); |
| 102 |
|
| 103 |
// Read push-promise frame 05054101010203 |
| 104 |
for i in &[0x05, 0x05, 0x41, 0x01, 0x01, 0x02] { |
| 105 |
assert!(fr.process::<HFrame>(&[*i]).is_none()); |
| 106 |
} |
| 107 |
let frame = fr.process(&[0x3]); |
| 108 |
|
| 109 |
assert!(frame.is_some()); |
| 110 |
if let HFrame::PushPromise { |
| 111 |
push_id, |
| 112 |
header_block, |
| 113 |
} = frame.unwrap() |
| 114 |
{ |
| 115 |
assert_eq!(push_id, PushId::new(257)); |
| 116 |
assert_eq!(header_block, &[0x1, 0x2, 0x3]); |
| 117 |
} else { |
| 118 |
panic!("wrong frame type"); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
// Test DATA |
| 123 |
#[test] |
| 124 |
fn frame_reading_with_stream_data() { |
| 125 |
let mut fr = FrameReaderTest::new(); |
| 126 |
|
| 127 |
// Read data frame 0003010203 |
| 128 |
let frame = fr.process(&[0x0, 0x3, 0x1, 0x2, 0x3]).unwrap(); |
| 129 |
assert!(matches!(frame, HFrame::Data { len } if len == 3)); |
| 130 |
|
| 131 |
// payload is still on the stream. |
| 132 |
// assert that we have 3 bytes in the stream |
| 133 |
let mut buf = [0_u8; 100]; |
| 134 |
let (amount, _) = fr.conn_c.stream_recv(fr.stream_id, &mut buf).unwrap(); |
| 135 |
assert_eq!(amount, 3); |
| 136 |
} |
| 137 |
|
| 138 |
// Test an unknown frame |
| 139 |
#[test] |
| 140 |
fn unknown_frame() { |
| 141 |
// Construct an unknown frame. |
| 142 |
const UNKNOWN_FRAME_LEN: usize = 832; |
| 143 |
|
| 144 |
let mut fr = FrameReaderTest::new(); |
| 145 |
|
| 146 |
let mut enc = Encoder::with_capacity(UNKNOWN_FRAME_LEN + 4); |
| 147 |
enc.encode_varint(1028_u64); // Arbitrary type. |
| 148 |
enc.encode_varint(UNKNOWN_FRAME_LEN as u64); |
| 149 |
let mut buf: Vec<_> = enc.into(); |
| 150 |
buf.resize(UNKNOWN_FRAME_LEN + buf.len(), 0); |
| 151 |
assert!(fr.process::<HFrame>(&buf).is_none()); |
| 152 |
|
| 153 |
// now receive a CANCEL_PUSH frame to see that frame reader is ok. |
| 154 |
let frame = fr.process(&[0x03, 0x01, 0x05]); |
| 155 |
assert!(frame.is_some()); |
| 156 |
if let HFrame::CancelPush { push_id } = frame.unwrap() { |
| 157 |
assert!(push_id == PushId::new(5)); |
| 158 |
} else { |
| 159 |
panic!("wrong frame type"); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
// Test receiving byte by byte for a WT_FRAME_CLOSE_SESSION frame. |
| 164 |
#[test] |
| 165 |
fn frame_reading_with_stream_wt_close_session() { |
| 166 |
let mut fr = FrameReaderTest::new(); |
| 167 |
|
| 168 |
// Read CloseSession frame 6843090000000548656c6c6f |
| 169 |
for i in &[ |
| 170 |
0x68, 0x43, 0x09, 0x00, 0x00, 0x00, 0x05, 0x48, 0x65, 0x6c, 0x6c, |
| 171 |
] { |
| 172 |
assert!(fr.process::<WebTransportFrame>(&[*i]).is_none()); |
| 173 |
} |
| 174 |
let frame = fr.process::<WebTransportFrame>(&[0x6f]); |
| 175 |
|
| 176 |
assert!(frame.is_some()); |
| 177 |
let WebTransportFrame::CloseSession { error, message } = frame.unwrap(); |
| 178 |
assert_eq!(error, 5); |
| 179 |
assert_eq!(message, "Hello".to_string()); |
| 180 |
} |
| 181 |
|
| 182 |
// Test an unknown frame for WebTransportFrames. |
| 183 |
#[test] |
| 184 |
fn unknown_wt_frame() { |
| 185 |
// Construct an unknown frame. |
| 186 |
const UNKNOWN_FRAME_LEN: usize = 832; |
| 187 |
|
| 188 |
let mut fr = FrameReaderTest::new(); |
| 189 |
|
| 190 |
let mut enc = Encoder::with_capacity(UNKNOWN_FRAME_LEN + 4); |
| 191 |
enc.encode_varint(1028_u64); // Arbitrary type. |
| 192 |
enc.encode_varint(UNKNOWN_FRAME_LEN as u64); |
| 193 |
let mut buf: Vec<_> = enc.into(); |
| 194 |
buf.resize(UNKNOWN_FRAME_LEN + buf.len(), 0); |
| 195 |
assert!(fr.process::<WebTransportFrame>(&buf).is_none()); |
| 196 |
|
| 197 |
// now receive a WT_FRAME_CLOSE_SESSION frame to see that frame reader is ok. |
| 198 |
let frame = fr.process(&[ |
| 199 |
0x68, 0x43, 0x09, 0x00, 0x00, 0x00, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, |
| 200 |
]); |
| 201 |
assert!(frame.is_some()); |
| 202 |
let WebTransportFrame::CloseSession { error, message } = frame.unwrap(); |
| 203 |
assert_eq!(error, 5); |
| 204 |
assert_eq!(message, "Hello".to_string()); |
| 205 |
} |
| 206 |
|
| 207 |
enum FrameReadingTestSend { |
| 208 |
OnlyData, |
| 209 |
DataWithFin, |
| 210 |
DataThenFin, |
| 211 |
} |
| 212 |
|
| 213 |
enum FrameReadingTestExpect { |
| 214 |
Error, |
| 215 |
Incomplete, |
| 216 |
FrameComplete, |
| 217 |
FrameAndStreamComplete, |
| 218 |
StreamDoneWithoutFrame, |
| 219 |
} |
| 220 |
|
| 221 |
fn test_reading_frame<T: FrameDecoder<T> + PartialEq + Debug>( |
| 222 |
buf: &[u8], |
| 223 |
test_to_send: &FrameReadingTestSend, |
| 224 |
expected_result: &FrameReadingTestExpect, |
| 225 |
) { |
| 226 |
let mut fr = FrameReaderTest::new(); |
| 227 |
|
| 228 |
fr.conn_s.stream_send(fr.stream_id, buf).unwrap(); |
| 229 |
if matches!(test_to_send, FrameReadingTestSend::DataWithFin) { |
| 230 |
fr.conn_s.stream_close_send(fr.stream_id).unwrap(); |
| 231 |
} |
| 232 |
|
| 233 |
let out = fr.conn_s.process_output(now()); |
| 234 |
drop(fr.conn_c.process(out.dgram(), now())); |
| 235 |
|
| 236 |
if matches!(test_to_send, FrameReadingTestSend::DataThenFin) { |
| 237 |
fr.conn_s.stream_close_send(fr.stream_id).unwrap(); |
| 238 |
let out = fr.conn_s.process_output(now()); |
| 239 |
drop(fr.conn_c.process(out.dgram(), now())); |
| 240 |
} |
| 241 |
|
| 242 |
let rv = fr.fr.receive::<T>(&mut StreamReaderConnectionWrapper::new( |
| 243 |
&mut fr.conn_c, |
| 244 |
fr.stream_id, |
| 245 |
)); |
| 246 |
|
| 247 |
match expected_result { |
| 248 |
FrameReadingTestExpect::Error => assert_eq!(Err(Error::HttpFrame), rv), |
| 249 |
FrameReadingTestExpect::Incomplete => { |
| 250 |
assert_eq!(Ok((None, false)), rv); |
| 251 |
} |
| 252 |
FrameReadingTestExpect::FrameComplete => { |
| 253 |
let (f, fin) = rv.unwrap(); |
| 254 |
assert!(!fin); |
| 255 |
assert!(f.is_some()); |
| 256 |
} |
| 257 |
FrameReadingTestExpect::FrameAndStreamComplete => { |
| 258 |
let (f, fin) = rv.unwrap(); |
| 259 |
assert!(fin); |
| 260 |
assert!(f.is_some()); |
| 261 |
} |
| 262 |
FrameReadingTestExpect::StreamDoneWithoutFrame => { |
| 263 |
let (f, fin) = rv.unwrap(); |
| 264 |
assert!(fin); |
| 265 |
assert!(f.is_none()); |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
#[test] |
| 271 |
fn complete_and_incomplete_unknown_frame() { |
| 272 |
// Construct an unknown frame. |
| 273 |
const UNKNOWN_FRAME_LEN: usize = 832; |
| 274 |
let mut enc = Encoder::with_capacity(UNKNOWN_FRAME_LEN + 4); |
| 275 |
enc.encode_varint(1028_u64); // Arbitrary type. |
| 276 |
enc.encode_varint(UNKNOWN_FRAME_LEN as u64); |
| 277 |
let mut buf: Vec<_> = enc.into(); |
| 278 |
buf.resize(UNKNOWN_FRAME_LEN + buf.len(), 0); |
| 279 |
|
| 280 |
let len = min(buf.len() - 1, 10); |
| 281 |
for i in 1..len { |
| 282 |
test_reading_frame::<HFrame>( |
| 283 |
&buf[..i], |
| 284 |
&FrameReadingTestSend::OnlyData, |
| 285 |
&FrameReadingTestExpect::Incomplete, |
| 286 |
); |
| 287 |
test_reading_frame::<HFrame>( |
| 288 |
&buf[..i], |
| 289 |
&FrameReadingTestSend::DataWithFin, |
| 290 |
&FrameReadingTestExpect::Error, |
| 291 |
); |
| 292 |
test_reading_frame::<HFrame>( |
| 293 |
&buf[..i], |
| 294 |
&FrameReadingTestSend::DataThenFin, |
| 295 |
&FrameReadingTestExpect::Error, |
| 296 |
); |
| 297 |
} |
| 298 |
test_reading_frame::<HFrame>( |
| 299 |
&buf, |
| 300 |
&FrameReadingTestSend::OnlyData, |
| 301 |
&FrameReadingTestExpect::Incomplete, |
| 302 |
); |
| 303 |
test_reading_frame::<HFrame>( |
| 304 |
&buf, |
| 305 |
&FrameReadingTestSend::DataWithFin, |
| 306 |
&FrameReadingTestExpect::StreamDoneWithoutFrame, |
| 307 |
); |
| 308 |
test_reading_frame::<HFrame>( |
| 309 |
&buf, |
| 310 |
&FrameReadingTestSend::DataThenFin, |
| 311 |
&FrameReadingTestExpect::StreamDoneWithoutFrame, |
| 312 |
); |
| 313 |
} |
| 314 |
|
| 315 |
// if we read more than done_state bytes FrameReader will be in done state. |
| 316 |
fn test_complete_and_incomplete_frame<T: FrameDecoder<T> + PartialEq + Debug>( |
| 317 |
buf: &[u8], |
| 318 |
done_state: usize, |
| 319 |
) { |
| 320 |
use std::cmp::Ordering; |
| 321 |
// Let's consume partial frames. It is enough to test partial frames |
| 322 |
// up to 10 byte. 10 byte is greater than frame type and frame |
| 323 |
// length and bit of data. |
| 324 |
let len = min(buf.len() - 1, 10); |
| 325 |
for i in 1..len { |
| 326 |
test_reading_frame::<T>( |
| 327 |
&buf[..i], |
| 328 |
&FrameReadingTestSend::OnlyData, |
| 329 |
if i >= done_state { |
| 330 |
&FrameReadingTestExpect::FrameComplete |
| 331 |
} else { |
| 332 |
&FrameReadingTestExpect::Incomplete |
| 333 |
}, |
| 334 |
); |
| 335 |
test_reading_frame::<T>( |
| 336 |
&buf[..i], |
| 337 |
&FrameReadingTestSend::DataWithFin, |
| 338 |
match i.cmp(&done_state) { |
| 339 |
Ordering::Greater => &FrameReadingTestExpect::FrameComplete, |
| 340 |
Ordering::Equal => &FrameReadingTestExpect::FrameAndStreamComplete, |
| 341 |
Ordering::Less => &FrameReadingTestExpect::Error, |
| 342 |
}, |
| 343 |
); |
| 344 |
test_reading_frame::<T>( |
| 345 |
&buf[..i], |
| 346 |
&FrameReadingTestSend::DataThenFin, |
| 347 |
match i.cmp(&done_state) { |
| 348 |
Ordering::Greater => &FrameReadingTestExpect::FrameComplete, |
| 349 |
Ordering::Equal => &FrameReadingTestExpect::FrameAndStreamComplete, |
| 350 |
Ordering::Less => &FrameReadingTestExpect::Error, |
| 351 |
}, |
| 352 |
); |
| 353 |
} |
| 354 |
test_reading_frame::<T>( |
| 355 |
buf, |
| 356 |
&FrameReadingTestSend::OnlyData, |
| 357 |
&FrameReadingTestExpect::FrameComplete, |
| 358 |
); |
| 359 |
test_reading_frame::<T>( |
| 360 |
buf, |
| 361 |
&FrameReadingTestSend::DataWithFin, |
| 362 |
if buf.len() == done_state { |
| 363 |
&FrameReadingTestExpect::FrameAndStreamComplete |
| 364 |
} else { |
| 365 |
&FrameReadingTestExpect::FrameComplete |
| 366 |
}, |
| 367 |
); |
| 368 |
test_reading_frame::<T>( |
| 369 |
buf, |
| 370 |
&FrameReadingTestSend::DataThenFin, |
| 371 |
if buf.len() == done_state { |
| 372 |
&FrameReadingTestExpect::FrameAndStreamComplete |
| 373 |
} else { |
| 374 |
&FrameReadingTestExpect::FrameComplete |
| 375 |
}, |
| 376 |
); |
| 377 |
} |
| 378 |
|
| 379 |
#[test] |
| 380 |
fn complete_and_incomplete_frames() { |
| 381 |
const FRAME_LEN: usize = 10; |
| 382 |
const HEADER_BLOCK: &[u8] = &[0x01, 0x02, 0x03, 0x04]; |
| 383 |
|
| 384 |
// H3_FRAME_TYPE_DATA len=0 |
| 385 |
let f = HFrame::Data { len: 0 }; |
| 386 |
let mut enc = Encoder::with_capacity(2); |
| 387 |
f.encode(&mut enc); |
| 388 |
let buf: Vec<_> = enc.into(); |
| 389 |
test_complete_and_incomplete_frame::<HFrame>(&buf, 2); |
| 390 |
|
| 391 |
// H3_FRAME_TYPE_DATA len=FRAME_LEN |
| 392 |
let f = HFrame::Data { |
| 393 |
len: FRAME_LEN as u64, |
| 394 |
}; |
| 395 |
let mut enc = Encoder::with_capacity(2); |
| 396 |
f.encode(&mut enc); |
| 397 |
let mut buf: Vec<_> = enc.into(); |
| 398 |
buf.resize(FRAME_LEN + buf.len(), 0); |
| 399 |
test_complete_and_incomplete_frame::<HFrame>(&buf, 2); |
| 400 |
|
| 401 |
// H3_FRAME_TYPE_HEADERS empty header block |
| 402 |
let f = HFrame::Headers { |
| 403 |
header_block: Vec::new(), |
| 404 |
}; |
| 405 |
let mut enc = Encoder::default(); |
| 406 |
f.encode(&mut enc); |
| 407 |
let buf: Vec<_> = enc.into(); |
| 408 |
test_complete_and_incomplete_frame::<HFrame>(&buf, 2); |
| 409 |
|
| 410 |
// H3_FRAME_TYPE_HEADERS |
| 411 |
let f = HFrame::Headers { |
| 412 |
header_block: HEADER_BLOCK.to_vec(), |
| 413 |
}; |
| 414 |
let mut enc = Encoder::default(); |
| 415 |
f.encode(&mut enc); |
| 416 |
let buf: Vec<_> = enc.into(); |
| 417 |
test_complete_and_incomplete_frame::<HFrame>(&buf, buf.len()); |
| 418 |
|
| 419 |
// H3_FRAME_TYPE_CANCEL_PUSH |
| 420 |
let f = HFrame::CancelPush { |
| 421 |
push_id: PushId::new(5), |
| 422 |
}; |
| 423 |
let mut enc = Encoder::default(); |
| 424 |
f.encode(&mut enc); |
| 425 |
let buf: Vec<_> = enc.into(); |
| 426 |
test_complete_and_incomplete_frame::<HFrame>(&buf, buf.len()); |
| 427 |
|
| 428 |
// H3_FRAME_TYPE_SETTINGS |
| 429 |
let f = HFrame::Settings { |
| 430 |
settings: HSettings::new(&[HSetting::new(HSettingType::MaxHeaderListSize, 4)]), |
| 431 |
}; |
| 432 |
let mut enc = Encoder::default(); |
| 433 |
f.encode(&mut enc); |
| 434 |
let buf: Vec<_> = enc.into(); |
| 435 |
test_complete_and_incomplete_frame::<HFrame>(&buf, buf.len()); |
| 436 |
|
| 437 |
// H3_FRAME_TYPE_PUSH_PROMISE |
| 438 |
let f = HFrame::PushPromise { |
| 439 |
push_id: PushId::new(4), |
| 440 |
header_block: HEADER_BLOCK.to_vec(), |
| 441 |
}; |
| 442 |
let mut enc = Encoder::default(); |
| 443 |
f.encode(&mut enc); |
| 444 |
let buf: Vec<_> = enc.into(); |
| 445 |
test_complete_and_incomplete_frame::<HFrame>(&buf, buf.len()); |
| 446 |
|
| 447 |
// H3_FRAME_TYPE_GOAWAY |
| 448 |
let f = HFrame::Goaway { |
| 449 |
stream_id: StreamId::new(5), |
| 450 |
}; |
| 451 |
let mut enc = Encoder::default(); |
| 452 |
f.encode(&mut enc); |
| 453 |
let buf: Vec<_> = enc.into(); |
| 454 |
test_complete_and_incomplete_frame::<HFrame>(&buf, buf.len()); |
| 455 |
|
| 456 |
// H3_FRAME_TYPE_MAX_PUSH_ID |
| 457 |
let f = HFrame::MaxPushId { |
| 458 |
push_id: PushId::new(5), |
| 459 |
}; |
| 460 |
let mut enc = Encoder::default(); |
| 461 |
f.encode(&mut enc); |
| 462 |
let buf: Vec<_> = enc.into(); |
| 463 |
test_complete_and_incomplete_frame::<HFrame>(&buf, buf.len()); |
| 464 |
} |
| 465 |
|
| 466 |
#[test] |
| 467 |
fn complete_and_incomplete_wt_frames() { |
| 468 |
// H3_FRAME_TYPE_MAX_PUSH_ID |
| 469 |
let f = WebTransportFrame::CloseSession { |
| 470 |
error: 5, |
| 471 |
message: "Hello".to_string(), |
| 472 |
}; |
| 473 |
let mut enc = Encoder::default(); |
| 474 |
f.encode(&mut enc); |
| 475 |
let buf: Vec<_> = enc.into(); |
| 476 |
test_complete_and_incomplete_frame::<WebTransportFrame>(&buf, buf.len()); |
| 477 |
} |
| 478 |
|
| 479 |
// Test closing a stream before any frame is sent should not cause an error. |
| 480 |
#[test] |
| 481 |
fn frame_reading_when_stream_is_closed_before_sending_data() { |
| 482 |
let mut fr = FrameReaderTest::new(); |
| 483 |
|
| 484 |
fr.conn_s.stream_send(fr.stream_id, &[0x00]).unwrap(); |
| 485 |
let out = fr.conn_s.process_output(now()); |
| 486 |
drop(fr.conn_c.process(out.dgram(), now())); |
| 487 |
|
| 488 |
assert_eq!(Ok(()), fr.conn_c.stream_close_send(fr.stream_id)); |
| 489 |
let out = fr.conn_c.process_output(now()); |
| 490 |
drop(fr.conn_s.process(out.dgram(), now())); |
| 491 |
assert_eq!( |
| 492 |
Ok((None, true)), |
| 493 |
fr.fr |
| 494 |
.receive::<HFrame>(&mut StreamReaderConnectionWrapper::new( |
| 495 |
&mut fr.conn_s, |
| 496 |
fr.stream_id |
| 497 |
)) |
| 498 |
); |
| 499 |
} |
| 500 |
|
| 501 |
// Test closing a stream before any frame is sent should not cause an error. |
| 502 |
// This is the same as the previous just for WebTransportFrame. |
| 503 |
#[test] |
| 504 |
fn wt_frame_reading_when_stream_is_closed_before_sending_data() { |
| 505 |
let mut fr = FrameReaderTest::new(); |
| 506 |
|
| 507 |
fr.conn_s.stream_send(fr.stream_id, &[0x00]).unwrap(); |
| 508 |
let out = fr.conn_s.process_output(now()); |
| 509 |
drop(fr.conn_c.process(out.dgram(), now())); |
| 510 |
|
| 511 |
assert_eq!(Ok(()), fr.conn_c.stream_close_send(fr.stream_id)); |
| 512 |
let out = fr.conn_c.process_output(now()); |
| 513 |
drop(fr.conn_s.process(out.dgram(), now())); |
| 514 |
assert_eq!( |
| 515 |
Ok((None, true)), |
| 516 |
fr.fr |
| 517 |
.receive::<WebTransportFrame>(&mut StreamReaderConnectionWrapper::new( |
| 518 |
&mut fr.conn_s, |
| 519 |
fr.stream_id |
| 520 |
)) |
| 521 |
); |
| 522 |
} |