Some cleanup

pull/146/head
Chip Senkbeil 2 years ago
parent f802a53c70
commit a63221b4f7
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -38,6 +38,13 @@ impl Verifier {
}
}
/// Creates a verifier that uses the [`NoneAuthenticationMethod`] exclusively.
pub fn none() -> Self {
Self::new(vec![
Box::new(NoneAuthenticationMethod::new()) as Box<dyn AuthenticationMethod>
])
}
/// Returns an iterator over the ids of the methods supported by the verifier
pub fn methods(&self) -> impl Iterator<Item = &'static str> + '_ {
self.methods.keys().copied()

@ -47,16 +47,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::{
auth::{
msg::{
Challenge, ChallengeResponse, Initialization, InitializationResponse, Verification,
VerificationResponse,
},
AuthHandler,
},
Client, Request, ServerCtx,
};
use crate::{auth::DummyAuthHandler, Client, Request, ServerCtx};
use async_trait::async_trait;
use std::net::{Ipv6Addr, SocketAddr};
use test_log::test;
@ -78,38 +69,17 @@ mod tests {
}
}
pub struct TestAuthHandler;
#[async_trait]
impl AuthHandler for TestAuthHandler {
async fn on_initialization(
&mut self,
x: Initialization,
) -> io::Result<InitializationResponse> {
Ok(InitializationResponse { methods: x.methods })
}
async fn on_challenge(&mut self, _: Challenge) -> io::Result<ChallengeResponse> {
Ok(ChallengeResponse {
answers: Vec::new(),
})
}
async fn on_verification(&mut self, _: Verification) -> io::Result<VerificationResponse> {
Ok(VerificationResponse { valid: true })
}
}
#[test(tokio::test)]
async fn should_invoke_handler_upon_receiving_a_request() {
let server = TcpServerBuilder::default()
.handler(TestServerHandler)
.verifier(Verifier::none())
.start(IpAddr::V6(Ipv6Addr::LOCALHOST), 0)
.await
.expect("Failed to start TCP server");
let mut client: Client<String, String> = Client::tcp()
.auth_handler(TestAuthHandler)
.auth_handler(DummyAuthHandler)
.connect(SocketAddr::from((server.ip_addr(), server.port())))
.await
.expect("Client failed to connect");

@ -48,16 +48,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::{
auth::{
msg::{
Challenge, ChallengeResponse, Initialization, InitializationResponse, Verification,
VerificationResponse,
},
AuthHandler,
},
Client, Request, ServerCtx,
};
use crate::{auth::DummyAuthHandler, Client, Request, ServerCtx};
use async_trait::async_trait;
use tempfile::NamedTempFile;
use test_log::test;
@ -79,28 +70,6 @@ mod tests {
}
}
pub struct TestAuthHandler;
#[async_trait]
impl AuthHandler for TestAuthHandler {
async fn on_initialization(
&mut self,
x: Initialization,
) -> io::Result<InitializationResponse> {
Ok(InitializationResponse { methods: x.methods })
}
async fn on_challenge(&mut self, _: Challenge) -> io::Result<ChallengeResponse> {
Ok(ChallengeResponse {
answers: Vec::new(),
})
}
async fn on_verification(&mut self, _: Verification) -> io::Result<VerificationResponse> {
Ok(VerificationResponse { valid: true })
}
}
#[test(tokio::test)]
async fn should_invoke_handler_upon_receiving_a_request() {
// Generate a socket path and delete the file after so there is nothing there
@ -111,12 +80,13 @@ mod tests {
let server = UnixSocketServerBuilder::default()
.handler(TestServerHandler)
.verifier(Verifier::none())
.start(path)
.await
.expect("Failed to start Unix socket server");
let mut client: Client<String, String> = Client::unix_socket()
.auth_handler(TestAuthHandler)
.auth_handler(DummyAuthHandler)
.connect(server.path())
.await
.expect("Client failed to connect");

@ -64,13 +64,7 @@ where
mod tests {
use super::*;
use crate::{
auth::{
msg::{
Challenge, ChallengeResponse, Initialization, InitializationResponse, Verification,
VerificationResponse,
},
AuthHandler, Authenticator,
},
use crate::{auth::DummyAuthHandler, Client, Request, ServerCtx};
Client, ConnectionCtx, Request, ServerCtx,
};
use async_trait::async_trait;
@ -84,13 +78,6 @@ mod tests {
type Response = String;
type LocalData = ();
async fn on_accept<A: Authenticator>(
&self,
ctx: ConnectionCtx<'_, A, Self::LocalData>,
) -> io::Result<()> {
ctx.authenticator.finished().await
}
async fn on_request(&self, ctx: ServerCtx<Self::Request, Self::Response, Self::LocalData>) {
// Echo back what we received
ctx.reply
@ -100,38 +87,17 @@ mod tests {
}
}
pub struct TestAuthHandler;
#[async_trait]
impl AuthHandler for TestAuthHandler {
async fn on_initialization(
&mut self,
x: Initialization,
) -> io::Result<InitializationResponse> {
Ok(InitializationResponse { methods: x.methods })
}
async fn on_challenge(&mut self, _: Challenge) -> io::Result<ChallengeResponse> {
Ok(ChallengeResponse {
answers: Vec::new(),
})
}
async fn on_verification(&mut self, _: Verification) -> io::Result<VerificationResponse> {
Ok(VerificationResponse { valid: true })
}
}
#[test(tokio::test)]
async fn should_invoke_handler_upon_receiving_a_request() {
let server = WindowsPipeServerBuilder::default()
.handler(TestServerHandler)
.verifier(Verifier::none())
.start_local(format!("test_pipe_{}", rand::random::<usize>()))
.await
.expect("Failed to start Windows pipe server");
let mut client: Client<String, String> = Client::windows_pipe()
.auth_handler(TestAuthHandler)
.auth_handler(DummyAuthHandler)
.connect(server.addr())
.await
.expect("Client failed to connect");

Loading…
Cancel
Save