File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed
Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff 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]
364377fn metrics_flag ( ) {
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ pub struct Config {
106106
107107impl 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 )
Original file line number Diff line number Diff 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 /*
You can’t perform that action at this time.
0 commit comments