Skip to content

Commit

Permalink
Merge pull request #3222 from didier-wenzek/fix/maybe_tenant_url
Browse files Browse the repository at this point in the history
fix: c8y http proxy wrongly assumes any hostname is from the same tenant
  • Loading branch information
didier-wenzek authored Nov 5, 2024
2 parents 7e72f03 + bc27f63 commit 73b343e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/core/c8y_api/src/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 73b343e

Please sign in to comment.