summaryrefslogtreecommitdiff
path: root/nitrokey/tests
diff options
context:
space:
mode:
Diffstat (limited to 'nitrokey/tests')
-rw-r--r--nitrokey/tests/device.rs57
-rw-r--r--nitrokey/tests/lib.rs3
-rw-r--r--nitrokey/tests/pws.rs23
3 files changed, 63 insertions, 20 deletions
diff --git a/nitrokey/tests/device.rs b/nitrokey/tests/device.rs
index e40ae12..849d2ff 100644
--- a/nitrokey/tests/device.rs
+++ b/nitrokey/tests/device.rs
@@ -260,6 +260,15 @@ fn unlock_user_pin(device: DeviceWrapper) {
#[test_device]
fn factory_reset(device: DeviceWrapper) {
+ let admin = device.authenticate_admin(ADMIN_PASSWORD).unwrap();
+ let otp_data = OtpSlotData::new(1, "test", "0123468790", OtpMode::SixDigits);
+ assert_eq!(Ok(()), admin.write_totp_slot(otp_data, 30));
+
+ let device = admin.device();
+ let pws = device.get_password_safe(USER_PASSWORD).unwrap();
+ assert_eq!(Ok(()), pws.write_slot(0, "test", "testlogin", "testpw"));
+ drop(pws);
+
assert_eq!(
Ok(()),
device.change_user_pin(USER_PASSWORD, USER_NEW_PASSWORD)
@@ -269,15 +278,6 @@ fn factory_reset(device: DeviceWrapper) {
device.change_admin_pin(ADMIN_PASSWORD, ADMIN_NEW_PASSWORD)
);
- let admin = device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap();
- let otp_data = OtpSlotData::new(1, "test", "0123468790", OtpMode::SixDigits);
- assert_eq!(Ok(()), admin.write_totp_slot(otp_data, 30));
-
- let device = admin.device();
- let pws = device.get_password_safe(USER_NEW_PASSWORD).unwrap();
- assert_eq!(Ok(()), pws.write_slot(0, "test", "testlogin", "testpw"));
- drop(pws);
-
assert_eq!(
Err(CommandError::WrongPassword),
device.factory_reset(USER_NEW_PASSWORD)
@@ -439,6 +439,45 @@ fn get_storage_status(device: Storage) {
}
#[test_device]
+fn get_production_info(device: Storage) {
+ let info = device.get_production_info().unwrap();
+ assert_eq!(0, info.firmware_version_major);
+ assert!(info.firmware_version_minor != 0);
+ assert!(info.serial_number_cpu != 0);
+ assert!(info.sd_card.serial_number != 0);
+ assert!(info.sd_card.size > 0);
+ assert!(info.sd_card.manufacturing_year > 10);
+ assert!(info.sd_card.manufacturing_year < 100);
+ // TODO: month value is not valid atm
+ // assert!(info.sd_card.manufacturing_month < 12);
+ assert!(info.sd_card.oem != 0);
+ assert!(info.sd_card.manufacturer != 0);
+
+ let status = device.get_status().unwrap();
+ assert_eq!(status.firmware_version_major, info.firmware_version_major);
+ assert_eq!(status.firmware_version_minor, info.firmware_version_minor);
+ assert_eq!(status.serial_number_sd_card, info.sd_card.serial_number);
+}
+
+#[test_device]
+fn clear_new_sd_card_warning(device: Storage) {
+ assert_eq!(Ok(()), device.factory_reset(ADMIN_PASSWORD));
+ thread::sleep(time::Duration::from_secs(3));
+ assert_eq!(Ok(()), device.build_aes_key(ADMIN_PASSWORD));
+
+ // We have to perform an SD card operation to reset the new_sd_card_found field
+ assert_eq!(Ok(()), device.lock());
+
+ let status = device.get_status().unwrap();
+ assert!(status.new_sd_card_found);
+
+ assert_eq!(Ok(()), device.clear_new_sd_card_warning(ADMIN_PASSWORD));
+
+ let status = device.get_status().unwrap();
+ assert!(!status.new_sd_card_found);
+}
+
+#[test_device]
fn export_firmware(device: Storage) {
assert_eq!(
Err(CommandError::WrongPassword),
diff --git a/nitrokey/tests/lib.rs b/nitrokey/tests/lib.rs
index 06de0ad..c92e224 100644
--- a/nitrokey/tests/lib.rs
+++ b/nitrokey/tests/lib.rs
@@ -2,7 +2,6 @@
fn get_library_version() {
let version = nitrokey::get_library_version();
- assert!(!version.git.is_empty());
- assert!(version.git.starts_with("v"));
+ assert!(version.git.is_empty() || version.git.starts_with("v"));
assert!(version.major > 0);
}
diff --git a/nitrokey/tests/pws.rs b/nitrokey/tests/pws.rs
index b349558..fbcc0c1 100644
--- a/nitrokey/tests/pws.rs
+++ b/nitrokey/tests/pws.rs
@@ -20,7 +20,7 @@ fn get_slot_name_direct(slot: u8) -> Result<String, CommandError> {
true => {
let error = unsafe { nitrokey_sys::NK_get_last_command_status() } as c_int;
match error {
- 0 => Err(CommandError::Undefined),
+ 0 => Ok(s),
other => Err(CommandError::from(other)),
}
}
@@ -92,10 +92,12 @@ fn get_data(device: DeviceWrapper) {
assert_eq!("password", pws.get_slot_password(1).unwrap());
assert_eq!(Ok(()), pws.erase_slot(1));
- // TODO: check error codes
- assert_eq!(Err(CommandError::Undefined), pws.get_slot_name(1));
- assert_eq!(Err(CommandError::Undefined), pws.get_slot_login(1));
- assert_eq!(Err(CommandError::Undefined), pws.get_slot_password(1));
+ assert_eq!(Err(CommandError::SlotNotProgrammed), pws.get_slot_name(1));
+ assert_eq!(Err(CommandError::SlotNotProgrammed), pws.get_slot_login(1));
+ assert_eq!(
+ Err(CommandError::SlotNotProgrammed),
+ pws.get_slot_password(1)
+ );
let name = "with å";
let login = "pär@test.com";
@@ -129,19 +131,22 @@ fn write(device: DeviceWrapper) {
);
assert_eq!(Ok(()), pws.write_slot(0, "", "login", "password"));
- assert_eq!(Err(CommandError::Undefined), pws.get_slot_name(0));
+ assert_eq!(Err(CommandError::SlotNotProgrammed), pws.get_slot_name(0));
assert_eq!(Ok(String::from("login")), pws.get_slot_login(0));
assert_eq!(Ok(String::from("password")), pws.get_slot_password(0));
assert_eq!(Ok(()), pws.write_slot(0, "name", "", "password"));
assert_eq!(Ok(String::from("name")), pws.get_slot_name(0));
- assert_eq!(Err(CommandError::Undefined), pws.get_slot_login(0));
+ assert_eq!(Err(CommandError::SlotNotProgrammed), pws.get_slot_login(0));
assert_eq!(Ok(String::from("password")), pws.get_slot_password(0));
assert_eq!(Ok(()), pws.write_slot(0, "name", "login", ""));
assert_eq!(Ok(String::from("name")), pws.get_slot_name(0));
assert_eq!(Ok(String::from("login")), pws.get_slot_login(0));
- assert_eq!(Err(CommandError::Undefined), pws.get_slot_password(0));
+ assert_eq!(
+ Err(CommandError::SlotNotProgrammed),
+ pws.get_slot_password(0)
+ );
}
#[test_device]
@@ -152,5 +157,5 @@ fn erase(device: DeviceWrapper) {
assert_eq!(Ok(()), pws.write_slot(0, "name", "login", "password"));
assert_eq!(Ok(()), pws.erase_slot(0));
assert_eq!(Ok(()), pws.erase_slot(0));
- assert_eq!(Err(CommandError::Undefined), pws.get_slot_name(0));
+ assert_eq!(Err(CommandError::SlotNotProgrammed), pws.get_slot_name(0));
}