2022-06-12 03:43:50 +03:00
|
|
|
mod fixtures;
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
use diqwest::blocking::WithDigestAuth;
|
|
|
|
use fixtures::{server, Error, TestServer};
|
|
|
|
use rstest::rstest;
|
|
|
|
|
|
|
|
#[rstest]
|
2022-06-19 06:26:03 +03:00
|
|
|
fn no_auth(#[with(&["--auth", "/@user:pass", "-A"])] server: TestServer) -> Result<(), Error> {
|
2022-06-12 03:43:50 +03:00
|
|
|
let resp = reqwest::blocking::get(server.url())?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
assert!(resp.headers().contains_key("www-authenticate"));
|
|
|
|
let url = format!("{}file1", server.url());
|
|
|
|
let resp = fetch!(b"PUT", &url).body(b"abc".to_vec()).send()?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
2022-06-19 06:26:03 +03:00
|
|
|
fn auth(#[with(&["--auth", "/@user:pass", "-A"])] server: TestServer) -> Result<(), Error> {
|
2022-06-12 03:43:50 +03:00
|
|
|
let url = format!("{}file1", server.url());
|
|
|
|
let resp = fetch!(b"PUT", &url).body(b"abc".to_vec()).send()?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
let resp = fetch!(b"PUT", &url)
|
|
|
|
.body(b"abc".to_vec())
|
|
|
|
.send_with_digest_auth("user", "pass")?;
|
|
|
|
assert_eq!(resp.status(), 201);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
2022-06-19 06:26:03 +03:00
|
|
|
fn auth_skip(#[with(&["--auth", "/@user:pass@*"])] server: TestServer) -> Result<(), Error> {
|
2022-06-12 03:43:50 +03:00
|
|
|
let resp = reqwest::blocking::get(server.url())?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-06-19 06:26:03 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn auth_readonly(
|
|
|
|
#[with(&["--auth", "/@user:pass@user2:pass2", "-A"])] server: TestServer,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let url = format!("{}index.html", server.url());
|
|
|
|
let resp = fetch!(b"GET", &url).send()?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
let resp = fetch!(b"GET", &url).send_with_digest_auth("user2", "pass2")?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
let url = format!("{}file1", server.url());
|
|
|
|
let resp = fetch!(b"PUT", &url)
|
|
|
|
.body(b"abc".to_vec())
|
|
|
|
.send_with_digest_auth("user2", "pass2")?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn auth_nest(
|
2022-12-11 10:18:44 +03:00
|
|
|
#[with(&["--auth", "/@user:pass@user2:pass2", "--auth", "/dir1@user3:pass3", "-A"])]
|
2022-06-19 06:26:03 +03:00
|
|
|
server: TestServer,
|
|
|
|
) -> Result<(), Error> {
|
2022-12-11 10:18:44 +03:00
|
|
|
let url = format!("{}dir1/file1", server.url());
|
2022-06-19 06:26:03 +03:00
|
|
|
let resp = fetch!(b"PUT", &url).body(b"abc".to_vec()).send()?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
let resp = fetch!(b"PUT", &url)
|
|
|
|
.body(b"abc".to_vec())
|
|
|
|
.send_with_digest_auth("user3", "pass3")?;
|
|
|
|
assert_eq!(resp.status(), 201);
|
|
|
|
let resp = fetch!(b"PUT", &url)
|
|
|
|
.body(b"abc".to_vec())
|
|
|
|
.send_with_digest_auth("user", "pass")?;
|
|
|
|
assert_eq!(resp.status(), 201);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn auth_nest_share(
|
2022-12-11 10:18:44 +03:00
|
|
|
#[with(&["--auth", "/@user:pass@*", "--auth", "/dir1@user3:pass3", "-A"])] server: TestServer,
|
2022-06-19 06:26:03 +03:00
|
|
|
) -> Result<(), Error> {
|
|
|
|
let url = format!("{}index.html", server.url());
|
|
|
|
let resp = fetch!(b"GET", &url).send()?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-06-20 06:25:09 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn auth_basic(
|
|
|
|
#[with(&["--auth", "/@user:pass", "--auth-method", "basic", "-A"])] server: TestServer,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let url = format!("{}file1", server.url());
|
|
|
|
let resp = fetch!(b"PUT", &url).body(b"abc".to_vec()).send()?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
let resp = fetch!(b"PUT", &url)
|
|
|
|
.body(b"abc".to_vec())
|
|
|
|
.basic_auth("user", Some("pass"))
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 201);
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-07-04 18:25:05 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn auth_webdav_move(
|
2022-12-11 10:18:44 +03:00
|
|
|
#[with(&["--auth", "/@user:pass@*", "--auth", "/dir1@user3:pass3", "-A"])] server: TestServer,
|
2022-07-04 18:25:05 +03:00
|
|
|
) -> Result<(), Error> {
|
2022-12-11 10:18:44 +03:00
|
|
|
let origin_url = format!("{}dir1/test.html", server.url());
|
2022-07-04 18:25:05 +03:00
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"MOVE", &origin_url)
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send_with_digest_auth("user3", "pass3")?;
|
|
|
|
assert_eq!(resp.status(), 403);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn auth_webdav_copy(
|
2022-12-11 10:18:44 +03:00
|
|
|
#[with(&["--auth", "/@user:pass@*", "--auth", "/dir1@user3:pass3", "-A"])] server: TestServer,
|
2022-07-04 18:25:05 +03:00
|
|
|
) -> Result<(), Error> {
|
2022-12-11 10:18:44 +03:00
|
|
|
let origin_url = format!("{}dir1/test.html", server.url());
|
2022-07-04 18:25:05 +03:00
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"COPY", &origin_url)
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send_with_digest_auth("user3", "pass3")?;
|
|
|
|
assert_eq!(resp.status(), 403);
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-10-08 04:14:42 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn auth_path_prefix(
|
|
|
|
#[with(&["--auth", "/@user:pass", "--path-prefix", "xyz", "-A"])] server: TestServer,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let url = format!("{}xyz/index.html", server.url());
|
|
|
|
let resp = fetch!(b"GET", &url).send()?;
|
|
|
|
assert_eq!(resp.status(), 401);
|
|
|
|
let resp = fetch!(b"GET", &url).send_with_digest_auth("user", "pass")?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
Ok(())
|
|
|
|
}
|