-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bindings: match tcp EOF behavior (#4323)
- Loading branch information
Showing
3 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; | ||
|
||
pub mod common; | ||
|
||
async fn assert_read_from_closed<S>(mut reader: S, writer: S) | ||
where | ||
S: AsyncRead + AsyncWrite + Unpin, | ||
{ | ||
drop(writer); | ||
let result = reader.read_u8().await; | ||
assert!(result.is_err()); | ||
let error = result.unwrap_err(); | ||
assert!(error.kind() == std::io::ErrorKind::UnexpectedEof); | ||
} | ||
|
||
#[tokio::test] | ||
async fn match_tcp_read_from_closed() -> Result<(), Box<dyn std::error::Error>> { | ||
let (tcp_server, tcp_client) = common::get_streams().await?; | ||
assert_read_from_closed(tcp_server, tcp_client).await; | ||
|
||
let (tls13_server, tls13_client) = common::get_tls_streams( | ||
common::server_config()?.build()?, | ||
common::client_config()?.build()?, | ||
) | ||
.await?; | ||
assert_read_from_closed(tls13_server, tls13_client).await; | ||
|
||
let (tls12_server, tls12_client) = common::get_tls_streams( | ||
common::server_config_tls12()?.build()?, | ||
common::client_config_tls12()?.build()?, | ||
) | ||
.await?; | ||
assert_read_from_closed(tls12_server, tls12_client).await; | ||
Result::Ok(()) | ||
} | ||
|
||
async fn assert_write_to_closed<S>(reader: S, mut writer: S) | ||
where | ||
S: AsyncRead + AsyncWrite + Unpin, | ||
{ | ||
drop(reader); | ||
let result = writer.write_u8(0).await; | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn match_tcp_write_to_closed() -> Result<(), Box<dyn std::error::Error>> { | ||
let (tcp_server, tcp_client) = common::get_streams().await?; | ||
assert_write_to_closed(tcp_server, tcp_client).await; | ||
|
||
let (tls13_server, tls13_client) = common::get_tls_streams( | ||
common::server_config()?.build()?, | ||
common::client_config()?.build()?, | ||
) | ||
.await?; | ||
assert_write_to_closed(tls13_server, tls13_client).await; | ||
|
||
let (tls12_server, tls12_client) = common::get_tls_streams( | ||
common::server_config_tls12()?.build()?, | ||
common::client_config_tls12()?.build()?, | ||
) | ||
.await?; | ||
assert_write_to_closed(tls12_server, tls12_client).await; | ||
Result::Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters