Lines
100 %
Functions
Branches
use std::os::unix::fs::PermissionsExt;
use super::Store;
const ACCESS: &str = "AKIA-test-access-key";
const SECRET: &str = "s3kr1t-test-secret-key";
fn store() -> Store {
Store {
access_key: ACCESS.to_string(),
secret_key: SECRET.to_string(),
bucket: "bucket".to_string(),
endpoint: "objects.example.test".to_string(),
}
#[test]
fn a_failing_s3cmd_neither_prints_nor_receives_the_keys_in_argv() {
let _processes = crate::test_support::processes();
let scratch = tempfile::tempdir().expect("tempdir");
let argv = scratch.path().join("argv");
let config = scratch.path().join("config");
let fake = scratch.path().join("s3cmd");
std::fs::write(
&fake,
format!(
"#!/bin/bash\necho \"$@\" > {}\ncp \"${{1#--config=}}\" {}\nexit 3\n",
argv.display(),
config.display()
),
)
.expect("fake s3cmd");
std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).expect("chmod");
let error = store()
.run_s3(&fake.to_string_lossy(), &["put", "a", "b"])
.expect_err("the fake fails");
let message = format!("{error:#}");
let recorded = std::fs::read_to_string(&argv).expect("argv recorded");
for text in [&message, &recorded] {
assert!(!text.contains(ACCESS) && !text.contains(SECRET), "{text}");
assert!(message.contains("exited with"), "{message}");
let delivered = std::fs::read_to_string(&config).expect("config recorded");
assert!(delivered.contains(ACCESS) && delivered.contains(SECRET));