aboutsummaryrefslogtreecommitdiff
path: root/nitrokey/tests
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-12 13:24:21 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-12 13:24:21 -0800
commit541819637e0bec0b58b32ed0721d51610a8a7d3b (patch)
treef0d7d270a4eaca1025709d02a508ef638fb076cf /nitrokey/tests
parent16ed68c0f5e3ccb330c7a5f7c11781bc7a129b03 (diff)
downloadnitrocli-541819637e0bec0b58b32ed0721d51610a8a7d3b.tar.gz
nitrocli-541819637e0bec0b58b32ed0721d51610a8a7d3b.tar.bz2
Update nitrokey crate to 0.3.2
This change updates the nitrokey crate to version 0.3.2. Import subrepo nitrokey/:nitrokey at 6ea73f29daa5db0215663a0a38334b764863671d
Diffstat (limited to 'nitrokey/tests')
-rw-r--r--nitrokey/tests/device.rs61
-rw-r--r--nitrokey/tests/lib.rs8
-rw-r--r--nitrokey/tests/otp.rs20
-rw-r--r--nitrokey/tests/util/mod.rs1
4 files changed, 76 insertions, 14 deletions
diff --git a/nitrokey/tests/device.rs b/nitrokey/tests/device.rs
index db8194c..e40ae12 100644
--- a/nitrokey/tests/device.rs
+++ b/nitrokey/tests/device.rs
@@ -6,13 +6,14 @@ use std::{thread, time};
use nitrokey::{
Authenticate, CommandError, Config, ConfigureOtp, Device, GenerateOtp, GetPasswordSafe,
- OtpMode, OtpSlotData,
+ OtpMode, OtpSlotData, Storage, VolumeMode,
};
use nitrokey_test::test as test_device;
-use crate::util::{ADMIN_PASSWORD, UPDATE_PIN, USER_PASSWORD};
+use crate::util::{ADMIN_PASSWORD, USER_PASSWORD};
static ADMIN_NEW_PASSWORD: &str = "1234567890";
+static UPDATE_PIN: &str = "12345678";
static UPDATE_NEW_PIN: &str = "87654321";
static USER_NEW_PASSWORD: &str = "abcdefghij";
@@ -45,9 +46,6 @@ fn connect_pro(device: Pro) {
assert!(nitrokey::connect().is_ok());
assert!(nitrokey::connect_model(nitrokey::Model::Pro).is_ok());
assert!(nitrokey::Pro::connect().is_ok());
-
- assert!(nitrokey::connect_model(nitrokey::Model::Storage).is_err());
- assert!(nitrokey::Storage::connect().is_err());
}
#[test_device]
@@ -58,9 +56,6 @@ fn connect_storage(device: Storage) {
assert!(nitrokey::connect().is_ok());
assert!(nitrokey::connect_model(nitrokey::Model::Storage).is_ok());
assert!(nitrokey::Storage::connect().is_ok());
-
- assert!(nitrokey::connect_model(nitrokey::Model::Pro).is_err());
- assert!(nitrokey::Pro::connect().is_err());
}
fn assert_empty_serial_number() {
@@ -404,9 +399,59 @@ fn lock(device: Storage) {
}
#[test_device]
+fn set_unencrypted_volume_mode(device: Storage) {
+ fn assert_mode(device: &Storage, mode: VolumeMode) {
+ let status = device.get_status();
+ assert!(status.is_ok());
+ assert_eq!(
+ status.unwrap().unencrypted_volume.read_only,
+ mode == VolumeMode::ReadOnly
+ );
+ }
+
+ fn assert_success(device: &Storage, mode: VolumeMode) {
+ assert_eq!(
+ Ok(()),
+ device.set_unencrypted_volume_mode(ADMIN_PASSWORD, mode)
+ );
+ assert_mode(&device, mode);
+ }
+
+ assert_success(&device, VolumeMode::ReadOnly);
+
+ assert_eq!(
+ Err(CommandError::WrongPassword),
+ device.set_unencrypted_volume_mode(USER_PASSWORD, VolumeMode::ReadOnly)
+ );
+ assert_mode(&device, VolumeMode::ReadOnly);
+
+ assert_success(&device, VolumeMode::ReadWrite);
+ assert_success(&device, VolumeMode::ReadWrite);
+ assert_success(&device, VolumeMode::ReadOnly);
+}
+
+#[test_device]
fn get_storage_status(device: Storage) {
let status = device.get_status().unwrap();
assert!(status.serial_number_sd_card > 0);
assert!(status.serial_number_smart_card > 0);
}
+
+#[test_device]
+fn export_firmware(device: Storage) {
+ assert_eq!(
+ Err(CommandError::WrongPassword),
+ device.export_firmware("someadminpn")
+ );
+ assert_eq!(Ok(()), device.export_firmware(ADMIN_PASSWORD));
+ assert_eq!(
+ Ok(()),
+ device.set_unencrypted_volume_mode(ADMIN_PASSWORD, VolumeMode::ReadWrite)
+ );
+ assert_eq!(Ok(()), device.export_firmware(ADMIN_PASSWORD));
+ assert_eq!(
+ Ok(()),
+ device.set_unencrypted_volume_mode(ADMIN_PASSWORD, VolumeMode::ReadOnly)
+ );
+}
diff --git a/nitrokey/tests/lib.rs b/nitrokey/tests/lib.rs
new file mode 100644
index 0000000..06de0ad
--- /dev/null
+++ b/nitrokey/tests/lib.rs
@@ -0,0 +1,8 @@
+#[test]
+fn get_library_version() {
+ let version = nitrokey::get_library_version();
+
+ assert!(!version.git.is_empty());
+ assert!(version.git.starts_with("v"));
+ assert!(version.major > 0);
+}
diff --git a/nitrokey/tests/otp.rs b/nitrokey/tests/otp.rs
index 2b46088..712f7a2 100644
--- a/nitrokey/tests/otp.rs
+++ b/nitrokey/tests/otp.rs
@@ -125,6 +125,11 @@ fn hotp_error(device: DeviceWrapper) {
Err(CommandError::InvalidSlot),
admin.write_hotp_slot(slot_data, 0)
);
+ let slot_data = OtpSlotData::new(1, "test", "foobar", OtpMode::SixDigits);
+ assert_eq!(
+ Err(CommandError::InvalidHexString),
+ admin.write_hotp_slot(slot_data, 0)
+ );
let code = admin.get_hotp_code(4);
assert_eq!(CommandError::InvalidSlot, code.unwrap_err());
}
@@ -256,17 +261,22 @@ fn totp_slot_name(device: DeviceWrapper) {
#[test_device]
fn totp_error(device: DeviceWrapper) {
let admin = make_admin_test_device(device);
- let slot_data = OtpSlotData::new(1, "", HOTP_SECRET, OtpMode::SixDigits);
+ let slot_data = OtpSlotData::new(1, "", TOTP_SECRET, OtpMode::SixDigits);
assert_eq!(
Err(CommandError::NoName),
- admin.write_hotp_slot(slot_data, 0)
+ admin.write_totp_slot(slot_data, 0)
);
- let slot_data = OtpSlotData::new(4, "test", HOTP_SECRET, OtpMode::SixDigits);
+ let slot_data = OtpSlotData::new(20, "test", TOTP_SECRET, OtpMode::SixDigits);
assert_eq!(
Err(CommandError::InvalidSlot),
- admin.write_hotp_slot(slot_data, 0)
+ admin.write_totp_slot(slot_data, 0)
);
- let code = admin.get_hotp_code(4);
+ let slot_data = OtpSlotData::new(4, "test", "foobar", OtpMode::SixDigits);
+ assert_eq!(
+ Err(CommandError::InvalidHexString),
+ admin.write_totp_slot(slot_data, 0)
+ );
+ let code = admin.get_totp_code(20);
assert_eq!(CommandError::InvalidSlot, code.unwrap_err());
}
diff --git a/nitrokey/tests/util/mod.rs b/nitrokey/tests/util/mod.rs
index 1e522fd..cbf6b93 100644
--- a/nitrokey/tests/util/mod.rs
+++ b/nitrokey/tests/util/mod.rs
@@ -1,3 +1,2 @@
pub static ADMIN_PASSWORD: &str = "12345678";
-pub static UPDATE_PIN: &str = "12345678";
pub static USER_PASSWORD: &str = "123456";