@@ -14,6 +14,15 @@ def mocked_run_one_test(mocker):
1414 return mocker .patch ("krux.pages.device_tests.DeviceTests.run_one_test" )
1515
1616
17+ @pytest .fixture
18+ def mock_multi_layer_decrypt (mocker ):
19+ """Fixture to mock multi_layer_decrypt failing"""
20+
21+ return mocker .patch (
22+ "krux.kef.Cipher.decrypt" , side_effect = lambda cpl , version : None
23+ )
24+
25+
1726@pytest .fixture
1827def mock_hw_acc_hashing (mocker ):
1928 """Fixture to mock the hardware acceleration hashing test to fail"""
@@ -165,6 +174,37 @@ def test_skip_all_tests(m5stickv, mocker, mocked_print_qr, mocked_run_one_test):
165174 assert ctx .input .wait_for_button .call_count == len (BTN_SEQUENCE )
166175
167176
177+ def test_fail_multi_layer_decrypt (m5stickv , mocker , mock_multi_layer_decrypt ):
178+ """Directly test multi_layer_decrypt() hitting the except block"""
179+ from krux .pages .device_tests import DeviceTests
180+ from krux .input import BUTTON_ENTER , BUTTON_PAGE_PREV
181+
182+ BTN_SEQUENCE = (
183+ BUTTON_PAGE_PREV , # select back
184+ BUTTON_ENTER , # go back
185+ )
186+
187+ ctx = create_ctx (mocker , BTN_SEQUENCE )
188+ page = DeviceTests (ctx )
189+ page .test_suite ()
190+
191+ # assert that kef.Cipher.decrypt was called
192+ decrypt = mock_multi_layer_decrypt
193+ assert decrypt .call_count > 0
194+
195+ # assert that the test suite results are displayed correctly
196+ # and that the on-device-test failed
197+ page .ctx .display .draw_hcentered_text .assert_has_calls (
198+ [
199+ mocker .call (
200+ "Test Suite Results\n success rate: 75%\n failed: 1/4" , info_box = True
201+ )
202+ ]
203+ )
204+
205+ assert ctx .input .wait_for_button .call_count == len (BTN_SEQUENCE )
206+
207+
168208def test_fail_hw_acc_hashing (m5stickv , mocker , mock_hw_acc_hashing ):
169209 """Directly test hw_acc_hashing() hmac hitting the except block"""
170210 from krux .pages .device_tests import DeviceTests
@@ -189,7 +229,7 @@ def test_fail_hw_acc_hashing(m5stickv, mocker, mock_hw_acc_hashing):
189229 page .ctx .display .draw_hcentered_text .assert_has_calls (
190230 [
191231 mocker .call (
192- "Test Suite Results\n success rate: 66 %\n failed: 1/3 " , info_box = True
232+ "Test Suite Results\n success rate: 50 %\n failed: 2/4 " , info_box = True
193233 )
194234 ]
195235 )
@@ -223,7 +263,7 @@ def test_fail_sha256(m5stickv, mocker, mock_hashlib_sha256):
223263 page .ctx .display .draw_hcentered_text .assert_has_calls (
224264 [
225265 mocker .call (
226- "Test Suite Results\n success rate: 66 %\n failed: 1/3 " , info_box = True
266+ "Test Suite Results\n success rate: 75 %\n failed: 1/4 " , info_box = True
227267 )
228268 ]
229269 )
@@ -259,7 +299,7 @@ def test_fail_hexilify(m5stickv, mocker, mock_hexlify_endianess):
259299 page .ctx .display .draw_hcentered_text .assert_has_calls (
260300 [
261301 mocker .call (
262- "Test Suite Results\n success rate: 66 %\n failed: 1/3 " , info_box = True
302+ "Test Suite Results\n success rate: 75 %\n failed: 1/4 " , info_box = True
263303 )
264304 ]
265305 )
@@ -295,7 +335,7 @@ def test_fail_b2a_base64(m5stickv, mocker, mock_b2a_base64_endianess):
295335 page .ctx .display .draw_hcentered_text .assert_has_calls (
296336 [
297337 mocker .call (
298- "Test Suite Results\n success rate: 66 %\n failed: 1/3 " , info_box = True
338+ "Test Suite Results\n success rate: 75 %\n failed: 1/4 " , info_box = True
299339 )
300340 ]
301341 )
@@ -340,7 +380,7 @@ def test_fail_deflate_compression(m5stickv, mocker, mock_deflate):
340380 page .ctx .display .draw_hcentered_text .assert_has_calls (
341381 [
342382 mocker .call (
343- "Test Suite Results\n success rate: 66 %\n failed: 1/3 " , info_box = True
383+ "Test Suite Results\n success rate: 75 %\n failed: 1/4 " , info_box = True
344384 )
345385 ]
346386 )
@@ -371,7 +411,7 @@ def test_fail_maixpy_code(m5stickv, mocker, mock_maixpy_code):
371411 page .ctx .display .draw_hcentered_text .assert_has_calls (
372412 [
373413 mocker .call (
374- "Test Suite Results\n success rate: 66 %\n failed: 1/3 " , info_box = True
414+ "Test Suite Results\n success rate: 75 %\n failed: 1/4 " , info_box = True
375415 )
376416 ]
377417 )
@@ -402,7 +442,7 @@ def test_fail_zlib_code(m5stickv, mocker, mock_zlib_code):
402442 page .ctx .display .draw_hcentered_text .assert_has_calls (
403443 [
404444 mocker .call (
405- "Test Suite Results\n success rate: 66 %\n failed: 1/3 " , info_box = True
445+ "Test Suite Results\n success rate: 75 %\n failed: 1/4 " , info_box = True
406446 )
407447 ]
408448 )
@@ -476,6 +516,27 @@ def test_run_intreactively(m5stickv, mocker):
476516 assert ctx .input .wait_for_button .call_count == len (BTN_SEQUENCE )
477517
478518
519+ def test_run_one_test_multi_layer_decrypt (m5stickv , mocker ):
520+ from krux .pages .device_tests import DeviceTests
521+ from krux .input import BUTTON_ENTER , BUTTON_PAGE_PREV
522+
523+ BTN_SEQUENCE = (
524+ BUTTON_ENTER , # hit enter to proceed
525+ BUTTON_PAGE_PREV , #
526+ BUTTON_ENTER , # go back
527+ )
528+
529+ ctx = create_ctx (mocker , BTN_SEQUENCE )
530+ page = DeviceTests (ctx )
531+
532+ # since bypassing test-suite, fake existing results
533+ page .results = [(page .multi_layer_decrypt , False )]
534+ page .run_one_test (page .multi_layer_decrypt )
535+ assert page .results == [(page .multi_layer_decrypt , True )]
536+
537+ assert ctx .input .wait_for_button .call_count == len (BTN_SEQUENCE )
538+
539+
479540def test_run_one_test_test_hw_acc_hashing (m5stickv , mocker ):
480541 from krux .pages .device_tests import DeviceTests
481542 from krux .input import BUTTON_ENTER , BUTTON_PAGE_PREV
0 commit comments