fix: basic auth sometimes does not work (#194)
parent
8d7a9053e2
commit
c92e45f2da
|
@ -211,7 +211,7 @@ impl AuthMethod {
|
||||||
pub fn get_user(&self, authorization: &HeaderValue) -> Option<String> {
|
pub fn get_user(&self, authorization: &HeaderValue) -> Option<String> {
|
||||||
match self {
|
match self {
|
||||||
AuthMethod::Basic => {
|
AuthMethod::Basic => {
|
||||||
let value: Vec<u8> = general_purpose::STANDARD_NO_PAD
|
let value: Vec<u8> = general_purpose::STANDARD
|
||||||
.decode(strip_prefix(authorization.as_bytes(), b"Basic ")?)
|
.decode(strip_prefix(authorization.as_bytes(), b"Basic ")?)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let parts: Vec<&str> = std::str::from_utf8(&value).ok()?.split(':').collect();
|
let parts: Vec<&str> = std::str::from_utf8(&value).ok()?.split(':').collect();
|
||||||
|
@ -236,7 +236,7 @@ impl AuthMethod {
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
match self {
|
match self {
|
||||||
AuthMethod::Basic => {
|
AuthMethod::Basic => {
|
||||||
let basic_value: Vec<u8> = general_purpose::STANDARD_NO_PAD
|
let basic_value: Vec<u8> = general_purpose::STANDARD
|
||||||
.decode(strip_prefix(authorization.as_bytes(), b"Basic ")?)
|
.decode(strip_prefix(authorization.as_bytes(), b"Basic ")?)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let parts: Vec<&str> = std::str::from_utf8(&basic_value).ok()?.split(':').collect();
|
let parts: Vec<&str> = std::str::from_utf8(&basic_value).ok()?.split(':').collect();
|
||||||
|
|
|
@ -106,15 +106,19 @@ fn auth_nest_share(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
|
#[case(server(&["--auth", "/@user:pass", "--auth-method", "basic", "-A"]), "user", "pass")]
|
||||||
|
#[case(server(&["--auth", "/@u1:p1", "--auth-method", "basic", "-A"]), "u1", "p1")]
|
||||||
fn auth_basic(
|
fn auth_basic(
|
||||||
#[with(&["--auth", "/@user:pass", "--auth-method", "basic", "-A"])] server: TestServer,
|
#[case] server: TestServer,
|
||||||
|
#[case] user: &str,
|
||||||
|
#[case] pass: &str,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let url = format!("{}file1", server.url());
|
let url = format!("{}file1", server.url());
|
||||||
let resp = fetch!(b"PUT", &url).body(b"abc".to_vec()).send()?;
|
let resp = fetch!(b"PUT", &url).body(b"abc".to_vec()).send()?;
|
||||||
assert_eq!(resp.status(), 401);
|
assert_eq!(resp.status(), 401);
|
||||||
let resp = fetch!(b"PUT", &url)
|
let resp = fetch!(b"PUT", &url)
|
||||||
.body(b"abc".to_vec())
|
.body(b"abc".to_vec())
|
||||||
.basic_auth("user", Some("pass"))
|
.basic_auth(user, Some(pass))
|
||||||
.send()?;
|
.send()?;
|
||||||
assert_eq!(resp.status(), 201);
|
assert_eq!(resp.status(), 201);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue