Skip to content

Commit

Permalink
add integration test for zip2bodyfile
Browse files Browse the repository at this point in the history
  • Loading branch information
janstarke committed Feb 29, 2024
1 parent 77a1d29 commit 7e4bca2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dfir-toolkit"
version = "0.11.0"
version = "0.11.1"
edition = "2021"
authors = ["Jan Starke <jan.starke@posteo.de>", "Deborah Mahn <deborah.mahn@dfir-dd.de>"]
description = "CLI tools for digital forensics and incident response"
Expand Down
Binary file added tests/data/zip2bodyfile/hello.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod mactime2;
mod ts2date;
mod lnk2bodyfile;
mod lnk2bodyfile;
mod zip2bodyfile;
48 changes: 48 additions & 0 deletions tests/zip2bodyfile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::{
io::{BufRead, BufReader, Cursor},
path::PathBuf,
};

use assert_cmd::Command;
use dfir_toolkit::common::bodyfile::{Bodyfile3Line, Accessed, Modified, Changed, Created};

#[test]
fn test_hello() {
do_test_hello(r#"hello.txt"#, vec![].into_iter());
}

#[test]
fn test_hello_with_archive_name() {
do_test_hello(r#"hello.txt (in archive hello.zip)"#, vec!["--show-archive-name"].into_iter());
}

fn do_test_hello(expected_name: &str, args: impl Iterator<Item = &'static str>) {
let mut cmd = Command::cargo_bin("zip2bodyfile").unwrap();
let mut data_path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
data_path.push("tests");
data_path.push("data");
data_path.push("zip2bodyfile");
data_path.push("hello.zip");

let result = cmd.arg(data_path).args(args).ok();
if result.is_err() {
println!("{}", result.as_ref().err().unwrap());
}

assert!(result.is_ok());

// parse the result as bodyfile 😈
let reader = BufReader::new(Cursor::new(result.unwrap().stdout));
let mut lines_iterator = reader.lines();
let first_line = lines_iterator.next().unwrap().unwrap();

let bfline = Bodyfile3Line::try_from(&first_line[..]).unwrap();
assert_eq!(bfline.get_name(), expected_name);
assert_eq!(*bfline.get_size(), 12);
assert_eq!(*bfline.get_atime(), Accessed::default());
assert_eq!(*bfline.get_mtime(), Modified::from(1709197630));
assert_eq!(*bfline.get_ctime(), Changed::default());
assert_eq!(*bfline.get_crtime(), Created::default());

assert!(lines_iterator.next().is_none());
}

0 comments on commit 7e4bca2

Please sign in to comment.