diff --git a/crates/core/c8y_api/src/http_proxy.rs b/crates/core/c8y_api/src/http_proxy.rs index b370e5d175..8a8dbb3b29 100644 --- a/crates/core/c8y_api/src/http_proxy.rs +++ b/crates/core/c8y_api/src/http_proxy.rs @@ -123,13 +123,13 @@ impl C8yEndPoint { let url = Url::parse(url).ok()?; let url_host = url.domain()?; - let (_, host) = url_host.split_once('.').unwrap_or((url_host, "")); + let (_, host) = url_host.split_once('.').unwrap_or(("", url_host)); let (_, c8y_http_host) = tenant_http_host .split_once('.') - .unwrap_or((tenant_http_host, "")); + .unwrap_or(("", tenant_http_host)); let (_, c8y_mqtt_host) = tenant_mqtt_host .split_once('.') - .unwrap_or((tenant_mqtt_host, "")); + .unwrap_or(("", tenant_mqtt_host)); // The configured `c8y.http` setting may have a port value specified, // but the incoming URL is less likely to have any port specified. @@ -414,6 +414,13 @@ mod tests { assert_eq!(c8y.maybe_tenant_url(url), Some(url.parse().unwrap())); } + #[test] + fn url_is_not_my_tenant_with_hostname_without_commas() { + let c8y = C8yEndPoint::new("custom-domain", "non-custom-mqtt-domain", "test_device"); + let url = "http://unrelated-domain/path"; + assert!(c8y.maybe_tenant_url(url).is_none()); + } + #[ignore = "Until #2804 is fixed"] #[test] fn url_is_my_tenant_check_not_too_broad() {