Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect VC default HTTP token path when the --datadir flag is present #6748

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion lighthouse/tests/validator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn http_store_keystore_passwords_in_secrets_dir_present() {
}

#[test]
fn http_token_path_flag() {
fn http_token_path_flag_present() {
let dir = TempDir::new().expect("Unable to create temporary directory");
CommandLineTest::new()
.flag("http", None)
Expand All @@ -359,6 +359,19 @@ fn http_token_path_flag() {
});
}

#[test]
fn http_token_path_default() {
CommandLineTest::new()
.flag("http", None)
.run()
.with_config(|config| {
assert_eq!(
config.http_api.http_token_path,
config.validator_dir.join("api-token.txt")
);
});
}

// Tests for Metrics flags.
#[test]
fn metrics_flag() {
Expand Down
1 change: 1 addition & 0 deletions validator_client/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct Config {

impl Default for Config {
fn default() -> Self {
// This value is always overridden when building config from CLI.
let http_token_path = dirs::home_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join(DEFAULT_ROOT_DIR)
Expand Down
9 changes: 5 additions & 4 deletions validator_client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ impl Config {
config.http_api.store_passwords_in_secrets_dir = true;
}

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

/*
Expand Down
Loading