aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-05 17:10:14 +0100
committerSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-05 17:10:14 +0100
commitd92707ca48137b47800006a09539470acb4e4d69 (patch)
tree36c87a71b3e2e7d208cb856b3ae219b44e14a904
parent27434dc0e877845cbfb229c5154c342107866fd5 (diff)
downloadlibnitrokey-d92707ca48137b47800006a09539470acb4e4d69.tar.gz
libnitrokey-d92707ca48137b47800006a09539470acb4e4d69.tar.bz2
adding basic tests
-rw-r--r--include/stick10_commands.h32
-rw-r--r--unittest/test.cc39
2 files changed, 69 insertions, 2 deletions
diff --git a/include/stick10_commands.h b/include/stick10_commands.h
index b140e99..ab1a5bb 100644
--- a/include/stick10_commands.h
+++ b/include/stick10_commands.h
@@ -196,6 +196,10 @@ class GetPasswordRetryCount : Command<CommandID::GET_PASSWORD_RETRY_COUNT> {
uint8_t password_retry_count;
bool isValid() const { return true; }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " password_retry_count\t" << password_retry_count<< std::endl;
+ return ss.str(); }
} __packed;
typedef Transaction<command_id(), struct EmptyPayload, struct ResponsePayload>
@@ -209,6 +213,10 @@ class GetUserPasswordRetryCount
uint8_t password_retry_count;
bool isValid() const { return true; }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " password_retry_count\t" << password_retry_count<< std::endl;
+ return ss.str(); }
} __packed;
typedef Transaction<command_id(), struct EmptyPayload, struct ResponsePayload>
@@ -233,12 +241,20 @@ class GetPasswordSafeSlotName : Command<CommandID::GET_PW_SAFE_SLOT_NAME> {
uint8_t slot_number;
bool isValid() const { return !(slot_number & 0xF0); }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << "slot_number\t" << slot_number << std::endl;
+ return ss.str(); }
} __packed;
struct ResponsePayload {
uint8_t slot_name[PWS_SLOTNAME_LENGTH];
bool isValid() const { return true; }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " slot_name\t" << slot_name << std::endl;
+ return ss.str(); }
} __packed;
typedef Transaction<command_id(), struct CommandPayload,
@@ -252,12 +268,20 @@ class GetPasswordSafeSlotPassword
uint8_t slot_number;
bool isValid() const { return !(slot_number & 0xF0); }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " slot_number\t" << slot_number<< std::endl;
+ return ss.str(); }
} __packed;
struct ResponsePayload {
uint8_t slot_password[PWS_PASSWORD_LENGTH];
bool isValid() const { return true; }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " slot_password\t" << slot_password << std::endl;
+ return ss.str(); }
} __packed;
typedef Transaction<command_id(), struct CommandPayload,
@@ -271,12 +295,20 @@ class GetPasswordSafeSlotLogin
uint8_t slot_number;
bool isValid() const { return !(slot_number & 0xF0); }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " slot_number\t" << slot_number<< std::endl;
+ return ss.str(); }
} __packed;
struct ResponsePayload {
uint8_t slot_login[PWS_LOGINNAME_LENGTH];
bool isValid() const { return true; }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " slot_login\t" << slot_login<< std::endl;
+ return ss.str(); }
} __packed;
typedef Transaction<command_id(), struct CommandPayload,
diff --git a/unittest/test.cc b/unittest/test.cc
index 2c77b60..2004d1e 100644
--- a/unittest/test.cc
+++ b/unittest/test.cc
@@ -22,9 +22,10 @@ std::string getSlotName(Stick10 &stick, int slotNo) {
TEST_CASE("Slot names are correct", "[slotNames]") {
Stick10 stick;
- stick.connect();
+ bool connected = stick.connect();
+ REQUIRE(connected == true);
- Log::instance().set_loglevel(Loglevel::DEBUG_L2);
+ // Log::instance().set_loglevel(Loglevel::DEBUG_L2);
auto resp = GetStatus::CommandTransaction::run(stick);
@@ -34,5 +35,39 @@ TEST_CASE("Slot names are correct", "[slotNames]") {
REQUIRE(getSlotName(stick, 0x20) == std::string("1"));
REQUIRE(getSlotName(stick, 0x21) == std::string("slot2"));
+
+ {
+ auto resp = GetPasswordRetryCount::CommandTransaction::run(stick);
+ REQUIRE( resp.password_retry_count == 3 );
+ }
+ {
+ auto resp = GetUserPasswordRetryCount::CommandTransaction::run(stick);
+ REQUIRE( resp.password_retry_count == 3 );
+ }
+
+ {
+ GetPasswordSafeSlotName::CommandTransaction::CommandPayload slot;
+ slot.slot_number = 0;
+ auto resp2 = GetPasswordSafeSlotName::CommandTransaction::run(stick, slot);
+ std::string sName(reinterpret_cast<char *>(resp2.slot_name));
+ REQUIRE(sName == std::string("web1"));
+ }
+
+ {
+ GetPasswordSafeSlotPassword::CommandTransaction::CommandPayload slot;
+ slot.slot_number = 0;
+ auto resp2 = GetPasswordSafeSlotPassword::CommandTransaction::run(stick, slot);
+ std::string sName(reinterpret_cast<char *>(resp2.slot_password));
+ REQUIRE(sName == std::string("pass1"));
+ }
+
+ {
+ GetPasswordSafeSlotLogin::CommandTransaction::CommandPayload slot;
+ slot.slot_number = 0;
+ auto resp2 = GetPasswordSafeSlotLogin::CommandTransaction::run(stick, slot);
+ std::string sName(reinterpret_cast<char *>(resp2.slot_login));
+ REQUIRE(sName == std::string("login1"));
+ }
+
stick.disconnect();
}