1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

add ssl handshake timeout tests

This commit is contained in:
Nikolay Kim 2018-10-02 11:32:43 -07:00
parent 724668910b
commit b59712c439
3 changed files with 96 additions and 4 deletions

View File

@ -206,7 +206,7 @@ where
// shutdown // shutdown
if self.flags.contains(Flags::SHUTDOWN) { if self.flags.contains(Flags::SHUTDOWN) {
if self.flags.intersects(Flags::WRITE_DISCONNECTED) { if self.flags.contains(Flags::WRITE_DISCONNECTED) {
return Ok(Async::Ready(())); return Ok(Async::Ready(()));
} }
return self.poll_flush(true); return self.poll_flush(true);
@ -220,7 +220,7 @@ where
self.poll_flush(false)?; self.poll_flush(false)?;
// deal with keep-alive and stream eof (client-side write shutdown) // deal with keep-alive and stream eof (client-side write shutdown)
if self.tasks.is_empty() && self.flags.intersects(Flags::FLUSHED) { if self.tasks.is_empty() && self.flags.contains(Flags::FLUSHED) {
// handle stream eof // handle stream eof
if self if self
.flags .flags

View File

@ -890,6 +890,100 @@ fn test_brotli_encoding_large() {
assert_eq!(bytes, Bytes::from(data)); assert_eq!(bytes, Bytes::from(data));
} }
#[cfg(all(feature = "brotli", future = "ssl"))]
#[test]
fn test_ssl_brotli_encoding_large() {
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
// load ssl keys
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
builder
.set_private_key_file("tests/key.pem", SslFiletype::PEM)
.unwrap();
builder
.set_certificate_chain_file("tests/cert.pem")
.unwrap();
let data = STR.repeat(10);
let mut srv = test::TestServer::build().ssl(builder).start(|app| {
app.handler(|req: &HttpRequest| {
req.body()
.and_then(|bytes: Bytes| {
Ok(HttpResponse::Ok()
.content_encoding(http::ContentEncoding::Identity)
.body(bytes))
}).responder()
})
});
let mut e = BrotliEncoder::new(Vec::new(), 5);
e.write_all(data.as_ref()).unwrap();
let enc = e.finish().unwrap();
// client request
let request = srv
.post()
.header(http::header::CONTENT_ENCODING, "br")
.body(enc)
.unwrap();
let response = srv.execute(request.send()).unwrap();
assert!(response.status().is_success());
// read response
let bytes = srv.execute(response.body()).unwrap();
assert_eq!(bytes, Bytes::from(data));
}
#[cfg(future = "rust-ssl")]
#[test]
fn test_reading_deflate_encoding_large_random_ssl() {
use rustls::internal::pemfile::{certs, rsa_private_keys};
use rustls::{NoClientAuth, ServerConfig};
use std::fs::File;
use std::io::BufReader;
// load ssl keys
let mut config = ServerConfig::new(NoClientAuth::new());
let cert_file = &mut BufReader::new(File::open("tests/cert.pem").unwrap());
let key_file = &mut BufReader::new(File::open("tests/key.pem").unwrap());
let cert_chain = certs(cert_file).unwrap();
let mut keys = rsa_private_keys(key_file).unwrap();
config.set_single_cert(cert_chain, keys.remove(0)).unwrap();
let data = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(160_000)
.collect::<String>();
let mut srv = test::TestServer::build().rustls(config).start(|app| {
app.handler(|req: &HttpRequest| {
req.body()
.and_then(|bytes: Bytes| {
Ok(HttpResponse::Ok()
.content_encoding(http::ContentEncoding::Identity)
.body(bytes))
}).responder()
})
});
let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
e.write_all(data.as_ref()).unwrap();
let enc = e.finish().unwrap();
// client request
let request = srv
.post()
.header(http::header::CONTENT_ENCODING, "deflate")
.body(enc)
.unwrap();
let response = srv.execute(request.send()).unwrap();
assert!(response.status().is_success());
// read response
let bytes = srv.execute(response.body()).unwrap();
assert_eq!(bytes.len(), data.len());
assert_eq!(bytes, Bytes::from(data));
}
#[test] #[test]
fn test_h2() { fn test_h2() {
let srv = test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR))); let srv = test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));

View File

@ -284,7 +284,6 @@ fn test_server_send_bin() {
#[test] #[test]
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
fn test_ws_server_ssl() { fn test_ws_server_ssl() {
extern crate openssl;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
// load ssl keys // load ssl keys
@ -320,7 +319,6 @@ fn test_ws_server_ssl() {
#[test] #[test]
#[cfg(feature = "rust-tls")] #[cfg(feature = "rust-tls")]
fn test_ws_server_rust_tls() { fn test_ws_server_rust_tls() {
extern crate rustls;
use rustls::internal::pemfile::{certs, rsa_private_keys}; use rustls::internal::pemfile::{certs, rsa_private_keys};
use rustls::{NoClientAuth, ServerConfig}; use rustls::{NoClientAuth, ServerConfig};
use std::fs::File; use std::fs::File;