]> OzVa Git service - ozva-cloud/commitdiff
fix: status code for MKCOL on existing resource (#142)
authorAneesh Agrawal <aneeshusa@gmail.com>
Thu, 10 Nov 2022 10:41:10 +0000 (05:41 -0500)
committerGitHub <noreply@github.com>
Thu, 10 Nov 2022 10:41:10 +0000 (18:41 +0800)
* Fix status code for MKCOL on existing resource

Per https://datatracker.ietf.org/doc/html/rfc4918#section-9.3.1,
MKCOL should return a 405 if the resource already exists.

Impetus for this change:
I am using dufs as a webdav server for [Joplin](https://joplinapp.org/)
which interpreted the previous behavior of returning a 403 as an error,
preventing syncing from working.

* add test

Co-authored-by: sigoden <sigoden@gmail.com>
src/server.rs
tests/webdav.rs

index 77deb8d1427dc52fcf93c14289abacb145f8d3ce..595721f8cbdb146146bdfec17535399c731c3f10 100644 (file)
@@ -270,8 +270,11 @@ impl Server {
                     }
                 }
                 "MKCOL" => {
-                    if !allow_upload || !is_miss {
+                    if !allow_upload {
                         status_forbid(&mut res);
+                    } else if !is_miss {
+                        *res.status_mut() = StatusCode::METHOD_NOT_ALLOWED;
+                        *res.body_mut() = Body::from("Already exists");
                     } else {
                         self.handle_mkcol(path, &mut res).await?;
                     }
index cedfad50acb62f1d5974e185ec7576806a88250d..04b4ae04746f57e96326f6afaaf4d815ebb0cdb6 100644 (file)
@@ -93,6 +93,13 @@ fn mkcol_not_allow_upload(server: TestServer) -> Result<(), Error> {
     Ok(())
 }
 
+#[rstest]
+fn mkcol_already_exists(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
+    let resp = fetch!(b"MKCOL", format!("{}dira", server.url())).send()?;
+    assert_eq!(resp.status(), 405);
+    Ok(())
+}
+
 #[rstest]
 fn copy_file(#[with(&["-A"])] server: TestServer) -> Result<(), Error> {
     let new_url = format!("{}test2.html", server.url());