aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-27 22:40:07 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-28 20:21:41 +0100
commit5d7bb087707915a78149da7492cccd772db2657e (patch)
tree7055a28d98bb695175a5a64e49a6195dde994ee1 /tests
parent1d68e24db4078ad1a004afd7bec90a81e7d31ec8 (diff)
downloadnitrokey-rs-5d7bb087707915a78149da7492cccd772db2657e.tar.gz
nitrokey-rs-5d7bb087707915a78149da7492cccd772db2657e.tar.bz2
Accept UTF-8 errors in password safe tests
After a factory reset or after building the AES key, the password safe contains garbage data. This will most likely not be valid UTF-8. Therefore we change the tests to also accept an UTF-8 error in these cases.
Diffstat (limited to 'tests')
-rw-r--r--tests/device.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/tests/device.rs b/tests/device.rs
index d80f011..cd37869 100644
--- a/tests/device.rs
+++ b/tests/device.rs
@@ -264,6 +264,14 @@ fn unlock_user_pin(device: DeviceWrapper) {
assert_ok!((), device.change_user_pin(USER_NEW_PASSWORD, USER_PASSWORD));
}
+fn assert_utf8_err_or_ne(left: &str, right: Result<String, Error>) {
+ match right {
+ Ok(s) => assert_ne!(left.to_string(), s),
+ Err(Error::Utf8Error(_)) => {}
+ Err(err) => panic!("Expected Utf8Error, got {}!", err),
+ }
+}
+
#[test_device]
fn factory_reset(device: DeviceWrapper) {
let admin = device.authenticate_admin(ADMIN_PASSWORD).unwrap();
@@ -298,9 +306,9 @@ fn factory_reset(device: DeviceWrapper) {
let device = user.device();
let pws = device.get_password_safe(USER_PASSWORD).unwrap();
- assert_ne!("test".to_string(), pws.get_slot_name(0).unwrap());
- assert_ne!("testlogin".to_string(), pws.get_slot_login(0).unwrap());
- assert_ne!("testpw".to_string(), pws.get_slot_password(0).unwrap());
+ assert_utf8_err_or_ne("test", pws.get_slot_name(0));
+ assert_utf8_err_or_ne("testlogin", pws.get_slot_login(0));
+ assert_utf8_err_or_ne("testpw", pws.get_slot_password(0));
assert_ok!((), device.build_aes_key(ADMIN_PASSWORD));
}
@@ -320,9 +328,9 @@ fn build_aes_key(device: DeviceWrapper) {
let device = device.authenticate_admin(ADMIN_PASSWORD).unwrap().device();
let pws = device.get_password_safe(USER_PASSWORD).unwrap();
- assert_ne!("test".to_string(), pws.get_slot_name(0).unwrap());
- assert_ne!("testlogin".to_string(), pws.get_slot_login(0).unwrap());
- assert_ne!("testpw".to_string(), pws.get_slot_password(0).unwrap());
+ assert_utf8_err_or_ne("test", pws.get_slot_name(0));
+ assert_utf8_err_or_ne("testlogin", pws.get_slot_login(0));
+ assert_utf8_err_or_ne("testpw", pws.get_slot_password(0));
}
#[test_device]