fix(test): fake the clock in test_fill_flash timeout test
What changed, and why it matters
This commit only changes a test file to make it run faster by faking the system clock. It does not modify any production code, so it has no direct security impact on users of the Krux device or software.
No security action required. This is a routine test-performance improvement. Reviewers may optionally verify that the fake clock still exercises the same timeout branch as the real clock did.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies tests/pages/test_fill_flash.py to patch time.time in the FillFlash module during the test_fill_flash_insufficient_entropy_scenario test. Previously the test waited roughly 25 real seconds for MAX_CAPTURE_PERIOD to elapse, generating ~500k mock call records. The new implementation increments a fake clock by 5 seconds per call, causing the timeout to fire after four frames and reducing runtime from ~25.1s to ~0.09s. No production code paths, cryptographic operations, or user-facing behavior are changed.
Changed components
tests/pages/test_fill_flash.pyInspect captured patch +13 / −4
diff --git a/tests/pages/test_fill_flash.py b/tests/pages/test_fill_flash.py
index 6554676..655cb04 100644
--- a/tests/pages/test_fill_flash.py
+++ b/tests/pages/test_fill_flash.py
@@ -123,8 +123,6 @@ def test_fill_flash_entropy_timeout_scenario(amigo, mocker):
def test_fill_flash_insufficient_entropy_scenario(amigo, mocker):
- # Test insufficient entropy scenario using mocker.patch instead of PropertyMock
- # Following @qlrd recommendation to avoid false positive assertions
from krux.pages.fill_flash import FillFlash
from krux.pages.capture_entropy import CameraEntropy, INSUFFICIENT_VARIANCE_TH
from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV
@@ -137,10 +135,21 @@ def test_fill_flash_insufficient_entropy_scenario(amigo, mocker):
ctx = create_ctx(mocker, btn_sequence)
fill_flash = FillFlash(ctx)
+
+ # Fake clock so the capture timeout elapses after a few frames, instead of
+ # spinning on the mocked camera for 25 real seconds and piling up mock calls
+ clock = [0]
+
+ def _fake_time():
+ clock[0] += 5
+ return clock[0]
+
+ mocker.patch("krux.pages.fill_flash.time.time", side_effect=_fake_time)
+
entropy_measurement = CameraEntropy(ctx)
- # Use mocker.patch.object instead of PropertyMock as per @qlrd recommendation
- # This avoids false positive assertions that can occur with PropertyMock
+ # Test insufficient entropy scenario using mocker.patch
+ # to avoid false positive assertions
mocker.patch.object(
entropy_measurement,
"rms_value",
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.