mirror of https://github.com/fafhrd91/actix-web
disable actix_tls::openssl::HandshakeError.use pinned Dispatcher in tests
This commit is contained in:
parent
5ca85a5020
commit
f548b5beb8
|
@ -4,7 +4,7 @@ use actix_connect::resolver::ResolveError;
|
||||||
use derive_more::{Display, From};
|
use derive_more::{Display, From};
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
use actix_connect::ssl::openssl::{HandshakeError, SslError};
|
use actix_connect::ssl::openssl::SslError;
|
||||||
|
|
||||||
use crate::error::{Error, ParseError, ResponseError};
|
use crate::error::{Error, ParseError, ResponseError};
|
||||||
use crate::http::{Error as HttpError, StatusCode};
|
use crate::http::{Error as HttpError, StatusCode};
|
||||||
|
@ -21,10 +21,10 @@ pub enum ConnectError {
|
||||||
#[display(fmt = "{}", _0)]
|
#[display(fmt = "{}", _0)]
|
||||||
SslError(SslError),
|
SslError(SslError),
|
||||||
|
|
||||||
/// SSL Handshake error
|
// /// SSL Handshake error
|
||||||
#[cfg(feature = "openssl")]
|
// #[cfg(feature = "openssl")]
|
||||||
#[display(fmt = "{}", _0)]
|
// #[display(fmt = "{}", _0)]
|
||||||
SslHandshakeError(String),
|
// SslHandshakeError(SslError),
|
||||||
|
|
||||||
/// Failed to resolve the hostname
|
/// Failed to resolve the hostname
|
||||||
#[display(fmt = "Failed resolving hostname: {}", _0)]
|
#[display(fmt = "Failed resolving hostname: {}", _0)]
|
||||||
|
@ -69,12 +69,12 @@ impl From<actix_connect::ConnectError> for ConnectError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
// #[cfg(feature = "openssl")]
|
||||||
impl<T: std::fmt::Debug> From<HandshakeError<T>> for ConnectError {
|
// impl<T: std::fmt::Debug> From<HandshakeError<T>> for ConnectError {
|
||||||
fn from(err: HandshakeError<T>) -> ConnectError {
|
// fn from(err: HandshakeError<T>) -> ConnectError {
|
||||||
ConnectError::SslHandshakeError(format!("{:?}", err))
|
// ConnectError::SslHandshakeError(format!("{:?}", err))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[derive(Debug, Display, From)]
|
#[derive(Debug, Display, From)]
|
||||||
pub enum InvalidUrl {
|
pub enum InvalidUrl {
|
||||||
|
|
|
@ -180,9 +180,9 @@ impl ResponseError for FormError {}
|
||||||
/// `InternalServerError` for `openssl::ssl::Error`
|
/// `InternalServerError` for `openssl::ssl::Error`
|
||||||
impl ResponseError for actix_connect::ssl::openssl::SslError {}
|
impl ResponseError for actix_connect::ssl::openssl::SslError {}
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
// #[cfg(feature = "openssl")]
|
||||||
/// `InternalServerError` for `openssl::ssl::HandshakeError`
|
// /// `InternalServerError` for `openssl::ssl::HandshakeError`
|
||||||
impl<T: std::fmt::Debug> ResponseError for actix_tls::openssl::HandshakeError<T> {}
|
// impl<T: std::fmt::Debug> ResponseError for actix_tls::openssl::HandshakeError<T> {}
|
||||||
|
|
||||||
/// Return `BAD_REQUEST` for `de::value::Error`
|
/// Return `BAD_REQUEST` for `de::value::Error`
|
||||||
impl ResponseError for DeError {
|
impl ResponseError for DeError {
|
||||||
|
|
|
@ -1002,7 +1002,7 @@ mod tests {
|
||||||
let mut pl = req.take_payload();
|
let mut pl = req.take_payload();
|
||||||
let mut body = BytesMut::new();
|
let mut body = BytesMut::new();
|
||||||
while let Some(chunk) = pl.next().await {
|
while let Some(chunk) = pl.next().await {
|
||||||
body.extend_from_slice(chunk.unwrap().bytes())
|
body.extend_from_slice(chunk.unwrap().chunk())
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok::<_, Error>(Response::Ok().body(body))
|
Ok::<_, Error>(Response::Ok().body(body))
|
||||||
|
@ -1015,7 +1015,7 @@ mod tests {
|
||||||
lazy(|cx| {
|
lazy(|cx| {
|
||||||
let buf = TestBuffer::new("GET /test HTTP/1\r\n\r\n");
|
let buf = TestBuffer::new("GET /test HTTP/1\r\n\r\n");
|
||||||
|
|
||||||
let mut h1 = Dispatcher::<_, _, _, _, UpgradeHandler<TestBuffer>>::new(
|
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler<TestBuffer>>::new(
|
||||||
buf,
|
buf,
|
||||||
ServiceConfig::default(),
|
ServiceConfig::default(),
|
||||||
CloneableService::new(ok_service()),
|
CloneableService::new(ok_service()),
|
||||||
|
@ -1026,15 +1026,17 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
match Pin::new(&mut h1).poll(cx) {
|
futures_util::pin_mut!(h1);
|
||||||
|
|
||||||
|
match h1.as_mut().poll(cx) {
|
||||||
Poll::Pending => panic!(),
|
Poll::Pending => panic!(),
|
||||||
Poll::Ready(res) => assert!(res.is_err()),
|
Poll::Ready(res) => assert!(res.is_err()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if let DispatcherState::Normal(ref mut inner) = h1.inner {
|
if let DispatcherStateProj::Normal(inner) = h1.project().inner.project() {
|
||||||
assert!(inner.flags.contains(Flags::READ_DISCONNECT));
|
assert!(inner.flags.contains(Flags::READ_DISCONNECT));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&inner.io.take().unwrap().write_buf[..26],
|
&inner.project().io.take().unwrap().write_buf[..26],
|
||||||
b"HTTP/1.1 400 Bad Request\r\n"
|
b"HTTP/1.1 400 Bad Request\r\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1054,7 +1056,7 @@ mod tests {
|
||||||
|
|
||||||
let cfg = ServiceConfig::new(KeepAlive::Disabled, 1, 1, false, None);
|
let cfg = ServiceConfig::new(KeepAlive::Disabled, 1, 1, false, None);
|
||||||
|
|
||||||
let mut h1 = Dispatcher::<_, _, _, _, UpgradeHandler<TestBuffer>>::new(
|
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler<TestBuffer>>::new(
|
||||||
buf,
|
buf,
|
||||||
cfg,
|
cfg,
|
||||||
CloneableService::new(echo_path_service()),
|
CloneableService::new(echo_path_service()),
|
||||||
|
@ -1065,9 +1067,11 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
futures_util::pin_mut!(h1);
|
||||||
|
|
||||||
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
||||||
|
|
||||||
match Pin::new(&mut h1).poll(cx) {
|
match h1.as_mut().poll(cx) {
|
||||||
Poll::Pending => panic!("first poll should not be pending"),
|
Poll::Pending => panic!("first poll should not be pending"),
|
||||||
Poll::Ready(res) => assert!(res.is_ok()),
|
Poll::Ready(res) => assert!(res.is_ok()),
|
||||||
}
|
}
|
||||||
|
@ -1075,8 +1079,8 @@ mod tests {
|
||||||
// polls: initial => shutdown
|
// polls: initial => shutdown
|
||||||
assert_eq!(h1.poll_count, 2);
|
assert_eq!(h1.poll_count, 2);
|
||||||
|
|
||||||
if let DispatcherState::Normal(ref mut inner) = h1.inner {
|
if let DispatcherStateProj::Normal(inner) = h1.project().inner.project() {
|
||||||
let res = &mut inner.io.take().unwrap().write_buf[..];
|
let res = &mut inner.project().io.take().unwrap().write_buf[..];
|
||||||
stabilize_date_header(res);
|
stabilize_date_header(res);
|
||||||
|
|
||||||
let exp = b"\
|
let exp = b"\
|
||||||
|
@ -1107,7 +1111,7 @@ mod tests {
|
||||||
|
|
||||||
let cfg = ServiceConfig::new(KeepAlive::Disabled, 1, 1, false, None);
|
let cfg = ServiceConfig::new(KeepAlive::Disabled, 1, 1, false, None);
|
||||||
|
|
||||||
let mut h1 = Dispatcher::<_, _, _, _, UpgradeHandler<TestBuffer>>::new(
|
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler<TestBuffer>>::new(
|
||||||
buf,
|
buf,
|
||||||
cfg,
|
cfg,
|
||||||
CloneableService::new(echo_path_service()),
|
CloneableService::new(echo_path_service()),
|
||||||
|
@ -1118,9 +1122,11 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
futures_util::pin_mut!(h1);
|
||||||
|
|
||||||
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
||||||
|
|
||||||
match Pin::new(&mut h1).poll(cx) {
|
match h1.as_mut().poll(cx) {
|
||||||
Poll::Pending => panic!("first poll should not be pending"),
|
Poll::Pending => panic!("first poll should not be pending"),
|
||||||
Poll::Ready(res) => assert!(res.is_err()),
|
Poll::Ready(res) => assert!(res.is_err()),
|
||||||
}
|
}
|
||||||
|
@ -1128,8 +1134,8 @@ mod tests {
|
||||||
// polls: initial => shutdown
|
// polls: initial => shutdown
|
||||||
assert_eq!(h1.poll_count, 1);
|
assert_eq!(h1.poll_count, 1);
|
||||||
|
|
||||||
if let DispatcherState::Normal(ref mut inner) = h1.inner {
|
if let DispatcherStateProj::Normal(inner) = h1.project().inner.project() {
|
||||||
let res = &mut inner.io.take().unwrap().write_buf[..];
|
let res = &mut inner.project().io.take().unwrap().write_buf[..];
|
||||||
stabilize_date_header(res);
|
stabilize_date_header(res);
|
||||||
|
|
||||||
let exp = b"\
|
let exp = b"\
|
||||||
|
@ -1155,7 +1161,7 @@ mod tests {
|
||||||
lazy(|cx| {
|
lazy(|cx| {
|
||||||
let mut buf = TestSeqBuffer::empty();
|
let mut buf = TestSeqBuffer::empty();
|
||||||
let cfg = ServiceConfig::new(KeepAlive::Disabled, 0, 0, false, None);
|
let cfg = ServiceConfig::new(KeepAlive::Disabled, 0, 0, false, None);
|
||||||
let mut h1 = Dispatcher::<_, _, _, _, UpgradeHandler<_>>::new(
|
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler<_>>::new(
|
||||||
buf.clone(),
|
buf.clone(),
|
||||||
cfg,
|
cfg,
|
||||||
CloneableService::new(echo_payload_service()),
|
CloneableService::new(echo_payload_service()),
|
||||||
|
@ -1175,7 +1181,9 @@ mod tests {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(Pin::new(&mut h1).poll(cx).is_pending());
|
futures_util::pin_mut!(h1);
|
||||||
|
|
||||||
|
assert!(h1.as_mut().poll(cx).is_pending());
|
||||||
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
||||||
|
|
||||||
// polls: manual
|
// polls: manual
|
||||||
|
@ -1192,7 +1200,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.extend_read_buf("12345");
|
buf.extend_read_buf("12345");
|
||||||
assert!(Pin::new(&mut h1).poll(cx).is_ready());
|
assert!(h1.as_mut().poll(cx).is_ready());
|
||||||
|
|
||||||
// polls: manual manual shutdown
|
// polls: manual manual shutdown
|
||||||
assert_eq!(h1.poll_count, 3);
|
assert_eq!(h1.poll_count, 3);
|
||||||
|
@ -1225,7 +1233,7 @@ mod tests {
|
||||||
lazy(|cx| {
|
lazy(|cx| {
|
||||||
let mut buf = TestSeqBuffer::empty();
|
let mut buf = TestSeqBuffer::empty();
|
||||||
let cfg = ServiceConfig::new(KeepAlive::Disabled, 0, 0, false, None);
|
let cfg = ServiceConfig::new(KeepAlive::Disabled, 0, 0, false, None);
|
||||||
let mut h1 = Dispatcher::<_, _, _, _, UpgradeHandler<_>>::new(
|
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler<_>>::new(
|
||||||
buf.clone(),
|
buf.clone(),
|
||||||
cfg,
|
cfg,
|
||||||
CloneableService::new(echo_path_service()),
|
CloneableService::new(echo_path_service()),
|
||||||
|
@ -1245,7 +1253,9 @@ mod tests {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(Pin::new(&mut h1).poll(cx).is_ready());
|
futures_util::pin_mut!(h1);
|
||||||
|
|
||||||
|
assert!(h1.as_mut().poll(cx).is_ready());
|
||||||
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
assert!(matches!(&h1.inner, DispatcherState::Normal(_)));
|
||||||
|
|
||||||
// polls: manual shutdown
|
// polls: manual shutdown
|
||||||
|
@ -1283,7 +1293,7 @@ mod tests {
|
||||||
lazy(|cx| {
|
lazy(|cx| {
|
||||||
let mut buf = TestSeqBuffer::empty();
|
let mut buf = TestSeqBuffer::empty();
|
||||||
let cfg = ServiceConfig::new(KeepAlive::Disabled, 0, 0, false, None);
|
let cfg = ServiceConfig::new(KeepAlive::Disabled, 0, 0, false, None);
|
||||||
let mut h1 = Dispatcher::<_, _, _, _, UpgradeHandler<_>>::new(
|
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler<_>>::new(
|
||||||
buf.clone(),
|
buf.clone(),
|
||||||
cfg,
|
cfg,
|
||||||
CloneableService::new(ok_service()),
|
CloneableService::new(ok_service()),
|
||||||
|
@ -1303,7 +1313,9 @@ mod tests {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(Pin::new(&mut h1).poll(cx).is_ready());
|
futures_util::pin_mut!(h1);
|
||||||
|
|
||||||
|
assert!(h1.as_mut().poll(cx).is_ready());
|
||||||
assert!(matches!(&h1.inner, DispatcherState::Upgrade(_)));
|
assert!(matches!(&h1.inner, DispatcherState::Upgrade(_)));
|
||||||
|
|
||||||
// polls: manual shutdown
|
// polls: manual shutdown
|
||||||
|
|
|
@ -101,7 +101,7 @@ mod openssl {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use actix_tls::openssl::{Acceptor, SslAcceptor, SslStream};
|
use actix_tls::openssl::{Acceptor, SslAcceptor, SslStream};
|
||||||
use actix_tls::{openssl::HandshakeError, TlsError};
|
use actix_tls::{openssl::Error as SslError, TlsError};
|
||||||
|
|
||||||
impl<S, B, X, U> H1Service<SslStream<TcpStream>, S, B, X, U>
|
impl<S, B, X, U> H1Service<SslStream<TcpStream>, S, B, X, U>
|
||||||
where
|
where
|
||||||
|
@ -129,7 +129,7 @@ mod openssl {
|
||||||
Config = (),
|
Config = (),
|
||||||
Request = TcpStream,
|
Request = TcpStream,
|
||||||
Response = (),
|
Response = (),
|
||||||
Error = TlsError<HandshakeError<TcpStream>, DispatchError>,
|
Error = TlsError<SslError, DispatchError>,
|
||||||
InitError = (),
|
InitError = (),
|
||||||
> {
|
> {
|
||||||
pipeline_factory(
|
pipeline_factory(
|
||||||
|
|
|
@ -107,7 +107,7 @@ where
|
||||||
mod openssl {
|
mod openssl {
|
||||||
use actix_service::{fn_factory, fn_service};
|
use actix_service::{fn_factory, fn_service};
|
||||||
use actix_tls::openssl::{Acceptor, SslAcceptor, SslStream};
|
use actix_tls::openssl::{Acceptor, SslAcceptor, SslStream};
|
||||||
use actix_tls::{openssl::HandshakeError, TlsError};
|
use actix_tls::{openssl::Error as SslError, TlsError};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ mod openssl {
|
||||||
Config = (),
|
Config = (),
|
||||||
Request = TcpStream,
|
Request = TcpStream,
|
||||||
Response = (),
|
Response = (),
|
||||||
Error = TlsError<HandshakeError<TcpStream>, DispatchError>,
|
Error = TlsError<SslError, DispatchError>,
|
||||||
InitError = S::InitError,
|
InitError = S::InitError,
|
||||||
> {
|
> {
|
||||||
pipeline_factory(
|
pipeline_factory(
|
||||||
|
|
|
@ -207,7 +207,7 @@ where
|
||||||
mod openssl {
|
mod openssl {
|
||||||
use super::*;
|
use super::*;
|
||||||
use actix_tls::openssl::{Acceptor, SslAcceptor, SslStream};
|
use actix_tls::openssl::{Acceptor, SslAcceptor, SslStream};
|
||||||
use actix_tls::{openssl::HandshakeError, TlsError};
|
use actix_tls::{openssl::Error as SSlError, TlsError};
|
||||||
|
|
||||||
impl<S, B, X, U> HttpService<SslStream<TcpStream>, S, B, X, U>
|
impl<S, B, X, U> HttpService<SslStream<TcpStream>, S, B, X, U>
|
||||||
where
|
where
|
||||||
|
@ -238,7 +238,7 @@ mod openssl {
|
||||||
Config = (),
|
Config = (),
|
||||||
Request = TcpStream,
|
Request = TcpStream,
|
||||||
Response = (),
|
Response = (),
|
||||||
Error = TlsError<HandshakeError<TcpStream>, DispatchError>,
|
Error = TlsError<SSlError, DispatchError>,
|
||||||
InitError = (),
|
InitError = (),
|
||||||
> {
|
> {
|
||||||
pipeline_factory(
|
pipeline_factory(
|
||||||
|
|
Loading…
Reference in New Issue