diff --git a/crates/openhuman-core/src/config/schema/resolved_endpoints_tests.rs b/crates/openhuman-core/src/config/schema/resolved_endpoints_tests.rs index 5275a9c7992..cb6e6cc207b 100644 --- a/crates/openhuman-core/src/config/schema/resolved_endpoints_tests.rs +++ b/crates/openhuman-core/src/config/schema/resolved_endpoints_tests.rs @@ -42,3 +42,38 @@ fn an_at_sign_after_the_query_fragment_or_path_is_not_userinfo() { assert!(!e.is_managed_host("https://evil.invalid\\@api.example.test/v1")); assert!(e.is_managed_host("https://api.example.test?next=a@b.invalid")); } + +/// `host_matches_any` is not replaceable by +/// `tinyagents_harness::url_guard::host_matches_allowlist`: the allowlist +/// treats a bare `example.com` as covering its subdomains, never matches a +/// leading-dot pattern, compares case-sensitively and honours `*`. A managed +/// host list depends on the opposite (exact unless `.suffix`), so this pins +/// both behaviours side by side. +#[test] +fn host_matching_differs_from_the_url_guard_allowlist() { + use tinyagents_harness::url_guard::host_matches_allowlist; + // (pattern, host, host_matches_any, host_matches_allowlist) + let cases = [ + (".example.com", "example.com", false, false), + (".example.com", "sub.example.com", true, false), + (".example.com", "badexample.com", false, false), + ("example.com", "example.com", true, true), + ("example.com", "sub.example.com", false, true), + ("example.com", "badexample.com", false, false), + (".example.com", "SUB.Example.COM", true, false), + ("*", "example.com", false, true), + ]; + for (pattern, host, ours, allowlist) in cases { + let patterns = vec![pattern.to_string()]; + assert_eq!( + host_matches_any(host, &patterns), + ours, + "host_matches_any({host:?}, [{pattern:?}])" + ); + assert_eq!( + host_matches_allowlist(host, &patterns), + allowlist, + "host_matches_allowlist({host:?}, [{pattern:?}])" + ); + } +}