Procházet zdrojové kódy

Only reject empty passwords when uploading

timvisee před 7 roky
rodič
revize
3cba92c494
3 změnil soubory, kde provedl 23 přidání a 26 odebrání
  1. 0 1
      IDEAS.md
  2. 20 9
      cli/src/cmd/arg/password.rs
  3. 3 16
      cli/src/util.rs

+ 0 - 1
IDEAS.md

@@ -1,6 +1,5 @@
 # First release
 - Only allow file extension renaming on upload with `-f` flag
-- Only allow empty passwords with `-f` flag
 - Check for file expiry everywhere
 - Soft limit uploads to 1GB and 2GB
 - Remember all uploaded files, make files listable

+ 20 - 9
cli/src/cmd/arg/password.rs

@@ -2,7 +2,7 @@ use clap::{Arg, ArgMatches};
 
 use cmd::matcher::{MainMatcher, Matcher};
 use super::{CmdArg, CmdArgFlag, CmdArgOption};
-use util::prompt_password;
+use util::{ErrorHintsBuilder, quit_error_msg, prompt_password};
 
 /// The password argument.
 pub struct ArgPassword { }
@@ -35,16 +35,27 @@ impl<'a> CmdArgOption<'a> for ArgPassword {
             return None;
         }
 
-        // Get the password from the argument if set
-        match Self::value_raw(matches) {
-            None => {},
-            p => return p.map(|p| p.into()),
-        }
-
         // Create a main matcher
         let matcher_main = MainMatcher::with(matches).unwrap();
 
-        // Prompt for the password
-        Some(prompt_password(&matcher_main))
+        // Get the password argument value, or prompt
+        let password = match Self::value_raw(matches) {
+            Some(password) => password.into(),
+            None => prompt_password(&matcher_main),
+        };
+
+        // Do not allow empty passwords unless forced
+        if !matcher_main.force() && password.is_empty() {
+            quit_error_msg(
+                "An empty password is not supported by the web interface",
+                ErrorHintsBuilder::default()
+                    .force(true)
+                    .verbose(false)
+                    .build()
+                    .unwrap(),
+            )
+        }
+
+        Some(password)
     }
 }

+ 3 - 16
cli/src/util.rs

@@ -164,7 +164,8 @@ pub fn set_clipboard(content: String) -> Result<(), Box<StdError>> {
 }
 
 /// Prompt the user to enter a password.
-// TODO: only allow emtpy password if forced
+///
+/// If `empty` is `false`, emtpy passwords aren't allowed unless forced.
 pub fn prompt_password(main_matcher: &MainMatcher) -> String {
     // Quit with an error if we may not interact
     if main_matcher.no_interact() {
@@ -179,26 +180,12 @@ pub fn prompt_password(main_matcher: &MainMatcher) -> String {
     }
 
     // Prompt for the password
-    let password = match prompt_password_stderr("Password: ") {
+    match prompt_password_stderr("Password: ") {
         Ok(password) => password,
         Err(err) => quit_error(err.context(
             "Failed to read password from password prompt"
         ), ErrorHints::default()),
-    };
-
-    // Do not allow empty passwords unless forced
-    if !main_matcher.force() && password.is_empty() {
-        quit_error_msg(
-            "An empty password is not supported by the web interface",
-            ErrorHintsBuilder::default()
-                .force(true)
-                .verbose(false)
-                .build()
-                .unwrap(),
-        )
     }
-
-    password
 }
 
 /// Get a password if required.