From 7716cc5a793a84925bca6298f669cc0ca70ca40a Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Mon, 5 Jul 2021 12:25:52 +0200 Subject: [PATCH] Add --force-encrypt integration test --- tests/cli.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/cli.rs b/tests/cli.rs index 3470ce6..2cdf0f5 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,4 +1,4 @@ -use std::{io::{self, Read, Write}, fs::{File, create_dir}, path::PathBuf}; +use std::{io::{self, Read, Write}, fs::{self, File, create_dir}, path::PathBuf}; use assert_cmd::{Command, cargo::{CargoError, cargo_bin}}; use tempfile::TempDir; @@ -37,7 +37,7 @@ fn files() -> io::Result<()> { doby_cmd().unwrap().arg(tmp_plaintext).arg(&tmp_ciphertext).assert().success().stdout("").stderr(""); - let tmp_decrypted = tmp_path.join("decryped"); + let tmp_decrypted = tmp_path.join("decrypted"); doby_cmd().unwrap().arg(tmp_ciphertext).arg(&tmp_decrypted).assert().success().stdout("").stderr(""); let mut buff = [0; PLAINTEXT.len()]; @@ -72,6 +72,34 @@ fn stdin() -> io::Result<()> { Ok(()) } +#[test] +fn force_encrypt() -> io::Result<()> { + let (tmp_path, tmp_plaintext, tmp_ciphertext_1) = setup_files()?; + + doby_cmd().unwrap().arg(tmp_plaintext).arg(&tmp_ciphertext_1).assert().success().stdout("").stderr(""); + + let tmp_ciphertext_2 = tmp_path.join("ciphertext_2"); + doby_cmd().unwrap().arg("-f").arg(&tmp_ciphertext_1).arg(&tmp_ciphertext_2).assert().success().stdout("").stderr(""); + let buff_ciphertext_1 = fs::read(tmp_ciphertext_1)?; + let buff_ciphertext_2 = fs::read(&tmp_ciphertext_2)?; + assert_ne!(buff_ciphertext_1, buff_ciphertext_2); + assert_ne!(buff_ciphertext_2, PLAINTEXT); + assert!(buff_ciphertext_2.len() >= buff_ciphertext_1.len()+190); + + let tmp_decrypted_1 = tmp_path.join("decrypted_1"); + doby_cmd().unwrap().arg(tmp_ciphertext_2).arg(&tmp_decrypted_1).assert().success().stdout("").stderr(""); + let buff_decrypted_1 = fs::read(&tmp_decrypted_1)?; + assert_eq!(buff_decrypted_1, buff_ciphertext_1); + assert_ne!(buff_decrypted_1, PLAINTEXT); + + let tmp_decrypted_2 = tmp_path.join("decrypted_2"); + doby_cmd().unwrap().arg(tmp_decrypted_1).arg(&tmp_decrypted_2).assert().success().stdout("").stderr(""); + let buff_decrypted_2 = fs::read(tmp_decrypted_2)?; + assert_eq!(buff_decrypted_2, PLAINTEXT); + + Ok(()) +} + #[test] fn argon2_params() -> io::Result<()> { Command::cargo_bin("doby").unwrap().arg("-i").arg("0").assert().failure().stderr("Invalid argon2 params: time cost is too small\n");