Skip to content

Commit 735b76d

Browse files
committed
refactor: enhance ha_test app with cli switch to disable cert validation
1 parent 23a2ab7 commit 735b76d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

.idea/runConfigurations/Run_ha_test.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/ha_test.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::env;
1111
use std::str::FromStr;
1212
use std::time::Duration;
1313
use uc_api::intg::ws::{R2Event, R2Request};
14-
use uc_intg_hass::configuration::{get_configuration, Settings, DEF_HA_URL, ENV_HASS_MSG_TRACING};
14+
use uc_intg_hass::configuration::{get_configuration, Settings, ENV_HASS_MSG_TRACING};
1515
use uc_intg_hass::{
1616
configuration, Controller, NewR2Session, R2EventMsg, R2RequestMsg, SendWsMessage, APP_VERSION,
1717
};
@@ -21,6 +21,14 @@ use url::Url;
2121
async fn main() -> anyhow::Result<()> {
2222
let cfg = parse_args_load_cfg()?;
2323

24+
println!(
25+
"Connecting to Home Assistant WebSocket server: {} (timeout={}s, request-timeout={}s, disable-cert={})",
26+
cfg.hass.get_url(),
27+
cfg.hass.connection_timeout,
28+
cfg.hass.request_timeout,
29+
cfg.hass.disable_cert_validation,
30+
);
31+
2432
let driver_metadata = configuration::get_driver_metadata()?;
2533
let controller = Controller::new(cfg, driver_metadata.clone()).start();
2634

@@ -59,9 +67,14 @@ fn parse_args_load_cfg() -> anyhow::Result<Settings> {
5967
.arg(
6068
Arg::new("url")
6169
.short('u')
62-
.default_value(DEF_HA_URL)
6370
.help("Home Assistant WebSocket API URL (overrides home-assistant.json)"),
6471
)
72+
.arg(
73+
Arg::new("disable_cert_validation")
74+
.long("disable-cert-validation")
75+
.num_args(0)
76+
.help("Disable SSL certificate verification (overrides home-assistant.json)"),
77+
)
6578
.arg(
6679
Arg::new("token")
6780
.short('t')
@@ -96,6 +109,9 @@ fn parse_args_load_cfg() -> anyhow::Result<Settings> {
96109
if let Some(url) = args.get_one::<String>("url") {
97110
cfg.hass.set_url(Url::parse(url)?);
98111
}
112+
if let Some(disable_cert_validation) = args.get_one::<bool>("disable_cert_validation") {
113+
cfg.hass.disable_cert_validation = *disable_cert_validation;
114+
}
99115
if let Some(token) = args.get_one::<String>("token") {
100116
cfg.hass.set_token(token);
101117
}

src/util/network.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub fn new_websocket_client(
6767
}
6868

6969
mod danger {
70+
use log::warn;
7071
use rustls::client::{ServerCertVerified, ServerCertVerifier};
7172
use std::time::SystemTime;
7273

@@ -82,6 +83,7 @@ mod danger {
8283
_ocsp_response: &[u8],
8384
_now: SystemTime,
8485
) -> Result<ServerCertVerified, rustls::Error> {
86+
warn!("Certificate verification disabled");
8587
Ok(ServerCertVerified::assertion())
8688
}
8789
}

0 commit comments

Comments
 (0)