Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(agent): rename and extend endpoint safety test for bearer credentials

Steven Enamakel14960249dd6d
diff --git a/src/embed/agent_tests.rs b/src/embed/agent_tests.rs
index 8f6a27f876..750fe86509 100644
--- a/src/embed/agent_tests.rs
+++ b/src/embed/agent_tests.rs
@@ -116,14 +116,23 @@ fn route_debug_redacts_bearer_and_url_embedded_credentials() {
}
#[test]
-fn is_https_endpoint_accepts_only_tls() {
- assert!(is_https_endpoint("https://api.example.com/v1"));
- assert!(is_https_endpoint("https://127.0.0.1:8443"));
- assert!(!is_https_endpoint("http://api.example.com/v1"));
+fn is_safe_endpoint_for_bearer_accepts_tls_and_loopback() {
+ // TLS is always safe for a bearer.
+ assert!(is_safe_endpoint_for_bearer("https://api.example.com/v1"));
+ assert!(is_safe_endpoint_for_bearer("https://127.0.0.1:8443"));
+ // Cleartext is refused for remote hosts...
+ assert!(!is_safe_endpoint_for_bearer("http://api.example.com/v1"));
+ assert!(!is_safe_endpoint_for_bearer("http://192.168.1.10/v1"));
+ // ...but accepted for loopback, where the credential never leaves the host.
+ assert!(is_safe_endpoint_for_bearer("http://127.0.0.1:8080/v1"));
+ assert!(is_safe_endpoint_for_bearer("http://localhost:8080/v1"));
+ assert!(is_safe_endpoint_for_bearer("http://[::1]:8080/v1"));
+ assert!(is_safe_endpoint_for_bearer("http://127.0.0.2:8080/v1"));
// Unparseable or non-URL values are refused, not silently allowed, so a
// bearer can never ride a cleartext or ambiguous channel.
- assert!(!is_https_endpoint("api.example.com"));
- assert!(!is_https_endpoint("ftp://api.example.com"));
+ assert!(!is_safe_endpoint_for_bearer("api.example.com"));
+ assert!(!is_safe_endpoint_for_bearer("ftp://api.example.com"));
+ assert!(!is_safe_endpoint_for_bearer("http://api.example.com:8080"));
}
#[test]