From 9234050ad4c510acdd780100a8df80b2557cb3e1 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sat, 21 Sep 2019 04:01:54 +0200 Subject: Remove explicit clap dependency in favor of structopt's re-exported version --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index dc98df0..a1217d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use actix_web::http::{Method, StatusCode}; use actix_web::{fs, middleware, server, App, HttpRequest, HttpResponse}; -use clap::crate_version; +use structopt::clap::crate_version; use simplelog::{Config, LevelFilter, TermLogger, TerminalMode}; use std::io::{self, Write}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -- cgit v1.2.3 From 441b2863fd36a5a0a5be96915fa597f165d57232 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sat, 21 Sep 2019 04:08:20 +0200 Subject: Actually make use of pretty_assertions --- src/args.rs | 1 + src/auth.rs | 32 ++++++++++++-------------------- 2 files changed, 13 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index 47f4d1f..8fde78a 100644 --- a/src/args.rs +++ b/src/args.rs @@ -172,6 +172,7 @@ pub fn parse_args() -> crate::MiniserveConfig { mod tests { use super::*; use rstest::rstest_parametrize; + use pretty_assertions::assert_eq; /// Helper function that creates a `RequiredAuth` structure fn create_required_auth(username: &str, password: &str, encrypt: &str) -> auth::RequiredAuth { diff --git a/src/auth.rs b/src/auth.rs index 2c98622..1c98c10 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -55,19 +55,17 @@ pub fn parse_basic_auth( /// Return `true` if `basic_auth` is matches any of `required_auth` pub fn match_auth(basic_auth: BasicAuthParams, required_auth: &[RequiredAuth]) -> bool { - required_auth.iter().any( - |RequiredAuth { username, password }| - basic_auth.username == *username && - compare_password(&basic_auth.password, password) - ) + required_auth + .iter() + .any(|RequiredAuth { username, password }| { + basic_auth.username == *username && compare_password(&basic_auth.password, password) + }) } /// Return `true` if `basic_auth_pwd` meets `required_auth_pwd`'s requirement -pub fn compare_password (basic_auth_pwd: &str, required_auth_pwd: &RequiredAuthPassword) -> bool { +pub fn compare_password(basic_auth_pwd: &str, required_auth_pwd: &RequiredAuthPassword) -> bool { match &required_auth_pwd { - RequiredAuthPassword::Plain(required_password) => { - *basic_auth_pwd == *required_password - } + RequiredAuthPassword::Plain(required_password) => *basic_auth_pwd == *required_password, RequiredAuthPassword::Sha256(password_hash) => { compare_hash::(basic_auth_pwd, password_hash) } @@ -106,16 +104,9 @@ impl Middleware for Auth { Ok(auth_req) => auth_req, Err(err) => { let auth_err = ContextualError::HTTPAuthenticationError(Box::new(err)); - return Ok(Response::Done( - HttpResponse::BadRequest().body( - build_unauthorized_response( - &req, - auth_err, - true, - StatusCode::BAD_REQUEST, - ), - ), - )); + return Ok(Response::Done(HttpResponse::BadRequest().body( + build_unauthorized_response(&req, auth_err, true, StatusCode::BAD_REQUEST), + ))); } }; @@ -135,7 +126,7 @@ impl Middleware for Auth { ContextualError::InvalidHTTPCredentials, true, StatusCode::UNAUTHORIZED, - )) + )), )) } } @@ -178,6 +169,7 @@ fn build_unauthorized_response( mod tests { use super::*; use rstest::{rstest, rstest_parametrize, fixture}; + use pretty_assertions::assert_eq; /// Return a hashing function corresponds to given name fn get_hash_func(name: &str) -> impl FnOnce(&str) -> Vec { -- cgit v1.2.3