Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions s3/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Bucket, S3Error> {
self.set_dangerous_config(accept_invalid_certs, accept_invalid_hostnames)
}

#[cfg(feature = "with-tokio")]
pub fn set_proxy(&self, proxy: reqwest::Proxy) -> Result<Bucket, S3Error> {
let mut options = self.client_options.clone();
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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
Expand Down
35 changes: 25 additions & 10 deletions s3/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
(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<u8> = 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<u8> = 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");
}
Expand Down
Loading