Skip to content

Commit 06009f5

Browse files
authored
Merge pull request #619 from tzneal/lowercase-hostnames
always lowercase the hostnames provided by the hostname helpers
2 parents b3a96d1 + abbcbe9 commit 06009f5

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

sources/dogtag/bin/imds.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

sources/dogtag/bin/reverse.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

sources/imdsclient/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)