From d6804fe450221feb2e7f4c9e82fdb491c21804d6 Mon Sep 17 00:00:00 2001
From: Felix Fontein <felix@fontein.de>
Date: Tue, 26 Dec 2023 17:08:08 +0100
Subject: [PATCH 1/3] Run cargo fmt.

Signed-off-by: Felix Fontein <felix@fontein.de>
---
 functional-tests/src/lib.rs | 505 ++++++++++++++++++++++--------------
 1 file changed, 309 insertions(+), 196 deletions(-)

diff --git a/functional-tests/src/lib.rs b/functional-tests/src/lib.rs
index 98881d4ee..1ec31f9ca 100644
--- a/functional-tests/src/lib.rs
+++ b/functional-tests/src/lib.rs
@@ -1,7 +1,7 @@
-extern crate tempdir;
 extern crate serde;
 extern crate serde_json;
 extern crate serde_yaml;
+extern crate tempdir;
 #[macro_use]
 extern crate lazy_static;
 #[macro_use]
@@ -13,13 +13,13 @@ mod tests {
     extern crate serde_json;
     extern crate serde_yaml;
 
+    use serde_yaml::Value;
     use std::env;
     use std::fs::File;
-    use std::io::{Write, Read};
-    use tempdir::TempDir;
-    use std::process::Command;
-    use serde_yaml::Value;
+    use std::io::{Read, Write};
     use std::path::Path;
+    use std::process::Command;
+    use tempdir::TempDir;
     const SOPS_BINARY_PATH: &'static str = "./sops";
     const KMS_KEY: &'static str = "FUNCTIONAL_TEST_KMS_ARN";
 
@@ -28,33 +28,37 @@ mod tests {
             assert!($object.get(&$key).is_some());
             match *$object.get(&$key).unwrap() {
                 Value::String(ref s) => {
-                   assert!(s.starts_with("ENC["), "Value is not encrypted");
+                    assert!(s.starts_with("ENC["), "Value is not encrypted");
                 }
                 _ => panic!("Value under key was not a string"),
             }
-        }
+        };
     }
 
     lazy_static! {
-        static ref TMP_DIR: TempDir = TempDir::new("sops-functional-tests")
-            .expect("Unable to create temporary directory");
+        static ref TMP_DIR: TempDir =
+            TempDir::new("sops-functional-tests").expect("Unable to create temporary directory");
     }
 
     fn prepare_temp_file(name: &str, contents: &[u8]) -> String {
         let file_path = TMP_DIR.path().join(name);
-        let mut tmp_file = File::create(file_path.clone()).expect("Unable to create temporary file");
-        tmp_file.write_all(&contents)
+        let mut tmp_file =
+            File::create(file_path.clone()).expect("Unable to create temporary file");
+        tmp_file
+            .write_all(&contents)
             .expect("Error writing to temporary file");
         file_path.to_string_lossy().into_owned()
     }
 
     #[test]
     fn encrypt_json_file() {
-        let file_path = prepare_temp_file("test_encrypt.json",
-                                          b"{
+        let file_path = prepare_temp_file(
+            "test_encrypt.json",
+            b"{
     \"foo\": 2,
     \"bar\": \"baz\"
-}");
+}",
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-e")
             .arg(file_path.clone())
@@ -65,8 +69,10 @@ mod tests {
         let data: Value = serde_json::from_str(json).expect("Error parsing sops's JSON output");
         match data.into() {
             Value::Mapping(m) => {
-                assert!(m.get(&Value::String("sops".to_owned())).is_some(),
-                        "sops metadata branch not found");
+                assert!(
+                    m.get(&Value::String("sops".to_owned())).is_some(),
+                    "sops metadata branch not found"
+                );
                 assert_encrypted!(&m, Value::String("foo".to_owned()));
                 assert_encrypted!(&m, Value::String("bar".to_owned()));
             }
@@ -77,87 +83,105 @@ mod tests {
     #[test]
     #[ignore]
     fn publish_json_file_s3() {
-        let file_path = prepare_temp_file("test_encrypt_publish_s3.json",
-                                          b"{
+        let file_path = prepare_temp_file(
+            "test_encrypt_publish_s3.json",
+            b"{
     \"foo\": 2,
     \"bar\": \"baz\"
-}");
-        assert!(Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops")
-            .status
-            .success(),
-            "SOPS failed to encrypt a file");
-        assert!(Command::new(SOPS_BINARY_PATH)
-            .arg("publish")
-            .arg("--yes")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops")
-            .status
-            .success(),
-            "sops failed to publish a file to S3");
+}",
+        );
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "SOPS failed to encrypt a file"
+        );
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("publish")
+                .arg("--yes")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops failed to publish a file to S3"
+        );
 
         //TODO: Check that file exists in S3 Bucket
     }
 
     #[test]
     fn publish_json_file_vault() {
-        let file_path = prepare_temp_file("test_encrypt_publish_vault.json",
-                                          b"{
+        let file_path = prepare_temp_file(
+            "test_encrypt_publish_vault.json",
+            b"{
     \"foo\": 2,
     \"bar\": \"baz\"
-}");
-        assert!(Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops")
-            .status
-            .success(),
-            "SOPS failed to encrypt a file");
-        assert!(Command::new(SOPS_BINARY_PATH)
-            .arg("publish")
-            .arg("--yes")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops")
-            .status
-            .success(),
-            "sops failed to publish a file to Vault");
+}",
+        );
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "SOPS failed to encrypt a file"
+        );
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("publish")
+                .arg("--yes")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops failed to publish a file to Vault"
+        );
 
         //TODO: Check that file exists in Vault
     }
 
     #[test]
     fn publish_json_file_vault_version_1() {
-        let file_path = prepare_temp_file("test_encrypt_publish_vault_version_1.json",
-                                          b"{
+        let file_path = prepare_temp_file(
+            "test_encrypt_publish_vault_version_1.json",
+            b"{
     \"foo\": 2,
     \"bar\": \"baz\"
-}");
-        assert!(Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops")
-            .status
-            .success(),
-            "SOPS failed to encrypt a file");
-        assert!(Command::new(SOPS_BINARY_PATH)
-            .arg("publish")
-            .arg("--yes")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops")
-            .status
-            .success(),
-            "sops failed to publish a file to Vault");
+}",
+        );
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "SOPS failed to encrypt a file"
+        );
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("publish")
+                .arg("--yes")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops failed to publish a file to Vault"
+        );
 
         //TODO: Check that file exists in Vault
     }
@@ -165,13 +189,16 @@ mod tests {
     #[test]
     #[ignore]
     fn encrypt_json_file_kms() {
-        let kms_arn = env::var(KMS_KEY).expect("Expected $FUNCTIONAL_TEST_KMS_ARN env var to be set");
+        let kms_arn =
+            env::var(KMS_KEY).expect("Expected $FUNCTIONAL_TEST_KMS_ARN env var to be set");
 
-        let file_path = prepare_temp_file("test_encrypt_kms.json",
-                                          b"{
+        let file_path = prepare_temp_file(
+            "test_encrypt_kms.json",
+            b"{
     \"foo\": 2,
     \"bar\": \"baz\"
-}");
+}",
+        );
 
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("--kms")
@@ -185,8 +212,10 @@ mod tests {
         let data: Value = serde_json::from_str(json).expect("Error parsing sops's JSON output");
         match data.into() {
             Value::Mapping(m) => {
-                assert!(m.get(&Value::String("sops".to_owned())).is_some(),
-                        "sops metadata branch not found");
+                assert!(
+                    m.get(&Value::String("sops".to_owned())).is_some(),
+                    "sops metadata branch not found"
+                );
                 assert_encrypted!(&m, Value::String("foo".to_owned()));
                 assert_encrypted!(&m, Value::String("bar".to_owned()));
             }
@@ -196,9 +225,11 @@ mod tests {
 
     #[test]
     fn encrypt_yaml_file() {
-        let file_path = prepare_temp_file("test_encrypt.yaml",
-                                          b"foo: 2
-bar: baz");
+        let file_path = prepare_temp_file(
+            "test_encrypt.yaml",
+            b"foo: 2
+bar: baz",
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-e")
             .arg(file_path.clone())
@@ -209,8 +240,10 @@ bar: baz");
         let data: Value = serde_yaml::from_str(&json).expect("Error parsing sops's JSON output");
         match data.into() {
             Value::Mapping(m) => {
-                assert!(m.get(&Value::String("sops".to_owned())).is_some(),
-                        "sops metadata branch not found");
+                assert!(
+                    m.get(&Value::String("sops".to_owned())).is_some(),
+                    "sops metadata branch not found"
+                );
                 assert_encrypted!(&m, Value::String("foo".to_owned()));
                 assert_encrypted!(&m, Value::String("bar".to_owned()));
             }
@@ -220,7 +253,8 @@ bar: baz");
 
     #[test]
     fn set_json_file_update() {
-        let file_path = prepare_temp_file("test_set_update.json", r#"{"a": 2, "b": "ba"}"#.as_bytes());
+        let file_path =
+            prepare_temp_file("test_set_update.json", r#"{"a": 2, "b": "ba"}"#.as_bytes());
         Command::new(SOPS_BINARY_PATH)
             .arg("-e")
             .arg("-i")
@@ -233,11 +267,16 @@ bar: baz");
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        println!("stdout: {}, stderr: {}",
-                 String::from_utf8_lossy(&output.stdout),
-                 String::from_utf8_lossy(&output.stderr));
+        println!(
+            "stdout: {}, stderr: {}",
+            String::from_utf8_lossy(&output.stdout),
+            String::from_utf8_lossy(&output.stderr)
+        );
         let mut s = String::new();
-        File::open(file_path).unwrap().read_to_string(&mut s).unwrap();
+        File::open(file_path)
+            .unwrap()
+            .read_to_string(&mut s)
+            .unwrap();
         let data: Value = serde_json::from_str(&s).expect("Error parsing sops's JSON output");
         if let Value::Mapping(data) = data {
             let a = data.get(&Value::String("a".to_owned())).unwrap();
@@ -251,7 +290,8 @@ bar: baz");
 
     #[test]
     fn set_json_file_insert() {
-        let file_path = prepare_temp_file("test_set_insert.json", r#"{"a": 2, "b": "ba"}"#.as_bytes());
+        let file_path =
+            prepare_temp_file("test_set_insert.json", r#"{"a": 2, "b": "ba"}"#.as_bytes());
         Command::new(SOPS_BINARY_PATH)
             .arg("-e")
             .arg("-i")
@@ -264,11 +304,16 @@ bar: baz");
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        println!("stdout: {}, stderr: {}",
-                 String::from_utf8_lossy(&output.stdout),
-                 String::from_utf8_lossy(&output.stderr));
+        println!(
+            "stdout: {}, stderr: {}",
+            String::from_utf8_lossy(&output.stdout),
+            String::from_utf8_lossy(&output.stderr)
+        );
         let mut s = String::new();
-        File::open(file_path).unwrap().read_to_string(&mut s).unwrap();
+        File::open(file_path)
+            .unwrap()
+            .read_to_string(&mut s)
+            .unwrap();
         let data: Value = serde_json::from_str(&s).expect("Error parsing sops's JSON output");
         if let Value::Mapping(data) = data {
             let a = data.get(&Value::String("c".to_owned())).unwrap();
@@ -280,13 +325,14 @@ bar: baz");
         panic!("Output JSON does not have the expected structure");
     }
 
-
     #[test]
     fn set_yaml_file_update() {
-        let file_path = prepare_temp_file("test_set_update.yaml",
-                                          r#"a: 2
+        let file_path = prepare_temp_file(
+            "test_set_update.yaml",
+            r#"a: 2
 b: ba"#
-                                              .as_bytes());
+                .as_bytes(),
+        );
         Command::new(SOPS_BINARY_PATH)
             .arg("-e")
             .arg("-i")
@@ -299,11 +345,16 @@ b: ba"#
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        println!("stdout: {}, stderr: {}",
-                 String::from_utf8_lossy(&output.stdout),
-                 String::from_utf8_lossy(&output.stderr));
+        println!(
+            "stdout: {}, stderr: {}",
+            String::from_utf8_lossy(&output.stdout),
+            String::from_utf8_lossy(&output.stderr)
+        );
         let mut s = String::new();
-        File::open(file_path).unwrap().read_to_string(&mut s).unwrap();
+        File::open(file_path)
+            .unwrap()
+            .read_to_string(&mut s)
+            .unwrap();
         let data: Value = serde_yaml::from_str(&s).expect("Error parsing sops's JSON output");
         if let Value::Mapping(data) = data {
             let a = data.get(&Value::String("a".to_owned())).unwrap();
@@ -317,10 +368,12 @@ b: ba"#
 
     #[test]
     fn set_yaml_file_insert() {
-        let file_path = prepare_temp_file("test_set_insert.yaml",
-                                          r#"a: 2
+        let file_path = prepare_temp_file(
+            "test_set_insert.yaml",
+            r#"a: 2
 b: ba"#
-                                              .as_bytes());
+                .as_bytes(),
+        );
         Command::new(SOPS_BINARY_PATH)
             .arg("-e")
             .arg("-i")
@@ -333,11 +386,16 @@ b: ba"#
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        println!("stdout: {}, stderr: {}",
-                 String::from_utf8_lossy(&output.stdout),
-                 String::from_utf8_lossy(&output.stderr));
+        println!(
+            "stdout: {}, stderr: {}",
+            String::from_utf8_lossy(&output.stdout),
+            String::from_utf8_lossy(&output.stderr)
+        );
         let mut s = String::new();
-        File::open(file_path).unwrap().read_to_string(&mut s).unwrap();
+        File::open(file_path)
+            .unwrap()
+            .read_to_string(&mut s)
+            .unwrap();
         let data: Value = serde_yaml::from_str(&s).expect("Error parsing sops's JSON output");
         if let Value::Mapping(data) = data {
             let a = data.get(&Value::String("c".to_owned())).unwrap();
@@ -351,10 +409,12 @@ b: ba"#
 
     #[test]
     fn set_yaml_file_string() {
-        let file_path = prepare_temp_file("test_set_string.yaml",
-                                          r#"a: 2
+        let file_path = prepare_temp_file(
+            "test_set_string.yaml",
+            r#"a: 2
 b: ba"#
-                                          .as_bytes());
+                .as_bytes(),
+        );
         Command::new(SOPS_BINARY_PATH)
             .arg("-e")
             .arg("-i")
@@ -375,11 +435,16 @@ b: ba"#
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        println!("stdout: {}, stderr: {}",
-                 String::from_utf8_lossy(&output.stdout),
-                 String::from_utf8_lossy(&output.stderr));
+        println!(
+            "stdout: {}, stderr: {}",
+            String::from_utf8_lossy(&output.stdout),
+            String::from_utf8_lossy(&output.stderr)
+        );
         let mut s = String::new();
-        File::open(file_path).unwrap().read_to_string(&mut s).unwrap();
+        File::open(file_path)
+            .unwrap()
+            .read_to_string(&mut s)
+            .unwrap();
         let data: Value = serde_yaml::from_str(&s).expect("Error parsing sops's YAML output");
         if let Value::Mapping(data) = data {
             let a = data.get(&Value::String("a".to_owned())).unwrap();
@@ -391,25 +456,32 @@ b: ba"#
 
     #[test]
     fn decrypt_file_no_mac() {
-        let file_path = prepare_temp_file("test_decrypt_no_mac.yaml", include_bytes!("../res/no_mac.yaml"));
-        assert!(!Command::new(SOPS_BINARY_PATH)
-                    .arg("-d")
-                    .arg(file_path.clone())
-                    .output()
-                    .expect("Error running sops")
-                    .status
-                    .success(),
-                "SOPS allowed decrypting a file with no MAC without --ignore-mac");
-
-        assert!(Command::new(SOPS_BINARY_PATH)
-                    .arg("-d")
-                    .arg("--ignore-mac")
-                    .arg(file_path.clone())
-                    .output()
-                    .expect("Error running sops")
-                    .status
-                    .success(),
-                "SOPS failed to decrypt a file with no MAC with --ignore-mac passed in");
+        let file_path = prepare_temp_file(
+            "test_decrypt_no_mac.yaml",
+            include_bytes!("../res/no_mac.yaml"),
+        );
+        assert!(
+            !Command::new(SOPS_BINARY_PATH)
+                .arg("-d")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "SOPS allowed decrypting a file with no MAC without --ignore-mac"
+        );
+
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-d")
+                .arg("--ignore-mac")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "SOPS failed to decrypt a file with no MAC with --ignore-mac passed in"
+        );
     }
 
     #[test]
@@ -421,8 +493,14 @@ b: ba"#
             .output()
             .expect("Error running sops");
         assert!(output.status.success(), "SOPS didn't return successfully");
-        assert!(!String::from_utf8_lossy(&output.stdout).contains("first comment in file"), "Comment was not encrypted");
-        assert!(!String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"), "Comment was not encrypted");
+        assert!(
+            !String::from_utf8_lossy(&output.stdout).contains("first comment in file"),
+            "Comment was not encrypted"
+        );
+        assert!(
+            !String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"),
+            "Comment was not encrypted"
+        );
     }
 
     #[test]
@@ -434,34 +512,52 @@ b: ba"#
             .output()
             .expect("Error running sops");
         assert!(output.status.success(), "SOPS didn't return successfully");
-        assert!(!String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"), "Comment was not encrypted");
-        assert!(!String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"), "Comment was not encrypted");
+        assert!(
+            !String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"),
+            "Comment was not encrypted"
+        );
+        assert!(
+            !String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"),
+            "Comment was not encrypted"
+        );
     }
 
     #[test]
     fn decrypt_comments() {
         let file_path = "res/comments.enc.yaml";
         let output = Command::new(SOPS_BINARY_PATH)
-                    .arg("-d")
-                    .arg(file_path.clone())
-                    .output()
-                    .expect("Error running sops");
+            .arg("-d")
+            .arg(file_path.clone())
+            .output()
+            .expect("Error running sops");
         assert!(output.status.success(), "SOPS didn't return successfully");
-        assert!(String::from_utf8_lossy(&output.stdout).contains("first comment in file"), "Comment was not decrypted");
-        assert!(String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"), "Comment was not decrypted");
+        assert!(
+            String::from_utf8_lossy(&output.stdout).contains("first comment in file"),
+            "Comment was not decrypted"
+        );
+        assert!(
+            String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"),
+            "Comment was not decrypted"
+        );
     }
 
     #[test]
     fn decrypt_comments_unencrypted_comments() {
         let file_path = "res/comments_unencrypted_comments.yaml";
         let output = Command::new(SOPS_BINARY_PATH)
-                    .arg("-d")
-                    .arg(file_path.clone())
-                    .output()
-                    .expect("Error running sops");
+            .arg("-d")
+            .arg(file_path.clone())
+            .output()
+            .expect("Error running sops");
         assert!(output.status.success(), "SOPS didn't return successfully");
-        assert!(String::from_utf8_lossy(&output.stdout).contains("first comment in file"), "Comment was not decrypted");
-        assert!(String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"), "Comment was not decrypted");
+        assert!(
+            String::from_utf8_lossy(&output.stdout).contains("first comment in file"),
+            "Comment was not decrypted"
+        );
+        assert!(
+            String::from_utf8_lossy(&output.stdout).contains("this-is-a-comment"),
+            "Comment was not decrypted"
+        );
     }
 
     #[test]
@@ -474,16 +570,19 @@ b: ba"#
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status.success(),
-                "SOPS failed to encrypt a file with Shamir Secret Sharing");
+        assert!(
+            output.status.success(),
+            "SOPS failed to encrypt a file with Shamir Secret Sharing"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-d")
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status
-                    .success(),
-                "SOPS failed to decrypt a file with Shamir Secret Sharing");
+        assert!(
+            output.status.success(),
+            "SOPS failed to decrypt a file with Shamir Secret Sharing"
+        );
         assert!(String::from_utf8_lossy(&output.stdout).contains("secret"));
     }
 
@@ -491,45 +590,54 @@ b: ba"#
     fn roundtrip_shamir_missing_decryption_key() {
         // The .sops.yaml file ensures this file is encrypted with two key groups, each with one GPG key,
         // but we don't have one of the private keys
-        let file_path = prepare_temp_file("test_roundtrip_keygroups_missing_decryption_key.yaml",
-                                          "a: secret".as_bytes());
+        let file_path = prepare_temp_file(
+            "test_roundtrip_keygroups_missing_decryption_key.yaml",
+            "a: secret".as_bytes(),
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-i")
             .arg("-e")
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status.success(),
-                "SOPS failed to encrypt a file with Shamir Secret Sharing");
+        assert!(
+            output.status.success(),
+            "SOPS failed to encrypt a file with Shamir Secret Sharing"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-d")
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(!output.status
-                    .success(),
-                "SOPS succeeded decrypting a file with a missing decryption key");
+        assert!(
+            !output.status.success(),
+            "SOPS succeeded decrypting a file with a missing decryption key"
+        );
     }
 
     #[test]
     fn test_decrypt_file_multiple_keys() {
-        let file_path = prepare_temp_file("test_decrypt_file_multiple_keys.yaml",
-                                          include_bytes!("../res/multiple_keys.yaml"));
+        let file_path = prepare_temp_file(
+            "test_decrypt_file_multiple_keys.yaml",
+            include_bytes!("../res/multiple_keys.yaml"),
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-d")
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status
-                    .success(),
-                "SOPS failed to decrypt a file that uses multiple keys");
+        assert!(
+            output.status.success(),
+            "SOPS failed to decrypt a file that uses multiple keys"
+        );
     }
 
-
     #[test]
     fn extract_string() {
-        let file_path = prepare_temp_file("test_extract_string.yaml",
-                                          "multiline: |\n  multi\n  line".as_bytes());
+        let file_path = prepare_temp_file(
+            "test_extract_string.yaml",
+            "multiline: |\n  multi\n  line".as_bytes(),
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-i")
             .arg("-e")
@@ -544,14 +652,11 @@ b: ba"#
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status
-                    .success(),
-                "SOPS failed to extract");
+        assert!(output.status.success(), "SOPS failed to extract");
 
         assert_eq!(output.stdout, b"multi\nline");
     }
 
-
     #[test]
     fn roundtrip_binary() {
         let data = b"\"\"{}this_is_binary_data";
@@ -562,29 +667,35 @@ b: ba"#
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status.success(),
-                "SOPS failed to encrypt a binary file");
+        assert!(
+            output.status.success(),
+            "SOPS failed to encrypt a binary file"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-d")
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status
-                    .success(),
-                "SOPS failed to decrypt a binary file");
+        assert!(
+            output.status.success(),
+            "SOPS failed to decrypt a binary file"
+        );
         assert_eq!(output.stdout, data);
     }
 
     #[test]
     #[ignore]
     fn roundtrip_kms_encryption_context() {
-        let kms_arn = env::var(KMS_KEY).expect("Expected $FUNCTIONAL_TEST_KMS_ARN env var to be set");
+        let kms_arn =
+            env::var(KMS_KEY).expect("Expected $FUNCTIONAL_TEST_KMS_ARN env var to be set");
 
-        let file_path = prepare_temp_file("test_roundtrip_kms_encryption_context.json",
-                                          b"{
+        let file_path = prepare_temp_file(
+            "test_roundtrip_kms_encryption_context.json",
+            b"{
     \"foo\": 2,
     \"bar\": \"baz\"
-}");
+}",
+        );
 
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("--kms")
@@ -603,9 +714,10 @@ b: ba"#
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status
-                    .success(),
-                "SOPS failed to decrypt a file with KMS Encryption Context");
+        assert!(
+            output.status.success(),
+            "SOPS failed to decrypt a file with KMS Encryption Context"
+        );
         assert!(String::from_utf8_lossy(&output.stdout).contains("foo"));
         assert!(String::from_utf8_lossy(&output.stdout).contains("baz"));
     }
@@ -621,9 +733,10 @@ b: ba"#
             .arg(input_path.clone())
             .output()
             .expect("Error running sops");
-        assert!(output.status
-                    .success(),
-                "SOPS failed to decrypt a binary file");
+        assert!(
+            output.status.success(),
+            "SOPS failed to decrypt a binary file"
+        );
         assert_eq!(output.stdout, <&[u8]>::default());
         let mut f = File::open(&output_path).expect("output file not found");
 

From 2290395f8785ea86dc4e1d4df48b449e6c836189 Mon Sep 17 00:00:00 2001
From: Felix Fontein <felix@fontein.de>
Date: Tue, 26 Dec 2023 17:12:01 +0100
Subject: [PATCH 2/3] Test more status codes.

Signed-off-by: Felix Fontein <felix@fontein.de>
---
 functional-tests/src/lib.rs | 111 ++++++++++++++++++++++++------------
 1 file changed, 73 insertions(+), 38 deletions(-)

diff --git a/functional-tests/src/lib.rs b/functional-tests/src/lib.rs
index 1ec31f9ca..a6424de82 100644
--- a/functional-tests/src/lib.rs
+++ b/functional-tests/src/lib.rs
@@ -255,18 +255,24 @@ bar: baz",
     fn set_json_file_update() {
         let file_path =
             prepare_temp_file("test_set_update.json", r#"{"a": 2, "b": "ba"}"#.as_bytes());
-        Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops");
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops didn't exit successfully"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("--set")
             .arg(r#"["a"] {"aa": "aaa"}"#)
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
+        assert!(output.status.success(), "sops didn't exit successfully");
         println!(
             "stdout: {}, stderr: {}",
             String::from_utf8_lossy(&output.stdout),
@@ -292,18 +298,24 @@ bar: baz",
     fn set_json_file_insert() {
         let file_path =
             prepare_temp_file("test_set_insert.json", r#"{"a": 2, "b": "ba"}"#.as_bytes());
-        Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops");
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops didn't exit successfully"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("--set")
             .arg(r#"["c"] {"cc": "ccc"}"#)
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
+        assert!(output.status.success(), "sops didn't exit successfully");
         println!(
             "stdout: {}, stderr: {}",
             String::from_utf8_lossy(&output.stdout),
@@ -333,18 +345,24 @@ bar: baz",
 b: ba"#
                 .as_bytes(),
         );
-        Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops");
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops didn't exit successfully"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("--set")
             .arg(r#"["a"] {"aa": "aaa"}"#)
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
+        assert!(output.status.success(), "sops didn't exit successfully");
         println!(
             "stdout: {}, stderr: {}",
             String::from_utf8_lossy(&output.stdout),
@@ -374,18 +392,24 @@ b: ba"#
 b: ba"#
                 .as_bytes(),
         );
-        Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops");
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops didn't exit successfully"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("--set")
             .arg(r#"["c"] {"cc": "ccc"}"#)
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
+        assert!(output.status.success(), "sops didn't exit successfully");
         println!(
             "stdout: {}, stderr: {}",
             String::from_utf8_lossy(&output.stdout),
@@ -415,26 +439,37 @@ b: ba"#
 b: ba"#
                 .as_bytes(),
         );
-        Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops");
-        Command::new(SOPS_BINARY_PATH)
-            .arg("-e")
-            .arg("-i")
-            .arg("--set")
-            .arg(r#"["a"] "aaa""#)
-            .arg(file_path.clone())
-            .output()
-            .expect("Error running sops");
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops didn't exit successfully"
+        );
+        assert!(
+            Command::new(SOPS_BINARY_PATH)
+                .arg("-e")
+                .arg("-i")
+                .arg("--set")
+                .arg(r#"["a"] "aaa""#)
+                .arg(file_path.clone())
+                .output()
+                .expect("Error running sops")
+                .status
+                .success(),
+            "sops didn't exit successfully"
+        );
         let output = Command::new(SOPS_BINARY_PATH)
             .arg("-d")
             .arg("-i")
             .arg(file_path.clone())
             .output()
             .expect("Error running sops");
+        assert!(output.status.success(), "sops didn't exit successfully");
         println!(
             "stdout: {}, stderr: {}",
             String::from_utf8_lossy(&output.stdout),

From 2ca683141dadb8c0227886577589e31f1ce59b50 Mon Sep 17 00:00:00 2001
From: Felix Fontein <felix@fontein.de>
Date: Tue, 26 Dec 2023 17:13:34 +0100
Subject: [PATCH 3/3] Change double command (--encrypt --set) to single command
 (--set).

Signed-off-by: Felix Fontein <felix@fontein.de>
---
 functional-tests/src/lib.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/functional-tests/src/lib.rs b/functional-tests/src/lib.rs
index a6424de82..e37e2dfa2 100644
--- a/functional-tests/src/lib.rs
+++ b/functional-tests/src/lib.rs
@@ -452,10 +452,9 @@ b: ba"#
         );
         assert!(
             Command::new(SOPS_BINARY_PATH)
-                .arg("-e")
-                .arg("-i")
                 .arg("--set")
                 .arg(r#"["a"] "aaa""#)
+                .arg("-i")
                 .arg(file_path.clone())
                 .output()
                 .expect("Error running sops")
