| 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 neqo_common::{Decoder, Encoder}; |
| 8 |
use neqo_transport::StreamId; |
| 9 |
use test_fixture::fixture_init; |
| 10 |
|
| 11 |
use super::enc_dec_hframe; |
| 12 |
use crate::{ |
| 13 |
frames::HFrame, |
| 14 |
settings::{HSetting, HSettingType, HSettings}, |
| 15 |
Priority, PushId, |
| 16 |
}; |
| 17 |
|
| 18 |
#[test] |
| 19 |
fn data_frame() { |
| 20 |
let f = HFrame::Data { len: 3 }; |
| 21 |
enc_dec_hframe(&f, "0003010203", 3); |
| 22 |
} |
| 23 |
|
| 24 |
#[test] |
| 25 |
fn headers_frame() { |
| 26 |
let f = HFrame::Headers { |
| 27 |
header_block: vec![0x01, 0x02, 0x03], |
| 28 |
}; |
| 29 |
enc_dec_hframe(&f, "0103010203", 0); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn cancel_push_frame4() { |
| 34 |
let f = HFrame::CancelPush { |
| 35 |
push_id: PushId::new(5), |
| 36 |
}; |
| 37 |
enc_dec_hframe(&f, "030105", 0); |
| 38 |
} |
| 39 |
|
| 40 |
#[test] |
| 41 |
fn settings_frame4() { |
| 42 |
let f = HFrame::Settings { |
| 43 |
settings: HSettings::new(&[HSetting::new(HSettingType::MaxHeaderListSize, 4)]), |
| 44 |
}; |
| 45 |
enc_dec_hframe(&f, "04020604", 0); |
| 46 |
} |
| 47 |
|
| 48 |
#[test] |
| 49 |
fn push_promise_frame4() { |
| 50 |
let f = HFrame::PushPromise { |
| 51 |
push_id: PushId::new(4), |
| 52 |
header_block: vec![0x61, 0x62, 0x63, 0x64], |
| 53 |
}; |
| 54 |
enc_dec_hframe(&f, "05050461626364", 0); |
| 55 |
} |
| 56 |
|
| 57 |
#[test] |
| 58 |
fn goaway_frame4() { |
| 59 |
let f = HFrame::Goaway { |
| 60 |
stream_id: StreamId::new(5), |
| 61 |
}; |
| 62 |
enc_dec_hframe(&f, "070105", 0); |
| 63 |
} |
| 64 |
|
| 65 |
#[test] |
| 66 |
fn grease() { |
| 67 |
fn make_grease() -> u64 { |
| 68 |
let mut enc = Encoder::default(); |
| 69 |
HFrame::Grease.encode(&mut enc); |
| 70 |
let mut dec = Decoder::from(&enc); |
| 71 |
let ft = dec.decode_varint().unwrap(); |
| 72 |
assert_eq!((ft - 0x21) % 0x1f, 0); |
| 73 |
let body = dec.decode_vvec().unwrap(); |
| 74 |
assert!(body.len() <= 7); |
| 75 |
ft |
| 76 |
} |
| 77 |
|
| 78 |
fixture_init(); |
| 79 |
let t1 = make_grease(); |
| 80 |
let t2 = make_grease(); |
| 81 |
assert_ne!(t1, t2); |
| 82 |
} |
| 83 |
|
| 84 |
#[test] |
| 85 |
fn priority_update_request_default() { |
| 86 |
let f = HFrame::PriorityUpdateRequest { |
| 87 |
element_id: 6, |
| 88 |
priority: Priority::default(), |
| 89 |
}; |
| 90 |
enc_dec_hframe(&f, "800f07000106", 0); |
| 91 |
} |
| 92 |
|
| 93 |
#[test] |
| 94 |
fn priority_update_request_incremental_default() { |
| 95 |
let f = HFrame::PriorityUpdateRequest { |
| 96 |
element_id: 7, |
| 97 |
priority: Priority::new(6, false), |
| 98 |
}; |
| 99 |
enc_dec_hframe(&f, "800f07000407753d36", 0); // "u=6" |
| 100 |
} |
| 101 |
|
| 102 |
#[test] |
| 103 |
fn priority_update_request_urgency_default() { |
| 104 |
let f = HFrame::PriorityUpdateRequest { |
| 105 |
element_id: 8, |
| 106 |
priority: Priority::new(3, true), |
| 107 |
}; |
| 108 |
enc_dec_hframe(&f, "800f0700020869", 0); // "i" |
| 109 |
} |
| 110 |
|
| 111 |
#[test] |
| 112 |
fn priority_update_push_default() { |
| 113 |
let f = HFrame::PriorityUpdatePush { |
| 114 |
element_id: 10, |
| 115 |
priority: Priority::default(), |
| 116 |
}; |
| 117 |
enc_dec_hframe(&f, "800f0701010a", 0); |
| 118 |
} |