Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jan 8, 2024
1 parent 3914994 commit 8dc65c4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2021"
features = ["ntex/tokio"]

[dependencies]
ntex = "1.0.0-b.0"
ntex = "1.0.0-b.1"
bitflags = "2.4"
log = "0.4"
pin-project-lite = "0.2"
Expand All @@ -25,9 +25,9 @@ thiserror = "1.0"

[dev-dependencies]
env_logger = "0.10"
ntex-tls = "1.0.0-b.0"
ntex-tls = "1.0.0-b.1"
rustls = "0.21"
rustls-pemfile = "1.0"
openssl = "0.10"
test-case = "3.2"
ntex = { version = "1.0.0-b.0", features = ["tokio", "rustls", "openssl"] }
ntex = { version = "1.0.0-b.1", features = ["tokio", "rustls", "openssl"] }
8 changes: 4 additions & 4 deletions examples/mqtt-ws-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use ntex::service::{chain_factory, ServiceFactory};
use ntex::util::{variant, Ready};
use ntex::ws;
use ntex_mqtt::{v3, v5, HandshakeError, MqttError, MqttServer, ProtocolError};
use ntex_tls::openssl::Acceptor;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use ntex_tls::openssl::SslAcceptor;
use openssl::ssl::{self, SslFiletype, SslMethod};

#[derive(Clone)]
struct Session;
Expand Down Expand Up @@ -69,15 +69,15 @@ async fn main() -> std::io::Result<()> {
// create self-signed certificates using:
// openssl req -x509 -nodes -subj '/CN=localhost' -newkey rsa:4096 -keyout examples/key8.pem -out examples/cert.pem -days 365 -keyform PEM
// openssl rsa -in examples/key8.pem -out examples/key.pem
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
let mut builder = ssl::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 acceptor = builder.build();

ntex::server::Server::build()
.bind("mqtt", "127.0.0.1:8883", move |_| {
// first switch to ssl stream
chain_factory(Acceptor::new(acceptor.clone()))
chain_factory(SslAcceptor::new(acceptor.clone()))
.map_err(|_err| MqttError::Service(ServerError {}))
// we need to read first 4 bytes and detect protocol GET or MQTT
.and_then(|io: Io<_>| async move {
Expand Down
8 changes: 4 additions & 4 deletions examples/openssl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ntex::service::chain_factory;
use ntex_mqtt::{v3, v5, MqttError, MqttServer};
use ntex_tls::openssl::Acceptor;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use ntex_tls::openssl::SslAcceptor;
use openssl::ssl::{self, SslFiletype, SslMethod};

#[derive(Clone)]
struct Session;
Expand Down Expand Up @@ -55,14 +55,14 @@ async fn main() -> std::io::Result<()> {
// create self-signed certificates using:
// openssl req -x509 -nodes -subj '/CN=localhost' -newkey rsa:4096 -keyout examples/key8.pem -out examples/cert.pem -days 365 -keyform PEM
// openssl rsa -in examples/key8.pem -out examples/key.pem
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
let mut builder = ssl::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 acceptor = builder.build();

ntex::server::Server::build()
.bind("mqtt", "127.0.0.1:8883", move |_| {
chain_factory(Acceptor::new(acceptor.clone()))
chain_factory(SslAcceptor::new(acceptor.clone()))
.map_err(|_err| MqttError::Service(ServerError {}))
.and_then(
MqttServer::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fs::File, io::BufReader, sync::Arc};

use ntex::service::chain_factory;
use ntex_mqtt::{v3, v5, MqttError, MqttServer};
use ntex_tls::rustls::Acceptor;
use ntex_tls::rustls::TlsAcceptor;
use rustls::{Certificate, PrivateKey, ServerConfig};
use rustls_pemfile::{certs, rsa_private_keys};

Expand Down Expand Up @@ -74,7 +74,7 @@ async fn main() -> std::io::Result<()> {

ntex::server::Server::build()
.bind("mqtt", "127.0.0.1:8883", move |_| {
chain_factory(Acceptor::new(tls_acceptor.clone()))
chain_factory(TlsAcceptor::new(tls_acceptor.clone()))
.map_err(|_err| MqttError::Service(ServerError {}))
.and_then(
MqttServer::new()
Expand Down
2 changes: 1 addition & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ mod tests {
codec: U,
service: F,
) -> (Self, nio::IoRef) {
let keepalive_timeout = Seconds(30).into();
let keepalive_timeout = Seconds(30);
let rio = io.get_ref();
let config = DispatcherConfig::default();

Expand Down
15 changes: 8 additions & 7 deletions tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,14 @@ async fn test_large_publish_openssl() -> std::io::Result<()> {
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};

let srv = server::test_server(move || {
chain_factory(server::openssl::Acceptor::new(ssl_acceptor()).map_err(|_| ())).and_then(
MqttServer::new(handshake)
.publish(|_| Ready::Ok(()))
.finish()
.map_err(|_| ())
.map_init_err(|_| ()),
)
chain_factory(server::openssl::SslAcceptor::new(ssl_acceptor()).map_err(|_| ()))
.and_then(
MqttServer::new(handshake)
.publish(|_| Ready::Ok(()))
.finish()
.map_err(|_| ())
.map_init_err(|_| ()),
)
});

let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
Expand Down

0 comments on commit 8dc65c4

Please sign in to comment.