diff --git a/s3/src/bucket.rs b/s3/src/bucket.rs index 87b6d82628..e341d299c1 100644 --- a/s3/src/bucket.rs +++ b/s3/src/bucket.rs @@ -819,12 +819,12 @@ impl Bucket { /// /// # fn example() -> Result<(), S3Error> { /// let bucket = Bucket::new("my-bucket", Region::from_str("us-east-1")?, Credentials::default()?)? - /// .set_dangereous_config(true, true)?; + /// .set_dangerous_config(true, true)?; /// # Ok(()) /// # } - /// + /// ``` #[cfg(any(feature = "tokio-native-tls", feature = "tokio-rustls-tls"))] - pub fn set_dangereous_config( + pub fn set_dangerous_config( &self, accept_invalid_certs: bool, accept_invalid_hostnames: bool, @@ -847,6 +847,20 @@ impl Bucket { }) } + /// Deprecated alias for [`Bucket::set_dangerous_config`]. + #[deprecated( + since = "0.37.3", + note = "use `set_dangerous_config`; this misspelled method remains for compatibility" + )] + #[cfg(any(feature = "tokio-native-tls", feature = "tokio-rustls-tls"))] + pub fn set_dangereous_config( + &self, + accept_invalid_certs: bool, + accept_invalid_hostnames: bool, + ) -> Result { + self.set_dangerous_config(accept_invalid_certs, accept_invalid_hostnames) + } + #[cfg(feature = "with-tokio")] pub fn set_proxy(&self, proxy: reqwest::Proxy) -> Result { let mut options = self.client_options.clone(); @@ -3173,6 +3187,34 @@ mod test { assert_eq!(requests.load(Ordering::SeqCst), 1); } + #[test] + #[cfg(any(feature = "tokio-native-tls", feature = "tokio-rustls-tls"))] + #[allow(deprecated)] + fn dangerous_config_correct_spelling_and_compat_alias_set_same_options() { + let bucket = Bucket::new( + "test-bucket", + Region::Custom { + region: "test-region".to_owned(), + endpoint: "https://example.com".to_owned(), + }, + Credentials::anonymous().unwrap(), + ) + .unwrap(); + + let corrected = bucket.set_dangerous_config(true, true).unwrap(); + let deprecated_alias = bucket.set_dangereous_config(true, true).unwrap(); + + assert!(corrected.client_options.accept_invalid_certs); + assert!(corrected.client_options.accept_invalid_hostnames); + assert_eq!( + corrected.client_options.accept_invalid_certs, + deprecated_alias.client_options.accept_invalid_certs + ); + assert_eq!( + corrected.client_options.accept_invalid_hostnames, + deprecated_alias.client_options.accept_invalid_hostnames + ); + } fn test_aws_credentials() -> Credentials { Credentials::new( Some(&env::var("EU_AWS_ACCESS_KEY_ID").unwrap()), @@ -4398,7 +4440,7 @@ mod test { .with_path_style(); // Set dangerous config (allow invalid certs, allow invalid hostnames) - let bucket = bucket.set_dangereous_config(true, true).unwrap(); + let bucket = bucket.set_dangerous_config(true, true).unwrap(); // Test that exists() works with the dangerous config // This should not panic or fail due to SSL certificate issues diff --git a/s3/src/utils/mod.rs b/s3/src/utils/mod.rs index 04918ccf19..3ec56ff23c 100644 --- a/s3/src/utils/mod.rs +++ b/s3/src/utils/mod.rs @@ -433,39 +433,54 @@ mod test { use std::fs::File; use std::io::Cursor; use std::io::prelude::*; + use std::path::PathBuf; fn object(size: u32) -> Vec { (0..size).map(|_| 33).collect() } + fn etag_test_path(test_name: &str) -> PathBuf { + let mut path = std::env::temp_dir(); + let unique = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos(); + + path.push(format!( + "rust-s3-{test_name}-{}-{unique}", + std::process::id() + )); + path + } + #[test] fn test_etag_large_file() { - let path = "test_etag"; - std::fs::remove_file(path).unwrap_or(()); + let path = etag_test_path("etag-large-file"); + std::fs::remove_file(&path).unwrap_or(()); let test: Vec = object(10_000_000); - let mut file = File::create(path).unwrap(); + let mut file = File::create(&path).unwrap(); file.write_all(&test).unwrap(); - let etag = etag_for_path(path).unwrap(); + let etag = etag_for_path(&path).unwrap(); - std::fs::remove_file(path).unwrap_or(()); + std::fs::remove_file(&path).unwrap_or(()); assert_eq!(etag, "e438487f09f09c042b2de097765e5ac2-2"); } #[test] fn test_etag_small_file() { - let path = "test_etag"; - std::fs::remove_file(path).unwrap_or(()); + let path = etag_test_path("etag-small-file"); + std::fs::remove_file(&path).unwrap_or(()); let test: Vec = object(1000); - let mut file = File::create(path).unwrap(); + let mut file = File::create(&path).unwrap(); file.write_all(&test).unwrap(); - let etag = etag_for_path(path).unwrap(); + let etag = etag_for_path(&path).unwrap(); - std::fs::remove_file(path).unwrap_or(()); + std::fs::remove_file(&path).unwrap_or(()); assert_eq!(etag, "8122ef1c2b2331f7986349560248cf56"); }