From 282bfb84e4e33419374d493543f409fd4b3a5a9d Mon Sep 17 00:00:00 2001 From: Albin Suresh Date: Thu, 28 Mar 2024 09:38:57 +0000 Subject: [PATCH] fixup! fixup! fixup! fixup! fix: Honor c8y.mqtt setting on tedge connect #2787 --- crates/core/c8y_api/src/http_proxy.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/core/c8y_api/src/http_proxy.rs b/crates/core/c8y_api/src/http_proxy.rs index 3b5e268ad89..237aaadf281 100644 --- a/crates/core/c8y_api/src/http_proxy.rs +++ b/crates/core/c8y_api/src/http_proxy.rs @@ -101,17 +101,20 @@ impl C8yEndPoint { // * . eg: t12345.c8y.io // These URLs may be both equivalent and point to the same tenant. // We are going to remove that and only check if the domain is the same. - let tenant_uri = &self.c8y_host; + let (tenant_host, _port) = self + .c8y_host + .split_once(':') + .unwrap_or((&self.c8y_host, "")); let url = Url::parse(url).ok()?; let url_host = url.domain()?; let (_, host) = url_host.split_once('.').unwrap_or((url_host, "")); - let (_, c8y_host) = tenant_uri.split_once('.').unwrap(); + let (_, c8y_host) = tenant_host.split_once('.').unwrap(); // The configured `c8y.http` setting may have a port value specified, // but the incoming URL is less likely to have any port specified. // Hence just matching the host prefix. - (c8y_host.starts_with(host)).then_some(url) + (host == c8y_host).then_some(url) } } @@ -241,6 +244,8 @@ mod tests { #[test_case("http://test.co.te")] #[test_case("http://test.com:123456")] #[test_case("http://test.com::12345")] + #[test_case("http://localhost")] + #[test_case("http://abc.com")] fn url_is_my_tenant_incorrect_urls(url: &str) { let c8y = C8yEndPoint::new("test.test.com", "test_device"); assert!(c8y.maybe_tenant_url(url).is_none());