Back to all posts
Day 260Sunday, October 18, 20264 min read

Keeping Test Failures Out of the Real Audit Log

cybersecurityauditabilitytestingdataintegrityobservabilitylearningprocess
View original post

🔄 Topic

An audit log is useful only when its readers can trust what the entries represent. While testing Hermes’ Apple bridge, I noticed that mocked timeouts and permission refusals were being appended to the same audit file used by the live command.

The tests were behaving correctly, but the evidence was not. A later investigation could see fake failures mixed with real operations and mistake test activity for an incident, or dismiss a real failure because the file was full of synthetic noise.

🎯 Goal

Keep production audit evidence separate from test evidence while still testing the logging behaviour itself. The desired properties were:

  • tests must not write into the real user audit file;
  • the test must still prove that an error is recorded;
  • the recorded operation and error code must remain inspectable;
  • the fix must not depend on remembering to clean up a shared log afterwards.

🛠 What I Did

The bridge’s main() function appends an entry to its configured audit path for each operation. The unit-test module now replaces that path with a temporary directory before running the tests. The original path is retained only for comparison, and the temporary directory is removed when the test module finishes.

I added a focused test that forces the agenda operation to raise a timeout. The test invokes the normal command path, reads the last line from the temporary audit file, and checks that the operation is agenda and the error code is timeout. This proves that the audit behaviour still runs while confirming that the event landed in the test file rather than the live log.

The change came from commit 98c501d, following the earlier Notes bridge work. It is a small change, but it changes the trust boundary around operational evidence: simulated failures have a different provenance from failures observed by the running service.

🔗 Key Cybersecurity Connections

🔍 Investigation Questions

When automated tests exercise code that writes security evidence, I should ask:

  1. Which destination does the test use for logs, state, and receipts?
  2. Can a mocked failure appear indistinguishable from a live failure?
  3. Does the test prove the logging contract without touching real state?
  4. Can the test run concurrently with an operational process safely?
  5. Is the separation enforced by the fixture, or left to a cleanup step someone may forget?

🚨 Detection Opportunities

Audit pipelines can record an environment or provenance field, but provenance is strongest when the destinations are separated mechanically. Useful checks include a test that rejects the production log path, a temporary-log assertion for expected events, and a review of file ownership and permissions on the live log.

🧭 MITRE ATT&CK Techniques

No direct ATT&CK technique mapping is claimed. The work is about trustworthy defensive telemetry and test isolation. A polluted log can make detection and incident reconstruction harder, but the test itself does not demonstrate an adversary technique.

⚠️ Challenges and Boundaries

Redirecting the path does not by itself prove that every subprocess or external library uses the same destination. The test covers the Python module’s audit path and its normal command invocation. A larger system would also need to inspect service logs, rotation, permissions, retention, and forwarding configuration.

I also did not delete or rewrite the existing operational audit file. The safer repair was to prevent new test contamination and preserve the old records for whatever historical review they may support.

📚 What I Learned

Evidence has provenance. A test that writes a fake timeout into a live audit stream is not merely untidy; it changes the meaning of the stream. Separating destinations makes the boundary explicit and makes the test repeatable without asking the operator to remember a cleanup command.

This is the same principle I have been applying to security automation elsewhere: verify the real postcondition, preserve the evidence needed to review it, and make simulated and live states distinguishable.

🧩 Lessons Learned

  • Never let unit tests share a live audit destination by default.
  • Test the audit contract with a temporary, inspectable log.
  • Preserve the original path only as a guardrail, not as a test target.
  • Treat synthetic failures as a separate evidence class.
  • Prefer mechanical isolation over cleanup after a test has already polluted state.
  • Check provenance before using a log as incident evidence.

😄 TL;DR

The Apple bridge tests were producing fake operational failures in the real audit log. I redirected tests to a temporary log and verified that the expected timeout was still recorded there, so future evidence has a clearer boundary between simulation and live activity.