From fd6454f625bb7efde3772ae106180cc6ac7c02dd Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 11 Jan 2016 22:32:43 -0800 Subject: Add stream panic propagation behind a nightly feature gate --- openssl/src/ssl/tests/mod.rs | 88 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'openssl/src/ssl/tests') diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs index af3c005e..7bd39170 100644 --- a/openssl/src/ssl/tests/mod.rs +++ b/openssl/src/ssl/tests/mod.rs @@ -957,3 +957,91 @@ fn broken_try_clone_doesnt_crash() { let stream1 = SslStream::connect(&context, inner).unwrap(); let _stream2 = stream1.try_clone().unwrap(); } + +#[test] +#[should_panic(message = "blammo")] +#[cfg(feature = "nightly")] +fn write_panic() { + struct ExplodingStream(TcpStream); + + impl Read for ExplodingStream { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + self.0.read(buf) + } + } + + impl Write for ExplodingStream { + fn write(&mut self, _: &[u8]) -> io::Result { + panic!("blammo"); + } + + fn flush(&mut self) -> io::Result<()> { + self.0.flush() + } + } + + let (_s, stream) = Server::new(); + let stream = ExplodingStream(stream); + + let ctx = SslContext::new(SslMethod::Sslv23).unwrap(); + let _ = SslStream::connect(&ctx, stream); +} + +#[test] +#[should_panic(message = "blammo")] +#[cfg(feature = "nightly")] +fn read_panic() { + struct ExplodingStream(TcpStream); + + impl Read for ExplodingStream { + fn read(&mut self, _: &mut [u8]) -> io::Result { + panic!("blammo"); + } + } + + impl Write for ExplodingStream { + fn write(&mut self, buf: &[u8]) -> io::Result { + self.0.write(buf) + } + + fn flush(&mut self) -> io::Result<()> { + self.0.flush() + } + } + + let (_s, stream) = Server::new(); + let stream = ExplodingStream(stream); + + let ctx = SslContext::new(SslMethod::Sslv23).unwrap(); + let _ = SslStream::connect(&ctx, stream); +} + +#[test] +#[should_panic(message = "blammo")] +#[cfg(feature = "nightly")] +fn flush_panic() { + struct ExplodingStream(TcpStream); + + impl Read for ExplodingStream { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + self.0.read(buf) + } + } + + impl Write for ExplodingStream { + fn write(&mut self, buf: &[u8]) -> io::Result { + self.0.write(buf) + } + + fn flush(&mut self) -> io::Result<()> { + panic!("blammo"); + } + } + + let (_s, stream) = Server::new(); + let stream = ExplodingStream(stream); + + let ctx = SslContext::new(SslMethod::Sslv23).unwrap(); + let mut stream = SslStream::connect(&ctx, stream).unwrap(); + let _ = stream.flush(); +} -- cgit v1.2.3 From 86e2f81f4388c652edaea7475cc121420a7b5b86 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 11 Jan 2016 23:45:12 -0800 Subject: Fix should_panic check --- openssl/src/ssl/tests/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'openssl/src/ssl/tests') diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs index 7bd39170..a763f496 100644 --- a/openssl/src/ssl/tests/mod.rs +++ b/openssl/src/ssl/tests/mod.rs @@ -959,7 +959,7 @@ fn broken_try_clone_doesnt_crash() { } #[test] -#[should_panic(message = "blammo")] +#[should_panic(expected = "blammo")] #[cfg(feature = "nightly")] fn write_panic() { struct ExplodingStream(TcpStream); @@ -988,7 +988,7 @@ fn write_panic() { } #[test] -#[should_panic(message = "blammo")] +#[should_panic(expected = "blammo")] #[cfg(feature = "nightly")] fn read_panic() { struct ExplodingStream(TcpStream); @@ -1017,7 +1017,7 @@ fn read_panic() { } #[test] -#[should_panic(message = "blammo")] +#[should_panic(expected = "blammo")] #[cfg(feature = "nightly")] fn flush_panic() { struct ExplodingStream(TcpStream); -- cgit v1.2.3 From d1825c7a86717faf518e0abd08f0f5c1e94c0ca8 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Mon, 18 Jan 2016 16:39:27 -0500 Subject: openssl/ssl/context: test that we are refcounting correctly Not a perfect test, on failure it _might_ exit with this output: Process didn't exit successfully: `/home/cody/g/rust-openssl/openssl/target/debug/openssl-8e712036e3aac4fe` (signal: 11) But unclear if we can do any better. --- openssl/src/ssl/tests/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'openssl/src/ssl/tests') diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs index a763f496..f5a42536 100644 --- a/openssl/src/ssl/tests/mod.rs +++ b/openssl/src/ssl/tests/mod.rs @@ -1045,3 +1045,16 @@ fn flush_panic() { let mut stream = SslStream::connect(&ctx, stream).unwrap(); let _ = stream.flush(); } + +#[test] +fn refcount_ssl_context() { + let ssl = { + let ctx = SslContext::new(SslMethod::Sslv23).unwrap(); + ssl::Ssl::new(&ctx).unwrap() + }; + + { + let new_ctx_a = SslContext::new(SslMethod::Sslv23).unwrap(); + let _new_ctx_b = ssl.set_ssl_context(&new_ctx_a); + } +} -- cgit v1.2.3