File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed
Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use sensitive_url::SensitiveUrl;
77use std:: fs:: File ;
88use std:: io:: Write ;
99use std:: net:: IpAddr ;
10+ use std:: path:: Path ;
1011use std:: path:: PathBuf ;
1112use std:: process:: Command ;
1213use std:: str:: FromStr ;
@@ -345,7 +346,7 @@ fn http_store_keystore_passwords_in_secrets_dir_present() {
345346}
346347
347348#[ test]
348- fn http_token_path_flag ( ) {
349+ fn http_token_path_flag_present ( ) {
349350 let dir = TempDir :: new ( ) . expect ( "Unable to create temporary directory" ) ;
350351 CommandLineTest :: new ( )
351352 . flag ( "http" , None )
@@ -359,6 +360,21 @@ fn http_token_path_flag() {
359360 } ) ;
360361}
361362
363+ #[ test]
364+ fn http_token_path_default ( ) {
365+ let custom_datadir = "/custom-datadir" ;
366+ CommandLineTest :: new ( )
367+ . flag ( "datadir" , Some ( custom_datadir) )
368+ . flag ( "http" , None )
369+ . run ( )
370+ . with_config ( |config| {
371+ assert_eq ! (
372+ config. http_api. http_token_path,
373+ Path :: new( custom_datadir) . join( "api-token.txt" )
374+ ) ;
375+ } ) ;
376+ }
377+
362378// Tests for Metrics flags.
363379#[ test]
364380fn 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