oxedyne/fe2o3/fe2o3_net/tests/locator.rs
2.1 KiB, 1 run
created by r1870400018:76230, 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 target read into an `HttpLocator` is written back byte for byte. A signed query |
| 2 | //! (sorted or not, with repeated keys, empty values, numbers or padded base64) must reach the |
| 3 | //! wire as it was signed, so the locator never rebuilds a query it was given (REL-1i: a |
| 4 | //! runner's wake was refused because the query went out as `"device"="..."&"ts"=(u32|...)`). |
| 5 | |
| 6 | use oxedyne_fe2o3_core::prelude::*; |
| 7 | use oxedyne_fe2o3_net::http::loc::HttpLocator; |
| 8 | |
| 9 | const TARGETS: &[&str] = &[ |
| 10 | "/api/sync/ws?w=rn1a2b3c19a3f0c2d11&device=r2cfixturedevice&ts=1793352150&nonce=oysOzVAmnE4uvsXKi1O7SQ&sigv=2&sig=bvwVjtvw7rJqeAa_wBv2yZbGPLzH1KsasCwJ-_kiGsBxiOite0daGgsuNXSDqn7if6ob3_1P8tHJ3wXwDvXvDQ&caps=pong", |
| 11 | "/p?b=2&a=1", // Keys out of order. |
| 12 | "/p?a=1&a=2", // A repeated key. |
| 13 | "/p?a=&b=x", // An empty value. |
| 14 | "/p?n=007&f=1.50&t=true", // Values a daticle reader would re-render. |
| 15 | "/p?sig=YWJj&pad=YQ==", // Padded base64. |
| 16 | "/p?have=s1%3A1&x=a+b", // Percent escapes and a plus, as sent. |
| 17 | "/p?q=a?b", // A `?` inside the query. |
| 18 | "/p?a=1#sec", // A fragment. |
| 19 | "/p", // No query. |
| 20 | ]; |
| 21 | |
| 22 | #[test] |
| 23 | fn test_a_locator_writes_its_target_back_byte_for_byte() -> Outcome<()> { |
| 24 | for t in TARGETS { |
| 25 | let loc = res!(HttpLocator::new(*t)); |
| 26 | assert_eq!(loc.to_string(), *t, "the locator rewrote {}", t); |
| 27 | } |
| 28 | Ok(()) |
| 29 | } |
| 30 | |
| 31 | #[test] |
| 32 | fn test_a_query_with_a_question_mark_is_kept_whole() -> Outcome<()> { |
| 33 | let loc = res!(HttpLocator::new("/p?q=a?b&r=1")); |
| 34 | assert_eq!(loc.query, "q=a?b&r=1"); |
| 35 | assert_eq!(loc.query_str("q"), Some(fmt!("a?b"))); |
| 36 | assert_eq!(loc.query_str("r"), Some(fmt!("1"))); |
| 37 | Ok(()) |
| 38 | } |
| 39 | |
| 40 | #[cfg(feature = "async")] |
| 41 | #[test] |
| 42 | fn test_a_websocket_dial_sends_the_target_it_was_given() -> Outcome<()> { |
| 43 | for t in TARGETS { |
| 44 | let (msg, _key) = res!(oxedyne_fe2o3_net::ws::core::connect_request("h.example", t, None)); |
| 45 | let line = fmt!("GET {} HTTP/1.1\r\n", t); |
| 46 | assert!(msg.header.to_string().starts_with(&line), "the dial rewrote {}", t); |
| 47 | } |
| 48 | Ok(()) |
| 49 | } |