From 3abe5ebd5fdf85c630db4492baf19d3cee0dd0fe Mon Sep 17 00:00:00 2001 From: Ghost Scripter Date: Mon, 16 Nov 2026 11:11:53 +0530 Subject: [PATCH] test(config): pin managed-host matching against the url_guard allowlist host_matches_any treats a bare pattern as exact and a leading-dot pattern as a subdomain suffix, case-insensitively. tinyagents_harness::url_guard:: host_matches_allowlist covers subdomains for a bare entry, never matches a leading-dot entry, is case-sensitive and honours "*", so it cannot replace the managed-host matcher. Pin both side by side (#350). Co-Authored-By: Claude Opus 5.5 --- .../config/schema/resolved_endpoints_tests.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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:?}])" + ); + } +}