aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-25 02:06:00 +0200
committerDaniel Mueller <deso@posteo.net>2021-01-10 21:05:59 -0800
commitf18fdc680c0bc616d64b116abaf2daede613f48b (patch)
tree7d17d0298c1017e71aa97401bc5408d823b1a85d /src/tests
parent3152a6d3c1e46243a69fe8ef8066027ca4d38d47 (diff)
downloadnitrocli-f18fdc680c0bc616d64b116abaf2daede613f48b.tar.gz
nitrocli-f18fdc680c0bc616d64b116abaf2daede613f48b.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.rs2
-rw-r--r--src/tests/mod.rs1
-rw-r--r--src/tests/run.rs44
-rw-r--r--src/tests/status.rs4
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]