Skip to content

Commit

Permalink
fix(test): ssl-test with native-tls needs different key file format
Browse files Browse the repository at this point in the history
  • Loading branch information
kolbma committed Oct 13, 2024
1 parent f83a7fc commit 427ad0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/ssl-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ mod support;
/// When all threads exited there would be an ungraceful server exit.
#[test]
fn ssl_handshake_fail_test() {
#[cfg(any(feature = "ssl-openssl", feature = "ssl-rustls"))]
let ssl = Some(SslConfig::new(
include_bytes!("./ssl_tests/cert.pem").to_vec(),
include_bytes!("./ssl_tests/key.pem").to_vec(),
));
#[cfg(feature = "ssl-native-tls")]
let ssl = Some(SslConfig::new(
include_bytes!("./ssl_tests/cert.pem").to_vec(),
include_bytes!("./ssl_tests/key-pkcs8.pem").to_vec(),
));

let mut server = tiny_http::MTServer::new(&ServerConfig {
addr: ConfigListenAddr::from_socket_addrs("127.0.0.1:0").unwrap(),
exit_graceful_timeout: Duration::from_secs(1),
ssl: Some(SslConfig::new(
include_bytes!("./ssl_tests/cert.pem").to_vec(),
include_bytes!("./ssl_tests/key.pem").to_vec(),
)),
ssl,
worker_thread_nr: 2,
..ServerConfig::default()
})
Expand Down Expand Up @@ -89,7 +97,7 @@ Priority: u=0, i\r\n";
}
});

thread::sleep(Duration::from_secs(2)); // wait some time for connections in thread
thread::sleep(Duration::from_secs(1)); // wait some time for connections in thread
assert_ne!(server.num_connections(), 0); // still have connections

stop_thread.store(true, Ordering::Relaxed);
Expand All @@ -99,7 +107,7 @@ Priority: u=0, i\r\n";
let inner_stop_server = Arc::clone(&stop_server);

let jh = thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_millis(100));
inner_stop_server.store(true, Ordering::Relaxed);
});

Expand Down
5 changes: 5 additions & 0 deletions tests/ssl_tests/key-pkcs8.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQghvabQSprP3MEzhKT
u0eg4Hj7ggIt8amg3ZZq5JXBsjKhRANCAASUneuvQtQUt61XK5xhjT3y51uD/cZZ
mFMyyaCh92CVOUZybMxhbDBHguEbMJi4tscrHqGdWM3HGSchoOvbt3eZ
-----END PRIVATE KEY-----

0 comments on commit 427ad0d

Please sign in to comment.