1
use std::os::unix::fs::PermissionsExt;
2

            
3
use super::Store;
4

            
5
const ACCESS: &str = "AKIA-test-access-key";
6
const SECRET: &str = "s3kr1t-test-secret-key";
7

            
8
1
fn store() -> Store {
9
1
    Store {
10
1
        access_key: ACCESS.to_string(),
11
1
        secret_key: SECRET.to_string(),
12
1
        bucket: "bucket".to_string(),
13
1
        endpoint: "objects.example.test".to_string(),
14
1
    }
15
1
}
16

            
17
#[test]
18
1
fn a_failing_s3cmd_neither_prints_nor_receives_the_keys_in_argv() {
19
1
    let _processes = crate::test_support::processes();
20
1
    let scratch = tempfile::tempdir().expect("tempdir");
21
1
    let argv = scratch.path().join("argv");
22
1
    let config = scratch.path().join("config");
23
1
    let fake = scratch.path().join("s3cmd");
24
1
    std::fs::write(
25
1
        &fake,
26
1
        format!(
27
1
            "#!/bin/bash\necho \"$@\" > {}\ncp \"${{1#--config=}}\" {}\nexit 3\n",
28
1
            argv.display(),
29
1
            config.display()
30
1
        ),
31
1
    )
32
1
    .expect("fake s3cmd");
33
1
    std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).expect("chmod");
34

            
35
1
    let error = store()
36
1
        .run_s3(&fake.to_string_lossy(), &["put", "a", "b"])
37
1
        .expect_err("the fake fails");
38

            
39
1
    let message = format!("{error:#}");
40
1
    let recorded = std::fs::read_to_string(&argv).expect("argv recorded");
41
1
    for text in [&message, &recorded] {
42
2
        assert!(!text.contains(ACCESS) && !text.contains(SECRET), "{text}");
43
    }
44
1
    assert!(message.contains("exited with"), "{message}");
45
1
    let delivered = std::fs::read_to_string(&config).expect("config recorded");
46
1
    assert!(delivered.contains(ACCESS) && delivered.contains(SECRET));
47
1
}