aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Flanagan <eli@typedspace.com>2019-09-25 00:21:45 +0000
committerEli Flanagan <eli@typedspace.com>2019-09-25 00:25:14 +0000
commita80a5f021460d77e3353633c623c7461ebd593fd (patch)
tree47979938893c836cfb6e149ae49afa9fbacbcd4f /src
parentadd a test for missing index file (diff)
parentActually make use of pretty_assertions (diff)
downloadminiserve-a80a5f021460d77e3353633c623c7461ebd593fd.tar.gz
miniserve-a80a5f021460d77e3353633c623c7461ebd593fd.zip
Merge branch 'master' into fix-156
Diffstat (limited to '')
-rw-r--r--src/args.rs1
-rw-r--r--src/auth.rs32
-rw-r--r--src/main.rs2
3 files changed, 14 insertions, 21 deletions
diff --git a/src/args.rs b/src/args.rs
index 0d4e3ce..ad5f1d6 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -177,6 +177,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::<Sha256>(basic_auth_pwd, password_hash)
}
@@ -106,16 +104,9 @@ impl Middleware<crate::MiniserveConfig> 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<crate::MiniserveConfig> 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<u8> {
diff --git a/src/main.rs b/src/main.rs
index 3bb521c..c31341e 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};