Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion ldk-server/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,16 @@ impl ConfigBuilder {
&& (metrics_username.is_some() != metrics_password.is_some())
{
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Both `metrics.username` and `metrics.password` must be set if authentication is used for metrics."));
"Both `metrics.username` and `metrics.password` must be set if authentication is used for metrics."));
}

if metrics_enabled
&& (metrics_username.as_deref() == Some("") || metrics_password.as_deref() == Some(""))
{
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Metrics authentication credentials must not be empty.",
));
}

let tor_proxy_address: Option<SocketAddress> = self
Expand Down Expand Up @@ -2240,6 +2249,22 @@ mod tests {
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
}

#[test]
fn test_metrics_enabled_fails_with_empty_auth() {
for (username, password) in [("", "password"), ("admin", ""), ("", "")] {
let config = format!(
"{}\n[metrics]\nenabled = true\nusername = {:?}\npassword = {:?}",
DEFAULT_CONFIG, username, password
);
let mut builder = ConfigBuilder::default();
builder.merge_toml(toml::from_str(&config).unwrap());

let err = builder.build().unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert_eq!(err.to_string(), "Metrics authentication credentials must not be empty.");
}
}

#[test]
fn test_hrn_config() {
let storage_path = std::env::temp_dir();
Expand Down