lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

inputs.rs (3487B)


      1 use radroots_ffi::{Error, InputFailure, InquiryInput, ListingInput, ListingReference};
      2 
      3 #[test]
      4 fn actual_shared_parser_retains_invalid_unsupported_and_limit_failures() {
      5     assert!(
      6         matches!(ListingInput::parse(b"{}".to_vec()), Err(Error::InvalidInput { field }) if field == "listing_input")
      7     );
      8     for input in [
      9         br#"{"profile":{"version":2}}"#.as_slice(),
     10         br#"{"profile":{"profile":"unknown"}}"#,
     11     ] {
     12         assert!(
     13             matches!(ListingInput::parse(input.to_vec()), Err(Error::CommandInput { field, kind: InputFailure::UnsupportedProfile }) if field == "listing_input")
     14         );
     15     }
     16     for input in [
     17         br#"{"profile":{"profile":"radroots.listing","version":1}}"#.as_slice(),
     18         br#"{"profile":[]}"#,
     19     ] {
     20         assert!(
     21             matches!(ListingInput::parse(input.to_vec()), Err(Error::InvalidInput { field }) if field == "listing_input")
     22         );
     23     }
     24     assert!(
     25         matches!(ListingInput::parse(vec![b' '; 65_537]), Err(Error::CommandInput { field, kind: InputFailure::LimitExceeded }) if field == "listing_input")
     26     );
     27 }
     28 
     29 #[test]
     30 fn exact_keys_and_private_text_limits_fail_without_input_disclosure() {
     31     let peer = "c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5";
     32     let secret_text = "private input must not enter the error";
     33     let error = InquiryInput::new(
     34         "22".repeat(32),
     35         peer.to_uppercase(),
     36         None,
     37         secret_text.into(),
     38     )
     39     .err()
     40     .unwrap();
     41     assert!(matches!(&error, Error::InvalidInput { field } if field == "peer"));
     42     assert!(!format!("{error:?} {error}").contains(secret_text));
     43     assert!(matches!(
     44         InquiryInput::new("22".repeat(32), peer.into(), None, "x".repeat(65_537)),
     45         Err(Error::CommandInput {
     46             kind: InputFailure::LimitExceeded,
     47             ..
     48         })
     49     ));
     50 }
     51 
     52 #[test]
     53 fn untrusted_listing_descriptors_validate_exact_source_fields_without_authority() {
     54     let peer = "c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5";
     55     let reference = ListingReference {
     56         author: peer.into(),
     57         discriminator: "11".repeat(16),
     58         event_id: "44".repeat(32),
     59     };
     60     assert!(
     61         InquiryInput::new(
     62             "22".repeat(32),
     63             peer.into(),
     64             Some(reference.clone()),
     65             "inquiry".into()
     66         )
     67         .is_ok()
     68     );
     69     for (changed, field) in [
     70         (
     71             ListingReference {
     72                 author: "bad".into(),
     73                 ..reference.clone()
     74             },
     75             "listing_author",
     76         ),
     77         (
     78             ListingReference {
     79                 event_id: "BAD".into(),
     80                 ..reference.clone()
     81             },
     82             "listing_event_id",
     83         ),
     84         (
     85             ListingReference {
     86                 discriminator: "bad".into(),
     87                 ..reference
     88             },
     89             "listing_reference",
     90         ),
     91     ] {
     92         assert!(
     93             matches!(InquiryInput::new("22".repeat(32), peer.into(), Some(changed), "private text".into()), Err(Error::InvalidInput { field: actual }) if actual == field)
     94         );
     95     }
     96     assert!(
     97         matches!(InquiryInput::new("invalid".into(), peer.into(), None, "private".into()), Err(Error::InvalidInput { field }) if field == "thread_id")
     98     );
     99     assert!(
    100         matches!(InquiryInput::new("22".repeat(32), "bad".into(), None, "private".into()), Err(Error::InvalidInput { field }) if field == "peer")
    101     );
    102 }