Skip to content

Commit c5726b7

Browse files
committed
tests: return bare configs from make_configs()
Let the callers put the configs into an `Arc`. This will allow re-using the setup logic from `utils::make_configs()` in contexts where customization of the client or server config is required.
1 parent 5222475 commit c5726b7

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/common/test_stream.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::io::{self, Cursor, Read, Write};
22
use std::pin::Pin;
3+
use std::sync::Arc;
34
use std::task::{Context, Poll};
45

56
use futures_util::future::poll_fn;
@@ -291,10 +292,10 @@ async fn stream_eof() -> io::Result<()> {
291292

292293
fn make_pair() -> (ServerConnection, ClientConnection) {
293294
let (sconfig, cconfig) = utils::make_configs();
294-
let server = ServerConnection::new(sconfig).unwrap();
295+
let server = ServerConnection::new(Arc::new(sconfig)).unwrap();
295296

296297
let domain = pki_types::ServerName::try_from("foobar.com").unwrap();
297-
let client = ClientConnection::new(cconfig, domain).unwrap();
298+
let client = ClientConnection::new(Arc::new(cconfig), domain).unwrap();
298299

299300
(server, client)
300301
}

tests/test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async fn test_lazy_config_acceptor() -> io::Result<()> {
155155
.unwrap()
156156
.to_owned();
157157
tokio::spawn(async move {
158-
let connector = crate::TlsConnector::from(cconfig);
158+
let connector = crate::TlsConnector::from(Arc::new(cconfig));
159159
let mut client = connector.connect(domain, cstream).await.unwrap();
160160
client.write_all(b"hello, world!").await.unwrap();
161161

@@ -175,7 +175,7 @@ async fn test_lazy_config_acceptor() -> io::Result<()> {
175175
Vec::<&[u8]>::new()
176176
);
177177

178-
let mut stream = start.into_stream(sconfig).await.unwrap();
178+
let mut stream = start.into_stream(Arc::new(sconfig)).await.unwrap();
179179
let mut buf = [0; 13];
180180
stream.read_exact(&mut buf).await.unwrap();
181181
assert_eq!(&buf[..], b"hello, world!");
@@ -279,7 +279,10 @@ async fn acceptor_alert() {
279279
panic!("timeout");
280280
};
281281

282-
let err = start_handshake.into_stream(sconfig).await.unwrap_err();
282+
let err = start_handshake
283+
.into_stream(Arc::new(sconfig))
284+
.await
285+
.unwrap_err();
283286

284287
assert_eq!(err.to_string(), "peer is incompatible: Tls12NotOffered");
285288

tests/utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
mod utils {
22
use std::io::{BufReader, Cursor, IoSlice};
3-
use std::sync::Arc;
43

54
use rustls::{ClientConfig, RootCertStore, ServerConfig};
65
use rustls_pemfile::{certs, rsa_private_keys};
76
use tokio::io::{self, AsyncWrite, AsyncWriteExt};
87

98
#[allow(dead_code)]
10-
pub fn make_configs() -> (Arc<ServerConfig>, Arc<ClientConfig>) {
9+
pub fn make_configs() -> (ServerConfig, ClientConfig) {
1110
const CERT: &str = include_str!("certs/end.cert");
1211
const CHAIN: &str = include_str!("certs/end.chain");
1312
const RSA: &str = include_str!("certs/end.rsa");
@@ -34,7 +33,7 @@ mod utils {
3433
.with_root_certificates(client_root_cert_store)
3534
.with_no_client_auth();
3635

37-
(Arc::new(sconfig), Arc::new(cconfig))
36+
(sconfig, cconfig)
3837
}
3938

4039
#[allow(dead_code)]

0 commit comments

Comments
 (0)