File tree Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,10 @@ async fn main() -> Result<()> {
2020 . fetch_hostname ( )
2121 . await
2222 . context ( error:: ImdsSnafu ) ?
23- . context ( error:: NoHostnameSnafu ) ?;
23+ . context ( error:: NoHostnameSnafu ) ?
24+ // the IMDS client returns a lowercase hostname anyway, but there's some
25+ // symmetry in having both helpers lowercase the result always
26+ . to_ascii_lowercase ( ) ;
2427 println ! ( "{hostname}" ) ;
2528 Ok ( ( ) )
2629}
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ async fn main() -> Result<()> {
2525 . await
2626 . map_err ( |e| error:: Error :: Lookup {
2727 source : Box :: new ( e) ,
28- } ) ?;
28+ } ) ?
29+ . to_ascii_lowercase ( ) ;
2930 println ! ( "{hostname}" ) ;
3031 Ok ( ( ) )
3132}
Original file line number Diff line number Diff line change @@ -242,8 +242,8 @@ impl ImdsClient {
242242 Ok ( self . fetch_string ( & hostname_target) . await ?. and_then ( |h| {
243243 h. split_whitespace ( )
244244 . next ( )
245- . map ( |h| h . trim_end_matches ( '.' ) )
246- . map ( String :: from )
245+ // trim any trailing dots and lowercase the result
246+ . map ( |h| h . trim_end_matches ( '.' ) . to_ascii_lowercase ( ) )
247247 } ) )
248248 }
249249
@@ -842,8 +842,9 @@ mod test {
842842 let base_uri = format ! ( "http://{}" , server. addr( ) ) ;
843843 let token = "some+token" ;
844844 let response_code = 200 ;
845+ // should always lowercase the response
845846 let response_body =
846- r#"ip-10-0-13-37.example .com. ip-10-0-13-37.eu-central-1.compute.internal"# ;
847+ r#"ip-10-0-13-37.EXAMPLE .com. ip-10-0-13-37.eu-central-1.compute.internal"# ;
847848 server. expect (
848849 Expectation :: matching ( request:: method_path ( "PUT" , "/latest/api/token" ) )
849850 . times ( 1 )
You can’t perform that action at this time.
0 commit comments