From 4ac5f8bbbd6e007ecd02be46bfbc0c11de010722 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 1 Aug 2016 22:11:07 +0200 Subject: C++ tests: use get_payload() function to clear packet before using Signed-off-by: Szczepan Zalega --- unittest/test_HOTP.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'unittest/test_HOTP.cc') diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc index a961b24..f25bad4 100644 --- a/unittest/test_HOTP.cc +++ b/unittest/test_HOTP.cc @@ -5,11 +5,13 @@ #include "log.h" #include "stick10_commands.h" #include +#include "misc.h" using namespace std; using namespace nitrokey::device; using namespace nitrokey::proto::stick10; using namespace nitrokey::log; +using namespace nitrokey::misc; void hexStringToByte(uint8_t data[], const char* hexString){ assert(strlen(hexString)%2==0); @@ -43,7 +45,7 @@ TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") { const char * temporary_password = "123456789012345678901234"; { - FirstAuthenticate::CommandTransaction::CommandPayload authreq; + auto authreq = get_payload(); strcpy((char *)(authreq.card_password), "12345678"); strcpy((char *)(authreq.temporary_password), temporary_password); FirstAuthenticate::CommandTransaction::run(stick, authreq); @@ -51,21 +53,20 @@ TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") { //test according to https://tools.ietf.org/html/rfc4226#page-32 { - WriteToHOTPSlot::CommandTransaction::CommandPayload hwrite; + auto hwrite = get_payload(); hwrite.slot_number = 0x10; strcpy(reinterpret_cast(hwrite.slot_name), "rfc4226_lib"); //strcpy(reinterpret_cast(hwrite.slot_secret), ""); const char* secretHex = "3132333435363738393031323334353637383930"; hexStringToByte(hwrite.slot_secret, secretHex); - // reset the HOTP counter -// memset(hwrite.slot_counter, 0, 8); + //hwrite.slot_config; //TODO check various configs in separate test cases //strcpy(reinterpret_cast(hwrite.slot_token_id), ""); //strcpy(reinterpret_cast(hwrite.slot_counter), ""); //authorize writehotp first { - Authorize::CommandTransaction::CommandPayload auth; + auto auth = get_payload(); strcpy((char *)(auth.temporary_password), temporary_password); auth.crc_to_authorize = WriteToHOTPSlot::CommandTransaction::getCRC(hwrite); Authorize::CommandTransaction::run(stick, auth); @@ -80,7 +81,7 @@ TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") { }; for( auto code: codes){ - GetHOTP::CommandTransaction::CommandPayload gh; + auto gh = get_payload(); gh.slot_number = 0x10; auto resp = GetHOTP::CommandTransaction::run(stick, gh); REQUIRE( resp.code == code); -- cgit v1.2.1