Skip to content

Commit 1070745

Browse files
committed
Adding tempfile to properly test SSL validation in HyperServerOptions
1 parent 4dc69b3 commit 1070745

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

Cargo.lock

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rust-mcp-sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ reqwest = { workspace = true, default-features = false, features = [
4747
"cookies",
4848
"multipart",
4949
] }
50+
tempfile = "3.23.0"
5051
tracing-subscriber = { workspace = true, features = [
5152
"env-filter",
5253
"std",

crates/rust-mcp-sdk/src/hyper_servers/server.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ async fn shutdown_signal(handle: Handle, state: Arc<McpAppState>) {
495495
mod tests {
496496
use super::*;
497497

498+
use tempfile::NamedTempFile;
499+
498500
#[test]
499501
fn test_server_options_base_url_custom() {
500502
let options = HyperServerOptions {
@@ -584,7 +586,45 @@ mod tests {
584586
let options = HyperServerOptions::default();
585587
assert!(options.validate().is_ok());
586588

587-
// TODO: validate with ssl
589+
// with ssl enabled but no cert or key provided, validate should fail
590+
let options = HyperServerOptions {
591+
enable_ssl: true,
592+
..Default::default()
593+
};
594+
assert!(options.validate().is_err());
595+
596+
// with ssl enabled and invalid cert/key paths, validate should fail
597+
let options = HyperServerOptions {
598+
enable_ssl: true,
599+
ssl_cert_path: Some(String::from("/invalid/path/to/cert.pem")),
600+
ssl_key_path: Some(String::from("/invalid/path/to/key.pem")),
601+
..Default::default()
602+
};
603+
assert!(options.validate().is_err());
604+
605+
// with ssl enabled and valid cert/key paths, validate should succeed
606+
let cert_file =
607+
NamedTempFile::with_suffix(".pem").expect("Expected to create test cert file");
608+
let ssl_cert_path = cert_file
609+
.path()
610+
.to_str()
611+
.expect("Expected to get cert path")
612+
.to_string();
613+
let key_file =
614+
NamedTempFile::with_suffix(".pem").expect("Expected to create test key file");
615+
let ssl_key_path = key_file
616+
.path()
617+
.to_str()
618+
.expect("Expected to get key path")
619+
.to_string();
620+
621+
let options = HyperServerOptions {
622+
enable_ssl: true,
623+
ssl_cert_path: Some(ssl_cert_path),
624+
ssl_key_path: Some(ssl_key_path),
625+
..Default::default()
626+
};
627+
assert!(options.validate().is_ok());
588628
}
589629

590630
#[tokio::test]

0 commit comments

Comments
 (0)