summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Birr-Pixton <jpixton@gmail.com>2024-05-17 14:24:14 +0100
committerJoe Birr-Pixton <jpixton@gmail.com>2024-05-17 17:26:06 +0000
commit2c72fb0c31094b2cdda26cab8fa813e2f881ba64 (patch)
treeb9835c8239222141ff50a240bceaeb9c2225227f
parent7d4e809e5eb535228fc4aef4f472b139a3adb4f4 (diff)
Test for more `close_notify` conditions
- before the handshake finishes - after a `close_notify` before the handshake finishes - after a `close_notify` after the handshake finishes - `read_tls` artificial EOF after `close_notify`
-rw-r--r--rustls/tests/api.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/rustls/tests/api.rs b/rustls/tests/api.rs
index f8de2558..bfebb640 100644
--- a/rustls/tests/api.rs
+++ b/rustls/tests/api.rs
@@ -6442,6 +6442,59 @@ fn test_data_after_close_notify_is_ignored() {
);
}
+#[test]
+fn test_close_notify_sent_prior_to_handshake_complete() {
+ let (mut client, mut server) = make_pair(KeyType::Rsa2048);
+ client.send_close_notify();
+ assert_eq!(
+ do_handshake_until_error(&mut client, &mut server),
+ Err(ErrorFromPeer::Server(Error::AlertReceived(
+ AlertDescription::CloseNotify
+ )))
+ );
+}
+
+#[test]
+fn test_subsequent_close_notify_ignored() {
+ let (mut client, mut server) = make_pair(KeyType::Rsa2048);
+ client.send_close_notify();
+ assert!(transfer(&mut client, &mut server) > 0);
+
+ // does nothing
+ client.send_close_notify();
+ assert_eq!(transfer(&mut client, &mut server), 0);
+}
+
+#[test]
+fn test_second_close_notify_after_handshake() {
+ let (mut client, mut server) = make_pair(KeyType::Rsa2048);
+ do_handshake(&mut client, &mut server);
+ client.send_close_notify();
+ assert!(transfer(&mut client, &mut server) > 0);
+ server.process_new_packets().unwrap();
+
+ // does nothing
+ client.send_close_notify();
+ assert_eq!(transfer(&mut client, &mut server), 0);
+}
+
+#[test]
+fn test_read_tls_artificial_eof_after_close_notify() {
+ let (mut client, mut server) = make_pair(KeyType::Rsa2048);
+ do_handshake(&mut client, &mut server);
+ client.send_close_notify();
+ assert!(transfer(&mut client, &mut server) > 0);
+ server.process_new_packets().unwrap();
+
+ let buf = [1, 2, 3, 4];
+ assert_eq!(
+ server
+ .read_tls(&mut io::Cursor::new(buf))
+ .unwrap(),
+ 0
+ );
+}
+
struct FakeStream<'a>(&'a [u8]);
impl<'a> io::Read for FakeStream<'a> {