Cotton code
50 lines · 2.1 KB · RustRaw
//! Which app's household an origin reaches, however it is spelled.use super::*;#[test]fn cotton_dev_refuses_a_real_households_origin_however_it_is_spelled() {    for origin in [        "https://studio.relay.cottondb.com",        "https://studio.relay.cottondb.com/",        "HTTPS://Studio.Relay.CottonDB.com",        "https://studio.relay.cottondb.com:443",    ] {        let refusal = origin_refusal(origin, Some(Flavor::Dev)).expect(origin);        assert!(refusal.contains("studio"), "the refusal names the name: {refusal}");    }    assert_eq!(origin_refusal("https://studio-dev.relay.cottondb.com", Some(Flavor::Dev)), None);}#[test]fn the_real_app_refuses_a_cotton_dev_origin_and_keeps_every_real_one() {    let refusal = origin_refusal("https://studio-dev.relay.cottondb.com", Some(Flavor::Real)).expect("a dev name");    assert!(refusal.contains("studio-dev"));    assert_eq!(origin_refusal("https://studio.relay.cottondb.com", Some(Flavor::Real)), None);}#[test]fn an_address_off_the_relay_is_no_business_of_the_name_rule_and_undeclared_has_none() {    for flavor in Flavor::ALL {        assert_eq!(origin_refusal("http://192.168.1.10:8790", Some(flavor)), None);        assert_eq!(origin_refusal("https://cotton.example.invalid", Some(flavor)), None);    }    assert_eq!(origin_refusal("https://studio.relay.cottondb.com", None), None);    assert_eq!(origin_refusal("https://studio-dev.relay.cottondb.com", None), None);}#[test]fn the_name_an_origin_reaches_is_not_talked_out_of_by_its_spelling() {    for origin in [        "https://studio.relay.cottondb.com",        "https://studio.relay.cottondb.com.",        "https://studio.relay.cottondb.com:8443/x",        "https://deeper.studio.relay.cottondb.com",        "wss://STUDIO.relay.cottondb.com",    ] {        assert_eq!(relay_name_reached(origin).as_deref(), Some("studio"), "for {origin}");    }    assert_eq!(relay_name_reached("https://relay.cottondb.com"), None);    assert_eq!(relay_name_reached("https://studio.relay.cottondb.com.evil.example"), None);    assert_eq!(relay_name_reached("http://192.168.1.10:8790"), None);}