]> OzVa Git service - ozva-cloud/commitdiff
fix: auth not works with --path-prefix (#138)
authorsigoden <sigoden@gmail.com>
Sat, 8 Oct 2022 01:14:42 +0000 (09:14 +0800)
committerGitHub <noreply@github.com>
Sat, 8 Oct 2022 01:14:42 +0000 (09:14 +0800)
close #137

src/auth.rs
tests/auth.rs

index 065fd04a1712b31154de90009f488b5726c952e4..ab2cd7b6d09d64e40aa5c10ac6aeec2f4dd5cd6d 100644 (file)
@@ -132,7 +132,12 @@ impl GuardType {
 }
 
 fn sanitize_path(path: &str, uri_prefix: &str) -> String {
-    encode_uri(&format!("{}{}", uri_prefix, path.trim_matches('/')))
+    let new_path = match (uri_prefix, path) {
+        ("/", "/") => "/".into(),
+        (_, "/") => uri_prefix.trim_end_matches('/').into(),
+        _ => format!("{}{}", uri_prefix, path.trim_matches('/')),
+    };
+    encode_uri(&new_path)
 }
 
 fn walk_path(path: &str) -> impl Iterator<Item = &str> {
index fad9ecb37e9ba7906a1f95e334830912ad08352c..83afb22b343c8ff193af3b23de9bebd3f76ec047 100644 (file)
@@ -121,3 +121,15 @@ fn auth_webdav_copy(
     assert_eq!(resp.status(), 403);
     Ok(())
 }
+
+#[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(())
+}