Skip to content

Add unit tests for UfedChatParser and ReportGenerator - #2928

Open
cleitonaugusto wants to merge 1 commit into
sepinf-inc:masterfrom
cleitonaugusto:#2926_ufed_chat_parser_tests
Open

Add unit tests for UfedChatParser and ReportGenerator#2928
cleitonaugusto wants to merge 1 commit into
sepinf-inc:masterfrom
cleitonaugusto:#2926_ufed_chat_parser_tests

Conversation

@cleitonaugusto

Copy link
Copy Markdown
Contributor

Morning @lfcnassif, opening this as mentioned in #2926.

UfedChatParser and ReportGenerator had zero coverage even though they're the render/extraction path for every UFDR-decoded chat — WhatsApp, Telegram, Signal, Skype, Instagram, all of it. Added 31 tests split across two layers: unit tests in iped-parsers-impl that build Chat/InstantMessage/Party objects by hand through the same setField() the XML handler uses internally (no binary fixture needed), plus an integration test in iped-engine that reuses the existing ufed-model-chat.xml fixture and runs it through the real UfedModelHandler, so it's not just proving the logic works against objects I built myself — it proves the actual XML parser output renders correctly too.

While writing these I ran into something worth flagging: UfedChatParser.extractActivityLog() re-emits the full activity log on every HTML fragment instead of slicing per fragment like it correctly does for messages. Didn't touch it here, it felt out of scope for a tests-only PR, but there's a test that locks in the current behavior with a comment explaining what's going on, so if it gets fixed later it'll be a deliberate change instead of a silent one.

Both module suites pass — iped-engine 97/97, iped-parsers-impl 212/212 minus the pre-existing OCR/PDF failures from a missing local Tesseract install, unrelated to this.

Closes #2926

Closes sepinf-inc#2926

iped.parsers.ufed.UfedChatParser and ReportGenerator had zero test
coverage despite being ~900 lines responsible for rendering the HTML
chat preview and extracting messages/activity logs for every
UFDR-decoded chat app (WhatsApp, Telegram, Signal, Skype, Instagram,
and others).

iped-parsers-impl (unit tests, hand-built fixtures):
- UfedChatFixtures: hand-builds small Chat/InstantMessage/Party/
  Attachment/Contact/ChatActivity model trees via the generic
  setField() mechanism (same one the XML-driven UfedModelHandler
  uses), so no binary UFDR fixture or cross-module test dependency
  is needed
- ReportGeneratorTest: exercises generateNextChatHtml() directly,
  covering message body/sender rendering, URL attachments, shared
  contacts, content-type dispatch case-insensitivity, and the
  minChatSplitSize pagination logic (previously fully untested)
- UfedChatParserTest: exercises the full Tika parse() path with
  Mockito-mocked IItemSearcher/IItemReader (stubbed enough that the
  reference-resolution query-building code actually runs instead of
  silently hitting a mock-artifact NullPointerException swallowed by
  BaseModelHandler.loadReferences()'s try/catch), covering chat
  preview metadata, message/activity extraction counts, and the
  ignoreEmptyChats option
- testActivityLogIsDuplicatedAcrossFragments documents a real,
  pre-existing behavior found while testing: UfedChatParser emits the
  full activity log once per HTML fragment instead of a per-fragment
  slice (unlike messages, which are correctly sliced). Not fixed here
  — out of scope for a test-only PR — but locked in by a test instead
  of silently missed, so a future fix is a deliberate, visible change

iped-engine (integration test, real XML-driven Chat):
- UfedChatRenderingIntegrationTest: parses the existing
  ufed-model-chat.xml fixture through the real UfedModelHandler (the
  same one used by UfedModelHandlerChatTest) and feeds the resulting
  real Chat into ReportGenerator/UfedChatParser. Closes the gap the
  hand-built fixtures above cannot: proving the actual XML-parser
  output renders correctly, including reply/quote rendering, which
  requires indexMessages()-populated lookup maps that only the real
  handler establishes

31 tests total (16 in iped-parsers-impl, plus the 7 in this new
iped-engine integration test, 8 already in the sibling
UfedModelHandlerChatTest). Both module suites pass in full (excluding
pre-existing, unrelated OCRParserTest/PDFTextParserTest failures in
iped-parsers-impl caused by a missing local Tesseract install).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for UfedChatParser and ReportGenerator

1 participant