diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/create_directories.rs | 4 | ||||
-rw-r--r-- | tests/fixtures/mod.rs | 10 | ||||
-rw-r--r-- | tests/navigation.rs | 19 | ||||
-rw-r--r-- | tests/qrcode.rs | 2 | ||||
-rw-r--r-- | tests/raw.rs | 8 | ||||
-rw-r--r-- | tests/readme.rs | 8 | ||||
-rw-r--r-- | tests/serve_request.rs | 32 | ||||
-rw-r--r-- | tests/tls.rs | 4 | ||||
-rw-r--r-- | tests/upload_files.rs | 7 |
9 files changed, 45 insertions, 49 deletions
diff --git a/tests/create_directories.rs b/tests/create_directories.rs index fa8f4b8..380c796 100644 --- a/tests/create_directories.rs +++ b/tests/create_directories.rs @@ -117,7 +117,7 @@ fn creating_directories_through_symlinks_is_prevented( .post( server .url() - .join(format!("/upload?path=/{}", symlink_directory_str).as_str())? + .join(format!("/upload?path=/{symlink_directory_str}").as_str())? ) .multipart(form) .send()? @@ -153,7 +153,7 @@ fn prevent_path_transversal_attacks( // This should fail assert!(Client::new() - .post(server.url().join(&format!("/upload/path={}", path))?) + .post(server.url().join(&format!("/upload/path={path}"))?) .multipart(form) .send()? .error_for_status() diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index ec17f3e..05b72f9 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -64,14 +64,14 @@ pub fn tmpdir() -> TempDir { for directory in directories { for file in &files { tmpdir - .child(format!("{}{}", directory, file)) - .write_str(&format!("This is {}{}", directory, file)) + .child(format!("{directory}{file}")) + .write_str(&format!("This is {directory}{file}")) .expect("Couldn't write to file"); } } tmpdir - .child(&DEEPLY_NESTED_FILE) + .child(DEEPLY_NESTED_FILE) .write_str("File in a deeply nested directory.") .expect("Couldn't write to file"); tmpdir @@ -144,11 +144,11 @@ where fn wait_for_port(port: u16) { let start_wait = Instant::now(); - while !port_check::is_port_reachable(format!("localhost:{}", port)) { + while !port_check::is_port_reachable(format!("localhost:{port}")) { sleep(Duration::from_millis(100)); if start_wait.elapsed().as_secs() > 1 { - panic!("timeout waiting for port {}", port); + panic!("timeout waiting for port {port}"); } } } diff --git a/tests/navigation.rs b/tests/navigation.rs index f4a2e1f..3bd7415 100644 --- a/tests/navigation.rs +++ b/tests/navigation.rs @@ -34,7 +34,7 @@ fn cant_navigate_up_the_root(server: TestServer) -> Result<(), Error> { .arg("-s") .arg("--fail") .arg("--path-as-is") - .arg(format!("{}/../", base_url)) + .arg(format!("{base_url}/../")) .stdout(Stdio::null()) .status()? .success(); @@ -50,13 +50,12 @@ fn can_navigate_into_dirs_and_back(server: TestServer) -> Result<(), Error> { let initial_body = reqwest::blocking::get(base_url.as_str())?.error_for_status()?; let initial_parsed = Document::from_read(initial_body)?; for &directory in DIRECTORIES { - let dir_elem = get_link_from_text(&initial_parsed, &directory).expect("Dir not found."); - let body = - reqwest::blocking::get(&format!("{}{}", base_url, dir_elem))?.error_for_status()?; + let dir_elem = get_link_from_text(&initial_parsed, directory).expect("Dir not found."); + let body = reqwest::blocking::get(&format!("{base_url}{dir_elem}"))?.error_for_status()?; let parsed = Document::from_read(body)?; let back_link = get_link_from_text(&parsed, "Parent directory").expect("Back link not found."); - let resp = reqwest::blocking::get(&format!("{}{}", base_url, back_link))?; + let resp = reqwest::blocking::get(&format!("{base_url}{back_link}"))?; // Now check that we can actually get back to the original location we came from using the // link. @@ -73,8 +72,8 @@ fn can_navigate_deep_into_dirs_and_back(server: TestServer) -> Result<(), Error> // remove that part. let dir_names = { let mut comps = DEEPLY_NESTED_FILE - .split("/") - .map(|d| format!("{}/", d)) + .split('/') + .map(|d| format!("{d}/")) .collect::<Vec<String>>(); comps.pop(); comps @@ -88,7 +87,7 @@ fn can_navigate_deep_into_dirs_and_back(server: TestServer) -> Result<(), Error> let resp = reqwest::blocking::get(next_url.as_str())?; let body = resp.error_for_status()?; let parsed = Document::from_read(body)?; - let dir_elem = get_link_from_text(&parsed, &dir_name).expect("Dir not found."); + let dir_elem = get_link_from_text(&parsed, dir_name).expect("Dir not found."); next_url = next_url.join(&dir_elem)?; } assert_ne!(base_url, next_url); @@ -119,8 +118,8 @@ fn can_navigate_using_breadcrumbs( // remove that part. let dir: String = { let mut comps = DEEPLY_NESTED_FILE - .split("/") - .map(|d| format!("{}/", d)) + .split('/') + .map(|d| format!("{d}/")) .collect::<Vec<String>>(); comps.pop(); comps.join("") diff --git a/tests/qrcode.rs b/tests/qrcode.rs index c47e634..48fa8c8 100644 --- a/tests/qrcode.rs +++ b/tests/qrcode.rs @@ -46,7 +46,7 @@ fn run_in_faketty_kill_and_get_stdout(template: &Command) -> Result<String, Erro .map(|s| s.to_str().expect("not UTF8")) .collect::<Vec<_>>() .join(" "); - format!("{} {}", bin, args) + format!("{bin} {args}") }; let mut child = bash_command(&cmd)?.stdin(Stdio::null()).spawn()?; diff --git a/tests/raw.rs b/tests/raw.rs index 99d6661..f212f58 100644 --- a/tests/raw.rs +++ b/tests/raw.rs @@ -67,13 +67,11 @@ fn raw_mode_links_to_directories_end_with_raw_true( "doesn't end with ?raw=true" ); } else if class == "file" { - assert!(true); + return; } else { - println!( - "This node is a link and neither of class directory, root or file: {:?}", - node + panic!( + "This node is a link and neither of class directory, root or file: {node:?}" ); - assert!(false); } } } diff --git a/tests/readme.rs b/tests/readme.rs index 3fcbe29..7faea7b 100644 --- a/tests/readme.rs +++ b/tests/readme.rs @@ -52,7 +52,7 @@ fn show_root_readme_contents( assert!(parsed.find(|x: &Node| x.text() == file).next().is_some()); } // ...in addition to the readme contents below the file listing. - assert_readme_contents(&parsed, &readme_name); + assert_readme_contents(&parsed, readme_name); remove_file(readme_path).unwrap(); Ok(()) } @@ -84,7 +84,7 @@ fn show_nested_readme_contents( assert!(parsed.find(|x: &Node| x.text() == file).next().is_some()); } // ...in addition to the readme contents below the file listing. - assert_readme_contents(&parsed, &readme_name); + assert_readme_contents(&parsed, readme_name); remove_file(readme_path).unwrap(); } Ok(()) @@ -94,7 +94,7 @@ fn write_readme_contents(path: PathBuf, filename: &str) -> PathBuf { let readme_path = path.join(filename); let mut readme_file = File::create(&readme_path).unwrap(); readme_file - .write(format!("Contents of {}", filename).to_string().as_bytes()) + .write_all(format!("Contents of {filename}").as_bytes()) .expect("Couldn't write readme"); readme_path } @@ -123,5 +123,5 @@ fn assert_readme_contents(parsed_dom: &Document, filename: &str) { .unwrap() .text() .trim() - .contains(&format!("Contents of {}", filename))); + .contains(&format!("Contents of {filename}"))); } diff --git a/tests/serve_request.rs b/tests/serve_request.rs index f376469..e717525 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -51,7 +51,7 @@ fn serves_requests_with_non_default_port(server: TestServer) -> Result<(), Error let f = parsed.find(|x: &Node| x.text() == file).next().unwrap(); reqwest::blocking::get(server.url().join(f.attr("href").unwrap())?)?.error_for_status()?; assert_eq!( - format!("/{}", file), + format!("/{file}"), percent_encoding::percent_decode_str(f.attr("href").unwrap()).decode_utf8_lossy(), ); } @@ -61,8 +61,7 @@ fn serves_requests_with_non_default_port(server: TestServer) -> Result<(), Error .find(|x: &Node| x.text() == directory) .next() .is_some()); - let dir_body = - reqwest::blocking::get(server.url().join(&directory)?)?.error_for_status()?; + let dir_body = reqwest::blocking::get(server.url().join(directory)?)?.error_for_status()?; let dir_body_parsed = Document::from_read(dir_body)?; for &file in FILES { assert!(dir_body_parsed @@ -80,23 +79,22 @@ fn serves_requests_hidden_files(#[with(&["--hidden"])] server: TestServer) -> Re let body = reqwest::blocking::get(server.url())?.error_for_status()?; let parsed = Document::from_read(body)?; - for &file in FILES.into_iter().chain(HIDDEN_FILES) { + for &file in FILES.iter().chain(HIDDEN_FILES) { let f = parsed.find(|x: &Node| x.text() == file).next().unwrap(); assert_eq!( - format!("/{}", file), + format!("/{file}"), percent_encoding::percent_decode_str(f.attr("href").unwrap()).decode_utf8_lossy(), ); } - for &directory in DIRECTORIES.into_iter().chain(HIDDEN_DIRECTORIES) { + for &directory in DIRECTORIES.iter().chain(HIDDEN_DIRECTORIES) { assert!(parsed .find(|x: &Node| x.text() == directory) .next() .is_some()); - let dir_body = - reqwest::blocking::get(server.url().join(&directory)?)?.error_for_status()?; + let dir_body = reqwest::blocking::get(server.url().join(directory)?)?.error_for_status()?; let dir_body_parsed = Document::from_read(dir_body)?; - for &file in FILES.into_iter().chain(HIDDEN_FILES) { + for &file in FILES.iter().chain(HIDDEN_FILES) { assert!(dir_body_parsed .find(|x: &Node| x.text() == file) .next() @@ -112,12 +110,12 @@ fn serves_requests_no_hidden_files_without_flag(server: TestServer) -> Result<() let body = reqwest::blocking::get(server.url())?.error_for_status()?; let parsed = Document::from_read(body)?; - for &hidden_item in HIDDEN_FILES.into_iter().chain(HIDDEN_DIRECTORIES) { + for &hidden_item in HIDDEN_FILES.iter().chain(HIDDEN_DIRECTORIES) { assert!(parsed .find(|x: &Node| x.text() == hidden_item) .next() .is_none()); - let resp = reqwest::blocking::get(server.url().join(&hidden_item)?)?; + let resp = reqwest::blocking::get(server.url().join(hidden_item)?)?; assert_eq!(resp.status(), StatusCode::BAD_REQUEST); } @@ -139,8 +137,8 @@ fn serves_requests_symlinks( // Set up some basic symlinks: // to dir, to file, to non-existent location - let orig = DIRECTORIES[0].strip_suffix("/").unwrap(); - let link = server.path().join(dir.strip_suffix("/").unwrap()); + let orig = DIRECTORIES[0].strip_suffix('/').unwrap(); + let link = server.path().join(dir.strip_suffix('/').unwrap()); symlink_dir(orig, link).expect("Couldn't create symlink"); symlink_file(FILES[0], server.path().join(file)).expect("Couldn't create symlink"); symlink_file("should-not-exist.xxx", server.path().join(broken)) @@ -150,7 +148,7 @@ fn serves_requests_symlinks( let parsed = Document::from_read(body)?; for &entry in &[file, dir] { - let status = reqwest::blocking::get(server.url().join(&entry)?)?.status(); + let status = reqwest::blocking::get(server.url().join(entry)?)?.status(); // We expect a 404 here for when `no_symlinks` is `true`. if no_symlinks { assert_eq!(status, StatusCode::NOT_FOUND); @@ -175,8 +173,8 @@ fn serves_requests_symlinks( } let node = node.unwrap(); - assert_eq!(node.attr("href").unwrap().strip_prefix("/").unwrap(), entry); - if entry.ends_with("/") { + assert_eq!(node.attr("href").unwrap().strip_prefix('/').unwrap(), entry); + if entry.ends_with('/') { let node = parsed .find(|x: &Node| x.name().unwrap_or_default() == "a" && x.text() == DIRECTORIES[0]) .next(); @@ -198,7 +196,7 @@ fn serves_requests_with_randomly_assigned_port(tmpdir: TempDir) -> Result<(), Er let mut child = Command::cargo_bin("miniserve")? .arg(tmpdir.path()) .arg("-p") - .arg("0".to_string()) + .arg("0") .stdout(Stdio::piped()) .spawn()?; diff --git a/tests/tls.rs b/tests/tls.rs index 6aa9460..a1c819a 100644 --- a/tests/tls.rs +++ b/tests/tls.rs @@ -34,7 +34,7 @@ fn tls_works(#[case] server: TestServer) -> Result<(), Error> { #[rstest] fn wrong_path_cert() -> Result<(), Error> { Command::cargo_bin("miniserve")? - .args(&["--tls-cert", "wrong", "--tls-key", "tests/data/key.pem"]) + .args(["--tls-cert", "wrong", "--tls-key", "tests/data/key.pem"]) .assert() .failure() .stderr(contains("Error: Couldn't access TLS certificate \"wrong\"")); @@ -46,7 +46,7 @@ fn wrong_path_cert() -> Result<(), Error> { #[rstest] fn wrong_path_key() -> Result<(), Error> { Command::cargo_bin("miniserve")? - .args(&["--tls-cert", "tests/data/cert.pem", "--tls-key", "wrong"]) + .args(["--tls-cert", "tests/data/cert.pem", "--tls-key", "wrong"]) .assert() .failure() .stderr(contains("Error: Couldn't access TLS key \"wrong\"")); diff --git a/tests/upload_files.rs b/tests/upload_files.rs index 196f3cd..8cb3e8e 100644 --- a/tests/upload_files.rs +++ b/tests/upload_files.rs @@ -189,7 +189,8 @@ fn prevent_path_traversal_attacks( create_dir_all(server.path().join("foo")).unwrap(); if !cfg!(windows) { for dir in &["C:/foo/C:", r"C:\foo", r"\foo"] { - create_dir_all(server.path().join(dir)).expect(&format!("failed to create: {:?}", dir)); + create_dir_all(server.path().join(dir)) + .unwrap_or_else(|_| panic!("failed to create: {dir:?}")); } } @@ -203,7 +204,7 @@ fn prevent_path_traversal_attacks( let form = multipart::Form::new().part("file_to_upload", part); Client::new() - .post(server.url().join(&format!("/upload?path={}", path))?) + .post(server.url().join(&format!("/upload?path={path}"))?) .multipart(form) .send()? .error_for_status()?; @@ -243,7 +244,7 @@ fn upload_to_symlink_directory( let form = multipart::Form::new().part("file_to_upload", part); let status = Client::new() - .post(server.url().join(&format!("/upload?path={}", dir))?) + .post(server.url().join(&format!("/upload?path={dir}"))?) .multipart(form) .send()? .error_for_status(); |