From e6f93ec9ce4de35875edfecfbd9103809291f54d Mon Sep 17 00:00:00 2001 From: Dobromir Marinov Date: Wed, 17 Apr 2024 18:20:18 +0100 Subject: [PATCH 1/2] * Replaced the host name with the correct String. --- .../swimos_server_app/src/server/runtime/downlinks/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/swimos_server_app/src/server/runtime/downlinks/mod.rs b/server/swimos_server_app/src/server/runtime/downlinks/mod.rs index fd724ae3a..3f220cebb 100644 --- a/server/swimos_server_app/src/server/runtime/downlinks/mod.rs +++ b/server/swimos_server_app/src/server/runtime/downlinks/mod.rs @@ -144,10 +144,10 @@ where let SchemeHostPort(scheme, host_name, port) = shp.clone(); if pending.push_remote_cmd(host_str.clone(), request) { tasks.push( - dns.resolve(host_name, port) + dns.resolve(host_name.clone(), port) .map(move |result| Event::Resolved { scheme, - host: host_str, + host: host_name.into(), result, }) .boxed(), @@ -182,10 +182,10 @@ where let SchemeHostPort(scheme, host_name, port) = shp; if pending.push_remote(host_str.clone(), request) { tasks.push( - dns.resolve(host_name, port) + dns.resolve(host_name.clone(), port) .map(move |result| Event::Resolved { scheme, - host: host_str, + host: host_name.into(), result, }) .boxed(), From 206324c8db94a35af35c2d86b1aa056a3665e024 Mon Sep 17 00:00:00 2001 From: Dobromir Marinov Date: Fri, 19 Apr 2024 16:08:33 +0100 Subject: [PATCH 2/2] * Fixed unit tests. --- server/swimos_server_app/Cargo.toml | 1 + .../swimos_server_app/src/server/runtime/downlinks/mod.rs | 6 ++---- .../src/server/runtime/downlinks/tests.rs | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/server/swimos_server_app/Cargo.toml b/server/swimos_server_app/Cargo.toml index 7f7ea92f2..35ae8da69 100644 --- a/server/swimos_server_app/Cargo.toml +++ b/server/swimos_server_app/Cargo.toml @@ -39,6 +39,7 @@ percent-encoding = { workspace = true } [dev-dependencies] swimos_recon = { path = "../../api/formats/swimos_recon", features = ["async_parser"] } tokio = { workspace = true, features = ["rt", "macros", "test-util"] } +rustls = { workspace = true } swimos_form = { path = "../../api/swimos_form" } swimos_messages = { path = "../../runtime/swimos_messages" } hyper = { workspace = true, features = ["client"] } diff --git a/server/swimos_server_app/src/server/runtime/downlinks/mod.rs b/server/swimos_server_app/src/server/runtime/downlinks/mod.rs index 3f220cebb..56de56afa 100644 --- a/server/swimos_server_app/src/server/runtime/downlinks/mod.rs +++ b/server/swimos_server_app/src/server/runtime/downlinks/mod.rs @@ -140,9 +140,8 @@ where match key { CommanderKey::Remote(shp) => { debug!(remote = %shp, "Handling request for remote command channel."); - let host_str: Text = shp.to_string().into(); let SchemeHostPort(scheme, host_name, port) = shp.clone(); - if pending.push_remote_cmd(host_str.clone(), request) { + if pending.push_remote_cmd(host_name.clone().into(), request) { tasks.push( dns.resolve(host_name.clone(), port) .map(move |result| Event::Resolved { @@ -178,9 +177,8 @@ where } = &request; if let Some(shp) = remote.clone() { debug!(remote = %shp, node = %address.node, lane = %address.lane, kind = ?kind, "Handling request for downlink to remote lane."); - let host_str: Text = shp.to_string().into(); let SchemeHostPort(scheme, host_name, port) = shp; - if pending.push_remote(host_str.clone(), request) { + if pending.push_remote(host_name.clone().into(), request) { tasks.push( dns.resolve(host_name.clone(), port) .map(move |result| Event::Resolved { diff --git a/server/swimos_server_app/src/server/runtime/downlinks/tests.rs b/server/swimos_server_app/src/server/runtime/downlinks/tests.rs index 2fd880368..e9eacbfc3 100644 --- a/server/swimos_server_app/src/server/runtime/downlinks/tests.rs +++ b/server/swimos_server_app/src/server/runtime/downlinks/tests.rs @@ -27,10 +27,10 @@ use futures::{ Future, FutureExt, SinkExt, StreamExt, }; use parking_lot::Mutex; +use rustls::ServerName; use swimos_api::{ downlink::DownlinkKind, error::DownlinkRuntimeError, - net::SchemeHostPort, protocol::downlink::{ DownlinkNotification, DownlinkOperation, DownlinkOperationEncoder, ValueNotificationDecoder, }, @@ -163,8 +163,8 @@ struct Endpoints { } fn check_hosts(actual: &str, expected: &str) { - let actual = actual.parse::().expect("Invalid host."); - let expected = expected.parse::().expect("Invalid host."); + let actual = ServerName::try_from(actual).expect("Invalid host."); + let expected = ServerName::try_from(expected).expect("Invalid host."); assert_eq!(actual, expected); } @@ -265,7 +265,7 @@ impl FakeServerTask { responder, .. }))) => { - check_hosts(host.as_str(), URL); + check_hosts(host.as_str(), HOST); let result = if sock_addrs.iter().any(|a| a == &addr) { Ok(EstablishedClient { tx: attach_tx.clone(),