From 89076a0c44dd12a73060dbfda419c20c4ce5285a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 18:12:37 +0200 Subject: Migrate commands to new format Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 unittest/test2.cc (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc new file mode 100644 index 0000000..6744b45 --- /dev/null +++ b/unittest/test2.cc @@ -0,0 +1,83 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() +#include "catch.hpp" + +#include +#include +#include "device_proto.h" +#include "log.h" +#include "stick10_commands.h" + +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) { + auto slot_req = get_payload(); + slot_req.slot_number = slotNo; + auto slot = ReadSlot::CommandTransaction::run(stick, slot_req); + std::string sName(reinterpret_cast(slot.data().slot_name)); + return sName; +} + +TEST_CASE("Slot names are correct", "[slotNames]") { + Stick10 stick; + bool connected = stick.connect(); + REQUIRE(connected == true); + + Log::instance().set_loglevel(Loglevel::DEBUG); + + auto resp = GetStatus::CommandTransaction::run(stick); + + auto authreq = get_payload(); + strcpy((char *)(authreq.card_password), "12345678"); + FirstAuthenticate::CommandTransaction::run(stick, authreq); + + { + auto authreq = get_payload(); + 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")); + + { + auto resp = GetPasswordRetryCount::CommandTransaction::run(stick); + REQUIRE(resp.data().password_retry_count == 3); + } + { + auto resp = GetUserPasswordRetryCount::CommandTransaction::run(stick); + REQUIRE(resp.data().password_retry_count == 3); + } + + { + auto slot = get_payload(); + slot.slot_number = 0; + auto resp2 = GetPasswordSafeSlotName::CommandTransaction::run(stick, slot); + std::string sName(reinterpret_cast(resp2.data().slot_name)); + REQUIRE(sName == std::string("web1")); + } + + { + auto slot = get_payload(); + slot.slot_number = 0; + auto resp2 = + GetPasswordSafeSlotPassword::CommandTransaction::run(stick, slot); + std::string sName(reinterpret_cast(resp2.data().slot_password)); + REQUIRE(sName == std::string("pass1")); + } + + { + auto slot = get_payload(); + slot.slot_number = 0; + auto resp2 = GetPasswordSafeSlotLogin::CommandTransaction::run(stick, slot); + std::string sName(reinterpret_cast(resp2.data().slot_login)); + REQUIRE(sName == std::string("login1")); + } + + stick.disconnect(); +} -- cgit v1.2.1 From 27355f0dd8eb11fe1a0d41bd05d3c7dcb74341d8 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 19:02:16 +0200 Subject: C++ tests for Storage commands Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 75 ++++++++++++------------------------------------------- 1 file changed, 16 insertions(+), 59 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 6744b45..dfc4182 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -3,80 +3,37 @@ #include #include +#include #include "device_proto.h" #include "log.h" -#include "stick10_commands.h" +//#include "stick10_commands.h" +#include "stick20_commands.h" using namespace std; using namespace nitrokey::device; -using namespace nitrokey::proto::stick10; +using namespace nitrokey::proto::stick20; using namespace nitrokey::log; using namespace nitrokey::misc; -std::string getSlotName(Stick10 &stick, int slotNo) { - auto slot_req = get_payload(); - slot_req.slot_number = slotNo; - auto slot = ReadSlot::CommandTransaction::run(stick, slot_req); - std::string sName(reinterpret_cast(slot.data().slot_name)); - return sName; -} - -TEST_CASE("Slot names are correct", "[slotNames]") { - Stick10 stick; +TEST_CASE("test", "[test]") { + Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); - Log::instance().set_loglevel(Loglevel::DEBUG); - - auto resp = GetStatus::CommandTransaction::run(stick); - - auto authreq = get_payload(); - strcpy((char *)(authreq.card_password), "12345678"); - FirstAuthenticate::CommandTransaction::run(stick, authreq); - - { - auto authreq = get_payload(); - 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")); - - { - auto resp = GetPasswordRetryCount::CommandTransaction::run(stick); - REQUIRE(resp.data().password_retry_count == 3); - } - { - auto resp = GetUserPasswordRetryCount::CommandTransaction::run(stick); - REQUIRE(resp.data().password_retry_count == 3); - } + Log::instance().set_loglevel(Loglevel::DEBUG_L2); { - auto slot = get_payload(); - slot.slot_number = 0; - auto resp2 = GetPasswordSafeSlotName::CommandTransaction::run(stick, slot); - std::string sName(reinterpret_cast(resp2.data().slot_name)); - REQUIRE(sName == std::string("web1")); + auto p = get_payload(); + p.set_kind_user(); + strcpyT(p.password, "123456"); + EnableEncryptedPartition::CommandTransaction::run(stick, p); } - - { - auto slot = get_payload(); - slot.slot_number = 0; - auto resp2 = - GetPasswordSafeSlotPassword::CommandTransaction::run(stick, slot); - std::string sName(reinterpret_cast(resp2.data().slot_password)); - REQUIRE(sName == std::string("pass1")); - } - - { - auto slot = get_payload(); - slot.slot_number = 0; - auto resp2 = GetPasswordSafeSlotLogin::CommandTransaction::run(stick, slot); - std::string sName(reinterpret_cast(resp2.data().slot_login)); - REQUIRE(sName == std::string("login1")); + { + auto p = get_payload(); + p.set_kind_user(); + strcpyT(p.password, "123456"); + DisableEncryptedPartition::CommandTransaction::run(stick, p); } stick.disconnect(); -- cgit v1.2.1 From 3b0452c05b84ede5a2085aee4a550a2a63ccdb65 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 19:31:59 +0200 Subject: C++ tests update Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index dfc4182..b328c37 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -11,6 +11,7 @@ using namespace std; using namespace nitrokey::device; +using namespace nitrokey::proto; using namespace nitrokey::proto::stick20; using namespace nitrokey::log; using namespace nitrokey::misc; @@ -23,17 +24,31 @@ TEST_CASE("test", "[test]") { Log::instance().set_loglevel(Loglevel::DEBUG_L2); + stick10::LockDevice::CommandTransaction::run(stick); +// { +// auto p = get_payload(); +// p.set_kind_user(); +// strcpyT(p.password, "123456"); +// EnableEncryptedPartition::CommandTransaction::run(stick, p); +// } +// { +// auto p = get_payload(); +// p.set_kind_user(); +// strcpyT(p.password, "123456"); +// DisableEncryptedPartition::CommandTransaction::run(stick, p); +// } + { auto p = get_payload(); p.set_kind_user(); strcpyT(p.password, "123456"); EnableEncryptedPartition::CommandTransaction::run(stick, p); } - { - auto p = get_payload(); + { + auto p = get_payload(); p.set_kind_user(); - strcpyT(p.password, "123456"); - DisableEncryptedPartition::CommandTransaction::run(stick, p); + strcpyT(p.password, "123123123"); + EnableHiddenEncryptedPartition::CommandTransaction::run(stick, p); } stick.disconnect(); -- cgit v1.2.1 From d8a6073f6118062266df8ef77c5a7969a9ed8be7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 19:35:26 +0200 Subject: C++ tests update (2) - wait before lock Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index b328c37..79417c6 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -50,6 +50,8 @@ TEST_CASE("test", "[test]") { strcpyT(p.password, "123123123"); EnableHiddenEncryptedPartition::CommandTransaction::run(stick, p); } + this_thread::sleep_for(1000ms); + stick10::LockDevice::CommandTransaction::run(stick); stick.disconnect(); } -- cgit v1.2.1 From 536d2b40239cbff94d7e562a0c0c9cf4f462576f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 14:52:53 +0200 Subject: Test: let device rest after enabling encrypted partition Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 79417c6..883e37b 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -44,6 +44,7 @@ TEST_CASE("test", "[test]") { strcpyT(p.password, "123456"); EnableEncryptedPartition::CommandTransaction::run(stick, p); } + this_thread::sleep_for(1000ms); { auto p = get_payload(); p.set_kind_user(); -- cgit v1.2.1 From 116523fbee311aa7af5151d1a601c8a0f11965e9 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 15:15:04 +0200 Subject: Test: reduced code bloat Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 883e37b..503ab49 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -17,6 +17,15 @@ using namespace nitrokey::log; using namespace nitrokey::misc; +template +void execute_password_command(Device &stick, const char *password) { + auto p = get_payload(); + p.set_kind_user(); + strcpyT(p.password, password); + CMDTYPE::CommandTransaction::run(stick, p); +} + + TEST_CASE("test", "[test]") { Stick20 stick; bool connected = stick.connect(); @@ -25,32 +34,11 @@ TEST_CASE("test", "[test]") { Log::instance().set_loglevel(Loglevel::DEBUG_L2); stick10::LockDevice::CommandTransaction::run(stick); -// { -// auto p = get_payload(); -// p.set_kind_user(); -// strcpyT(p.password, "123456"); -// EnableEncryptedPartition::CommandTransaction::run(stick, p); -// } -// { -// auto p = get_payload(); -// p.set_kind_user(); -// strcpyT(p.password, "123456"); -// DisableEncryptedPartition::CommandTransaction::run(stick, p); -// } - - { - auto p = get_payload(); - p.set_kind_user(); - strcpyT(p.password, "123456"); - EnableEncryptedPartition::CommandTransaction::run(stick, p); - } +// execute_password_command(stick, "123456"); +// execute_password_command(stick, "123456"); + execute_password_command(stick, "123456"); this_thread::sleep_for(1000ms); - { - auto p = get_payload(); - p.set_kind_user(); - strcpyT(p.password, "123123123"); - EnableHiddenEncryptedPartition::CommandTransaction::run(stick, p); - } + execute_password_command(stick, "123123123"); this_thread::sleep_for(1000ms); stick10::LockDevice::CommandTransaction::run(stick); -- cgit v1.2.1 From 003189e780af8208f243bbd312df5f5295015eb1 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 15:50:15 +0200 Subject: Test: check more commands Add delay after each command by default. Check EnableHiddenEncryptedPartition more than once. Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 503ab49..61fb502 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -18,11 +18,16 @@ using namespace nitrokey::misc; template -void execute_password_command(Device &stick, const char *password) { +void execute_password_command(Device &stick, const char *password, const char kind = 'P') { auto p = get_payload(); - p.set_kind_user(); + if (kind == 'P'){ + p.set_kind_user(); + } else { + p.set_kind_admin(); + } strcpyT(p.password, password); CMDTYPE::CommandTransaction::run(stick, p); + this_thread::sleep_for(1000ms); } @@ -36,10 +41,33 @@ TEST_CASE("test", "[test]") { stick10::LockDevice::CommandTransaction::run(stick); // execute_password_command(stick, "123456"); // execute_password_command(stick, "123456"); - execute_password_command(stick, "123456"); this_thread::sleep_for(1000ms); - execute_password_command(stick, "123123123"); + execute_password_command(stick, "123456"); + this_thread::sleep_for(4000ms); + bool passed = false; + for(int i=0; i<5; i++){ + try { + execute_password_command(stick, "123123123"); + CHECK(true); + passed=true; + break; + } + catch (CommandFailedException &e){ + this_thread::sleep_for(2000ms); + } + } + if(!passed){ + CHECK(false); + } + + execute_password_command(stick, "123123123"); + execute_password_command(stick, "123456"); + execute_password_command(stick, "123456"); + execute_password_command(stick, "12345678", 'A'); this_thread::sleep_for(1000ms); +// execute_password_command(stick, "123123123"); +// execute_password_command(stick, "123123123"); //FIRMWARE PIN + stick10::LockDevice::CommandTransaction::run(stick); stick.disconnect(); -- cgit v1.2.1 From 29974c0d51f099af9869e49597f77936fc069376 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 16:19:50 +0200 Subject: Test: another commands Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 61fb502..91982c9 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -65,8 +65,12 @@ TEST_CASE("test", "[test]") { execute_password_command(stick, "123456"); execute_password_command(stick, "12345678", 'A'); this_thread::sleep_for(1000ms); -// execute_password_command(stick, "123123123"); -// execute_password_command(stick, "123123123"); //FIRMWARE PIN +// execute_password_command(stick, "123123123"); //CAUTION +// execute_password_command(stick, "123123123"); //CAUTION FIRMWARE PIN + + execute_password_command(stick, "12345678", 'A'); +// execute_password_command(stick, "12345678", 'A'); + stick10::LockDevice::CommandTransaction::run(stick); -- cgit v1.2.1 From d02c321effbc8b1ae6e8e54f93df53d57ab0d7e1 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 17:52:15 +0200 Subject: Test: check device status. Use automatic disconnection. Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 91982c9..9739217 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -64,6 +64,7 @@ TEST_CASE("test", "[test]") { execute_password_command(stick, "123456"); execute_password_command(stick, "123456"); execute_password_command(stick, "12345678", 'A'); + stick20::GetDeviceStatus::CommandTransaction::run(stick); this_thread::sleep_for(1000ms); // execute_password_command(stick, "123123123"); //CAUTION // execute_password_command(stick, "123123123"); //CAUTION FIRMWARE PIN @@ -71,8 +72,5 @@ TEST_CASE("test", "[test]") { execute_password_command(stick, "12345678", 'A'); // execute_password_command(stick, "12345678", 'A'); - stick10::LockDevice::CommandTransaction::run(stick); - - stick.disconnect(); } -- cgit v1.2.1 From b0412c73b8ff129183f570a4eed72bdafd9f55d3 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 25 Oct 2016 18:41:59 +0200 Subject: Handle FillSDCardWithRandomChars command and test it Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 9739217..3cfc5c1 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -31,6 +31,40 @@ void execute_password_command(Device &stick, const char *password, const char ki } +TEST_CASE("long operation test", "[test_long]") { + Stick20 stick; + bool connected = stick.connect(); + REQUIRE(connected == true); + Log::instance().set_loglevel(Loglevel::DEBUG_L2); + try{ +// execute_password_command(stick, "12345678", 'P'); + auto p = get_payload(); + p.set_defaults(); + strcpyT(p.password, "12345678"); + FillSDCardWithRandomChars::CommandTransaction::run(stick, p); + this_thread::sleep_for(1000ms); + + CHECK(false); + } + catch (LongOperationInProgressException &progressException){ + CHECK(true); + } + + + for (int i = 0; i < 30; ++i) { + try { + stick10::GetStatus::CommandTransaction::run(stick); + } + catch (LongOperationInProgressException &progressException){ + CHECK((int)progressException.progress_bar_value>=0); + CAPTURE((int)progressException.progress_bar_value); + this_thread::sleep_for(2000ms); + } + + } + +} + TEST_CASE("test", "[test]") { Stick20 stick; bool connected = stick.connect(); -- cgit v1.2.1 From d7ee36dfdfc5a896f5ef7d04b7f1f70f05256ebc Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 27 Oct 2016 20:23:04 +0200 Subject: Test command ids correctness and getting device status Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 3cfc5c1..8e3dacc 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -65,7 +65,68 @@ TEST_CASE("long operation test", "[test_long]") { } -TEST_CASE("test", "[test]") { + +#include "test_command_ids_header.h" + +TEST_CASE("test device commands ids", "[fast]") { + +// REQUIRE(STICK20_CMD_START_VALUE == static_cast(CommandID::START_VALUE)); + REQUIRE(STICK20_CMD_ENABLE_CRYPTED_PARI == static_cast(CommandID::ENABLE_CRYPTED_PARI)); + REQUIRE(STICK20_CMD_DISABLE_CRYPTED_PARI == static_cast(CommandID::DISABLE_CRYPTED_PARI)); + REQUIRE(STICK20_CMD_ENABLE_HIDDEN_CRYPTED_PARI == static_cast(CommandID::ENABLE_HIDDEN_CRYPTED_PARI)); + REQUIRE(STICK20_CMD_DISABLE_HIDDEN_CRYPTED_PARI == static_cast(CommandID::DISABLE_HIDDEN_CRYPTED_PARI)); + REQUIRE(STICK20_CMD_ENABLE_FIRMWARE_UPDATE == static_cast(CommandID::ENABLE_FIRMWARE_UPDATE)); + REQUIRE(STICK20_CMD_EXPORT_FIRMWARE_TO_FILE == static_cast(CommandID::EXPORT_FIRMWARE_TO_FILE)); + REQUIRE(STICK20_CMD_GENERATE_NEW_KEYS == static_cast(CommandID::GENERATE_NEW_KEYS)); + REQUIRE(STICK20_CMD_FILL_SD_CARD_WITH_RANDOM_CHARS == static_cast(CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS)); + + REQUIRE(STICK20_CMD_WRITE_STATUS_DATA == static_cast(CommandID::WRITE_STATUS_DATA)); + REQUIRE(STICK20_CMD_ENABLE_READONLY_UNCRYPTED_LUN == static_cast(CommandID::ENABLE_READONLY_UNCRYPTED_LUN)); + REQUIRE(STICK20_CMD_ENABLE_READWRITE_UNCRYPTED_LUN == static_cast(CommandID::ENABLE_READWRITE_UNCRYPTED_LUN)); + + REQUIRE(STICK20_CMD_SEND_PASSWORD_MATRIX == static_cast(CommandID::SEND_PASSWORD_MATRIX)); + REQUIRE(STICK20_CMD_SEND_PASSWORD_MATRIX_PINDATA == static_cast(CommandID::SEND_PASSWORD_MATRIX_PINDATA)); + REQUIRE(STICK20_CMD_SEND_PASSWORD_MATRIX_SETUP == static_cast(CommandID::SEND_PASSWORD_MATRIX_SETUP)); + + REQUIRE(STICK20_CMD_GET_DEVICE_STATUS == static_cast(CommandID::GET_DEVICE_STATUS)); + REQUIRE(STICK20_CMD_SEND_DEVICE_STATUS == static_cast(CommandID::SEND_DEVICE_STATUS)); + + REQUIRE(STICK20_CMD_SEND_HIDDEN_VOLUME_PASSWORD == static_cast(CommandID::SEND_HIDDEN_VOLUME_PASSWORD)); + REQUIRE(STICK20_CMD_SEND_HIDDEN_VOLUME_SETUP == static_cast(CommandID::SEND_HIDDEN_VOLUME_SETUP)); + REQUIRE(STICK20_CMD_SEND_PASSWORD == static_cast(CommandID::SEND_PASSWORD)); + REQUIRE(STICK20_CMD_SEND_NEW_PASSWORD == static_cast(CommandID::SEND_NEW_PASSWORD)); + REQUIRE(STICK20_CMD_CLEAR_NEW_SD_CARD_FOUND == static_cast(CommandID::CLEAR_NEW_SD_CARD_FOUND)); + + REQUIRE(STICK20_CMD_SEND_STARTUP == static_cast(CommandID::SEND_STARTUP)); + REQUIRE(STICK20_CMD_SEND_CLEAR_STICK_KEYS_NOT_INITIATED == static_cast(CommandID::SEND_CLEAR_STICK_KEYS_NOT_INITIATED)); + REQUIRE(STICK20_CMD_SEND_LOCK_STICK_HARDWARE == static_cast(CommandID::SEND_LOCK_STICK_HARDWARE)); + + REQUIRE(STICK20_CMD_PRODUCTION_TEST == static_cast(CommandID::PRODUCTION_TEST)); + REQUIRE(STICK20_CMD_SEND_DEBUG_DATA == static_cast(CommandID::SEND_DEBUG_DATA)); + + REQUIRE(STICK20_CMD_CHANGE_UPDATE_PIN == static_cast(CommandID::CHANGE_UPDATE_PIN)); + +} + +TEST_CASE("test device internal status with various commands", "[fast]") { + Stick20 stick; + bool connected = stick.connect(); + REQUIRE(connected == true); + + Log::instance().set_loglevel(Loglevel::DEBUG_L2); + auto p = get_payload(); + p.set_defaults(); + auto device_status = stick20::SendStartup::CommandTransaction::run(stick, p); + REQUIRE(device_status.data().AdminPwRetryCount == 3); + REQUIRE(device_status.data().UserPwRetryCount == 3); + REQUIRE(device_status.data().ActiveSmartCardID_u32 != 0); + + auto production_status = stick20::ProductionTest::CommandTransaction::run(stick); + REQUIRE(production_status.data().SD_Card_Size_u8 == 8); + REQUIRE(production_status.data().SD_CardID_u32 != 0); +} + +TEST_CASE("general test", "[test]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); -- cgit v1.2.1 From d58f3fd3bb6df5d3f46e3c4c3b719174e31b7201 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 27 Oct 2016 21:14:17 +0200 Subject: Support for setting hidden volume and test for it Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 8e3dacc..d79042a 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -126,6 +126,26 @@ TEST_CASE("test device internal status with various commands", "[fast]") { REQUIRE(production_status.data().SD_CardID_u32 != 0); } +TEST_CASE("setup hidden volume test", "[hidden]") { + Stick20 stick; + bool connected = stick.connect(); + REQUIRE(connected == true); + Log::instance().set_loglevel(Loglevel::DEBUG_L2); + stick10::LockDevice::CommandTransaction::run(stick); + this_thread::sleep_for(2000ms); + + execute_password_command(stick, "123456"); + + auto p = get_payload(); + p.set_defaults(); + auto hidden_volume_password = "123123123"; + strcpyT(p.HiddenVolumePassword_au8, hidden_volume_password); + stick20::SetupHiddenVolume::CommandTransaction::run(stick, p); + this_thread::sleep_for(2000ms); + + execute_password_command(stick, hidden_volume_password); +} + TEST_CASE("general test", "[test]") { Stick20 stick; bool connected = stick.connect(); -- cgit v1.2.1 From 9772055e79da77c6ec9ea6992cc77891efc1265a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 11:31:16 +0200 Subject: Test multiple hidden volumes with different passwords and locations Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index d79042a..21122ef 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -146,6 +146,38 @@ TEST_CASE("setup hidden volume test", "[hidden]") { execute_password_command(stick, hidden_volume_password); } +TEST_CASE("setup multiple hidden volumes", "[hidden2]") { + Stick20 stick; + bool connected = stick.connect(); + REQUIRE(connected == true); + Log::instance().set_loglevel(Loglevel::DEBUG_L2); + + auto user_pin = "123456"; + stick10::LockDevice::CommandTransaction::run(stick); + this_thread::sleep_for(2000ms); + execute_password_command(stick, user_pin); + + constexpr int volume_count = 4; + for (int i = 0; i < volume_count; ++i) { + auto p = get_payload(); + p.SlotNr_u8 = i; + p.StartBlockPercent_u8 = 20 + 10*i; + p.EndBlockPercent_u8 = p.StartBlockPercent_u8+i+1; + auto hidden_volume_password = std::string("123123123")+std::to_string(i); + strcpyT(p.HiddenVolumePassword_au8, hidden_volume_password.c_str()); + stick20::SetupHiddenVolume::CommandTransaction::run(stick, p); + this_thread::sleep_for(2000ms); + } + + + for (int i = 0; i < volume_count; ++i) { + execute_password_command(stick, user_pin); + auto hidden_volume_password = std::string("123123123")+std::to_string(i); + execute_password_command(stick, hidden_volume_password.c_str()); + this_thread::sleep_for(2000ms); + } +} + TEST_CASE("general test", "[test]") { Stick20 stick; bool connected = stick.connect(); -- cgit v1.2.1 From 3b1926164b2e0eb91cf3a7e9c854cca85f7d4c8e Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 14:33:25 +0200 Subject: Support for changing firmware update password and test Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 21122ef..8db91b7 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -178,7 +178,30 @@ TEST_CASE("setup multiple hidden volumes", "[hidden2]") { } } -TEST_CASE("general test", "[test]") { +//in case of a bug this could change update PIN to some unexpected value +// - please save log with packet dump if this test will not pass +TEST_CASE("update password change", "[dangerous]") { + Stick20 stick; + bool connected = stick.connect(); + REQUIRE(connected == true); + Log::instance().set_loglevel(Loglevel::DEBUG_L2); + + auto pass1 = "12345678"; + auto pass2 = "12345678901234567890"; + + auto data = { + make_pair(pass1, pass2), + make_pair(pass2, pass1), + }; + for (auto && password: data) { + auto p = get_payload(); + strcpyT(p.current_update_password, password.first); + strcpyT(p.new_update_password, password.second); + stick20::ChangeUpdatePassword::CommandTransaction::run(stick, p); + } +} + + TEST_CASE("general test", "[test]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); -- cgit v1.2.1 From 6343eea03980627cb763de777af6b316130bdf43 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 14:55:56 +0200 Subject: Support getting SD card occupancy and test Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 8db91b7..f5d2b28 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -124,6 +124,12 @@ TEST_CASE("test device internal status with various commands", "[fast]") { auto production_status = stick20::ProductionTest::CommandTransaction::run(stick); REQUIRE(production_status.data().SD_Card_Size_u8 == 8); REQUIRE(production_status.data().SD_CardID_u32 != 0); + + auto sdcard_occupancy = stick20::GetSDCardOccupancy::CommandTransaction::run(stick); + REQUIRE((int) sdcard_occupancy.data().ReadLevelMin >= 0); + REQUIRE((int) sdcard_occupancy.data().ReadLevelMax <= 100); + REQUIRE((int) sdcard_occupancy.data().WriteLevelMin >= 0); + REQUIRE((int) sdcard_occupancy.data().WriteLevelMax <= 100); } TEST_CASE("setup hidden volume test", "[hidden]") { -- cgit v1.2.1 From ce30b49b4d50f2eff39a40ddd0c02ad96b78654c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 16:29:55 +0200 Subject: Make packet variables' names more clear General fixes Remove default values from hidden volume setup command rename password -> pin Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index f5d2b28..9aaef3f 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -40,7 +40,7 @@ TEST_CASE("long operation test", "[test_long]") { // execute_password_command(stick, "12345678", 'P'); auto p = get_payload(); p.set_defaults(); - strcpyT(p.password, "12345678"); + strcpyT(p.admin_pin, "12345678"); FillSDCardWithRandomChars::CommandTransaction::run(stick, p); this_thread::sleep_for(1000ms); @@ -143,7 +143,9 @@ TEST_CASE("setup hidden volume test", "[hidden]") { execute_password_command(stick, "123456"); auto p = get_payload(); - p.set_defaults(); + p.SlotNr_u8 = 0; + p.StartBlockPercent_u8 = 70; + p.EndBlockPercent_u8 = 90; auto hidden_volume_password = "123123123"; strcpyT(p.HiddenVolumePassword_au8, hidden_volume_password); stick20::SetupHiddenVolume::CommandTransaction::run(stick, p); -- cgit v1.2.1 From 6af0fa2c553ca1a31da63b7164b53defe11172df Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 19:07:51 +0200 Subject: Tests refactoring - replace magic values with constants Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 9aaef3f..94a0dd3 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -1,4 +1,8 @@ #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() +static const char *const default_admin_pin = "12345678"; + +static const char *const default_user_pin = "123456"; + #include "catch.hpp" #include @@ -37,10 +41,9 @@ TEST_CASE("long operation test", "[test_long]") { REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG_L2); try{ -// execute_password_command(stick, "12345678", 'P'); auto p = get_payload(); p.set_defaults(); - strcpyT(p.admin_pin, "12345678"); + strcpyT(p.admin_pin, default_admin_pin); FillSDCardWithRandomChars::CommandTransaction::run(stick, p); this_thread::sleep_for(1000ms); @@ -140,7 +143,8 @@ TEST_CASE("setup hidden volume test", "[hidden]") { stick10::LockDevice::CommandTransaction::run(stick); this_thread::sleep_for(2000ms); - execute_password_command(stick, "123456"); + auto user_pin = default_user_pin; + execute_password_command(stick, user_pin); auto p = get_payload(); p.SlotNr_u8 = 0; @@ -160,7 +164,7 @@ TEST_CASE("setup multiple hidden volumes", "[hidden2]") { REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG_L2); - auto user_pin = "123456"; + auto user_pin = default_user_pin; stick10::LockDevice::CommandTransaction::run(stick); this_thread::sleep_for(2000ms); execute_password_command(stick, user_pin); @@ -194,7 +198,7 @@ TEST_CASE("update password change", "[dangerous]") { REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG_L2); - auto pass1 = "12345678"; + auto pass1 = default_admin_pin; auto pass2 = "12345678901234567890"; auto data = { @@ -220,7 +224,7 @@ TEST_CASE("update password change", "[dangerous]") { // execute_password_command(stick, "123456"); // execute_password_command(stick, "123456"); this_thread::sleep_for(1000ms); - execute_password_command(stick, "123456"); + execute_password_command(stick, default_user_pin); this_thread::sleep_for(4000ms); bool passed = false; for(int i=0; i<5; i++){ @@ -239,9 +243,11 @@ TEST_CASE("update password change", "[dangerous]") { } execute_password_command(stick, "123123123"); - execute_password_command(stick, "123456"); - execute_password_command(stick, "123456"); - execute_password_command(stick, "12345678", 'A'); + + + execute_password_command(stick, default_user_pin); + execute_password_command(stick, default_user_pin); + execute_password_command(stick, default_admin_pin, 'A'); stick20::GetDeviceStatus::CommandTransaction::run(stick); this_thread::sleep_for(1000ms); // execute_password_command(stick, "123123123"); //CAUTION -- cgit v1.2.1 From 4200d7428ac200fd7c0fb57e67aed9f492bfb3d5 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 20:04:14 +0200 Subject: Tests: skip long and dangerous tests remove hidden volume test from general test Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index 94a0dd3..e4edf87 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -1,6 +1,6 @@ #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() -static const char *const default_admin_pin = "12345678"; +static const char *const default_admin_pin = "12345678"; static const char *const default_user_pin = "123456"; #include "catch.hpp" @@ -34,8 +34,19 @@ void execute_password_command(Device &stick, const char *password, const char ki this_thread::sleep_for(1000ms); } +/** + * fail on purpose (will result in failed test) + * disable from running unwillingly + */ +void SKIP_TEST() { + CAPTURE("Failing current test to SKIP it"); + REQUIRE(false); +} + TEST_CASE("long operation test", "[test_long]") { + SKIP_TEST(); + Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); @@ -158,7 +169,7 @@ TEST_CASE("setup hidden volume test", "[hidden]") { execute_password_command(stick, hidden_volume_password); } -TEST_CASE("setup multiple hidden volumes", "[hidden2]") { +TEST_CASE("setup multiple hidden volumes", "[hidden]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); @@ -190,9 +201,12 @@ TEST_CASE("setup multiple hidden volumes", "[hidden2]") { } } + //in case of a bug this could change update PIN to some unexpected value // - please save log with packet dump if this test will not pass TEST_CASE("update password change", "[dangerous]") { + SKIP_TEST(); + Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); @@ -213,7 +227,7 @@ TEST_CASE("update password change", "[dangerous]") { } } - TEST_CASE("general test", "[test]") { +TEST_CASE("general test", "[test]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); @@ -223,27 +237,7 @@ TEST_CASE("update password change", "[dangerous]") { stick10::LockDevice::CommandTransaction::run(stick); // execute_password_command(stick, "123456"); // execute_password_command(stick, "123456"); - this_thread::sleep_for(1000ms); - execute_password_command(stick, default_user_pin); - this_thread::sleep_for(4000ms); - bool passed = false; - for(int i=0; i<5; i++){ - try { - execute_password_command(stick, "123123123"); - CHECK(true); - passed=true; - break; - } - catch (CommandFailedException &e){ - this_thread::sleep_for(2000ms); - } - } - if(!passed){ - CHECK(false); - } - - execute_password_command(stick, "123123123"); - +// execute_password_command(stick, "123123123"); execute_password_command(stick, default_user_pin); execute_password_command(stick, default_user_pin); -- cgit v1.2.1 From 0a15620115f4f6d56ec99777e1996497d7175bc2 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 2 Nov 2016 21:52:09 +0100 Subject: Decrease debug log output in c++ tests Signed-off-by: Szczepan Zalega --- unittest/test2.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'unittest/test2.cc') diff --git a/unittest/test2.cc b/unittest/test2.cc index e4edf87..00e70e3 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -50,7 +50,7 @@ TEST_CASE("long operation test", "[test_long]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); - Log::instance().set_loglevel(Loglevel::DEBUG_L2); + Log::instance().set_loglevel(Loglevel::DEBUG); try{ auto p = get_payload(); p.set_defaults(); @@ -127,8 +127,8 @@ TEST_CASE("test device internal status with various commands", "[fast]") { bool connected = stick.connect(); REQUIRE(connected == true); - Log::instance().set_loglevel(Loglevel::DEBUG_L2); - auto p = get_payload(); + Log::instance().set_loglevel(Loglevel::DEBUG); + auto p = get_payload(); p.set_defaults(); auto device_status = stick20::SendStartup::CommandTransaction::run(stick, p); REQUIRE(device_status.data().AdminPwRetryCount == 3); @@ -150,7 +150,7 @@ TEST_CASE("setup hidden volume test", "[hidden]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); - Log::instance().set_loglevel(Loglevel::DEBUG_L2); + Log::instance().set_loglevel(Loglevel::DEBUG); stick10::LockDevice::CommandTransaction::run(stick); this_thread::sleep_for(2000ms); @@ -173,7 +173,7 @@ TEST_CASE("setup multiple hidden volumes", "[hidden]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); - Log::instance().set_loglevel(Loglevel::DEBUG_L2); + Log::instance().set_loglevel(Loglevel::DEBUG); auto user_pin = default_user_pin; stick10::LockDevice::CommandTransaction::run(stick); @@ -210,7 +210,7 @@ TEST_CASE("update password change", "[dangerous]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); - Log::instance().set_loglevel(Loglevel::DEBUG_L2); + Log::instance().set_loglevel(Loglevel::DEBUG); auto pass1 = default_admin_pin; auto pass2 = "12345678901234567890"; @@ -232,7 +232,7 @@ TEST_CASE("general test", "[test]") { bool connected = stick.connect(); REQUIRE(connected == true); - Log::instance().set_loglevel(Loglevel::DEBUG_L2); + Log::instance().set_loglevel(Loglevel::DEBUG); stick10::LockDevice::CommandTransaction::run(stick); // execute_password_command(stick, "123456"); -- cgit v1.2.1