feat: initial wipe implementation - block device safety, HDD overwrite, NVMe/secure-discard, verification
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#![allow(unused_imports, dead_code, unused_variables)]
|
||||
use assert_cmd::Command;
|
||||
use predicates::prelude::*;
|
||||
use std::fs;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
use std::process::Command as StdCommand;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
fn wipe_bin() -> String {
|
||||
// cargo test runs with target/debug/wipe built
|
||||
// Use Command::cargo_bin to locate
|
||||
assert_cmd::Command::cargo_bin("wipe")
|
||||
.unwrap()
|
||||
.get_program()
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overwrite_zero_via_loop_sim() {
|
||||
// This test uses a regular file as device path but will fail device validation (not block device)
|
||||
// So we test the overwrite engine via unit tests instead; here we test CLI rejects regular file
|
||||
let tmp = NamedTempFile::new().unwrap();
|
||||
let path = tmp.path().to_str().unwrap();
|
||||
// This will fail at /dev check, not at overwrite, so just verify it fails appropriately
|
||||
Command::cargo_bin("wipe")
|
||||
.unwrap()
|
||||
.args([path, "--whole-disk", "--yes"])
|
||||
.assert()
|
||||
.failure()
|
||||
.code(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_buffer_size_variants() {
|
||||
for size in ["16M", "32M", "64M", "128M", "1M", "64MiB", "128MiB"] {
|
||||
let output = Command::cargo_bin("wipe")
|
||||
.unwrap()
|
||||
.args([
|
||||
"/dev/null",
|
||||
"--whole-disk",
|
||||
"--buffer-size",
|
||||
size,
|
||||
"--dry-run",
|
||||
"--yes",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
// Should fail as not block device, but not as invalid args (code 5 vs 2)
|
||||
// So buffer size parsing succeeded
|
||||
assert_ne!(
|
||||
output.status.code().unwrap(),
|
||||
2,
|
||||
"buffer size {size} should be valid"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_passes_validation() {
|
||||
Command::cargo_bin("wipe")
|
||||
.unwrap()
|
||||
.args([
|
||||
"/dev/sda",
|
||||
"--whole-disk",
|
||||
"--passes",
|
||||
"0",
|
||||
"--dry-run",
|
||||
"--yes",
|
||||
])
|
||||
.assert()
|
||||
.failure()
|
||||
.code(2);
|
||||
}
|
||||
Reference in New Issue
Block a user