Skip to content

Commit b584ce7

Browse files
authored
Merge pull request #456 from durch/fix/issue-433-dangerous-config-typo
Fix dangerous config method typo
2 parents 3ce16e8 + dc67eab commit b584ce7

2 files changed

Lines changed: 71 additions & 14 deletions

File tree

s3/src/bucket.rs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,12 @@ impl Bucket {
819819
///
820820
/// # fn example() -> Result<(), S3Error> {
821821
/// let bucket = Bucket::new("my-bucket", Region::from_str("us-east-1")?, Credentials::default()?)?
822-
/// .set_dangereous_config(true, true)?;
822+
/// .set_dangerous_config(true, true)?;
823823
/// # Ok(())
824824
/// # }
825-
///
825+
/// ```
826826
#[cfg(any(feature = "tokio-native-tls", feature = "tokio-rustls-tls"))]
827-
pub fn set_dangereous_config(
827+
pub fn set_dangerous_config(
828828
&self,
829829
accept_invalid_certs: bool,
830830
accept_invalid_hostnames: bool,
@@ -847,6 +847,20 @@ impl Bucket {
847847
})
848848
}
849849

850+
/// Deprecated alias for [`Bucket::set_dangerous_config`].
851+
#[deprecated(
852+
since = "0.37.3",
853+
note = "use `set_dangerous_config`; this misspelled method remains for compatibility"
854+
)]
855+
#[cfg(any(feature = "tokio-native-tls", feature = "tokio-rustls-tls"))]
856+
pub fn set_dangereous_config(
857+
&self,
858+
accept_invalid_certs: bool,
859+
accept_invalid_hostnames: bool,
860+
) -> Result<Bucket, S3Error> {
861+
self.set_dangerous_config(accept_invalid_certs, accept_invalid_hostnames)
862+
}
863+
850864
#[cfg(feature = "with-tokio")]
851865
pub fn set_proxy(&self, proxy: reqwest::Proxy) -> Result<Bucket, S3Error> {
852866
let mut options = self.client_options.clone();
@@ -3173,6 +3187,34 @@ mod test {
31733187
assert_eq!(requests.load(Ordering::SeqCst), 1);
31743188
}
31753189

3190+
#[test]
3191+
#[cfg(any(feature = "tokio-native-tls", feature = "tokio-rustls-tls"))]
3192+
#[allow(deprecated)]
3193+
fn dangerous_config_correct_spelling_and_compat_alias_set_same_options() {
3194+
let bucket = Bucket::new(
3195+
"test-bucket",
3196+
Region::Custom {
3197+
region: "test-region".to_owned(),
3198+
endpoint: "https://example.com".to_owned(),
3199+
},
3200+
Credentials::anonymous().unwrap(),
3201+
)
3202+
.unwrap();
3203+
3204+
let corrected = bucket.set_dangerous_config(true, true).unwrap();
3205+
let deprecated_alias = bucket.set_dangereous_config(true, true).unwrap();
3206+
3207+
assert!(corrected.client_options.accept_invalid_certs);
3208+
assert!(corrected.client_options.accept_invalid_hostnames);
3209+
assert_eq!(
3210+
corrected.client_options.accept_invalid_certs,
3211+
deprecated_alias.client_options.accept_invalid_certs
3212+
);
3213+
assert_eq!(
3214+
corrected.client_options.accept_invalid_hostnames,
3215+
deprecated_alias.client_options.accept_invalid_hostnames
3216+
);
3217+
}
31763218
fn test_aws_credentials() -> Credentials {
31773219
Credentials::new(
31783220
Some(&env::var("EU_AWS_ACCESS_KEY_ID").unwrap()),
@@ -4398,7 +4440,7 @@ mod test {
43984440
.with_path_style();
43994441

44004442
// Set dangerous config (allow invalid certs, allow invalid hostnames)
4401-
let bucket = bucket.set_dangereous_config(true, true).unwrap();
4443+
let bucket = bucket.set_dangerous_config(true, true).unwrap();
44024444

44034445
// Test that exists() works with the dangerous config
44044446
// This should not panic or fail due to SSL certificate issues

s3/src/utils/mod.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,39 +433,54 @@ mod test {
433433
use std::fs::File;
434434
use std::io::Cursor;
435435
use std::io::prelude::*;
436+
use std::path::PathBuf;
436437

437438
fn object(size: u32) -> Vec<u8> {
438439
(0..size).map(|_| 33).collect()
439440
}
440441

442+
fn etag_test_path(test_name: &str) -> PathBuf {
443+
let mut path = std::env::temp_dir();
444+
let unique = std::time::SystemTime::now()
445+
.duration_since(std::time::UNIX_EPOCH)
446+
.unwrap()
447+
.as_nanos();
448+
449+
path.push(format!(
450+
"rust-s3-{test_name}-{}-{unique}",
451+
std::process::id()
452+
));
453+
path
454+
}
455+
441456
#[test]
442457
fn test_etag_large_file() {
443-
let path = "test_etag";
444-
std::fs::remove_file(path).unwrap_or(());
458+
let path = etag_test_path("etag-large-file");
459+
std::fs::remove_file(&path).unwrap_or(());
445460
let test: Vec<u8> = object(10_000_000);
446461

447-
let mut file = File::create(path).unwrap();
462+
let mut file = File::create(&path).unwrap();
448463
file.write_all(&test).unwrap();
449464

450-
let etag = etag_for_path(path).unwrap();
465+
let etag = etag_for_path(&path).unwrap();
451466

452-
std::fs::remove_file(path).unwrap_or(());
467+
std::fs::remove_file(&path).unwrap_or(());
453468

454469
assert_eq!(etag, "e438487f09f09c042b2de097765e5ac2-2");
455470
}
456471

457472
#[test]
458473
fn test_etag_small_file() {
459-
let path = "test_etag";
460-
std::fs::remove_file(path).unwrap_or(());
474+
let path = etag_test_path("etag-small-file");
475+
std::fs::remove_file(&path).unwrap_or(());
461476
let test: Vec<u8> = object(1000);
462477

463-
let mut file = File::create(path).unwrap();
478+
let mut file = File::create(&path).unwrap();
464479
file.write_all(&test).unwrap();
465480

466-
let etag = etag_for_path(path).unwrap();
481+
let etag = etag_for_path(&path).unwrap();
467482

468-
std::fs::remove_file(path).unwrap_or(());
483+
std::fs::remove_file(&path).unwrap_or(());
469484

470485
assert_eq!(etag, "8122ef1c2b2331f7986349560248cf56");
471486
}

0 commit comments

Comments
 (0)