Cotton code
33 lines · 1.9 KB · RustRaw
use super::*;/// RULE: A connection reaches the service's own server or a server on this Mac; a known hosted gateway is refused and anything else is warned about, because no third party is ever in the path.#[test]fn the_services_own_server_and_this_mac_pass_a_gateway_is_refused_and_the_rest_is_warned() {    assert_eq!(judge("https://mcp.cloudflare.com/mcp"), Verdict::Own { service: "Cloudflare" });    assert_eq!(judge("https://dns-analytics.mcp.cloudflare.com/mcp"), Verdict::Own { service: "Cloudflare" });    assert_eq!(judge("https://api.githubcopilot.com/mcp/"), Verdict::Own { service: "GitHub" });    assert_eq!(judge("http://127.0.0.1:8787/mcp"), Verdict::OnThisMac);    assert_eq!(judge("http://localhost:3000/mcp"), Verdict::OnThisMac);    assert_eq!(judge("http://[::1]:3000/mcp"), Verdict::OnThisMac);    assert_eq!(judge("http://studio.local:3000/mcp"), Verdict::OnThisMac);    assert_eq!(        judge("https://server.smithery.ai/x/mcp"),        Verdict::Refused(ConnectionRefusal::Gateway { host: "server.smithery.ai".into(), gateway: "smithery.ai".into() })    );    assert!(matches!(judge("https://mcp.composio.dev/x"), Verdict::Refused(_)));    assert_eq!(judge("https://mcp.example.org/mcp"), Verdict::ThirdParty { host: "mcp.example.org".into() });}#[test]fn plain_http_to_the_internet_and_non_urls_are_refused() {    assert_eq!(        judge("http://mcp.cloudflare.com/mcp"),        Verdict::Refused(ConnectionRefusal::PlainHttp { url: "http://mcp.cloudflare.com/mcp".into() })    );    assert!(matches!(judge("ftp://mcp.cloudflare.com/mcp"), Verdict::Refused(_)));    assert!(matches!(judge("not a url"), Verdict::Refused(_)));    assert!(matches!(judge("https://"), Verdict::Refused(_)));    // A lookalike is not the service: `cloudflare.com.evil.example` ends in    // `.example`, not `.cloudflare.com`.    assert!(matches!(judge("https://cloudflare.com.evil.example/mcp"), Verdict::ThirdParty { .. }));}