aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/args.rs16
-rw-r--r--src/config.rs4
-rw-r--r--tests/upload_files.rs10
3 files changed, 12 insertions, 18 deletions
diff --git a/src/args.rs b/src/args.rs
index 56c834c..8cd8ffa 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -108,28 +108,22 @@ pub struct CliArgs {
pub qrcode: bool,
/// Enable file uploading
- #[clap(short = 'u', long = "upload-files")]
- pub file_upload: bool,
-
- /// Allowed upload directories (together with -u)
- ///
- /// If this is set, uploads are only allowed into the provided directories.
- #[clap(long, requires = "file-upload", value_hint = ValueHint::FilePath)]
- pub allowed_upload_dir: Vec<PathBuf>,
+ #[clap(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, min_values = 0)]
+ pub allowed_upload_dir: Option<Vec<PathBuf>>,
/// Enable creating directories
- #[clap(short = 'U', long = "mkdir", requires = "file-upload")]
+ #[clap(short = 'U', long = "mkdir", requires = "allowed-upload-dir")]
pub mkdir_enabled: bool,
/// Specify uploadable media types
- #[clap(arg_enum, short = 'm', long = "media-type", requires = "file-upload")]
+ #[clap(arg_enum, short = 'm', long = "media-type", requires = "allowed-upload-dir")]
pub media_type: Option<Vec<MediaType>>,
/// Directly specify the uploadable media type expression
#[clap(
short = 'M',
long = "raw-media-type",
- requires = "file-upload",
+ requires = "allowed-upload-dir",
conflicts_with = "media-type"
)]
pub media_type_raw: Option<String>,
diff --git a/src/config.rs b/src/config.rs
index 2b10440..4f794d1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -250,8 +250,8 @@ impl MiniserveConfig {
overwrite_files: args.overwrite_files,
show_qrcode: args.qrcode,
mkdir_enabled: args.mkdir_enabled,
- file_upload: args.file_upload,
- allowed_upload_dir: args.allowed_upload_dir,
+ file_upload: !args.allowed_upload_dir.is_none(),
+ allowed_upload_dir: args.allowed_upload_dir.unwrap_or(vec![]),
uploadable_media_type,
tar_enabled: args.enable_tar,
tar_gz_enabled: args.enable_tar_gz,
diff --git a/tests/upload_files.rs b/tests/upload_files.rs
index de96aff..ca9f007 100644
--- a/tests/upload_files.rs
+++ b/tests/upload_files.rs
@@ -84,8 +84,8 @@ fn uploading_files_is_prevented(server: TestServer) -> Result<(), Error> {
/// This test runs the server with --allowed-upload-dir argument and
/// checks that file upload to a different directory is actually prevented.
#[rstest]
-#[case(server_no_stderr(&["-u", "--allowed-upload-dir", "someDir"]))]
-#[case(server_no_stderr(&["-u", "--allowed-upload-dir", "someDir/some_sub_dir"]))]
+#[case(server_no_stderr(&["-u", "someDir"]))]
+#[case(server_no_stderr(&["-u", "someDir/some_sub_dir"]))]
fn uploading_files_is_restricted(#[case] server: TestServer) -> Result<(), Error> {
let test_file_name = "uploaded test file.txt";
@@ -117,9 +117,9 @@ fn uploading_files_is_restricted(#[case] server: TestServer) -> Result<(), Error
/// This tests that we can upload files to the directory specified by --allow-upload-dir
#[rstest]
-#[case(server(&["-u", "--allowed-upload-dir", "someDir"]), vec!["someDir"])]
-#[case(server(&["-u", "--allowed-upload-dir", "someDir/some_sub_dir"]), vec!["someDir/some_sub_dir"])]
-#[case(server(&["-u", "--allowed-upload-dir", "someDir/some_sub_dir", "--allowed-upload-dir", "someDir/some_other_dir"]),
+#[case(server(&["-u", "someDir"]), vec!["someDir"])]
+#[case(server(&["-u", "someDir/some_sub_dir"]), vec!["someDir/some_sub_dir"])]
+#[case(server(&["-u", "someDir/some_sub_dir", "-u", "someDir/some_other_dir"]),
vec!["someDir/some_sub_dir", "someDir/some_other_dir"])]
fn uploading_files_to_allowed_dir_works(
#[case] server: TestServer,