diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-09-25 02:06:00 +0200 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-10-11 14:58:35 -0700 |
commit | 6fce98ec044241abd1d0f54dca307af6cd9f648f (patch) | |
tree | 1c184d6f5d04ab2e2729c7b33c9a2be089c41684 /src/tests | |
parent | dc99d8ffabcd51bc549981998c5d53b1fba789e9 (diff) | |
download | nitrocli-6fce98ec044241abd1d0f54dca307af6cd9f648f.tar.gz nitrocli-6fce98ec044241abd1d0f54dca307af6cd9f648f.tar.bz2 |
Update nitrokey to v0.8.0
This patch updates the nitrokey dependency to version 0.8.0 and applies
all breaking changes (Config fields renaming, DeviceWrapper and Model
non-exhaustiveness, changed Display implementation for Model).
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/list.rs | 2 | ||||
-rw-r--r-- | src/tests/mod.rs | 1 | ||||
-rw-r--r-- | src/tests/run.rs | 44 | ||||
-rw-r--r-- | src/tests/status.rs | 4 |
4 files changed, 31 insertions, 20 deletions
diff --git a/src/tests/list.rs b/src/tests/list.rs index cc969c6..e9f9506 100644 --- a/src/tests/list.rs +++ b/src/tests/list.rs @@ -17,7 +17,7 @@ fn not_connected() -> anyhow::Result<()> { fn connected(model: nitrokey::Model) -> anyhow::Result<()> { let re = regex::Regex::new( r#"^USB path\tmodel\tserial number -([[:^space:]]+\t(Pro|Storage|unknown)\t0x[[:xdigit:]]+ +([[:^space:]]+\t(Nitrokey Pro|Nitrokey Storage|unknown)\t0x[[:xdigit:]]+ )+$"#, ) .unwrap(); diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 1871f3c..23eecc5 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -78,6 +78,7 @@ impl Nitrocli { match model { nitrokey::Model::Pro => "--model=pro", nitrokey::Model::Storage => "--model=storage", + _ => panic!("Unexpected model in test suite: {}", model), } } diff --git a/src/tests/run.rs b/src/tests/run.rs index b39b1da..33191d3 100644 --- a/src/tests/run.rs +++ b/src/tests/run.rs @@ -4,10 +4,13 @@ // SPDX-License-Identifier: GPL-3.0-or-later use std::collections; +use std::convert; +use std::convert::TryInto as _; use std::ops; use std::path; use super::*; +use crate::args; #[test] fn no_command_or_option() { @@ -173,32 +176,33 @@ fn connect_wrong_usb_path(_model: nitrokey::Model) { fn connect_model(_model: nitrokey::Model) -> anyhow::Result<()> { let devices = nitrokey::list_devices()?; let mut model_counts = collections::BTreeMap::new(); - let _ = model_counts.insert(nitrokey::Model::Pro.to_string(), 0); - let _ = model_counts.insert(nitrokey::Model::Storage.to_string(), 0); - for model in devices.iter().filter_map(|d| d.model) { - *model_counts.entry(model.to_string()).or_default() += 1; + let _ = model_counts.insert(args::DeviceModel::Pro, 0); + let _ = model_counts.insert(args::DeviceModel::Storage, 0); + for nkmodel in devices.iter().filter_map(|d| d.model) { + let model = nkmodel.try_into().expect("Unexpected Nitrokey model"); + *model_counts.entry(model).or_default() += 1; } for (model, count) in model_counts { - let res = Nitrocli::new().handle(&["status", &format!("--model={}", model.to_lowercase())]); + let res = Nitrocli::new().handle(&["status", &format!("--model={}", model)]); if count == 0 { let err = res.unwrap_err().to_string(); assert_eq!( err, - format!( - "Nitrokey device not found (filter: model={})", - model.to_lowercase() - ) + format!("Nitrokey device not found (filter: model={})", model) ); } else if count == 1 { - assert!(res?.contains(&format!("model: {}\n", model))); + assert!(res?.contains(&format!( + "model: {}\n", + nitrokey::Model::from(model) + ))); } else { let err = res.unwrap_err().to_string(); assert_eq!( err, format!( "Multiple Nitrokey devices found (filter: model={}). ", - model.to_lowercase() + model ) + "Use the --model, --serial-number, and --usb-path options to select one" ); } @@ -211,11 +215,14 @@ fn connect_model(_model: nitrokey::Model) -> anyhow::Result<()> { fn connect_usb_path_model_serial(_model: nitrokey::Model) -> anyhow::Result<()> { let devices = nitrokey::list_devices()?; for device in devices { + let model = device.model.map(|nkmodel| { + convert::TryInto::<args::DeviceModel>::try_into(nkmodel).expect("Unexpected Nitrokey model") + }); let mut args = Vec::new(); args.push("status".to_owned()); args.push(format!("--usb-path={}", device.path)); - if let Some(model) = device.model { - args.push(format!("--model={}", model.to_string().to_lowercase())); + if let Some(model) = model { + args.push(format!("--model={}", model)); } if let Some(sn) = device.serial_number { args.push(format!("--serial-number={}", sn)); @@ -236,22 +243,25 @@ fn connect_usb_path_model_serial(_model: nitrokey::Model) -> anyhow::Result<()> fn connect_usb_path_model_wrong_serial(_model: nitrokey::Model) -> anyhow::Result<()> { let devices = nitrokey::list_devices()?; for device in devices { + let model = device.model.map(|nkmodel| { + convert::TryInto::<args::DeviceModel>::try_into(nkmodel).expect("Unexpected Nitrokey model") + }); let mut args = Vec::new(); args.push("status".to_owned()); args.push(format!("--usb-path={}", device.path)); - if let Some(model) = device.model { - args.push(format!("--model={}", model.to_string().to_lowercase())); + if let Some(model) = model { + args.push(format!("--model={}", model)); } args.push("--serial-number=0xdeadbeef".to_owned()); let res = Nitrocli::new().handle(&args.iter().map(ops::Deref::deref).collect::<Vec<_>>()); let err = res.unwrap_err().to_string(); - if let Some(model) = device.model { + if let Some(model) = model { assert_eq!( err, format!( "Nitrokey device not found (filter: model={}, serial number in [0xdeadbeef], usb path={})", - model.to_string().to_lowercase(), + model, device.path ) ); diff --git a/src/tests/status.rs b/src/tests/status.rs index ca16121..873bc69 100644 --- a/src/tests/status.rs +++ b/src/tests/status.rs @@ -25,7 +25,7 @@ fn not_found() { fn output_pro(model: nitrokey::Model) -> anyhow::Result<()> { let re = regex::Regex::new( r#"^Status: - model: Pro + model: Nitrokey Pro serial number: 0x[[:xdigit:]]{8} firmware version: v\d+\.\d+ user retry count: [0-3] @@ -43,7 +43,7 @@ $"#, fn output_storage(model: nitrokey::Model) -> anyhow::Result<()> { let re = regex::Regex::new( r#"^Status: - model: Storage + model: Nitrokey Storage serial number: 0x[[:xdigit:]]{8} firmware version: v\d+\.\d+ user retry count: [0-3] |