2022-06-12 03:43:50 +03:00
|
|
|
mod fixtures;
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
use fixtures::{server, Error, TestServer, FILES};
|
|
|
|
use rstest::rstest;
|
|
|
|
use xml::escape::escape_str_pcdata;
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn propfind_dir(server: TestServer) -> Result<(), Error> {
|
2022-12-11 10:18:44 +03:00
|
|
|
let resp = fetch!(b"PROPFIND", format!("{}dir1", server.url())).send()?;
|
2022-06-12 03:43:50 +03:00
|
|
|
assert_eq!(resp.status(), 207);
|
|
|
|
let body = resp.text()?;
|
2022-12-11 10:18:44 +03:00
|
|
|
assert!(body.contains("<D:href>/dir1/</D:href>"));
|
|
|
|
assert!(body.contains("<D:displayname>dir1</D:displayname>"));
|
2022-06-12 03:43:50 +03:00
|
|
|
for f in FILES {
|
2022-12-11 10:18:44 +03:00
|
|
|
assert!(body.contains(&format!("<D:href>/dir1/{}</D:href>", utils::encode_uri(f))));
|
2022-06-12 03:43:50 +03:00
|
|
|
assert!(body.contains(&format!(
|
|
|
|
"<D:displayname>{}</D:displayname>",
|
|
|
|
escape_str_pcdata(f)
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn propfind_dir_depth0(server: TestServer) -> Result<(), Error> {
|
2022-12-11 10:18:44 +03:00
|
|
|
let resp = fetch!(b"PROPFIND", format!("{}dir1", server.url()))
|
2022-06-12 03:43:50 +03:00
|
|
|
.header("depth", "0")
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 207);
|
|
|
|
let body = resp.text()?;
|
2022-12-11 10:18:44 +03:00
|
|
|
assert!(body.contains("<D:href>/dir1/</D:href>"));
|
|
|
|
assert!(body.contains("<D:displayname>dir1</D:displayname>"));
|
2022-06-12 03:43:50 +03:00
|
|
|
assert_eq!(
|
|
|
|
body.lines()
|
|
|
|
.filter(|v| *v == "<D:status>HTTP/1.1 200 OK</D:status>")
|
|
|
|
.count(),
|
|
|
|
1
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-06-14 17:16:50 +03:00
|
|
|
#[rstest]
|
|
|
|
fn propfind_dir_depth2(server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"PROPFIND", format!("{}dir1", server.url()))
|
|
|
|
.header("depth", "2")
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 400);
|
|
|
|
let body = resp.text()?;
|
|
|
|
assert_eq!(body, "Invalid depth: only 0 and 1 are allowed.");
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-06-12 03:43:50 +03:00
|
|
|
#[rstest]
|
|
|
|
fn propfind_404(server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"PROPFIND", format!("{}404", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 404);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-11-10 14:28:01 +03:00
|
|
|
#[rstest]
|
|
|
|
fn propfind_double_slash(server: TestServer) -> Result<(), Error> {
|
2024-02-07 11:27:22 +03:00
|
|
|
let resp = fetch!(b"PROPFIND", server.url()).send()?;
|
2022-11-10 14:28:01 +03:00
|
|
|
assert_eq!(resp.status(), 207);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-06-12 03:43:50 +03:00
|
|
|
#[rstest]
|
|
|
|
fn propfind_file(server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"PROPFIND", format!("{}test.html", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 207);
|
|
|
|
let body = resp.text()?;
|
|
|
|
assert!(body.contains("<D:href>/test.html</D:href>"));
|
|
|
|
assert!(body.contains("<D:displayname>test.html</D:displayname>"));
|
|
|
|
assert_eq!(
|
|
|
|
body.lines()
|
|
|
|
.filter(|v| *v == "<D:status>HTTP/1.1 200 OK</D:status>")
|
|
|
|
.count(),
|
|
|
|
1
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn proppatch_file(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"PROPPATCH", format!("{}test.html", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 207);
|
|
|
|
let body = resp.text()?;
|
|
|
|
assert!(body.contains("<D:href>/test.html</D:href>"));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn proppatch_404(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"PROPPATCH", format!("{}404", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 404);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn mkcol_dir(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"MKCOL", format!("{}newdir", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 201);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn mkcol_not_allow_upload(server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"MKCOL", format!("{}newdir", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 403);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-11-10 13:41:10 +03:00
|
|
|
#[rstest]
|
|
|
|
fn mkcol_already_exists(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
2022-12-11 10:18:44 +03:00
|
|
|
let resp = fetch!(b"MKCOL", format!("{}dir1", server.url())).send()?;
|
2022-11-10 13:41:10 +03:00
|
|
|
assert_eq!(resp.status(), 405);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-06-12 03:43:50 +03:00
|
|
|
#[rstest]
|
|
|
|
fn copy_file(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"COPY", format!("{}test.html", server.url()))
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 204);
|
|
|
|
let resp = reqwest::blocking::get(new_url)?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn copy_not_allow_upload(server: TestServer) -> Result<(), Error> {
|
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"COPY", format!("{}test.html", server.url()))
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 403);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn copy_file_404(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"COPY", format!("{}404", server.url()))
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 404);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn move_file(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let origin_url = format!("{}test.html", server.url());
|
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"MOVE", &origin_url)
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 204);
|
|
|
|
let resp = reqwest::blocking::get(new_url)?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
let resp = reqwest::blocking::get(origin_url)?;
|
|
|
|
assert_eq!(resp.status(), 404);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn move_not_allow_upload(#[with(&["--allow-delete"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let origin_url = format!("{}test.html", server.url());
|
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"MOVE", &origin_url)
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 403);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn move_not_allow_delete(#[with(&["--allow-upload"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let origin_url = format!("{}test.html", server.url());
|
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"MOVE", &origin_url)
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 403);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn move_file_404(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let new_url = format!("{}test2.html", server.url());
|
|
|
|
let resp = fetch!(b"MOVE", format!("{}404", server.url()))
|
|
|
|
.header("Destination", &new_url)
|
|
|
|
.send()?;
|
|
|
|
assert_eq!(resp.status(), 404);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn lock_file(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"LOCK", format!("{}test.html", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
let body = resp.text()?;
|
|
|
|
assert!(body.contains("<D:href>/test.html</D:href>"));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn lock_file_404(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"LOCK", format!("{}404", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 404);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn unlock_file(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"LOCK", format!("{}test.html", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn unlock_file_404(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"LOCK", format!("{}404", server.url())).send()?;
|
|
|
|
assert_eq!(resp.status(), 404);
|
|
|
|
Ok(())
|
|
|
|
}
|