diff options
| author | Steven Fackler <[email protected]> | 2016-10-25 20:40:18 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-10-25 20:40:18 -0700 |
| commit | 39279455c8b0132d58742b8a08e884c3fde404fd (patch) | |
| tree | 0eeb8dd24c6625d49da03a89f79044a2a4fa393f /openssl/src/ssl/tests | |
| parent | Fix ordering (diff) | |
| download | rust-openssl-39279455c8b0132d58742b8a08e884c3fde404fd.tar.xz rust-openssl-39279455c8b0132d58742b8a08e884c3fde404fd.zip | |
Add a shutdown method
Diffstat (limited to 'openssl/src/ssl/tests')
| -rw-r--r-- | openssl/src/ssl/tests/mod.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs index d11073f2..4bc6f216 100644 --- a/openssl/src/ssl/tests/mod.rs +++ b/openssl/src/ssl/tests/mod.rs @@ -19,7 +19,7 @@ use ssl; use ssl::SSL_VERIFY_PEER; use ssl::{SslMethod, HandshakeError}; use ssl::error::Error; -use ssl::{SslContext, SslStream, Ssl}; +use ssl::{SslContext, SslStream, Ssl, ShutdownResult}; use x509::X509StoreContextRef; use x509::X509FileType; use x509::X509; @@ -1084,6 +1084,38 @@ fn invalid_hostname() { assert!(ssl.connect(s).is_err()); } +#[test] +fn shutdown() { + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let port = listener.local_addr().unwrap().port(); + + thread::spawn(move || { + let stream = listener.accept().unwrap().0; + let mut ctx = SslContext::new(SslMethod::tls()).unwrap(); + ctx.set_certificate_file(&Path::new("test/cert.pem"), X509FileType::PEM).unwrap(); + ctx.set_private_key_file(&Path::new("test/key.pem"), X509FileType::PEM).unwrap(); + let ssl = Ssl::new(&ctx).unwrap(); + let mut stream = ssl.accept(stream).unwrap(); + + stream.write_all(b"hello").unwrap(); + let mut buf = [0; 1]; + assert_eq!(stream.read(&mut buf).unwrap(), 0); + assert_eq!(stream.shutdown().unwrap(), ShutdownResult::Received); + }); + + let stream = TcpStream::connect(("127.0.0.1", port)).unwrap(); + let ctx = SslContext::new(SslMethod::tls()).unwrap(); + let ssl = Ssl::new(&ctx).unwrap(); + let mut stream = ssl.connect(stream).unwrap(); + + let mut buf = [0; 5]; + stream.read_exact(&mut buf).unwrap(); + assert_eq!(b"hello", &buf); + + assert_eq!(stream.shutdown().unwrap(), ShutdownResult::Sent); + assert_eq!(stream.shutdown().unwrap(), ShutdownResult::Received); +} + fn _check_kinds() { fn is_send<T: Send>() {} fn is_sync<T: Sync>() {} |