Skip to content

Commit d2c19d6

Browse files
committed
test(gateway): cover corrupt ACME credential handling
1 parent f174d3d commit d2c19d6

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

dstack/gateway/src/distributed_certbot.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,25 @@ fn extract_account_uri(credentials_json: &str) -> Option<String> {
519519
.filter(|c| !c.account_id.is_empty())
520520
.map(|c| c.account_id)
521521
}
522+
523+
#[cfg(test)]
524+
mod credential_tests {
525+
use super::acme_url_matches;
526+
527+
#[test]
528+
fn corrupt_acme_credentials_fail_closed() {
529+
assert!(acme_url_matches("not-json", "https://acme.test/directory").is_err());
530+
assert!(acme_url_matches("{}", "https://acme.test/directory").is_err());
531+
}
532+
533+
#[test]
534+
fn valid_acme_credentials_distinguish_directory() {
535+
let credentials = r#"{"acme_url":"https://acme.test/directory"}"#;
536+
assert!(acme_url_matches(credentials, "https://acme.test/directory")
537+
.expect("valid credentials rejected"));
538+
assert!(
539+
!acme_url_matches(credentials, "https://other.test/directory")
540+
.expect("valid credentials rejected")
541+
);
542+
}
543+
}

0 commit comments

Comments
 (0)