]> OzVa Git service - ozva-cloud/commitdiff
fix: basic auth sometimes does not work (#194)
authorsigoden <sigoden@gmail.com>
Sun, 12 Mar 2023 04:58:36 +0000 (12:58 +0800)
committerGitHub <noreply@github.com>
Sun, 12 Mar 2023 04:58:36 +0000 (12:58 +0800)
src/auth.rs
tests/auth.rs

index 018a7a7ced2fe7e492309f51b38e26026cf5ff84..ecd9f9061c7a7c80598630f92cf1f6a653248e61 100644 (file)
@@ -211,7 +211,7 @@ impl AuthMethod {
     pub fn get_user(&self, authorization: &HeaderValue) -> Option<String> {
         match self {
             AuthMethod::Basic => {
-                let value: Vec<u8> = general_purpose::STANDARD_NO_PAD
+                let value: Vec<u8> = general_purpose::STANDARD
                     .decode(strip_prefix(authorization.as_bytes(), b"Basic ")?)
                     .ok()?;
                 let parts: Vec<&str> = std::str::from_utf8(&value).ok()?.split(':').collect();
@@ -236,7 +236,7 @@ impl AuthMethod {
     ) -> Option<()> {
         match self {
             AuthMethod::Basic => {
-                let basic_value: Vec<u8> = general_purpose::STANDARD_NO_PAD
+                let basic_value: Vec<u8> = general_purpose::STANDARD
                     .decode(strip_prefix(authorization.as_bytes(), b"Basic ")?)
                     .ok()?;
                 let parts: Vec<&str> = std::str::from_utf8(&basic_value).ok()?.split(':').collect();
index 077523ba69f0560dd767d835a6e3c2f12964a793..8d98b89b07798862edab5dddb6b2c7de4d8b25d7 100644 (file)
@@ -106,15 +106,19 @@ fn auth_nest_share(
 }
 
 #[rstest]
+#[case(server(&["--auth", "/@user:pass", "--auth-method", "basic", "-A"]), "user", "pass")]
+#[case(server(&["--auth", "/@u1:p1", "--auth-method", "basic", "-A"]), "u1", "p1")]
 fn auth_basic(
-    #[with(&["--auth", "/@user:pass", "--auth-method", "basic", "-A"])] server: TestServer,
+    #[case] server: TestServer,
+    #[case] user: &str,
+    #[case] pass: &str,
 ) -> 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"))
+        .basic_auth(user, Some(pass))
         .send()?;
     assert_eq!(resp.status(), 201);
     Ok(())