@@ -531,6 +531,57 @@ mod tests {
531
531
Ok ( ( ) )
532
532
}
533
533
534
+ #[ test]
535
+ fn test_parsing_valid_hosts_in_client_opts ( ) {
536
+ let input = ClientTlsOpts {
537
+ component_ids : vec ! [ "component-id-foo" . to_string( ) ] ,
538
+ hosts : vec ! [ "fermyon.com" . to_string( ) , "fermyon.com:5443" . to_string( ) ] ,
539
+ custom_root_ca_file : None ,
540
+ cert_chain_file : None ,
541
+ private_key_file : None ,
542
+ } ;
543
+
544
+ let parsed = parse_client_tls_opts ( & input) ;
545
+ assert ! ( parsed. is_ok( ) ) ;
546
+ assert_eq ! ( parsed. unwrap( ) . hosts. len( ) , 2 )
547
+ }
548
+
549
+ #[ test]
550
+ fn test_parsing_empty_hosts_in_client_opts ( ) {
551
+ let input = ClientTlsOpts {
552
+ component_ids : vec ! [ "component-id-foo" . to_string( ) ] ,
553
+ hosts : vec ! [ "" . to_string( ) , "fermyon.com:5443" . to_string( ) ] ,
554
+ custom_root_ca_file : None ,
555
+ cert_chain_file : None ,
556
+ private_key_file : None ,
557
+ } ;
558
+
559
+ let parsed = parse_client_tls_opts ( & input) ;
560
+ assert ! ( parsed. is_err( ) ) ;
561
+ assert_eq ! (
562
+ "failed to parse uri ''. error: InvalidUri(Empty)" ,
563
+ parsed. unwrap_err( ) . to_string( )
564
+ )
565
+ }
566
+
567
+ #[ test]
568
+ fn test_parsing_invalid_hosts_in_client_opts ( ) {
569
+ let input = ClientTlsOpts {
570
+ component_ids : vec ! [ "component-id-foo" . to_string( ) ] ,
571
+ hosts : vec ! [ "perc%ent:443" . to_string( ) , "fermyon.com:5443" . to_string( ) ] ,
572
+ custom_root_ca_file : None ,
573
+ cert_chain_file : None ,
574
+ private_key_file : None ,
575
+ } ;
576
+
577
+ let parsed = parse_client_tls_opts ( & input) ;
578
+ assert ! ( parsed. is_err( ) ) ;
579
+ assert_eq ! (
580
+ "failed to parse uri 'perc%ent:443'. error: InvalidUri(InvalidAuthority)" ,
581
+ parsed. unwrap_err( ) . to_string( )
582
+ )
583
+ }
584
+
534
585
fn merge_config_toml ( config : & mut RuntimeConfig , value : toml:: Value ) {
535
586
let data = toml:: to_vec ( & value) . expect ( "encode toml" ) ;
536
587
let mut file = NamedTempFile :: new ( ) . expect ( "temp file" ) ;
@@ -581,7 +632,7 @@ fn parse_client_tls_opts(inp: &ClientTlsOpts) -> Result<ParsedClientTlsOpts, any
581
632
. into_iter ( )
582
633
. map ( |s| {
583
634
s. parse :: < Authority > ( )
584
- . map_err ( |e| anyhow:: anyhow!( "failed to parse uri {: ?}" , e) )
635
+ . map_err ( |e| anyhow:: anyhow!( "failed to parse uri '{}'. error: {: ?}" , s , e) )
585
636
} )
586
637
. collect :: < Result < Vec < Authority > , anyhow:: Error > > ( ) ?;
587
638
0 commit comments