Add stdin/stdout integration tests
This commit is contained in:
parent
b4839b95c7
commit
1619728721
|
@ -9,6 +9,7 @@ doby started as a fork of [aef](https://github.com/wyhaya/aef) by [wyhaya](https
|
||||||
* Fast: written in [rust](https://www.rust-lang.org), encrypts with [AES-256-CTR](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR)) or [XChaCha20](https://en.wikipedia.org/wiki/Salsa20#XChaCha)
|
* Fast: written in [rust](https://www.rust-lang.org), encrypts with [AES-256-CTR](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR)) or [XChaCha20](https://en.wikipedia.org/wiki/Salsa20#XChaCha)
|
||||||
* [HMAC](https://en.wikipedia.org/wiki/HMAC) ciphertext authentication
|
* [HMAC](https://en.wikipedia.org/wiki/HMAC) ciphertext authentication
|
||||||
* Password brute-force resistance with [Argon2](https://en.wikipedia.org/wiki/Argon2)
|
* Password brute-force resistance with [Argon2](https://en.wikipedia.org/wiki/Argon2)
|
||||||
|
* Increase the plaintext size of only 190 bytes
|
||||||
* Encryption from STDIN/STDOUT or from files
|
* Encryption from STDIN/STDOUT or from files
|
||||||
* Adjustable performance & secuity parameters
|
* Adjustable performance & secuity parameters
|
||||||
|
|
||||||
|
|
70
tests/cli.rs
70
tests/cli.rs
|
@ -1,37 +1,77 @@
|
||||||
use std::{io::{self, Read, Write}, fs::File, path::PathBuf};
|
use std::{io::{self, Read, Write}, fs::{File, create_dir}, path::PathBuf};
|
||||||
use assert_cmd::{Command, cargo::CargoError};
|
use assert_cmd::{Command, cargo::{CargoError, cargo_bin}};
|
||||||
use tempfile::{NamedTempFile, TempDir};
|
use tempfile::TempDir;
|
||||||
|
|
||||||
fn doby_cmd<>() -> Result<Command, CargoError> {
|
const PLAINTEXT: &[u8] = b"the plaintext";
|
||||||
const PASSWORD: &str = "the password";
|
const PASSWORD: &str = "the password";
|
||||||
|
|
||||||
|
fn setup_files<'a>() -> io::Result<(PathBuf, PathBuf, PathBuf)> {
|
||||||
|
let tmp_dir = TempDir::new()?;
|
||||||
|
let tmp_path = PathBuf::from(tmp_dir.path());
|
||||||
|
drop(tmp_dir);
|
||||||
|
create_dir(&tmp_path)?;
|
||||||
|
|
||||||
|
let tmp_plaintext = tmp_path.join("plaintext");
|
||||||
|
let tmp_ciphertext = tmp_path.join("ciphertext");
|
||||||
|
|
||||||
|
File::create(&tmp_plaintext)?.write_all(PLAINTEXT)?;
|
||||||
|
|
||||||
|
Ok((tmp_path, tmp_plaintext, tmp_ciphertext))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn doby_cmd() -> Result<Command, CargoError> {
|
||||||
let mut cmd = Command::cargo_bin("doby")?;
|
let mut cmd = Command::cargo_bin("doby")?;
|
||||||
cmd.arg("-p").arg(PASSWORD);
|
cmd.arg("-p").arg(PASSWORD);
|
||||||
Ok(cmd)
|
Ok(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bash_cmd() -> Command {
|
||||||
|
let mut cmd = Command::new("bash");
|
||||||
|
cmd.arg("-c");
|
||||||
|
cmd
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn files() -> io::Result<()> {
|
fn files() -> io::Result<()> {
|
||||||
const PLAINTEXT: &[u8] = b"the plaintext";
|
let (tmp_path, tmp_plaintext, tmp_ciphertext) = setup_files()?;
|
||||||
|
|
||||||
let tmp_dir = TempDir::new()?;
|
doby_cmd().unwrap().arg(tmp_plaintext).arg(&tmp_ciphertext).assert().success().stdout("").stderr("");
|
||||||
let tmp_path = PathBuf::from(tmp_dir.path());
|
|
||||||
|
|
||||||
let mut tmp_plaintext = NamedTempFile::new_in(&tmp_dir)?;
|
|
||||||
tmp_plaintext.write_all(PLAINTEXT)?;
|
|
||||||
let tmp_ciphertext = tmp_path.join("ciphertext");
|
|
||||||
doby_cmd().unwrap().arg(tmp_plaintext.path()).arg(&tmp_ciphertext).assert().success().stdout("").stderr("");
|
|
||||||
|
|
||||||
let tmp_decrypted = tmp_path.join("decryped");
|
let tmp_decrypted = tmp_path.join("decryped");
|
||||||
doby_cmd().unwrap().arg(tmp_ciphertext).arg(&tmp_decrypted).assert().success().stdout("").stderr("");
|
doby_cmd().unwrap().arg(tmp_ciphertext).arg(&tmp_decrypted).assert().success().stdout("").stderr("");
|
||||||
|
|
||||||
let mut tmp_decrypted = File::open(tmp_decrypted).unwrap();
|
|
||||||
let mut buff = [0; PLAINTEXT.len()];
|
let mut buff = [0; PLAINTEXT.len()];
|
||||||
assert_eq!(tmp_decrypted.read(&mut buff)?, PLAINTEXT.len());
|
assert_eq!(File::open(tmp_decrypted)?.read(&mut buff)?, PLAINTEXT.len());
|
||||||
assert_eq!(buff, PLAINTEXT);
|
assert_eq!(buff, PLAINTEXT);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stdout() -> io::Result<()> {
|
||||||
|
let (_, tmp_plaintext, tmp_ciphertext) = setup_files()?;
|
||||||
|
|
||||||
|
let shell_cmd = format!("{} -p \"{}\" {} > {}", cargo_bin("doby").to_str().unwrap(), PASSWORD, tmp_plaintext.to_str().unwrap(), tmp_ciphertext.to_str().unwrap());
|
||||||
|
bash_cmd().arg(shell_cmd).assert().success().stdout("").stderr("");
|
||||||
|
|
||||||
|
doby_cmd().unwrap().arg(tmp_ciphertext).assert().success().stdout(PLAINTEXT);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stdin() -> io::Result<()> {
|
||||||
|
let (_, tmp_plaintext, tmp_ciphertext) = setup_files()?;
|
||||||
|
|
||||||
|
let mut shell_cmd = format!("cat {} | {} -p \"{}\" - {}", tmp_plaintext.to_str().unwrap(), cargo_bin("doby").to_str().unwrap(), PASSWORD, tmp_ciphertext.to_str().unwrap());
|
||||||
|
bash_cmd().arg(shell_cmd).assert().success().stdout("").stderr("");
|
||||||
|
|
||||||
|
shell_cmd = format!("cat {} | {} -p \"{}\"", tmp_ciphertext.to_str().unwrap(), cargo_bin("doby").to_str().unwrap(), PASSWORD);
|
||||||
|
bash_cmd().arg(shell_cmd).assert().success().stdout(PLAINTEXT);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn argon2_params() -> io::Result<()> {
|
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");
|
Command::cargo_bin("doby").unwrap().arg("-i").arg("0").assert().failure().stderr("Invalid argon2 params: time cost is too small\n");
|
||||||
|
|
Loading…
Reference in New Issue