oxedyne/fe2o3/fe2o3_steel/tests/ambiguous_length_refused.rs
1.6 KiB, 1 run
created by r1435043967:77610, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! A request whose length can be read two ways is answered 400 and its connection closed. |
| 2 | //! |
| 3 | //! RFC 9112 §6.3: a front proxy that frames such a request one way while Steel frames it the |
| 4 | //! other lets a second request ride inside the first. The reader refuses it; this checks that |
| 5 | //! the refusal reaches the client as a bad request rather than as a silent drop. |
| 6 | |
| 7 | mod vhost_rig; |
| 8 | |
| 9 | use vhost_rig::{ |
| 10 | Rig, |
| 11 | Scratch, |
| 12 | Site, |
| 13 | }; |
| 14 | |
| 15 | use oxedyne_fe2o3_core::prelude::*; |
| 16 | |
| 17 | use std::time::Duration; |
| 18 | |
| 19 | const HOST: &str = "length.test"; |
| 20 | |
| 21 | fn refused(label: &str, fields: &str) -> Outcome<()> { |
| 22 | let web = res!(Scratch::new(label)); |
| 23 | res!(web.put("index.html", "<p>home</p>")); |
| 24 | let runtime = res!(vhost_rig::runtime()); |
| 25 | let raw = fmt!("POST / HTTP/1.1\r\nHost: {}\r\n{}\r\n", HOST, fields); |
| 26 | let x = res!(runtime.block_on(async { |
| 27 | let rig = res!(Rig::new(vec![Site::new(HOST, &web.0)])); |
| 28 | rig.exchange(HOST, &raw, Duration::from_millis(3000)).await |
| 29 | })); |
| 30 | assert_eq!(x.reply.status(), 400, "{:?} was not refused: {:?}", fields, x.reply.head); |
| 31 | assert!(x.closed, "{:?} was refused but the connection stayed open", fields); |
| 32 | Ok(()) |
| 33 | } |
| 34 | |
| 35 | #[test] |
| 36 | fn content_length_with_transfer_encoding_is_answered_400_and_closed() -> Outcome<()> { |
| 37 | refused("cl_te", "Content-Length: 3\r\nTransfer-Encoding: chunked\r\n") |
| 38 | } |
| 39 | |
| 40 | #[test] |
| 41 | fn two_differing_content_lengths_are_answered_400_and_closed() -> Outcome<()> { |
| 42 | refused("cl_cl", "Content-Length: 3\r\nContent-Length: 5\r\n") |
| 43 | } |
| 44 | |
| 45 | #[test] |
| 46 | fn a_folded_header_line_is_answered_400_and_closed() -> Outcome<()> { |
| 47 | refused("fold", "X-Note: one\r\n two\r\n") |
| 48 | } |