Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fix: Honor c8y.mqtt setting on tedge conn…
Browse files Browse the repository at this point in the history
…ect #2787
  • Loading branch information
albinsuresh committed Mar 28, 2024
1 parent 2233e35 commit 282bfb8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/core/c8y_api/src/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ impl C8yEndPoint {
// * <tenant_id>.<domain> 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)
}
}

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 282bfb8

Please sign in to comment.