Skip to content

Commit

Permalink
add test for pin canceled ref fibercrypto#381
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Denis committed Mar 4, 2020
1 parent 6f12ead commit fef704f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tiny-firmware/tests/test_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,17 @@ START_TEST(test_msgChangePinSecondRejected)
}
END_TEST

START_TEST(test_msgChangePinShouldReturnCanceledAccordingToPinReader)
{
ChangePin msg = ChangePin_init_zero;
storage_wipe();

// Pin mismatch
ck_assert_int_eq(msgChangePinImpl(&msg, &pin_reader_canceled), ErrPinCancelled);
ck_assert_int_eq(storage_hasPin(), false);
}
END_TEST

START_TEST(test_msgSkycoinCheckMessageSignatureBip44Ok)
{
for (size_t wi = 0; wi < sizeof(wcs) / sizeof(*wcs); ++wi) {
Expand Down Expand Up @@ -532,6 +543,7 @@ TCase* add_fsm_tests(TCase* tc)
tcase_add_test(tc, test_msgEntropyAckChgMixerNotInternal);
tcase_add_test(tc, test_msgChangePinSuccess);
tcase_add_test(tc, test_msgChangePinSecondRejected);
tcase_add_test(tc, test_msgChangePinShouldReturnCanceledAccordingToPinReader);
tcase_add_test(tc, test_msgChangePinEditSuccess);
tcase_add_test(tc, test_msgChangePinRemoveSuccess);
tcase_add_test(tc, test_isSha256DigestHex);
Expand Down
13 changes: 13 additions & 0 deletions tiny-firmware/tests/test_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ ErrCode_t pin_reader_wrong(PinMatrixRequestType pinReqType, const char* text, ch
strcpy(pin_out, "789");
return ErrPinMismatch;
}

ErrCode_t pin_reader_canceled(PinMatrixRequestType pinReqType, const char* text, char* pin_out)
{
(void)text;
(void)pin_out;
switch (pinReqType) {
case PinMatrixRequestType_PinMatrixRequestType_NewFirst:
case PinMatrixRequestType_PinMatrixRequestType_NewSecond:
return ErrPinCancelled;
default:
return ErrInvalidArg;
}
}
2 changes: 2 additions & 0 deletions tiny-firmware/tests/test_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ ErrCode_t pin_reader_ok(PinMatrixRequestType pinReqType, const char* text, char*
ErrCode_t pin_reader_alt(PinMatrixRequestType pinReqType, const char* text, char* pin_out);

ErrCode_t pin_reader_wrong(PinMatrixRequestType pinReqType, const char* text, char* pin_out);

ErrCode_t pin_reader_canceled(PinMatrixRequestType pinReqType, const char* text, char* pin_out);

0 comments on commit fef704f

Please sign in to comment.