Debian Codegraph @

crt/s2n/bindings/rust/extended/s2n-tls-tokio/tests/tcp.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
5
6 pub mod common;
7
8 async fn assert_read_from_closed<S>(mut reader: S, writer: S)
9 where
10 S: AsyncRead + AsyncWrite + Unpin,
11 {
12 drop(writer);
13 let result = reader.read_u8().await;
14 assert!(result.is_err());
15 let error = result.unwrap_err();
16 assert!(error.kind() == std::io::ErrorKind::UnexpectedEof);
17 }
18
19 #[tokio::test]
20 async fn match_tcp_read_from_closed() -> Result<(), Box<dyn std::error::Error>> {
21 let (tcp_server, tcp_client) = common::get_streams().await?;
22 assert_read_from_closed(tcp_server, tcp_client).await;
23
24 let (tls13_server, tls13_client) = common::get_tls_streams(
25 common::server_config()?.build()?,
26 common::client_config()?.build()?,
27 )
28 .await?;
29 assert_read_from_closed(tls13_server, tls13_client).await;
30
31 let (tls12_server, tls12_client) = common::get_tls_streams(
32 common::server_config_tls12()?.build()?,
33 common::client_config_tls12()?.build()?,
34 )
35 .await?;
36 assert_read_from_closed(tls12_server, tls12_client).await;
37 Result::Ok(())
38 }
39
40 async fn assert_write_to_closed<S>(reader: S, mut writer: S)
41 where
42 S: AsyncRead + AsyncWrite + Unpin,
43 {
44 drop(reader);
45 let result = writer.write_u8(0).await;
46 assert!(result.is_ok());
47 }
48
49 #[tokio::test]
50 async fn match_tcp_write_to_closed() -> Result<(), Box<dyn std::error::Error>> {
51 let (tcp_server, tcp_client) = common::get_streams().await?;
52 assert_write_to_closed(tcp_server, tcp_client).await;
53
54 let (tls13_server, tls13_client) = common::get_tls_streams(
55 common::server_config()?.build()?,
56 common::client_config()?.build()?,
57 )
58 .await?;
59 assert_write_to_closed(tls13_server, tls13_client).await;
60
61 let (tls12_server, tls12_client) = common::get_tls_streams(
62 common::server_config_tls12()?.build()?,
63 common::client_config_tls12()?.build()?,
64 )
65 .await?;
66 assert_write_to_closed(tls12_server, tls12_client).await;
67 Result::Ok(())
68 }