diff options
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/requirements.txt | 1 | ||||
-rw-r--r-- | unittest/test_memory.c | 63 | ||||
-rw-r--r-- | unittest/test_offline.cc | 4 | ||||
-rw-r--r-- | unittest/test_pro.py | 7 |
4 files changed, 75 insertions, 0 deletions
diff --git a/unittest/requirements.txt b/unittest/requirements.txt index 6d718ad..d8a7e29 100644 --- a/unittest/requirements.txt +++ b/unittest/requirements.txt @@ -1,4 +1,5 @@ cffi +pytest pytest-repeat pytest-randomly tqdm diff --git a/unittest/test_memory.c b/unittest/test_memory.c new file mode 100644 index 0000000..20b11b2 --- /dev/null +++ b/unittest/test_memory.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2020 Nitrokey UG + * + * This file is part of libnitrokey. + * + * libnitrokey is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * libnitrokey is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libnitrokey. If not, see <http://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: LGPL-3.0 + */ + +#include <stdlib.h> +#include "../NK_C_API.h" + +// This test should be run with valgrind to make sure that there are no +// memory leaks in the tested functions: +// valgrind ./test_memory +int main() { + int result = NK_login_auto(); + if (result != 1) + return 1; + + int retry_count = NK_get_admin_retry_count(); + if (retry_count != 3) + return 1; + retry_count = NK_get_user_retry_count(); + if (retry_count != 3) + return 1; + + enum NK_device_model model = NK_get_device_model(); + if (model != NK_PRO && model != NK_STORAGE) + return 1; + + uint8_t *config = NK_read_config(); + if (config == NULL) + return 1; + NK_free_config(config); + + result = NK_enable_password_safe("123456"); + if (result != 0) + return 1; + + uint8_t *slot_status = NK_get_password_safe_slot_status(); + if (slot_status == NULL) { + return 1; + } + NK_free_password_safe_slot_status(slot_status); + + NK_logout(); + + return 0; +} + diff --git a/unittest/test_offline.cc b/unittest/test_offline.cc index 320ad48..3ca3905 100644 --- a/unittest/test_offline.cc +++ b/unittest/test_offline.cc @@ -67,6 +67,10 @@ TEST_CASE("Test C++ side behaviour in offline", "[fast]") { REQUIRE(serial_number.empty()); REQUIRE_THROWS_AS( + i->get_serial_number_as_u32(), DeviceNotConnected + ); + + REQUIRE_THROWS_AS( i->get_status(), DeviceNotConnected ); diff --git a/unittest/test_pro.py b/unittest/test_pro.py index e61d8bf..0d8c536 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -728,6 +728,13 @@ def test_get_serial_number(C): print(('Serial number of the device: ', sn)) +@pytest.mark.status +def test_get_serial_number_as_u32(C): + sn = C.NK_device_serial_number_as_u32() + assert sn > 0 + print(('Serial number of the device (u32): ', sn)) + + @pytest.mark.otp @pytest.mark.parametrize("secret", ['000001', '00'*10+'ff', '00'*19+'ff', '000102', '00'*29+'ff', '00'*39+'ff', '002EF43F51AFA97BA2B46418768123C9E1809A5B' ]) |