refactor: improve invalid auth (#356)
This commit is contained in:
parent
95eb648411
commit
f92c8ee91d
2 changed files with 21 additions and 2 deletions
|
@ -109,11 +109,11 @@ impl AccessControl {
|
||||||
}
|
}
|
||||||
if check_auth(authorization, method.as_str(), &user, pass).is_some() {
|
if check_auth(authorization, method.as_str(), &user, pass).is_some() {
|
||||||
return (Some(user), paths.find(path, !is_readonly_method(method)));
|
return (Some(user), paths.find(path, !is_readonly_method(method)));
|
||||||
} else {
|
|
||||||
return (None, None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (None, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
if method == Method::OPTIONS {
|
if method == Method::OPTIONS {
|
||||||
|
|
|
@ -39,6 +39,25 @@ fn auth(#[case] server: TestServer, #[case] user: &str, #[case] pass: &str) -> R
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn invalid_auth(
|
||||||
|
#[with(&["-a", "user:pass@/:rw", "-a", "@/", "-A"])] server: TestServer,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let resp = fetch!(b"GET", server.url())
|
||||||
|
.basic_auth("user", Some("-"))
|
||||||
|
.send()?;
|
||||||
|
assert_eq!(resp.status(), 401);
|
||||||
|
let resp = fetch!(b"GET", server.url())
|
||||||
|
.basic_auth("-", Some("pass"))
|
||||||
|
.send()?;
|
||||||
|
assert_eq!(resp.status(), 401);
|
||||||
|
let resp = fetch!(b"GET", server.url())
|
||||||
|
.header("Authorization", "Basic Og==")
|
||||||
|
.send()?;
|
||||||
|
assert_eq!(resp.status(), 401);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
const HASHED_PASSWORD_AUTH: &str = "user:$6$gQxZwKyWn/ZmWEA2$4uV7KKMnSUnET2BtWTj/9T5.Jq3h/MdkOlnIl5hdlTxDZ4MZKmJ.kl6C.NL9xnNPqC4lVHC1vuI0E5cLpTJX81@/:rw"; // user:pass
|
const HASHED_PASSWORD_AUTH: &str = "user:$6$gQxZwKyWn/ZmWEA2$4uV7KKMnSUnET2BtWTj/9T5.Jq3h/MdkOlnIl5hdlTxDZ4MZKmJ.kl6C.NL9xnNPqC4lVHC1vuI0E5cLpTJX81@/:rw"; // user:pass
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
|
|
Loading…
Reference in a new issue