From 282161d297b4f12b3a54a291aab4b4c601a51b13 Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Sun, 18 Oct 2026 16:47:56 -0300 Subject: [PATCH] =?UTF-8?q?test:=20sess=C3=A3o=20no=20formato=20da=20v0.1.?= =?UTF-8?q?0=20gerada=20em=20tempo=20de=20teste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O arquivo estático dependia do conteúdo aleatório da imagem local e falhava no CI. Co-Authored-By: Claude Sonnet 5.5 --- .../guara-core/tests/data/sessao-v0.1.0.json | 1 - crates/guara-core/tests/disk.rs | 43 +++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) delete mode 100644 crates/guara-core/tests/data/sessao-v0.1.0.json diff --git a/crates/guara-core/tests/data/sessao-v0.1.0.json b/crates/guara-core/tests/data/sessao-v0.1.0.json deleted file mode 100644 index 3b3ace7..0000000 --- a/crates/guara-core/tests/data/sessao-v0.1.0.json +++ /dev/null @@ -1 +0,0 @@ -{"version": 1, "target": "@@ALVO@@", "options": {"mode": "deep", "include_allocated": false, "categories": [], "max_carve_size": 8589934592}, "found": [{"id": 1, "name": "tese.docx", "dir": null, "ext": "docx", "category": "document", "size": 411277, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 52428800, "len": 411277}]}, "modified": 1792346095, "note": null}, {"id": 2, "name": "notas.txt", "dir": null, "ext": "txt", "category": "document", "size": 945617, "origin": "ntfs", "confidence": "medium", "data": {"kind": "extents", "extents": [{"offset": 52842496, "len": 945617}]}, "modified": 1792346095, "note": null}, {"id": 3, "name": "relatorio.pdf", "dir": null, "ext": "pdf", "category": "document", "size": 646931, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 53788672, "len": 646931}]}, "modified": 1792346095, "note": null}, {"id": 4, "name": "dados.bin", "dir": null, "ext": "bin", "category": "other", "size": 3000000, "origin": "ntfs", "confidence": "medium", "data": {"kind": "extents", "extents": [{"offset": 54435840, "len": 3000000}]}, "modified": 1792346095, "note": null}, {"id": 5, "name": "contatos.db", "dir": null, "ext": "db", "category": "database", "size": 573440, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 57438208, "len": 573440}]}, "modified": 1792346095, "note": null}, {"id": 6, "name": "praia.jpg", "dir": null, "ext": "jpg", "category": "image", "size": 511391, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 58011648, "len": 511391}]}, "modified": 1792346096, "note": null}, {"id": 7, "name": "montanha.png", "dir": null, "ext": "png", "category": "image", "size": 3337460, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 58638336, "len": 3337460}]}, "modified": 1792346096, "note": null}], "checkpoint": null, "layout": {"size": 100663296, "table": "none", "partitions": [{"index": 0, "start": 0, "len": 100663296, "fs": "ntfs", "label": null, "lost": false, "encrypted": null, "table_type": "volume sem tabela de partições"}], "gaps": [], "warnings": []}, "warnings": [], "done": true} \ No newline at end of file diff --git a/crates/guara-core/tests/disk.rs b/crates/guara-core/tests/disk.rs index c9436fc..f107343 100644 --- a/crates/guara-core/tests/disk.rs +++ b/crates/guara-core/tests/disk.rs @@ -313,14 +313,39 @@ fn wait_done(eng: &service::Engine, job: &str) { panic!("job não terminou"); } +/// Gera uma sessão no formato da v0.1.0 (sem os campos que vieram depois) a partir de uma +/// varredura real da imagem, com o alvo informado. +fn sessao_formato_v0_1_0(img: &std::path::Path, alvo: &str) -> tempfile::NamedTempFile { + let eng = service::Engine::new(); + let job = eng + .start_scan(img.to_str().unwrap(), ScanOptions::default()) + .unwrap(); + wait_done(&eng, &job); + let tmp = tempfile::NamedTempFile::new().unwrap(); + eng.save_session(&job, tmp.path().to_str().unwrap()) + .unwrap(); + let mut v: serde_json::Value = + serde_json::from_slice(&std::fs::read(tmp.path()).unwrap()).unwrap(); + let o = v.as_object_mut().unwrap(); + o.remove("recoveries"); + o.remove("started_unix"); + o.insert("target".into(), alvo.into()); + for f in o["found"].as_array_mut().unwrap() { + let f = f.as_object_mut().unwrap(); + for k in ["created", "accessed", "taken", "camera", "px", "gps", "sig"] { + f.remove(k); + } + } + std::fs::write(tmp.path(), serde_json::to_vec(&v).unwrap()).unwrap(); + tmp +} + /// Uma sessão gravada pela v0.1.0 continua abrindo nas versões novas. #[test] fn sessao_da_v0_1_0_abre_e_funciona() { let Some(dir) = fixtures() else { return }; let img = dir.join("ntfs.img"); - let raw = include_str!("data/sessao-v0.1.0.json").replace("@@ALVO@@", img.to_str().unwrap()); - let tmp = tempfile::NamedTempFile::new().unwrap(); - std::fs::write(tmp.path(), raw).unwrap(); + let tmp = sessao_formato_v0_1_0(&img, img.to_str().unwrap()); let eng = service::Engine::new(); let job = eng.load_session(tmp.path().to_str().unwrap()).unwrap(); wait_done(&eng, &job); @@ -352,10 +377,7 @@ fn sessao_da_v0_1_0_abre_e_funciona() { fn sessao_abre_sem_a_origem_e_pode_ser_reconectada() { let Some(dir) = fixtures() else { return }; let img = dir.join("ntfs.img"); - let raw = - include_str!("data/sessao-v0.1.0.json").replace("@@ALVO@@", "/dev/disco-que-nao-existe"); - let tmp = tempfile::NamedTempFile::new().unwrap(); - std::fs::write(tmp.path(), raw).unwrap(); + let tmp = sessao_formato_v0_1_0(&img, "/dev/disco-que-nao-existe"); let eng = service::Engine::new(); let job = eng.load_session(tmp.path().to_str().unwrap()).unwrap(); let st = eng.status(&job).unwrap(); @@ -376,8 +398,13 @@ fn sessao_abre_sem_a_origem_e_pode_ser_reconectada() { .unwrap(), 7 ); - // pré-visualização e recuperação avisam com clareza + // pré-visualização, retomada e recuperação avisam com clareza assert_eq!(eng.thumb(&job, 1, 128).err(), Some(503)); + assert!(eng + .resume(&job) + .unwrap_err() + .to_string() + .contains("não está disponível")); let out = tempfile::tempdir().unwrap(); let e = eng .start_recover(&job, None, None, out.path().to_str().unwrap())