summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'unittest')
-rw-r--r--unittest/test.cc17
-rw-r--r--unittest/test_HOTP.cc13
2 files changed, 17 insertions, 13 deletions
diff --git a/unittest/test.cc b/unittest/test.cc
index 02f742c..6267512 100644
--- a/unittest/test.cc
+++ b/unittest/test.cc
@@ -11,9 +11,11 @@ using namespace std;
using namespace nitrokey::device;
using namespace nitrokey::proto::stick10;
using namespace nitrokey::log;
+using namespace nitrokey::misc;
+
std::string getSlotName(Stick10 &stick, int slotNo) {
- ReadSlot::CommandTransaction::CommandPayload slot_req;
+ auto slot_req = get_payload<ReadSlot>();
slot_req.slot_number = slotNo;
auto slot = ReadSlot::CommandTransaction::run(stick, slot_req);
std::string sName(reinterpret_cast<char *>(slot.slot_name));
@@ -29,16 +31,17 @@ TEST_CASE("Slot names are correct", "[slotNames]") {
auto resp = GetStatus::CommandTransaction::run(stick);
- FirstAuthenticate::CommandTransaction::CommandPayload authreq;
+ auto authreq = get_payload<FirstAuthenticate>();
strcpy((char *)(authreq.card_password), "12345678");
FirstAuthenticate::CommandTransaction::run(stick, authreq);
{
- EnablePasswordSafe::CommandTransaction::CommandPayload authreq;
- strcpy((char *)(authreq.password), "123456");
+ auto authreq = get_payload<EnablePasswordSafe>();
+ strcpy((char *)(authreq.user_password), "123456");
EnablePasswordSafe::CommandTransaction::run(stick, authreq);
}
+ //assuming these values were set earlier, thus failing on normal use
REQUIRE(getSlotName(stick, 0x20) == std::string("1"));
REQUIRE(getSlotName(stick, 0x21) == std::string("slot2"));
@@ -52,7 +55,7 @@ TEST_CASE("Slot names are correct", "[slotNames]") {
}
{
- GetPasswordSafeSlotName::CommandTransaction::CommandPayload slot;
+ auto slot = get_payload<GetPasswordSafeSlotName>();
slot.slot_number = 0;
auto resp2 = GetPasswordSafeSlotName::CommandTransaction::run(stick, slot);
std::string sName(reinterpret_cast<char *>(resp2.slot_name));
@@ -60,7 +63,7 @@ TEST_CASE("Slot names are correct", "[slotNames]") {
}
{
- GetPasswordSafeSlotPassword::CommandTransaction::CommandPayload slot;
+ auto slot = get_payload<GetPasswordSafeSlotPassword>();
slot.slot_number = 0;
auto resp2 =
GetPasswordSafeSlotPassword::CommandTransaction::run(stick, slot);
@@ -69,7 +72,7 @@ TEST_CASE("Slot names are correct", "[slotNames]") {
}
{
- GetPasswordSafeSlotLogin::CommandTransaction::CommandPayload slot;
+ auto slot = get_payload<GetPasswordSafeSlotLogin>();
slot.slot_number = 0;
auto resp2 = GetPasswordSafeSlotLogin::CommandTransaction::run(stick, slot);
std::string sName(reinterpret_cast<char *>(resp2.slot_login));
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 <cstdlib>
+#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<FirstAuthenticate>();
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<WriteToHOTPSlot>();
hwrite.slot_number = 0x10;
strcpy(reinterpret_cast<char *>(hwrite.slot_name), "rfc4226_lib");
//strcpy(reinterpret_cast<char *>(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<char *>(hwrite.slot_token_id), "");
//strcpy(reinterpret_cast<char *>(hwrite.slot_counter), "");
//authorize writehotp first
{
- Authorize::CommandTransaction::CommandPayload auth;
+ auto auth = get_payload<Authorize>();
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<GetHOTP>();
gh.slot_number = 0x10;
auto resp = GetHOTP::CommandTransaction::run(stick, gh);
REQUIRE( resp.code == code);