mirror of
https://github.com/telemt/telemt.git
synced 2026-11-01 21:31:58 +03:00
WEB: Resolve opt-in decoy hostnames during config preparation #929
Co-Authored-By: brekotis <93345790+brekotis@users.noreply.github.com>
This commit is contained in:
+30
-2
@@ -8,13 +8,17 @@ use crate::config::ProxyConfig;
|
||||
|
||||
const HEALTHCHECK_RESPONSE_MAX_BYTES: u64 = 64 * 1024;
|
||||
|
||||
/// API health contract selected by the standalone healthcheck command.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum HealthcheckMode {
|
||||
/// Require a responsive API process.
|
||||
Liveness,
|
||||
/// Require the active runtime to report readiness.
|
||||
Ready,
|
||||
}
|
||||
|
||||
impl HealthcheckMode {
|
||||
/// Parses the supported command-line healthcheck modes.
|
||||
pub(crate) fn from_cli_arg(value: &str) -> Option<Self> {
|
||||
match value {
|
||||
"liveness" => Some(Self::Liveness),
|
||||
@@ -31,6 +35,7 @@ impl HealthcheckMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs the bounded API healthcheck without preparing a new proxy generation.
|
||||
pub(crate) fn run(config_path: &str, mode: HealthcheckMode) -> i32 {
|
||||
match run_inner(config_path, mode) {
|
||||
Ok(()) => 0,
|
||||
@@ -42,8 +47,9 @@ pub(crate) fn run(config_path: &str, mode: HealthcheckMode) -> i32 {
|
||||
}
|
||||
|
||||
fn run_inner(config_path: &str, mode: HealthcheckMode) -> Result<(), String> {
|
||||
let config =
|
||||
ProxyConfig::load(config_path).map_err(|error| format!("config load failed: {error}"))?;
|
||||
let config = ProxyConfig::parse_source(config_path)
|
||||
.map_err(|error| format!("config load failed: {error}"))?
|
||||
.config;
|
||||
let api_cfg = &config.server.api;
|
||||
if !api_cfg.enabled {
|
||||
return Ok(());
|
||||
@@ -229,4 +235,26 @@ mod tests {
|
||||
|
||||
assert!(read_response_bounded(&mut payload.as_slice()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decoy_dns_healthcheck_reads_source_without_resolution() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("config.toml");
|
||||
std::fs::write(
|
||||
&path,
|
||||
r#"
|
||||
[server.api]
|
||||
enabled = false
|
||||
[[web.vhosts]]
|
||||
host = "proxy.example.com"
|
||||
public_addr = "203.0.113.10:443"
|
||||
[web.vhosts.decoy]
|
||||
mode = "http_upstream"
|
||||
upstream = "http://unresolvable.example.invalid:8080"
|
||||
resolve = "startup"
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
super::run_inner(path.to_str().unwrap(), HealthcheckMode::Liveness).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user