refactor: return 400 for propfind request when depth is neither 0 nor 1 (#403)
This commit is contained in:
parent
dc7a7cbb3f
commit
f1e90686dc
2 changed files with 16 additions and 4 deletions
|
@ -963,9 +963,10 @@ impl Server {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let depth: u32 = match headers.get("depth") {
|
let depth: u32 = match headers.get("depth") {
|
||||||
Some(v) => match v.to_str().ok().and_then(|v| v.parse().ok()) {
|
Some(v) => match v.to_str().ok().and_then(|v| v.parse().ok()) {
|
||||||
Some(v) => v,
|
Some(0) => 0,
|
||||||
None => {
|
Some(1) => 1,
|
||||||
status_bad_request(res, "");
|
_ => {
|
||||||
|
status_bad_request(res, "Invalid depth: only 0 and 1 are allowed.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -975,7 +976,7 @@ impl Server {
|
||||||
Some(v) => vec![v],
|
Some(v) => vec![v],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
if depth != 0 {
|
if depth == 1 {
|
||||||
match self
|
match self
|
||||||
.list_dir(path, &self.args.serve_path, access_paths)
|
.list_dir(path, &self.args.serve_path, access_paths)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -40,6 +40,17 @@ fn propfind_dir_depth0(server: TestServer) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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(())
|
||||||
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn propfind_404(server: TestServer) -> Result<(), Error> {
|
fn propfind_404(server: TestServer) -> Result<(), Error> {
|
||||||
let resp = fetch!(b"PROPFIND", format!("{}404", server.url())).send()?;
|
let resp = fetch!(b"PROPFIND", format!("{}404", server.url())).send()?;
|
||||||
|
|
Loading…
Reference in a new issue