Skip to content

Commit 87b72de

Browse files
authored
Fix incorrect VC default HTTP token path when the --datadir flag is present (#6748)
* Fix incorrect default http token path when datadir flag is present.
1 parent 80cfbea commit 87b72de

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lighthouse/tests/validator_client.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn http_store_keystore_passwords_in_secrets_dir_present() {
345345
}
346346

347347
#[test]
348-
fn http_token_path_flag() {
348+
fn http_token_path_flag_present() {
349349
let dir = TempDir::new().expect("Unable to create temporary directory");
350350
CommandLineTest::new()
351351
.flag("http", None)
@@ -359,6 +359,19 @@ fn http_token_path_flag() {
359359
});
360360
}
361361

362+
#[test]
363+
fn http_token_path_default() {
364+
CommandLineTest::new()
365+
.flag("http", None)
366+
.run()
367+
.with_config(|config| {
368+
assert_eq!(
369+
config.http_api.http_token_path,
370+
config.validator_dir.join("api-token.txt")
371+
);
372+
});
373+
}
374+
362375
// Tests for Metrics flags.
363376
#[test]
364377
fn metrics_flag() {

validator_client/http_api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub struct Config {
106106

107107
impl Default for Config {
108108
fn default() -> Self {
109+
// This value is always overridden when building config from CLI.
109110
let http_token_path = dirs::home_dir()
110111
.unwrap_or_else(|| PathBuf::from("."))
111112
.join(DEFAULT_ROOT_DIR)

validator_client/src/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,11 @@ impl Config {
314314
config.http_api.store_passwords_in_secrets_dir = true;
315315
}
316316

317-
if cli_args.get_one::<String>("http-token-path").is_some() {
318-
config.http_api.http_token_path = parse_required(cli_args, "http-token-path")
319-
// For backward compatibility, default to the path under the validator dir if not provided.
320-
.unwrap_or_else(|_| config.validator_dir.join(PK_FILENAME));
317+
if let Some(http_token_path) = cli_args.get_one::<String>("http-token-path") {
318+
config.http_api.http_token_path = PathBuf::from(http_token_path);
319+
} else {
320+
// For backward compatibility, default to the path under the validator dir if not provided.
321+
config.http_api.http_token_path = config.validator_dir.join(PK_FILENAME);
321322
}
322323

323324
/*

0 commit comments

Comments
 (0)